HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/cloudinit/sources/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceSmartOS.cpython-311.pyc
�

܍~c]����UddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZ
ddl
mZmZmZddlmZmZe
je��Zdddd	d
ddd
dddddd�
Zdddd�ZdZdZdZdegZgd�ZdZdZdZ ee eegd d!d"id#�Z!d!d$d d d%�id!d&d!d'�gd(�Z"d)Z#d*Z$Gd+�d,ej%��Z&Gd-�d.e'��Z(Gd/�d0e(��Z)Gd1�d2��Z*Gd3�d4e*��Z+Gd5�d6e*��Z,Gd7�d8e,��Z-deee dfd9�Z.d:�Z/	dJd<�Z0dKd=�Z1	dLd>�Z2e&ej3ffgZ4d?�Z5ed@kr�ddl6Z6e.��Z7e7�e8dA��e6j9dB��e:e6j;��dBkr@e<e�=����e<e�=����zdCgzZ=ne6j;dBd�Z=dD�Z>iZ?e@eAdE<e=D]ZBe>e7eBe?�F���e8ejCe?dBdGdH�I����dSdS)M�N)�dmi)�log)�sources�subp�util)�
EventScope�	EventType)zsdc:uuidT)�hostnameT)�root_authorized_keysT)�user-scriptF)�	user-dataF)zcloud-init:user-dataF)�iptables_disableT)�
motd_sys_infoT)�sdc:datacenter_nameT)zsdc:vendor-dataF)zsdc:operator-scriptF)zsdc:hostnameT)zsdc:dns_domainT)
�instance-id�local-hostnamezpublic-keysr�legacy-user-datar
rr�availability_zone�vendor-data�operator-scriptr
�
dns_domainzsdc:nicsz
sdc:resolversz
sdc:routes)�network-data�dns_servers�routeszlx-brand�kvm�SmartOS�
datasource)rrrrzsdc:uuiduser-datarz"/native/.zonecontrol/metadata.sockz
/dev/ttyS1�<F�
ephemeral0z/dev/vdb)�
serial_device�serial_timeout�metadata_sockfile�no_base64_decode�base64_keys�
base64_all�disk_aliases�mbr)�
table_type�layout�	overwrite�ext4)�label�
filesystem�device)�
disk_setup�fs_setupaU#cloud-boothook
#!/bin/sh
fname="%(per_boot_d)s/01_smartos_vendor_data.sh"
mkdir -p "${fname%%/*}"
cat > "$fname" <<"END_SCRIPT"
#!/bin/sh
##
# This file is written as part of the default vendor data for SmartOS.
# The SmartOS datasource writes the listed file from the listed metadata key
#   sdc:operator-script -> %(operator_script)s
#   user-script -> %(user_script)s
#
# You can view content with 'mdata-get <key>'
#
for script in "%(operator_script)s" "%(user_script)s"; do
    [ -x "$script" ] || continue
    echo "executing '$script'" 1>&2
    "$script"
done
END_SCRIPT
chmod +x "$fname"
z/var/dbc��eZdZdZejZejZej	e
je
je
j
hiZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd	�Zd
�Zed���ZdS)
�DataSourceSmartOS�Joyentc��tj�||||��tj|jtj|ti��tg��|_i|_	d|_
d|_tj
�|j�d����|_|���dS)N�scripts)r�
DataSource�__init__r�
mergemanydict�ds_cfg�get_cfg_by_path�DS_CFG_PATH�BUILTIN_DS_CONFIG�metadata�network_data�_network_config�os�path�join�paths�	get_cpath�
script_base_d�_init)�self�sys_cfg�distrorCs    �E/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceSmartOS.pyr7zDataSourceSmartOS.__init__�s�����#�#�D�'�6�5�A�A�A��(����$�W�k�2�>�>�!�
�
�
�����
� ���#����W�\�\�$�*�*>�*>�y�*I�*I�J�J����
�
������c�Z�tj�|��}|�d|j�d�S)Nz	 [client=�])rr6�__str__�	md_client)rG�roots  rJrNzDataSourceSmartOS.__str__�s-���!�)�)�$�/�/��#'�4�4�����8�8rKc��|jtjkr!t��|_|j�d|_|jtjkr@t|j|jd|jd|jd���|_dSdS)Nr"r r!)�smartos_typer"r r!)rRr�UNSET�get_smartos_environrO�jmc_client_factoryr9�rGs rJrFzDataSourceSmartOS._init�s������
�-�-� 3� 5� 5�D��� �(�!%����>�W�]�*�*�/�!�.�"&�+�.A�"B�"�k�/�:�#�{�+;�<�	���D�N�N�N�+�*rKc�(�t�d��d}tj�d�|dg����rAtjd�|dg��d�|dg����dSdS)a�Mark the instance provisioning state as successful.

        When run in a zone, the host OS will look for /var/svc/provisioning
        to be renamed as /var/svc/provision_success.   This should be done
        after meta-data is successfully retrieved and from this point
        the host considers the provision of the zone to be a success and
        keeps the zone running.
        z-Instance provisioning state set as successfulz/var/svc�/�provisioning�provision_successN)�LOG�debugr@rA�existsrB�rename)rG�svc_paths  rJ�_set_provisionedz"DataSourceSmartOS._set_provisioned�s���	�	�	�A�B�B�B���
�7�>�>�#�(�(�H�n�#=�>�>�?�?�	��I����(�N�3�4�4����(�$7�8�9�9�
�
�
�
�
�	�	rKc�2�|���i}d}|jst�d��dS|j���s"t�d|j��dS|j���t���D])\}}|\}}|j�	||���||<�*t���D]"\}}|j�|��||<�#|j���tj�|j���d|dd��}tj�|d	��}d
t$z}	t'|�	d	��||	dd�
��tj�|d��}
t'|�	d��|
dd���|�	d��}dt$z}t'||��|ds|dr|d|d<n|d|d<d}|dr|d}|dsGt(||
tj�|j�d��d��d�z|d<t+j||jg��|_||_|d|_|d|_|d|_|���dS)N�zNot running on smartosFz4No metadata device '%r' found for SmartOS datasource��strip�	instancesr�datarz%s/user-scriptTi�)�	content_f�link�shebang�moder)rgrirjrz%s/mdata-user-datarr
r
rr5zper-boot)�user_script�operator_script�
per_boot_drr)rFrRr[r\rOr]�open_transport�SMARTOS_ATTRIB_MAP�items�get�SMARTOS_ATTRIB_JSON�get_json�close_transportr@rArBrCrD�
LEGACY_USER_D�write_boot_content�BUILTIN_VENDOR_DATArr8r=�userdata_raw�vendordata_rawr>�routes_datar`)
rG�md�ud�ci_noun�	attribute�smartos_nounrd�data_drk�
u_script_lrl�u_data�u_data_fs
             rJ�	_get_datazDataSourceSmartOS._get_data�s2���
�
����
��
��� �	��I�I�.�/�/�/��5��~�$�$�&�&�	��I�I�F���
�
�
��5�	
��%�%�'�'�'�"4�":�":�"<�"<�	H�	H��G�Y�"+��L�%��.�,�,�\��,�G�G�B�w�K�K�%8�%>�%>�%@�%@�	@�	@�!�G�\��.�1�1�,�?�?�B�w�K�K���&�&�(�(�(������J� � �"�"�K��M�1B�F�
�
���g�l�l�6�=�9�9��%�
�5�
���F�F�=�!�!�!����	
�	
�	
�	
��'�,�,�v�/@�A�A����F�F�$�%�%�%���		
�	
�	
�	
����*�+�+��'�-�7���6�8�,�,�,��"�#�	9��*�~�
9�')�*�~��#�$�$�')�-�'8��#�$�
��
�k�?�	!��K��B��-� �	� 3�*�#2� �g�l�l��J�(�(��3�3�Z���7�7�!�B�}���*�B��
�+>�?�?��
���� ��/����~�.����h�<����������trKc��dtzS)Nzserial (%s))�
SERIAL_DEVICErVs rJ�_get_subplatformz"DataSourceSmartOS._get_subplatformNs
���}�,�,rKc�B�|jd�|��S)Nr&)r9rq)rG�names  rJ�device_name_to_devicez'DataSourceSmartOS.device_name_to_deviceQs���{�>�*�.�.�t�4�4�4rKc�4�|jtkrtSiS�N)rR�SMARTOS_ENV_KVM�BUILTIN_CLOUD_CONFIGrVs rJ�get_config_objz DataSourceSmartOS.get_config_objTs�����/�/�'�'��	rKc��|jdS)Nr)r=rVs rJ�get_instance_idz!DataSourceSmartOS.get_instance_idYs���}�]�+�+rKc���|jtjkrd|_|j�?|j�8t	|j|jd|jd|j���|_|jS)Nrr�r>rrr)r?rrSr>�convert_smartos_network_datar=rzrVs rJ�network_configz DataSourceSmartOS.network_config\sp����7�=�0�0�#'�D� ���'�� �,�'C�!%�!2� $�
�m� <�#�}�\�:��+�	(�(�(��$��#�#rKN)�__name__�
__module__�__qualname__�dsnamerrSrRrOr�NETWORKr	�BOOT_NEW_INSTANCE�BOOT�BOOT_LEGACY�default_update_eventsr7rNrFr`r�r�r�r�r��propertyr��rKrJr2r2�s�������
�F��=�L��
�I����'��N��!�
������$9�9�9�������$a�a�a�F-�-�-�5�5�5����
,�,�,��
$�
$��X�
$�
$�
$rKr2c��eZdZdS)�JoyentMetadataFetchExceptionN�r�r�r�r�rKrJr�r�m��������DrKr�c��eZdZdS)�JoyentMetadataTimeoutExceptionNr�r�rKrJr�r�qr�rKr�c��eZdZdZejd��Zdd�Zd�Zd�Z	d�Z
d�Zd	�Zdd
�Z
dd�Zdd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�JoyentMetadataClientz�
    A client implementing v2 of the Joyent Metadata Protocol Specification.

    The full specification can be found at
    http://eng.joyent.com/mdata/protocol.html
    z~V2 (?P<length>\d+) (?P<checksum>[0-9a-f]+) (?P<body>(?P<request_id>[0-9a-f]+) (?P<status>SUCCESS|NOTFOUND)( (?P<payload>.+))?)Nc�B�|�t��}||_||_dSr�)rTrR�fp)rGrRr�s   rJr7zJoyentMetadataClient.__init__�s&����.�0�0�L�(�������rKc�|�d�tj|�d����dz��S)N�{0:08x}zutf-8���)�format�binascii�crc32�encode)rG�bodys  rJ�	_checksumzJoyentMetadataClient._checksum�s8������N�4�;�;�w�/�/�0�0�:�=�
�
�	
rKc	��|j�|�����}t|d��t	|d��kr<td�|dt	|d�������|�|d��}|d|kr)td�||d�����|d|kr)td�||d�����|�dd��st�
d	��dStj|d��}t�
d
|��|S)N�lengthr�z*Incorrect frame length given ({0} != {1}).�checksumz*Invalid checksum (expected: {0}; got {1}).�
request_idz-Request ID mismatch (expected: {0}; got {1}).�payloadzNo value found.zValue "%s" found.)
�
line_regex�match�	groupdict�int�lenr�r�r�rqr[r\r�b64d)rG�expected_request_id�frame�
frame_data�expected_checksum�values      rJ�_get_value_from_framez*JoyentMetadataClient._get_value_from_frame�s}���_�*�*�5�1�1�;�;�=�=�
��z�(�#�$�$��J�v�,>�(?�(?�?�?�.�<�C�C��x�(�#�j��.@�*A�*A�����
�
!�N�N�:�f�+=�>�>���j�!�%6�6�6�.�<�C�C�%�z�*�'=�����
�
�l�#�':�:�:�.�?�F�F�'��L�)A�����
�
�~�~�i��.�.�	��I�I�'�(�(�(��4��	�*�Y�/�0�0���	�	�%�u�-�-�-��rKc�|��g��fd�}d}		|j�d��}t|��dkrt||��z���|dkr
|��S��|��nC#t
$r6}|jtjkrt||��z��|��d}~wwxYw��)z�
        Reads a line a byte at a time until 
 is encountered.  Returns an
        ascii string with the trailing newline removed.

        If a timeout (per-byte) is set and it expires, a
        JoyentMetadataFetchException will be thrown.
        c�T��d�����d��S)NrK�ascii)rB�decode)�responses�rJ�as_asciiz0JoyentMetadataClient._readline.<locals>.as_ascii�s#����8�8�H�%�%�,�,�W�5�5�5rKzPartial response: '%s'T�r�
N)r��readr�r��append�OSError�errno�EAGAIN)rGr��msg�byte�excr�s     @rJ�	_readlinezJoyentMetadataClient._readline�s������	6�	6�	6�	6�	6�'��
	�
��w�|�|�A�����t�9�9��>�>�8��x�x�z�z�9I�J�J�J��5�=�=�#�8�:�:�%�����%�%�%�%���
�
�
��9���,�,�8��h�h�j�j�(����������
����
	s�AA:�$A:�:
B:�1B5�5B:c��|j�|�d����|j���dS)Nr�)r��writer��flush)rGr�s  rJ�_writezJoyentMetadataClient._write�s5����
�
�c�j�j��)�)�*�*�*���
�
�����rKc�&�t�d��|�d��|���}t�d|��|dkrt	d|z���t�d��dS)NzNegotiating protocol V2z
NEGOTIATE V2
z	read "%s"�V2_OKz'Invalid response "%s" to "NEGOTIATE V2"zNegotiation complete)r[r\r�r�r�)rGr�s  rJ�
_negotiatezJoyentMetadataClient._negotiate�s����	�	�+�,�,�,����$�%�%�%��>�>�#�#���	�	�+�x�(�(�(��w���.�9�H�D���
�	�	�	�(�)�)�)�)�)rKc���d�tjdd����}d�||f��}|r>|dt	j|��������zz
}d�t|��|�	|��|��}t�d|��d}|js|�
��d}|�|��|���}|r|���t�d	|��d
|vrdS|�||��}|S)Nr�rr�� zV2 {0} {1} {2}
z#Writing "%s" to metadata transport.FTz"Read "%s" from metadata transport.�SUCCESS)r��random�randintrB�base64�	b64encoder�r�r�r�r[r\r�rnr�r�rtr�)	rG�rtype�paramr��message_bodyr��
need_closer�r�s	         rJ�requestzJoyentMetadataClient.request�s_���%�%�f�n�Q�
�&C�&C�D�D�
��x�x���
�
�
���	L��C�&�"2�5�<�<�>�>�"B�"B�"I�"I�"K�"K�K�K�L� �'�'�����t�~�~�l�;�;�\�
�
��	�	�	�7��=�=�=��
��w�	����!�!�!��J����C�����>�>�#�#���	#�� � �"�"�"��	�	�6��A�A�A��H�$�$��4��*�*�:�x�@�@���rKFc�l�|�d|���}|�|S|r|r|���}|S)N�GET�r�r�)r�rd)rG�key�defaultrd�results     rJrqzJoyentMetadataClient.get�sB�����E���5�5���>��N��	$�e�	$��\�\�^�^�F��
rKc�`�|�||���}|�|Stj|��S)N)r�)rq�json�loads)rGr�r�r�s    rJrszJoyentMetadataClient.get_json�s1�����#�w��/�/���>��N��z�&�!�!�!rKc�`�|�d���}|sgS|�d��S)N�KEYS)r��
)r��split)rGr�s  rJ�listzJoyentMetadataClient.lists4�����F��+�+���	��I��|�|�D�!�!�!rKc��d�d�||fD�������}|�d|���S)N� c�Z�g|](}tj|�������)Sr�)r�r�r�)�.0�is  rJ�
<listcomp>z,JoyentMetadataClient.put.<locals>.<listcomp>
s+��>�>�>�a�V�
�a�h�h�j�j�
)�
)�>�>�>rK�PUTr�)rBr�r�)rGr��valr�s    rJ�putzJoyentMetadataClient.putsN���	�	�>�>�C��:�>�>�>�
�
�
�&�(�(�	��|�|�%�u�|�5�5�5rKc�0�|�d|���S)N�DELETEr�)r�)rGr�s  rJ�deletezJoyentMetadataClient.deletes���|�|�(�#�|�6�6�6rKc�X�|jr"|j���d|_dSdSr�)r��closerVs rJrtz$JoyentMetadataClient.close_transports0���7�	��G�M�M�O�O�O��D�G�G�G�	�	rKc�@�|jr|S|���|Sr�)r�rnrVs rJ�	__enter__zJoyentMetadataClient.__enter__s(���7�	��K��������rKc�.�|���dSr�)rt)rG�exc_type�	exc_value�	tracebacks    rJ�__exit__zJoyentMetadataClient.__exit__s���������rKc��t�r�)�NotImplementedErrorrVs rJrnz#JoyentMetadataClient.open_transport#s��!�!rK�NNr��NF)r�r�r��__doc__�re�compiler�r7r�r�r�r�r�r�rqrsr�r�rrtrrrnr�rKrJr�r�us=�����������	 ���J�����
�
�
�
���8���:���	*�	*�	*�����B����"�"�"�"�"�"�"�6�6�6�7�7�7����
������"�"�"�"�"rKr�c�4��eZdZef�fd�	Zd�Zd�Zd�Z�xZS)�JoyentMetadataSocketClientc�f��tt|���|��||_dSr�)�superrr7�
socketpath)rGrrR�	__class__s   �rJr7z#JoyentMetadataSocketClient.__init__(s-���
�(�$�/�/�8�8��F�F�F�$����rKc���tjtjtj��}|�|j��|�d��|_|���dS)N�rwb)�socket�AF_UNIX�SOCK_STREAM�connectr�makefiler�r�)rG�socks  rJrnz)JoyentMetadataSocketClient.open_transport,sU���}�V�^�V�-?�@�@�����T�_�%�%�%��-�-��&�&����������rKc�J�tj�|j��Sr�)r@rAr]rrVs rJr]z!JoyentMetadataSocketClient.exists2s���w�~�~�d�o�.�.�.rKc�0�|jj�d|j�d�S)Nz(socketpath=�))rr�rrVs rJ�__repr__z#JoyentMetadataSocketClient.__repr__5s��&*�n�&=�&=�&=�t����O�OrK)	r�r�r��SMARTOS_ENV_LX_BRANDr7rnr]r$�
__classcell__�rs@rJrr'st�������0D�%�%�%�%�%�%����/�/�/�P�P�P�P�P�P�PrKrc�>��eZdZdedf�fd�	Zd�Zd�Zd�Zd�Z�xZ	S)�JoyentMetadataSerialClient�
Nc�v��tt|���||��||_||_dSr�)rr)r7r.�timeout)rGr.r,rRr�rs     �rJr7z#JoyentMetadataSerialClient.__init__:s8���	�(�$�/�/�8�8��r�J�J�J��������rKc�J�tj�|j��Sr�)r@rAr]r.rVs rJr]z!JoyentMetadataSerialClient.existsAs���w�~�~�d�k�*�*�*rKc�F�|j�qtj|j|j���}|���st
d|jz���||_tj|tj	��|�
��|���dS)N)r,zUnable to open %s)r��serial�Serialr.r,�isOpen�SystemError�fcntl�lockf�LOCK_EX�_flushr�)rG�sers  rJrnz)JoyentMetadataSerialClient.open_transportDs����7�?��-���T�\�B�B�B�C��:�:�<�<�
E�!�"5���"C�D�D�D��D�G��K��U�]�+�+�+����
�
�
��������rKc���t�d��|jj}d|j_		|���n#t
$rYnwxYw�'t�d��|dkr
d|j_n||j_	t�d��|�d��	|���}|dkrnh|d	krt�d
���mt�d|��n*#t
$rt�d��YnwxYw��t�d
��||j_dS)NzFlushing inputg�������?TzInput empty�z,Writing newline, expecting "invalid command"r�zinvalid command�FAILUREzGot "FAILURE".  Retrying.z%Unexpected response "%s" during flushzQTimeout while initializing metadata client. Is the host metadata service running?z'Got "invalid command".  Flush complete.)r[r\r�r,r�r�r��warning)rGr,r�s   rJr6z!JoyentMetadataSerialClient._flushNs����	�	�"�#�#�#��'�/������	�
���� � � � ��1�
�
�
���
����	�
	�	�	�-� � � ��Q�;�;��D�G�O�O�%�D�G�O�	��I�I�D�E�E�E��K�K�����
��>�>�+�+���0�0�0���y�(�(��I�I�9�:�:�:�����C�X�N�N�N�N��1�
�
�
����<������
����	� 	�	�	�;�<�<�<�!�����s/�A
�

A�A�D�  D�D�$E�Ec�@�|jj�d|j�d|j�d�S)Nz(device=z
, timeout=r#)rr�r.r,rVs rJr$z#JoyentMetadataSerialClient.__repr__us,���N�#�#�#��K�K�K��L�L�L�
�	
rK)
r�r�r�r�r7r]rnr6r$r&r's@rJr)r)9s�������� ��4�������+�+�+����%"�%"�%"�N
�
�
�
�
�
�
rKr)c�H��eZdZdZd
�fd�	Zdd�Zd�fd�	Zdd�Zdd	�Z�xZ	S)
� JoyentMetadataLegacySerialClienta�V1 of the protocol was not safe for all values.
    Thus, we allowed the user to pass values in as base64 encoded.
    Users may still reasonably expect to be able to send base64 data
    and have it transparently decoded.  So even though the V2 format is
    now used, and is safe (using base64 itself), we keep legacy support.

    The way for a user to do this was:
      a.) specify 'base64_keys' key whose value is a comma delimited
          list of keys that were base64 encoded.
      b.) base64_all: string interpreted as a boolean that indicates
          if all keys are base64 encoded.
      c.) set a key named b64-<keyname> with a boolean indicating that
          <keyname> is base64 encoded.r*Nc�|��tt|��}|�|||��d|_d|_dSr�)rr>r7r$r%)rGr.r,rR�srs     �rJr7z)JoyentMetadataLegacySerialClient.__init__�s<����2�D�9�9��	�
�
�6�7�L�1�1�1��������rKFc��|rd|_d|_d}|j�L|���}d|vr-tj|�d����|_nd|_|jrdS|j��|�|���}t
��}d|vr5t
|�d���d����}d�|D��D]X}tj|�|����r|�|���?||vr|�	|���Y||_dSdS)Nr%Fr$�,c�L�g|]!}|�d���|dd���"S)zb64-�N)�
startswith)r��ks  rJr�zFJoyentMetadataLegacySerialClient._init_base64_keys.<locals>.<listcomp>�s1��D�D�D�!�q�|�|�F�/C�/C�D��!�"�"��D�D�DrK)
r$r%r�r�is_true�_get�setr��add�remove)rG�reset�keys�b64_keysr�s     rJ�_init_base64_keysz2JoyentMetadataLegacySerialClient._init_base64_keys�sL���	#�#�D��"�D�O����?�"��9�9�;�;�D��t�#�#�"&�,�t�y�y��/F�/F�"G�"G����"'����?�	��F���#��|��y�y�{�{���u�u�H���$�$��t�y�y��7�7�=�=�c�B�B�C�C��E�D�t�D�D�D�
-�
-���<��	�	�#���/�/�-��L�L��%�%�%�%��h��� ����,�,�,��'�D����$�#rKc�Z��tt|���|||���S)N)r�rd)rr>rq)rGr�r�rdrs    �rJrHz%JoyentMetadataLegacySerialClient._get�s3����5�t�<�<�@�@����A�
�
�	
rKc�h�|tvrdS|�|���|jrdS||jvS)NF)rLT)�NO_BASE64_DECODErOr%r$)rGr�rLs   rJ�is_b64_encodedz/JoyentMetadataLegacySerialClient.is_b64_encoded�sG���"�"�"��5����U��+�+�+��?�	��4��d�&�&�&rKc��t��}|�|d|���}||ur|S|�|��rk	tj|��������}n1#tj$rt�
d||��YnwxYw|r|���}|S)NF)rdr�z#Failed base64 decoding key '%s': %s)�objectrHrSr��	b64decoder�r�r��Errorr[r;rd)rGr�r�rd�mdefaultr�s      rJrqz$JoyentMetadataLegacySerialClient.get�s����8�8���i�i��5�(�i�;�;���(�?�?��N����s�#�#�	M�
M��&�s�z�z�|�|�4�4�;�;�=�=�����>�
M�
M�
M����A�3��L�L�L�L�L�
M�����	��)�)�+�+�C��
s�8A<�<+B*�)B*)r*N)Fr)
r�r�r�rr7rOrHrSrqr&r's@rJr>r>}s��������*�*������� (� (� (� (�D
�
�
�
�
�
�
'�'�'�'��������rKr>c���|�t|��}|�dS|tkrt|||���S|tkrt	||���Std|z���)N)r.r,rR)rrRz"Unknown value for smartos_type: %s)rTr�r>r%r�
ValueError)rRr"r r!�
uname_versions     rJrUrU�s�����*�=�9�9�����t�	��	(�	(�/� �"�%�
�
�
�	
�

�-�	-�	-�)�(�|�
�
�
�	
��9�L�H�
I�
I�IrKc�"�ddd|g}d}	tj|��\}}t�d||��n;#tj$r)}t	jtd|z|f��Yd}~nd}~wwxYw|�dn|���S)N�filez--briefz--mime-typezscript %s mime type is %sz%Failed to identify script type for %s)rr[r\�ProcessExecutionErrorr�logexcrd)rg�cmd�f_type�_err�es     rJ�
identify_filerd�s����9�m�Y�
7�C�
�F�
���3�������	�	�-�y�&�A�A�A�A���%�
�
�
����9�I�E�q�I�	
�	
�	
�	
�	
�	
�	
�	
�����
�����>�4�4�v�|�|�~�~�5s�3>�A6�
A1�1A6�c��|s3tj�|��rtj|��|r3tj�|��rtj|��|sdStj|||���|rq|�d��s\t|��}|dkrGtj|d�	d|g��|���t�d|��|r�	tj�|��rtj|��|rgtj�|��rJtjtj�
|����tj||��dSdSdS#t$r&}tjtd|��Yd}~dSd}~wwxYwdS)	a
    Write the content to content_f. Under the following rules:
        1. If no content, remove the file
        2. Write the content
        3. If executable and no file magic, add it
        4. If there is a link, create it

    @param content: what to write
    @param content_f: the file name
    @param backup_d: the directory to save the backup at
    @param link: if defined, location to create a symlink to
    @param shebang: if no file magic, set shebang
    @param mode: file mode

    Becuase of the way that Cloud-init executes scripts (no shell),
    a script will fail to execute if does not have a magic bit (shebang) set
    for the file. If shebang=True, then the script will be checked for a magic
    bit and to the SmartOS default of assuming that bash.
    N)rjz#!z
text/plainr�z#!/bin/bashzadded shebang to file %sz$failed establishing content link: %s)r@rAr]�unlink�islinkr�
write_filerErdrBr[r\�
ensure_dir�dirname�symlink�IOErrorr_)�contentrgrhrirjrarcs       rJrvrv�s���.��r�w�~�~�i�0�0��
�	�)����������t�$�$��
�	�$���������O�I�w�T�2�2�2�2��=�w�)�)�$�/�/�=��y�)�)���\�!�!��O��4�9�9�m�W�%=�>�>�T�
�
�
�
�
�I�I�0�)�<�<�<��H�	H��w�~�~�d�#�#�
 ��	�$�����
,�2�7�>�>�)�4�4�
,�������� 5� 5�6�6�6��
�9�d�+�+�+�+�+�
,�
,�
,�
,���	H�	H�	H��K��C�Q�G�G�G�G�G�G�G�G�G�����	H����H�Hs�<BF�
G�&G�Gc���tj��}|�|d}|dkrtS|�tjd��}n|}|r|�d��rtSdS)NrDzBrandZ virtual linuxzsystem-product-name�SmartDC)r@�unamer%r�
read_dmi_datarEr�)r[�product_namerq�system_types    rJrTrT0sv���H�J�J�E����a��
��.�.�.�#�#����'�(=�>�>���"����{�-�-�i�8�8�����4rKc�����gd�gd�ddgd��|r t|ttf��s|g}ng}|r t|ttf��s|g}ng}|sg}d�}d�}|dd	�|dd	�d
��g}|D�]8}t�fd�|���D����}|�d|d
d���d|vr|�d|di��g}	|�dg��D�]�}
|
dkrddi}�n_g}t�fd�|���D����}|�d|
d���||
��rdnd�d|vr�|�dd��rt��dsf��fd�|�dg��D��}
t|
��r4|
d��d<|�d��di��|D]x}t�fd �|���D����}|�d|d!i��|�|��|�d"|i���y|	�|�����|�d#|	i��|�|����:|r|�d$||d%���d&|d'�S)(aReturn a dictionary of network_config by parsing provided
       SMARTOS sdc:nics configuration data

    sdc:nics data is a dictionary of properties of a nic and the ip
    configuration desired.  Additional nic dictionaries are appended
    to the list.

    Converting the format is straightforward though it does include
    duplicate information as well as data which appears to be relevant
    to the hostOS rather than the guest.

    For each entry in the nics list returned from query sdc:nics, we
    create a type: physical entry, and extract the interface properties:
    'mac' -> 'mac_address', 'mtu', 'interface' -> 'name'.  The remaining
    keys are related to ip configuration.  For each ip in the 'ips' list
    we create a subnet entry under 'subnets' pairing the ip to a one in
    the 'gateways' list.

    Each route in sdc:routes is mapped to a route on each interface.
    The sdc:routes properties 'dst' and 'gateway' map to 'network' and
    'gateway'.  The 'linklocal' sdc:routes property is ignored.
    )�mac_address�mtur��params�subnets�type)	�address�	broadcast�dns_nameservers�
dns_search�metric�pointopointr�scoperz�network�gateway)�physical�subnet�routec�
�d|vS)N�.r���addrs rJ�
is_valid_ipv4z3convert_smartos_network_data.<locals>.is_valid_ipv4�����d�{�rKc�
�d|vS)N�:r�r�s rJ�
is_valid_ipv6z3convert_smartos_network_data.<locals>.is_valid_ipv6�r�rKN)r��gw)�ipv4�ipv6c3�:�K�|]\}}|�dv�||fV��dS)r�Nr��r�rF�v�
valid_keyss   �rJ�	<genexpr>z/convert_smartos_network_data.<locals>.<genexpr>�sC�����
�
��q�!�a�:�j�3I�.I�.I�Q��F�.I�.I�.I�.I�
�
rKr��	interface)rzr��macrv�ips�dhcprz�dhcp4c3�:�K�|]\}}|�dv�||fV��dS)r�Nr�r�s   �rJr�z/convert_smartos_network_data.<locals>.<genexpr>�sC�������#�q�!�a�:�h�;O�6O�6O�Q��F�6O�6O�6O�6O��rK�static)rzr{r�r��primaryFr�c�B��g|]}��d|���|��S)r�r�)r�r��pgws�protos  ��rJr�z0convert_smartos_network_data.<locals>.<listcomp>�sB���$�$�$� "�3�t�E�{�7�3�B�7�7�$��$�$�$rK�gatewaysrc3�:�K�|]\}}|�dv�||fV��dS)r�Nr�r�s   �rJr�z/convert_smartos_network_data.<locals>.<genexpr>�sG����� � � �A�q��
�7� 3�3�3��A��3�3�3�3� � rK�dstrry�
nameserver)rzr{�searchr�)�version�config)	�
isinstancer��tuple�dictrp�updaterqr�r�)r>rrrr�r�r��nic�cfgry�ipr��	routeentsr�r��rcfgr�r�r�s                @@@rJr�r�Fs�����6
�
�
�

�

�

�
��
�)��J�4���+��e�}�5�5�	(�&�-�K�������*�t�U�m�4�4�	&�$��J���
�����������(�t�4�4�'�t�4�4���D�
�F��A�A���
�
�
�
�"�y�y�{�{�
�
�
�
�
��	�
�
�J��K�0@�A�A�B�B�B��C�<�<��J�J�
�s�5�z�2�3�3�3����'�'�%��$�$�6	#�6	#�B��V�|�|� �'�*����	������'*�y�y�{�{��������
�
� (�#%������#0�-��"3�"3�?�������#�#����	�5�(A�(A�#�
 ��;�t�,�J�$�$�$�$�$�&)�g�g�j�"�&=�&=�$�$�$��
�x�=�=�J�08���D��K��-�"�M�M�9�d�5�k�$�6G�*H�I�I�I�#�9�9�E�� � � � �$)�K�K�M�M� � � ���D�"�K�K��E�%�L� 9�:�:�:��$�$�T�*�*�*��M�M�8�Y�"7�8�8�8�8��N�N�6�"�"�"�"��
�
�I�w�'�(�(�(��
�
�c������
��
�
�$�&�$�
�
�	
�	
�	
��F�+�+�+rKc�6�tj|t��Sr�)r�list_from_depends�datasources)�dependss rJ�get_datasource_listr��s���$�W�k�:�:�:rK�__main__zDo not appear to be on smartos.r�r�c��||vr||S|tvr&t|}|�|��||<n�|dkrEdD]}t|||���t|d|d|d|d���||<n8|tvrt|\}}n|d}}|�||�	��||<||S)
Nr�)rrrrrrrrr�Frc)rrrs�load_keyr�rorq)�clientr�rf�keyname�depkeyrds      rJr�r��s����$�;�;���9���%�%�%�)�#�.�G�����0�0�D��I�I�
�$�
$�
$��
/�
/������.�.�.�.�4�!�.�1� ��/���-��H�~�	���D��I�I��(�(�(�!3�C�!8�����"%�u����
�
�7�%�
�8�8�D��I��C�y�rKrf)r�r�rfT)rBz: )�indent�	sort_keys�
separators)NFrer)NNNN)Dr�r�r�r3r�r@r�rrr/�	cloudinitrr�loggingrrr�cloudinit.eventrr	�	getLoggerr�r[rorrr%r��DS_NAMEr;rR�METADATA_SOCKFILEr��SERIAL_TIMEOUTr<r�rwrur6r2�	Exceptionr�r�r�rr)r>rUrdrvrTr��DEP_FILESYSTEMr�r��sys�jmc�print�exitr��argvr�rMr�rfr��__annotations__r��dumpsr�rKrJ�<module>r�s��.�
�
�
�
�����������������	�	�	�	�
�
�
�
�	�	�	�	�
�
�
�
�
�
�
�
�������$�$�$�$�$�$�)�)�)�)�)�)�)�)�)�)�1�1�1�1�1�1�1�1��g���!�!��&�(�1�)�,�0�2�,�6�-�5�&�*����&�"��	���"����
���W�%������9���
���"#�$�*�(���!�:�.����	����
�
���f��M�M�����8��8�
�C$�C$�C$�C$�C$��*�C$�C$�C$�L	�	�	�	�	�9�	�	�	�	�	�	�	�	�%A�	�	�	�o"�o"�o"�o"�o"�o"�o"�o"�dP�P�P�P�P�!5�P�P�P�$A
�A
�A
�A
�A
�!5�A
�A
�A
�HU�U�U�U�U�'A�U�U�U�r�'��!��J�J�J�J�6
6�
6�
6�8=�0H�0H�0H�0H�f����.BF�[,�[,�[,�[,�@��/�1�2���;�;�;��z����J�J�J�
�
�
�
�C�
�{�
��/�0�0�0��������
�s�3�8�}�}�����D�$�)�)�+�+�,�,��d�%�*�*�,�,�-�-�
.�� �
!�	
���x����|�����<�D�$�O�O�O��1�1������4�0�0�0�0�0�	�E�*�$�*�T�!�t��
L�
L�
L�M�M�M�M�M�e�rK