404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.128.199.242: ~ $
3

\�me#8�@sdZddlZddlZddlZddlZddlmZmZmZm	Z	ddl
mZeje
�ZdZGdd�d�ZejejfZGdd	�d	ej�Zd
d�Zdd
�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 eZdZdZdZdZdZdZdS)�	PlatformszTemplate/Live/MetadatazUNABLE TO BE IDENTIFIED.zTemplate/Provisioning/Metadataz!Template/Provisioning/No-MetadatazOS-Code/LiveN)�__name__�
__module__�__qualname__�TEMPLATE_LIVE_METADATAZTEMPLATE_LIVE_NODATA�TEMPLATE_PROVISIONING_METADATA�TEMPLATE_PROVISIONING_NODATA�OS_CODE�rr�(/usr/lib/python3.6/DataSourceIBMCloud.pyrls
rcsTeZdZdZdZ�fdd�Z�fdd�Zdd�Zd	d
�Zdd�Z	e
d
d��Z�ZS)�DataSourceIBMCloudZIBMCloudNcs0tt|�j|||�d|_d|_d|_d|_dS)N)�superr�__init__�source�_network_config�network_json�platform)�self�sys_cfgZdistro�paths)�	__class__rrrs
zDataSourceIBMCloud.__init__cs$tt|�j�}d||j|jf}|S)Nz
%s [%s %s])rr�__str__rr)r�rootZmstr)rrrr�szDataSourceIBMCloud.__str__cCs�t�}|dkrdS|d|_|d|_|d|_|jd�|_|jd�|_|jd�}||_|d|_yt	j
|�|_Wn4tk
r�}zt
jd	|�d|_WYdd}~XnXd
S)NFrr�metadata�userdata�networkdata�
vendordatazsystem-uuidz"Invalid content in vendor-data: %sT)�read_mdrrr�getZuserdata_rawrZvendordata_pure�system_uuidrZconvert_vendordataZvendordata_raw�
ValueError�LOG�warning)r�resultsZvd�errr�	_get_data�s"




zDataSourceIBMCloud._get_datacCsd|j|jfS)z/Return the subplatform metadata source details.z%s (%s))rr)rrrr�_get_subplatform�sz#DataSourceIBMCloud._get_subplatformcCs|jdkrdS|jt�kS)aquickly (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.NF)r$�_read_system_uuid)rrrrr�check_instance_id�s
z$DataSourceIBMCloud.check_instance_idcCsX|jtjkrddd�S|jdkrR|jdk	rHtjd�tj|jdd�|_n
tjd�|jS)NZdisabled�)�config�versionz(network config provided via network_json)Z
known_macsz#no network configuration available.)	rrrrrr&�debugrZconvert_net_json)rrrr�network_config�s




z!DataSourceIBMCloud.network_config)
rr	r
Zdsnamer$rrr*r+r-�propertyr2�
__classcell__rr)rrrzs
rcCs&d}tjj|�sdStj|�j�j�S)Nz/sys/hypervisor/uuid)�os�path�isfiler�	load_file�strip�lower)Z	uuid_pathrrrr,�sr,cCstjjd�S)Nz	/proc/xen)r5r6�existsrrrr�_is_xen�sr<�#/root/provisioningConfiguration.cfg�/root/swinstall.log�/proc/1/environcCs�tjj|�r�d|}d}tjj|�rxtjj|�rbtj|�jtj|�jk}|d||rVdndf7}q�|d||f7}d}q�|d|7}ndd	|}}tjd
||�|S)z@Return boolean indicating if this boot is ibm provisioning boot.zconfig '%s' exists.Tz log '%s' from %s boot.ZcurrentZpreviousz. log '%s' existed, but no reference file '%s'.Fz log '%s' did not exist.zconfig '%s' did not exist.zibm_provisioning=%s: %s)r5r6r;�stat�st_mtimer&r1)Zprov_cfgZinst_logZboot_ref�msg�resultrrr�_is_ibm_provisioning�s"
rDcCsZd}d}d}t�s|Si}ytj�}Wn.tjk
rT}ztjd|�dSd}~XnXx�t|j��D]�}||}|j	dd�j
�}|j	dd�j
�}	|||fkr�qd||kr�tjd||||�qd||kr�|	tkr�tjd	|||	|�qd|||<qdW|j	|i�j	d
�}
|j	|i�j	d
�}|�r t
j|fS|
�rDt��r8t
j|
fSt
j|
fSnt��rVt
jdfS|S)
z�Return a tuple (Platform, path)

    If this is Not IBM cloud, then the return value is (None, None).
    An instance in provisioning mode is considered running on IBM cloud.ZMETADATAzCONFIG-2NzFailed to run blkid: %sZLABEL�ZUUIDz.Duplicate fslabel '%s'. existing=%s current=%sz/Skipping %s with LABEL=%s due to uuid != %s: %sZDEVNAME)NN)NN)r<rZblkidrZProcessExecutionErrorr&r'�sorted�keysr#�upper�IBM_CONFIG_UUIDr1rrrDrrr
)Zlabel_mdataZ
label_cfg2Z	not_foundZfslabelsZdevsr)Zdev�dataZlabel�uuidZ
metadata_pathZ	cfg2_pathrrr�get_ibm_platform�sX


rLcCs�t�\}}|dkr tjd�dS|tkr8tjd|�dS||t�d�}y&tjj|�r^t|�}nt	j
|t�}Wn8tjk
r�}zt
d|||f�|�WYdd}~XnX|j|�|S)aRead data from IBM Cloud.

    @return: None if not running on IBM Cloud.
             dictionary with guaranteed fields: metadata, version
             and optional fields: userdata, vendordata, networkdata.
             Also includes the system uuid from /sys/hypervisor/uuid.Nz!This is not an IBMCloud platform.z/Cloud-init is disabled during provisioning: %s.)rrzsystem-uuidz8Failed reading IBM config disk (platform=%s path=%s): %s)rLr&r1�PROVISIONINGr,r5r6�isdir�metadata_from_dirrZmount_cbr�BrokenMetadata�RuntimeError�update)rr6�retr(r)rrrr"&s*




r"c Cs�dd�}dd�}d|d�|fd|d�d	fd
|d�|fd|d
�|fg}i}x�|D]�\}}}tjj||�}d	}	ytj|dd�}	Wn0tk
r�}
ztjd||
�WYd	d	}
~
XnX|	d	ks�|d	kr�|	}nDy||	�}Wn6tk
�r}
zt	j
d||
f��WYd	d	}
~
XnX|||<qNW|jd�d	k�r2t	j
d|��i|d<|d}|d}
d|k�r�ytj
|d�|
d<Wn6ttfk
�r�}
zt	j
d|
��WYd	d	}
~
XnXd}x(|D] \}}||k�r�|||
|<�q�W|S) a�Walk source_dir extracting standardized metadata.

    Certain metadata keys are renamed to present a standardized set of metadata
    keys.

    This function has a lot in common with ConfigDriveReader.read_v2 but
    there are a number of inconsistencies, such key renames and as only
    presenting a 'latest' version which make it an unlikely candidate to share
    code.

    @return: Dict containing translated metadata, userdata, vendordata,
        networkdata as present.
    cSstjjdd|�S)NrZlatest)r5r6�join)Zfnamerrr�opathYsz metadata_from_dir.<locals>.opathcSstj|jd��S)Nzutf-8)�json�loads�decode)Zblobrrr�load_json_bytes\sz*metadata_from_dir.<locals>.load_json_bytesZmetadata_rawzmeta_data.jsonrZ	user_dataNr!zvendor_data.jsonr znetwork_data.jsonF)rXzFailed reading path '%s': %szFailed decoding %s: %sz)%s missing required file 'meta_data.json'rZrandom_seedz.Badly formatted metadata random_seed entry: %s�public_keys�public-keys�hostname�local-hostnamerK�instance-id�rZr[�r\r]�rKr^)r_r`ra)r5r6rTrr8�IOErrorr&r1�	ExceptionrrPr#�base64Z	b64decoder%�	TypeError)Z
source_dirrUrY�filesr(�namer6ZtranslZfpath�rawr)rJZmd_rawZmd�renamesZmdnameZnewnamerrrrOJsR  


rOcCstj|t�S)N)rZlist_from_depends�datasources)Zdependsrrr�get_datasource_list�srk�__main__zQuery IBM Cloud Metadata)�description)r=r>r?)'�__doc__rdrVZloggingr5Z	cloudinitrrrrZcloudinit.sources.helpersrZ	getLoggerrr&rIrrr
rMZ
DataSourcerr,r<rDrLr"rOZDEP_FILESYSTEMrjrk�argparse�ArgumentParser�parser�
parse_args�argsrJ�printZ
json_dumpsrrrr�<module>^s8
	E
<$Q


Filemanager

Name Type Size Permission Actions
DataSourceAkamai.cpython-36.opt-1.pyc File 8.18 KB 0644
DataSourceAkamai.cpython-36.pyc File 8.18 KB 0644
DataSourceAliYun.cpython-36.opt-1.pyc File 3.22 KB 0644
DataSourceAliYun.cpython-36.pyc File 3.22 KB 0644
DataSourceAltCloud.cpython-36.opt-1.pyc File 6.74 KB 0644
DataSourceAltCloud.cpython-36.pyc File 6.74 KB 0644
DataSourceAzure.cpython-36.opt-1.pyc File 47.95 KB 0644
DataSourceAzure.cpython-36.pyc File 47.95 KB 0644
DataSourceBigstep.cpython-36.opt-1.pyc File 1.84 KB 0644
DataSourceBigstep.cpython-36.pyc File 1.84 KB 0644
DataSourceCloudSigma.cpython-36.opt-1.pyc File 3.62 KB 0644
DataSourceCloudSigma.cpython-36.pyc File 3.62 KB 0644
DataSourceCloudStack.cpython-36.opt-1.pyc File 5.97 KB 0644
DataSourceCloudStack.cpython-36.pyc File 5.97 KB 0644
DataSourceConfigDrive.cpython-36.opt-1.pyc File 8.18 KB 0644
DataSourceConfigDrive.cpython-36.pyc File 8.18 KB 0644
DataSourceDigitalOcean.cpython-36.opt-1.pyc File 3.65 KB 0644
DataSourceDigitalOcean.cpython-36.pyc File 3.65 KB 0644
DataSourceEc2.cpython-36.opt-1.pyc File 23.49 KB 0644
DataSourceEc2.cpython-36.pyc File 23.49 KB 0644
DataSourceExoscale.cpython-36.opt-1.pyc File 5.92 KB 0644
DataSourceExoscale.cpython-36.pyc File 5.92 KB 0644
DataSourceGCE.cpython-36.opt-1.pyc File 9.83 KB 0644
DataSourceGCE.cpython-36.pyc File 9.93 KB 0644
DataSourceHetzner.cpython-36.opt-1.pyc File 3.78 KB 0644
DataSourceHetzner.cpython-36.pyc File 3.78 KB 0644
DataSourceIBMCloud.cpython-36.opt-1.pyc File 12.44 KB 0644
DataSourceIBMCloud.cpython-36.pyc File 12.44 KB 0644
DataSourceLXD.cpython-36.opt-1.pyc File 13.31 KB 0644
DataSourceLXD.cpython-36.pyc File 13.31 KB 0644
DataSourceMAAS.cpython-36.opt-1.pyc File 11.86 KB 0644
DataSourceMAAS.cpython-36.pyc File 11.86 KB 0644
DataSourceNWCS.cpython-36.opt-1.pyc File 3.77 KB 0644
DataSourceNWCS.cpython-36.pyc File 3.77 KB 0644
DataSourceNoCloud.cpython-36.opt-1.pyc File 7.97 KB 0644
DataSourceNoCloud.cpython-36.pyc File 7.97 KB 0644
DataSourceNone.cpython-36.opt-1.pyc File 1.47 KB 0644
DataSourceNone.cpython-36.pyc File 1.47 KB 0644
DataSourceOVF.cpython-36.opt-1.pyc File 9.15 KB 0644
DataSourceOVF.cpython-36.pyc File 9.15 KB 0644
DataSourceOpenNebula.cpython-36.opt-1.pyc File 11.75 KB 0644
DataSourceOpenNebula.cpython-36.pyc File 11.75 KB 0644
DataSourceOpenStack.cpython-36.opt-1.pyc File 7.91 KB 0644
DataSourceOpenStack.cpython-36.pyc File 7.91 KB 0644
DataSourceOracle.cpython-36.opt-1.pyc File 10.99 KB 0644
DataSourceOracle.cpython-36.pyc File 10.99 KB 0644
DataSourceRbxCloud.cpython-36.opt-1.pyc File 7.19 KB 0644
DataSourceRbxCloud.cpython-36.pyc File 7.19 KB 0644
DataSourceScaleway.cpython-36.opt-1.pyc File 10.84 KB 0644
DataSourceScaleway.cpython-36.pyc File 10.84 KB 0644
DataSourceSmartOS.cpython-36.opt-1.pyc File 24.51 KB 0644
DataSourceSmartOS.cpython-36.pyc File 24.51 KB 0644
DataSourceUpCloud.cpython-36.opt-1.pyc File 4.36 KB 0644
DataSourceUpCloud.cpython-36.pyc File 4.36 KB 0644
DataSourceVMware.cpython-36.opt-1.pyc File 23.66 KB 0644
DataSourceVMware.cpython-36.pyc File 23.66 KB 0644
DataSourceVultr.cpython-36.opt-1.pyc File 3.44 KB 0644
DataSourceVultr.cpython-36.pyc File 3.44 KB 0644
__init__.cpython-36.opt-1.pyc File 30.52 KB 0644
__init__.cpython-36.pyc File 30.52 KB 0644