3 \�me#8 � @ s d Z ddlZddlZddlZddlZddlmZmZmZm Z ddl mZ eje �ZdZG dd� d�ZejejfZG dd � d ej�Zd d� Zdd � Zddd�Zdd� Zdd� Zdd� ZeejffgZdd� Ze dk�rddlZej dd�Z!e!j"� Z#e� Z$e%ej&e$�� dS )a, Datasource for IBMCloud. IBMCloud is also know as SoftLayer or BlueMix. IBMCloud hypervisor is xen (2018-03-10). There are 2 different api exposed launch methods. * template: This is the legacy method of launching instances. When booting from an image template, the system boots first into a "provisioning" mode. There, host <-> guest mechanisms are utilized to execute code in the guest and configure it. The configuration includes configuring the system network and possibly installing packages and other software stack. After the provisioning is finished, the system reboots. * os_code: Essentially "launch by OS Code" (Operating System Code). This is a more modern approach. There is no specific "provisioning" boot. Instead, cloud-init does all the customization. With or without user-data provided, an OpenStack ConfigDrive like disk is attached. Only disks with label 'config-2' and UUID '9796-932E' are considered. This is to avoid this datasource claiming ConfigDrive. This does mean that 1 in 8^16 (~4 billion) Xen ConfigDrive systems will be incorrectly identified as IBMCloud. The combination of these 2 launch methods and with or without user-data creates 6 boot scenarios. A. os_code with user-data B. os_code without user-data Cloud-init is fully operational in this mode. There is a block device attached with label 'config-2'. As it differs from OpenStack's config-2, we have to differentiate. We do so by requiring the UUID on the filesystem to be "9796-932E". This disk will have the following files. Specifically note, there is no versioned path to the meta-data, only 'latest': openstack/latest/meta_data.json openstack/latest/network_data.json openstack/latest/user_data [optional] openstack/latest/vendor_data.json vendor_data.json as of 2018-04 looks like this: {"cloud-init":"#!/bin/bash echo 'root:$6$<snip>' | chpasswd -e"} The only difference between A and B in this mode is the presence of user_data on the config disk. C. template, provisioning boot with user-data D. template, provisioning boot without user-data. With ds-identify cloud-init is fully disabled in this mode. Without ds-identify, cloud-init None datasource will be used. This is currently identified by the presence of /root/provisioningConfiguration.cfg . That file is placed into the system before it is booted. The difference between C and D is the presence of the METADATA disk as described in E below. There is no METADATA disk attached unless user-data is provided. E. template, post-provisioning boot with user-data. Cloud-init is fully operational in this mode. This is identified by a block device with filesystem label "METADATA". The looks similar to a version-1 OpenStack config drive. It will have the following files: openstack/latest/user_data openstack/latest/meta_data.json openstack/content/interfaces meta.js meta.js contains something similar to user_data. cloud-init ignores it. cloud-init ignores the 'interfaces' style file here. In this mode, cloud-init has networking code disabled. It relies on the provisioning boot to have configured networking. F. template, post-provisioning boot without user-data. With ds-identify, cloud-init will be fully disabled. Without ds-identify, cloud-init None datasource will be used. There is no information available to identify this scenario. The user will be able to SSH in as as root with their public keys that have been installed into /root/ssh/.authorized_keys during the provisioning stage. TODO: * is uuid (/sys/hypervisor/uuid) stable for life of an instance? it seems it is not the same as data's uuid in the os_code case but is in the template case. � N)� atomic_helper�sources�subp�util)� openstackz 9796-932Ec @ s e Zd ZdZdZdZdZdZdS )� PlatformszTemplate/Live/MetadatazUNABLE TO BE IDENTIFIED.zTemplate/Provisioning/Metadataz!Template/Provisioning/No-MetadatazOS-Code/LiveN)�__name__� __module__�__qualname__�TEMPLATE_LIVE_METADATAZTEMPLATE_LIVE_NODATA�TEMPLATE_PROVISIONING_METADATA�TEMPLATE_PROVISIONING_NODATA�OS_CODE� r r �(/usr/lib/python3.6/DataSourceIBMCloud.pyr l s r c sT e Zd ZdZdZ� fdd�Z� fdd�Zdd� Zd d � Zdd� Z e d d� �Z� ZS )�DataSourceIBMCloudZIBMCloudNc s0 t t| �j|||� d | _d | _d | _d | _d S )N)�superr �__init__�source�_network_config�network_json�platform)�self�sys_cfgZdistro�paths)� __class__r r r s zDataSourceIBMCloud.__init__c s$ t t| �j� }d|| j| jf }|S )Nz %s [%s %s])r r �__str__r r )r �rootZmstr)r r r r � s zDataSourceIBMCloud.__str__c C s� t � }|d krdS |d | _|d | _|d | _|jd�| _|jd�| _|jd�}|| _|d | _yt j |�| _W n4 tk r� } zt jd |� d | _W Y d d }~X nX d S )NFr r �metadata�userdata�networkdata� vendordatazsystem-uuidz"Invalid content in vendor-data: %sT)�read_mdr r r �getZuserdata_rawr Zvendordata_pure�system_uuidr Zconvert_vendordataZvendordata_raw� ValueError�LOG�warning)r �resultsZvd�er r r � _get_data� s"