%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/sources/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceIBMCloud.cpython-312.pyc

�

�f!8����dZddlZddlZddlZddlZddlmZmZmZm	Z	ddl
mZeje
�ZdZGd�d�Zej"ej$fZGd�d	ej(�Zd
�Zd�Z			dd�Zd
�Zd�Zd�Zeej8ffgZd�Ze
dk(rGddlZej@d��Z!e!jE�Z#e�Z$e%ejLe$��yy)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� �eZdZdZdZdZdZdZy)�	PlatformszTemplate/Live/MetadatazUNABLE TO BE IDENTIFIED.zTemplate/Provisioning/Metadataz!Template/Provisioning/No-MetadatazOS-Code/LiveN)�__name__�
__module__�__qualname__�TEMPLATE_LIVE_METADATA�TEMPLATE_LIVE_NODATA�TEMPLATE_PROVISIONING_METADATA�TEMPLATE_PROVISIONING_NODATA�OS_CODE���F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceIBMCloud.pyr	r	ls��5��5��%E�"�#F� ��Grr	c�R��eZdZdZdZ�fd�Z�fd�Zd�Zd�Zd�Z	e
d��Z�xZS)	�DataSourceIBMCloud�IBMCloudNc�h��tt|�|||�d|_d|_d|_d|_y�N)�superr�__init__�source�_network_config�network_json�platform)�self�sys_cfg�distro�paths�	__class__s    �rrzDataSourceIBMCloud.__init__s5���
� �$�0��&�%�H����#��� �����
rc�j��tt|��}|�d|j�d|j�d�}|S)Nz [� �])rr�__str__rr)r �root�mstrr$s   �rr(zDataSourceIBMCloud.__str__�s,����'��6�8��#�T�]�]�D�K�K�@���rc��t�}|�y|d|_|d|_|d|_|j	d�|_|j	d�|_|j	d�}||_|d|_	tj|�|_y
#t$r'}tjd	|�d|_Yd}~y
d}~wwxYw)NFrr�metadata�userdata�networkdata�
vendordata�system-uuidz"Invalid content in vendor-data: %sT)�read_mdrrr,�get�userdata_rawr�vendordata_pure�system_uuidr�convert_vendordata�vendordata_raw�
ValueError�LOG�warning)r �results�vd�es    r�	_get_datazDataSourceIBMCloud._get_data�s����)���?���h�'����
�+��
��
�+��
�#�K�K�
�3���#�K�K�
�6���
�[�[��
&��!���"�=�1���	'�")�"<�"<�R�"@�D��
��	�	'��K�K�<�a�@�"&�D�����		'�s�;B�	C�C�Cc�:�|j�d|j�d�S)z/Return the subplatform metadata source details.z (�))rr�r s r�_get_subplatformz#DataSourceIBMCloud._get_subplatform�s�� �M�M�4�;�;�7�7rc�J�|j�y|jt�k(S)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.F)r5�_read_system_uuid)r r!s  r�check_instance_idz$DataSourceIBMCloud.check_instance_id�s(�����#�����#4�#6�6�6rc�F�|jtjk7rddd�S|j�h|j�Gt
j
d�tj|jd��|_|jSt
j
d�|jS)N�disabled�)�config�versionz(network config provided via network_json)�
known_macsz#no network configuration available.)	rr	rrrr9�debugr�convert_net_jsonrAs r�network_configz!DataSourceIBMCloud.network_config�s����=�=�I�-�-�-�)�Q�7�7����'�� � �,��	�	�D�E�'0�'A�'A��%�%�$�(��$�
�#�#�#��	�	�?�@��#�#�#r)
r
rr�dsnamer5rr(r>rBrE�propertyrN�
__classcell__)r$s@rrrzs:���
�F��K���
�*8�7��
$��
$rrc��d}tjj|�sytj|�j�j
�S)Nz/sys/hypervisor/uuid)�os�path�isfiler�load_text_file�strip�lower)�	uuid_paths rrDrD�s=��&�I�
�7�7�>�>�)�$�����y�)�/�/�1�7�7�9�9rc�@�tjjd�S)Nz	/proc/xen)rSrT�existsrrr�_is_xenr\�s��
�7�7�>�>�+�&�&rc���tjj|�r�d|z}d}tjj|�r~tjj|�rPtj|�jtj|�jkD}|d|�d|rdnd�d�z
}n|d|�d|�d	�z
}d
}n|d|zz
}nd
d|z}}t
j
d
||�|S)z@Return boolean indicating if this boot is ibm provisioning boot.zconfig '%s' exists.Tz log 'z' from �current�previousz boot.z"' existed, but no reference file 'z'.Fz log '%s' did not exist.zconfig '%s' did not exist.zibm_provisioning=%s: %s)rSrTr[�stat�st_mtimer9rL)�prov_cfg�inst_log�boot_ref�msg�results     r�_is_ibm_provisioningrg�s���
�w�w�~�~�h��#�h�.����
�7�7�>�>�(�#��w�w�~�~�h�'��G�G�H�%�.�.�����1B�1K�1K�K����!'�I�Z�7����
���������-��8�8�C��:�X�E����I�I�'���5��Mrc�v�d}d}d}t�s|Si}	tj�}t|j��D]�}||}|jdd�j�}|jdd�j�}	|||fvr�O||vrt
j
d	||||��o||k(r#|	tk7rt
jd
|||	|���|||<��|j|i�jd�}
|j|i�jd�}|rtj|fS|
r.t�rtj |
fStj"|
fSt�rtj$dfS|S#tj$r }t
j
d|�Yd}~yd}~wwxYw)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.�METADATAzCONFIG-2)NNzFailed to run blkid: %sN�LABEL��UUIDz.Duplicate fslabel '%s'. existing=%s current=%sz/Skipping %s with LABEL=%s due to uuid != %s: %s�DEVNAME)r\r�blkidr�ProcessExecutionErrorr9r:�sorted�keysr2�upper�IBM_CONFIG_UUIDrLr	rrgrr
r)�label_mdata�
label_cfg2�	not_found�fslabels�devsr=�dev�data�label�uuid�
metadata_path�	cfg2_paths            r�get_ibm_platformr�s���
�K��J��I��9����H���z�z�|��
�d�i�i�k�"����C�y������"�%�+�+�-���x�x���#�)�)�+����j�1�1���H���K�K�@������	
�
��J��4�?�#:��I�I�A�����
�
�����/�2�L�L��b�1�5�5�i�@�M����Z��,�0�0��;�I���!�!�9�-�-�	��!��<�<�m�L�L��4�4�m�D�D�	�	��6�6��=�=����S�%�%�����-�q�1����s�F�F8�F3�3F8c	��t�\}}|�tjd�y|tvrtjd|�y||t	�d�}	t
jj|�rt|�}ntj|t�}|j|�|S#tj$r}td|�d|�d|���|�d}~wwxYw)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.)rrr0z)Failed reading IBM config disk (platform=z path=z): )rr9rL�PROVISIONINGrDrSrT�isdir�metadata_from_dirr�mount_cbr�BrokenMetadata�RuntimeError�update)rrT�retr;r=s     rr1r1&s���&�'�N�H�d����	�	�5�6��	�\�	!��	�	�C�X�N����(�*��C�	�
�7�7�=�=���'��-�G��m�m�D�*;�<�G��J�J�w���J���!�!�����q�
"�
��	���s�AB,�,C�?C�Cc��d�}d�}d|d�|fd|d�dfd|d	�|fd
|d�|fg}i}|D]S\}}}tjj||�}d}		tj|�}	|	�|�|	}n		||	�}|||<�U|jd��tjd|z��i|d<|d}|d}
d|vr	tj|d�|
d<d}|D]\}}||vs�|||
|<�|S#t
$r!}
tjd||
�Yd}
~
��d}
~
wwxYw#t$r }
tjd
|�d|
����d}
~
wwxYw#ttf$r}
tjd|
z��d}
~
wwxYw)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.
    c�D�tjjdd|�S)Nr�latest)rSrT�join)�fnames r�opathz metadata_from_dir.<locals>.opathYs���w�w�|�|�K��5�9�9rc�J�tj|jd��S)Nzutf-8)�json�loads�decode)�blobs r�load_json_bytesz*metadata_from_dir.<locals>.load_json_bytes\s���z�z�$�+�+�g�.�/�/r�metadata_rawzmeta_data.jsonr-�	user_dataNr/zvendor_data.jsonr.znetwork_data.jsonzFailed reading path '%s': %szFailed decoding z: z)%s missing required file 'meta_data.json'r,�random_seedz.Badly formatted metadata random_seed entry: %s))�public_keyszpublic-keys)�hostnamezlocal-hostname)r|zinstance-id)rSrTr�r�load_binary_file�IOErrorr9rL�	Exceptionrr�r2�base64�	b64decoder8�	TypeError)�
source_dirr�r��filesr;�namerT�transl�fpath�rawr=rz�md_raw�md�renames�mdname�newnames                 rr�r�Js���:�0�

��/�0�/�B�	�U�;�'��.�	�u�/�0�/�B�	��1�2�O�D�
�E��G� %����t�V������Z��.����	@��'�'��.�C��;�&�.��D�
��c�{�����
�%�(�{�{�>�"�*��$�$�7�*�D�
�	
��G�J��
�^�
$�F�	��	�B����	� &� 0� 0��
�1F� G�B�}���G�
#�)�����V�� ��.�B�w�K�)��N��S�	@��I�I�4�e�Q�?�?��	@���
��,�,�04�a�8����
��&�I�&�	��(�(�@�1�D��
��	�sH�C>�<D+�E�>	D(�D#�#D(�+	E�4E�E�F�&E>�>Fc�6�tj|t�Sr)r�list_from_depends�datasources)�dependss r�get_datasource_listr��s���$�$�W�k�:�:r�__main__zQuery IBM Cloud Metadata)�description)z#/root/provisioningConfiguration.cfgz/root/swinstall.logz/proc/1/environ)'�__doc__r�r��loggingrS�	cloudinitrrrr�cloudinit.sources.helpersr�	getLoggerr
r9rsr	rrr��
DataSourcerrDr\rgrr1r��DEP_FILESYSTEMr�r��argparse�ArgumentParser�parser�
parse_args�argsrz�print�
json_dumpsrrr�<module>r�s��\�z���	�8�8�/��g����!�������,�,�
�*�*���B$��+�+�B$�J:�'�
3�
"�
��@9�x!�HL�b�'�0�0�2�3���;��z���
$�X�
$�
$�1K�
L�F�����D��9�D�	�
"�-�
"�
"�4�
(�)�
r

Zerion Mini Shell 1.0