ó oBú]c@sqdZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ej e ƒZ dZdefd „ƒYZejejfZd ejfd „ƒYZd „Zd „Zdddd„Zd„Zd„Zd„ZeejffgZd„Ze dkrmddlZej ddƒZ!e!j"ƒZ#eƒZ$e j%e$ƒGHndS(s,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$' | 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. iÿÿÿÿN(tlog(tsources(t openstack(tutils 9796-932Et PlatformscBs&eZdZdZdZdZdZRS(sTemplate/Live/MetadatasUNABLE TO BE IDENTIFIED.sTemplate/Provisioning/Metadatas!Template/Provisioning/No-Metadatas OS-Code/Live(t__name__t __module__tTEMPLATE_LIVE_METADATAtTEMPLATE_LIVE_NODATAtTEMPLATE_PROVISIONING_METADATAtTEMPLATE_PROVISIONING_NODATAtOS_CODE(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyRms tDataSourceIBMCloudcBsPeZdZdZd„Zd„Zd„Zd„Zd„Z e d„ƒZ RS(tIBMCloudcCsDtt|ƒj|||ƒd|_d|_d|_d|_dS(N(tsuperR t__init__tNonetsourcet_network_configt network_jsontplatform(tselftsys_cfgtdistrotpaths((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyRs    cCs2tt|ƒjƒ}d||j|jf}|S(Ns %s [%s %s](RR t__str__RR(Rtroottmstr((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyR†scCsÒtƒ}|dkrtS|d|_|d|_|d|_|jdƒ|_|jdƒ|_|jdƒ}||_ |d|_ yt j |ƒ|_ Wn,tk rÍ}tjd|ƒd|_ nXtS( NRRtmetadatatuserdatat networkdatat vendordatas system-uuids"Invalid content in vendor-data: %s(tread_mdRtFalseRRRtgett userdata_rawRtvendordata_puret system_uuidRtconvert_vendordatatvendordata_rawt ValueErrortLOGtwarningtTrue(Rtresultstvdte((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyt _get_data‹s"        cCsd|j|jfS(s/Return the subplatform metadata source details.s%s (%s)(RR(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyt_get_subplatform scCs#|jdkrtS|jtƒkS(squickly (local check only) if self.instance_id is still valid in Template mode, the system uuid (/sys/hypervisor/uuid) is the same as found in the METADATA disk. But that is not true in OS_CODE mode. So we read the system_uuid and keep that for later compare.N(R%RR!t_read_system_uuid(RR((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pytcheck_instance_id¤scCs„|jtjkr$idd6dd6S|jdkr}|jdk rmtjdƒtj |jddƒ|_q}tjdƒn|jS(Ntdisabledtconfigitversions(network config provided via network_jsont known_macss#no network configuration available.( RRR RRRR)tdebugRtconvert_net_json(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pytnetwork_config®s N( RRtdsnameRR%RRR/R0R2tpropertyR9(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyR zs     cCs5d}tjj|ƒsdStj|ƒjƒjƒS(Ns/sys/hypervisor/uuid(tostpathtisfileRRt load_filetstriptlower(t uuid_path((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyR1¾scCstjjdƒS(Ns /proc/xen(R<R=texists(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyt_is_xenÅss#/root/provisioningConfiguration.cfgs/root/swinstall.logs/proc/1/environcCsãtjj|ƒr»d|}t}tjj|ƒrªtjj|ƒrtj|ƒjtj|ƒjk}|d||rdndf7}q¸|d||f7}t}qÌ|d|7}ntd|}}tjd||ƒ|S( s@Return boolean indicating if this boot is ibm provisioning boot.sconfig '%s' exists.s log '%s' from %s boot.tcurrenttpreviouss. log '%s' existed, but no reference file '%s'.s log '%s' did not exist.sconfig '%s' did not exist.sibm_provisioning=%s: %s( R<R=RCR+tstattst_mtimeR!R)R7(tprov_cfgtinst_logtboot_reftmsgtresult((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceIBMCloud.pyt_is_ibm_provisioningÉs   c CsÊd}d}d }tƒs|Si}ytjƒ}Wn'tjk r^}tjd|ƒd SXxÙt|jƒƒD]Å}||}|j ddƒj ƒ}|j ddƒj ƒ} |||fkrÊqrn||krötjd||||ƒqrn||kr-| t kr-tj d||| |ƒqrn|||^s:     D    3 ! L