%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/cloud/clouds/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyc

�
���^c@@s8dZddlmZmZmZddlmZddlmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlZddljZddlZddlZddlZddlZddlZddlZddlmZmZmZm Z e!Z"yTddl#j$j%j&Z'ddl(j$j)j&Z*ddl+m,Z,dd	l-m.Z.e/Z"Wne0k
r�nXd
Z1e
j2e3�Z4d�Z5e6e6d�Z7e6d
�Z8d�Z9d�Z:d�Z;e6e6d�Z<e6d�Z=e6d�Z>e6d�Z?e6d�Z@e6d�ZAe6d�ZBe6d�ZCe6e6d�ZDd�ZEd�ZFe6e6d�ZGd�ZHd�ZIe6e6d�ZJe6d �ZKd!�ZLe6d"�ZMe6e6d#�ZNe6e6d$�ZOe6e6d%�ZPe6e6d&�ZQe6e6d'�ZRe6e6d(�ZSe6d)�ZTe6d*�ZUdS(+u
Azure ARM Cloud Module
======================

.. versionadded:: 2016.11.0

.. versionchanged:: 2019.2.0

The Azure ARM cloud module is used to control access to Microsoft Azure Resource Manager

:depends:
    * `azure <https://pypi.python.org/pypi/azure>`_ >= 2.0.0rc6
    * `azure-common <https://pypi.python.org/pypi/azure-common>`_ >= 1.1.4
    * `azure-mgmt <https://pypi.python.org/pypi/azure-mgmt>`_ >= 0.30.0rc6
    * `azure-mgmt-compute <https://pypi.python.org/pypi/azure-mgmt-compute>`_ >= 0.33.0
    * `azure-mgmt-network <https://pypi.python.org/pypi/azure-mgmt-network>`_ >= 0.30.0rc6
    * `azure-mgmt-resource <https://pypi.python.org/pypi/azure-mgmt-resource>`_ >= 0.30.0
    * `azure-mgmt-storage <https://pypi.python.org/pypi/azure-mgmt-storage>`_ >= 0.30.0rc6
    * `azure-mgmt-web <https://pypi.python.org/pypi/azure-mgmt-web>`_ >= 0.30.0rc6
    * `azure-storage <https://pypi.python.org/pypi/azure-storage>`_ >= 0.32.0
    * `msrestazure <https://pypi.python.org/pypi/msrestazure>`_ >= 0.4.21
:configuration:
    Required provider parameters:

    if using username and password:
      * ``subscription_id``
      * ``username``
      * ``password``

    if using a service principal:
      * ``subscription_id``
      * ``tenant``
      * ``client_id``
      * ``secret``

    Optional provider parameters:

    **cloud_environment**: Used to point the cloud driver to different API endpoints, such as Azure GovCloud. Possible values:
      * ``AZURE_PUBLIC_CLOUD`` (default)
      * ``AZURE_CHINA_CLOUD``
      * ``AZURE_US_GOV_CLOUD``
      * ``AZURE_GERMAN_CLOUD``
      * HTTP base URL for a custom endpoint, such as Azure Stack. The ``/metadata/endpoints`` path will be added to the URL.

    **userdata** and **userdata_file**:
      Azure Resource Manager uses a separate VirtualMachineExtension object to pass userdata scripts to the virtual
      machine. Arbitrary shell commands can be passed via the ``userdata`` parameter, or via a file local to the Salt
      Cloud system using the ``userdata_file`` parameter. Note that the local file is not treated as a script by the
      extension, so "one-liners" probably work best. If greater functionality is desired, a web-hosted script file can
      be specified via ``userdata_file: https://raw.githubusercontent.com/account/repo/master/azure-script.py``, which
      will be executed on the system after VM creation. For Windows systems, script files ending in ``.ps1`` will be
      executed with ``powershell.exe``. The ``userdata`` parameter takes precedence over the ``userdata_file`` parameter
      when creating the custom script extension.

    **win_installer**:
      This parameter, which holds the local path to the Salt Minion installer package, is used to determine if the
      virtual machine type will be "Windows". Only set this parameter on profiles which install Windows operating systems.


Example ``/etc/salt/cloud.providers`` or
``/etc/salt/cloud.providers.d/azure.conf`` configuration:

.. code-block:: yaml

    my-azure-config with username and password:
      driver: azurearm
      subscription_id: 3287abc8-f98a-c678-3bde-326766fd3617
      username: larry
      password: 123pass

    Or my-azure-config with service principal:
      driver: azurearm
      subscription_id: 3287abc8-f98a-c678-3bde-326766fd3617
      tenant: ABCDEFAB-1234-ABCD-1234-ABCDEFABCDEF
      client_id: ABCDEFAB-1234-ABCD-1234-ABCDEFABCDEF
      secret: XXXXXXXXXXXXXXXXXXXXXXXX
      cloud_environment: AZURE_US_GOV_CLOUD

      The Service Principal can be created with the new Azure CLI (https://github.com/Azure/azure-cli) with:
      az ad sp create-for-rbac -n "http://<yourappname>" --role <role> --scopes <scope>
      For example, this creates a service principal with 'owner' role for the whole subscription:
      az ad sp create-for-rbac -n "http://mysaltapp" --role owner --scopes /subscriptions/3287abc8-f98a-c678-3bde-326766fd3617

      *Note: review the details of Service Principals. Owner role is more than you normally need, and you can restrict
      scope to a resource group or individual resources.
i(tabsolute_importtprint_functiontunicode_literals(t	cpu_count(t
ThreadPoolN(tsix(tSaltCloudConfigErrortSaltCloudSystemExittSaltCloudExecutionFailuretSaltCloudExecutionTimeout(tBlockBlobService(t
CloudErroruazurearmcC@s0t�tkrtSt�tkr,tdfStS(u)
    Check for Azure configurations.
    u�The following dependencies are required to use the AzureARM driver: Microsoft Azure SDK for Python >= 2.0rc6, Microsoft Azure Storage SDK for Python >= 0.32, MS REST Azure (msrestazure) >= 0.4(tget_configured_providertFalsetget_dependenciest__virtualname__(((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt__virtual__�scC@s�|d
kri}nd|kr0td��nd|krKtd��ng}yutdd�}|jjd|d�}xF|jD];}tj|j�|dkr�|j	�}|d}q�q�WWn't
k
r�}td	d|j�nX|S(u*
    Get a resource type api versions
    uresource_provideru%A resource_provider must be specifiedu
resource_typeu!A resource_type must be specifiedtclient_typeuresourcetresource_provider_namespaceuapi_versionsuazurearm.log_cloud_errorN(
tNoneRtget_connt	providerstgettresource_typesRt	text_typet
resource_typetas_dictRt	__utils__tmessage(tcalltkwargstapi_versionstresconntprovider_querytresourcet
resource_dicttexc((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytget_api_versions�s(	
cC@s�i}yYtdd�}|jjd|d|�}|j�}|dk	rX||}n|}Wn7tk
r�}tdd|j�i|jd6}nX|S(u(
    Get an AzureARM resource by id
    Ruresourcetresource_idtapi_versionuazurearm.log_cloud_erroruErrorN(Rt	resourcest	get_by_idRRRRR(R&R't
extract_valuetretR tresource_queryR#R$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytget_resource_by_id�s	

cC@sOdd�}|ttptd	�}|tkrK|ttp?td
�}n|S(u8
    Return the first configured provider instance.
    c	S@s6d|kr�|jd�\}}||dkr5tS||d|krMtSx6|D].}|d||j|d�dkrTtSqTW|d||Sx�tj|d�D]�\}}xutj|�D]d\}}||kr�q�nt}x0|D](}|j|d�dkr�t}Pq�q�W|r)q�n|SWq�WtS(u6
        Check if the provider is configured.
        u:u	providersN(tsplitR
RRRt	iteritemstTrue(	toptstprovidert
required_keystaliastdrivertkeytdriverstprovider_detailst
skip_provider((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt__is_provider_configured�s.
$ 
	usubscription_idutenantu	client_idusecretuusernameupassword((usubscription_idutenantu	client_idusecret(usubscription_iduusernameupassword(t__opts__t__active_provider_name__RR
(R:R2((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR�s"			cC@stjtitd6�S(u*
    Warn if dependencies aren't met.
    uazurearm(tconfigtcheck_driver_dependenciesRtHAS_LIBS(((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyRsc	C@sji}tjjjtjdt�tdt��|d<tjdt�tdt�}|dk	rn||d<ntjdt�tdt�}|dk	r�tjdt�tdt�}tjdt�tdt�}|j
i|d6|d6|d6�nWtjdt�tdt�}tjdt�tdt�}|j
i|d6|d6�td	d
||�}|S(u7
    Return a connection object for a client type.
    usubscription_idt
search_globalucloud_environmentutenantu	client_idusecretuusernameupassworduazurearm.get_clientRN(tsalttutilststringutilstto_strR=tget_cloud_config_valueRR;R
RtupdateR(	Rtconn_kwargst	cloud_envttenantt	client_idtsecrettusernametpasswordtclient((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyRs@

cC@s>|si}nt�}|j|�tjd|tdt�S(uB
    Return the location that is configured for this provider
    ulocationR@(RRFR=RER;R
(RRtvm_dict((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytget_locationLs		
c
C@s|dkrtd��ni}g|d<y�tdd�}|jjdd�}g}xB|jD]7}tj|j�dkrb|j�}|d}qbqbWx7|D]/}|j	�j
d	d
�}|dj|�q�WWn7tk
r}	t
dd|	j�i|	jd6}nX|S(
u1
    Return a dict of all available regions.
    uactionufThe avail_locations function must be called with -f or --function, or with the --list-locations optionu	locationsRuresourceRuMicrosoft.ComputeuvirtualMachinesu uuazurearm.log_cloud_erroruError(RRRRRRRRRtlowertreplacetappendRRR(
RR+R R!t	locationsR"R#tlocationt	lowercaseR$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytavail_locationsZs*
	
c
@s|dkrtd��ntdd��t��g}i}��fd�}yG�jjd��}x+|D]#}|j�}|j|d�qpWWn'tk
r�}tdd|j	�nXt
t�d	�}|j||�}	|	j
�d
�|	j�D�}|S(u?
    Return a dict of all available images on the provider
    uactionu`The avail_images function must be called with -f or --function, or with the --list-images optionRucomputec
@sgi}y#�jjd�d|�}x|D]�}|j�}�jjd�d|d|d�}x�|D]�}|j�}�jjd�d|d|dd|d�}xs|D]k}	|	j�}
dj||d|d|
df�}i|d6|dd6|dd	6|
dd
6||<q�WqiWq+WWn7tk
rb}tdd|j�i|j|6}nX|S(
u:
        Get all images from a specific publisher
        RUtpublisher_nametofferunametskusu|u	publisheruofferuskuuversionuazurearm.log_cloud_errorucompute(	tvirtual_machine_imagestlist_offersRt	list_skustlisttjoinRRR(
t	publishertdatatofferst	offer_objRYRZtsku_objtskutresultstversion_objtversiontnameR$(tcompconntregion(s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt_get_publisher_images�sD	





"RUunameuazurearm.log_cloud_erroricS@s5i|]+}tj|�D]\}}||�qqS((RR/(t.0tresulttktv((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pys
<dictcomp>�s	(RRRPR[tlist_publishersRRSRRRRRt	map_asynctwaitR(
Rt
publishersR+Rltpublishers_queryt
publisher_objR`R$tpoolRf((RjRks>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytavail_images{s*	-	

cC@s�|dkrtd��ntdd�}i}t�}yD|jjd|�}x(|D] }|j�}|||d<qXWWn7tk
r�}tdd|j�i|jd6}nX|S(	u<
    Return a list of sizes available from the provider
    uactionu^The avail_sizes function must be called with -f or --function, or with the --list-sizes optionRucomputeRUunameuazurearm.log_cloud_erroruError(	RRRPtvirtual_machine_sizesR^RRRR(RRjR+RUtsizestsize_objtsizeR$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytavail_sizes�s 		
cC@s||dkrtd��ni}t�}xK|D]C}i|d6||<x)d
D]!}||j|�|||<qOWq1W|S(u(
    List VMs on this Azure account
    uactionu=The list_nodes function must be called with -f or --function.unameuiduimageusizeustateuprivate_ipsu
public_ips(uiduimageusizeustateuprivate_ipsu
public_ips(Rtlist_nodes_fullR(RR+tnodestnodetprop((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt
list_nodes�s	

#c
@s|dkrtd��ntdidd6dd6�}|d�td	d
�}i}�fd�}x�t�D]�}g}|jjd|�}x1|D])}|j�}	||	d
<|j|	�q�Wtt	�d�}
|
j
||�}|j�d�|j�D�}|j
|�qpW|S(u@
    List all VMs on the subscription with full information
    uactionuBThe list_nodes_full function must be called with -f or --function.RuMicrosoft.Networkuresource_providerunetworkInterfacesu
resource_typeiRucomputec	@s�i}|d|d<|dd|d<|d|d<g|d<g|d	<|||d
<yA|dd}d
j|d|d|d|dg�|d<Wnzttfk
ry|dddd|d<Wqttfk
r|jdi�jdi�jd�|d<qXnXy�|dd}x�t|�D]y\}}t|d�d
�}t||d�\}}}|dd|j|�|dj|�|d	j|�q2WWnt	k
r�nX|||d
<|S(u 
        Get node info.
        uvm_iduiduhardware_profileuvm_sizeusizeuprovisioning_stateustateu
public_ipsuprivate_ipsunameustorage_profileuimage_referenceu|u	publisheruofferuskuuversionuimageuos_diskuuriunetwork_profileunetwork_interfacesuresource_group(
R_t	TypeErrortKeyErrorRt	enumerateR-t_get_network_interfaceRFtextendt	Exception(	R�tnode_rett	image_reft	netifacestindextnetifacet
netiface_nametpubipstprivips(tnetapi_version(s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt_get_node_infosH

3	
tresource_group_nameuresource_groupicS@s5i|]+}tj|�D]\}}||�qqS((RR/(RmRnRoRp((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pys
<dictcomp>Hs	(RR%Rtlist_resource_groupstvirtual_machinesR^RRSRRRrRsRRF(
Rtnetapi_versionsRjR+R�tgroupRtnodes_querytnode_objR�RwRft	group_ret((R�s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR~�s0	

.	


cC@s�|dkrtd��ntdd�}i}y>|jj�}x(|D] }|j�}|||d<qIWWn7tk
r�}tdd|j�i|jd6}nX|S(u?
    List resource groups associated with the subscription
    uactionuFThe list_hosted_services function must be called with -f or --functionRuresourceunameuazurearm.log_cloud_erroruError(RRtresource_groupsR^RRRR(RR R+tgroupst	group_objR�R$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR�Ns
cC@sq|dkrtd��nytd�|}Wn'tk
rXtjd|�i}nXtd|tt�|S(u?
    Show the details from AzureARM concerning an instance
    uactionu<The show_instance action must be called with -a or --action.ufunctionu Failed to get data for node '%s'ucloud.cache_node(RR~R�tlogtdebugRR<R;(RiRR�((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt
show_instancegs

cC@s|dkri}ntdd�}|jd�dkr[tjditdt�|d<ng}|jj|d|d�}|j}x!|j	D]}|j
|j�q�W|jj|d|d�}|j�x1|D])}|j
j|d|�}|j�q�Wi||6S(u%
    Delete a network interface.
    Runetworkuresource_groupR@u
iface_nameN(RRRR=RER;R0tnetwork_interfacesRitip_configurationsRStdeleteRstpublic_ip_addresses(RRtnetconntipstifacet
iface_nametip_tpoller((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytdelete_interfacezs*		
		


cC@sxtdd�}y+|jjd|d|�}|j�}Wn7tk
rs}tdd|j�i|jd6}nX|S(u4
    Get the public ip address details by name.
    RunetworkR�tpublic_ip_address_nameuazurearm.log_cloud_erroruerror(RR�RRRRR(Ritresource_groupR�tpubip_querytpubipR$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt_get_public_ip�s	c
C@s.g}g}tdidd6dd6�}|d}tdd�}|jjd	|d
|�}|j�}x�t|d�D]�\}	}
|
jd�dk	r�|j|
d�nd
|
jdi�krzt|
dd
|d�}t	||�}|j|d�|d|	dj
|�qzqzW|||fS(u"
    Get a network interface.
    RuMicrosoft.Networkuresource_providerupublicIPAddressesu
resource_typeiRunetworkR�tnetwork_interface_nameuip_configurationsuprivate_ip_addressuidupublic_ip_addressunameu
ip_addressN(R%RR�RRR�RRSR-R�RF(
RiR�t
public_ipstprivate_ipsR�R�R�tnetiface_queryR�R�t	ip_configtpublic_ip_namet	public_ip((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR��s.	

		 cC@s�|dkrtd��nttd�}ttd�}ttd�}ttd�}t|t�soi}n|}tdd�}|jd	�d0kr�t�|d	<n|jd�d0kr�t	j
d|td
t�|d<n|jd�d0krt	j
d|td
t�|d<n|jd�d0krNt	j
d
|td
t�|d<n|jd�d0kr}dj
|d�|d<ny1|jjd|dd|dd|d�}Wn@tk
r�}	tdj
|	j|d|d|d���nXi}
d0}d|kr�|d}t|t�r�g}
x�|j�D]�\}}x�|D]�}y>|jj|d
||�}|
ji|j�dd6�WqHtk
r�}	tjdtj|	��qHtk
r�}	tjdtj|	��qHXqHWq5W|
|
d<q�nd|j�kr.|d|
d<|j|
d<n
|j|
d<|jd�tkr�dj
|d�}|jjd|d
d|d|d|d	d |j��}d!}|j �xtr�yq|jj|d
|�}|j!r'|d"tj|j"��|
d#<|d$dj
|d�d%||
�g}PnWn#tk
rM}	tjd|	�nX|d&7}|d'krst#d(��nt$j%d)�q�Wn.dj
|d�}|d$|d%||
�g}d0}|jd*�d0k	r�|j&jd|d
d+|d*�}n|d|d	d,|d-|�}|j'j|d
|d|�}y|j �Wn#t(k
rh}	tj)d.|	�nXd!}xitr�yt*|d|d
�SWqrtk
r�|d&7}|d'kr�t#d/��nt$j%d)�qrXqrWd0S(1u%
    Create a network interface.
    uactionuGThe create_network_interface action must be called with -a or --action.uIPAllocationMethoduNetworkInterfaceuNetworkInterfaceIPConfigurationuPublicIPAddressRunetworkulocationR@usubnetunetwork_resource_groupuresource_groupu
iface_nameu
{0}-iface0unameR�tvirtual_network_nametsubnet_nameu7{0} (Resource Group: "{1}", VNET: "{2}", Subnet: "{3}")u#load_balancer_backend_address_poolsuiduThere was a cloud error: %su2There was an error getting the Backend Pool ID: %suprivate_ip_addressuprivate_ip_allocation_methoduallocate_public_ipu{0}-ipR�t
parametersRUtpublic_ip_allocation_methoditidupublic_ip_addressRitsubnetiixu(Timed out waiting for public IP Address.iusecurity_grouptnetwork_security_group_nametnetwork_security_groupR�ulNetwork interface creation could not be polled. It is likely that we are reusing an existing interface. (%s)u,Timed out waiting for operation to complete.N(+Rtgetattrtnetwork_modelst
isinstancetdictRRRRPR=RER;R
tformattsubnetsRRtitemst#load_balancer_backend_address_poolsRSRR�terrorRRR�tkeyststatictdynamicR0R�tcreate_or_updateRst
ip_addressR�t
ValueErrorttimetsleeptnetwork_security_groupsR�R�twarningR�(RRtIPAllocationMethodtNetworkInterfacetNetworkInterfaceIPConfigurationtPublicIPAddresstvm_R�t
subnet_objR$t	ip_kwargsR�t
pool_dictstpool_idstload_baltbe_poolsRwt
lbbep_datatpub_ip_nameR�tcounttpub_ip_datatpriv_ip_nameR�tiface_params((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytcreate_network_interface�s�					



		"%



				


				

cCC@s<tdd�}ttd�}ttd�}ttd�}ttd�}ttd�}ttd�}ttd	�}ttd
�}	ttd�}
ttd�}ttd
�}ttd�}
ttd�}ttd�}ttd�}ttd�}tjdt�tdt�}|jd�d%kr?d|d<n|jd�d%krdt
�|d<n|jd�d%kr�tjd|tdt�|d<n|jd�d%kr�tjd|tdt�|d<ntddd|�\}}}|d|d<dj
|d�}tjd |tdtd!tjd"|tdt��}d%}tjd#|tdtd!d%�}|d%k	r�y1tjjj|d$��}|j�}Wd%QXWq�tk
r�}td&j
||jd'���q�Xntjd(|tdtd!t�}i}tjd)|tdt�}|r�|d%k	r�|	d*|d+d,j
|��}|d-|g�} |d.|d/| �}!|!|d0<d%}"nEtjjjtjd1|tdtd!tjd2|tdt���}"|s�|"d%k	r�|r�t|"t�std3��nt|"�d4ks0t|"�d5kr?td6��nd7}#td8�|"D��rh|#d97}#ntd:�|"D��r�|#d97}#ntd;�|"D��r�|#d97}#ntd<�|"D��r�|#d97}#n|#d=kr�td>��n|"|d?<ntjd@|tdtd!d%�}$|$d%k	r[t|$tj�r[idAj
||d|$�d6}$nd%}$t�}%|%j j!}&t|jdB�tj�r�tjj"j#|dB�}'n|jdB�}'d%}(t|'t$�r�g}(ng}'d7})g}*x�|'D]�}+t|+tj�ri|+d6}+n|+j%d|+jd|+jddCj
|dtj&|)�����|+j%dD|+jdE|+jdFdG���|+j%dH|+jdIdJ��x7|)|*kr�|)d97})|)dKkr�t'j(dL�Pq�q�W|+j%dM|)�|)d97})dN|+kr||+dN�|+dO<|+dN=ni|+jdO�dPkrd|dQj
|dR|&|d|+dM��|+dO<n#dO|+kr�||+dO�|+dO<ndS|+kr�dT|+dU<n#dV|+kr�dV|+dU<n
dW|+dU<|(j)||+��q�Wd%},|dSj*dX�s|jdO�dPkr#	|dSj*dX�r.||dS�}-n�d%}-dY|dSkr�|dSj+dY�\}.}/}0}1|dZ|.d[|/d\|0d]|1�},n)|dSj*d^�r�|d_|dS�},n|r�d`}2nda}2|db|j,dc|j-dd|de|dfj
|dR|&|��dg|2dh|-di|jdj��}3n�d%}-d%}2|dc|j-di|jdj��}3dY|dSkr�	|dSj+dY�\}.}/}0}1|dZ|.d[|/d\|0d]|1�},n)|dSj*d^�r�	|d_|dS�},ntjdk|tdtd!d%�}4tjdl|tdtd!d%�}5tjdm|tdtd!d%�}6|4rz
t.j/j0|4�rz
tjjj|4d$��}7|7j�}5Wd%QXqz
n|5rX|6rXtjdn|tdtd!d%�}8|8r:tjj1j2tjdo|t��\|dp<|dq<|jd�}9dr|krdsj3|9|drg�}9ntjj1j4tdt|dq|9�ntjj1j5t||5�}5nd%}:|5d%k	sv|4d%k	r�y|r�du};dv}<dw}=|4r�|4j6dx�r�dy}>q�dz}>nd{};d|}<d}}=dz}>i}?|5r�|5|?d~<nB|4j*dX�r+|4g|?d<|>d�|4|4j7d��d9|?d~<ni
|dd6|dd�6|dd�d�6|dd6|;d�6|<d�6|=d�6td�6|?d�6d%d�6}:Wq�tk
r�}t'j8d�|�q�Xn|d�|dd�d%d�|d�t||dFj9���d�|d�|3d�|(d�|,�d�|
d�|d�|d|�d�|d�|
d_|d�g�d�|$�}@t:d�d�d�d�j
|d�d�t:d�d�|dd�d�dg�d�td�d�td��ye|j;j<d�|dd�|dd�|@�}A|Aj=�|Aj>�}B|Bj?�}B|:rt@d|:�nWn-tAk
r7}t:d�d|jB�i}BnX|BS(�u"
    Request a VM from Azure.
    RucomputeuCachingTypesuDataDiskuDiskCreateOptionTypesuHardwareProfileuImageReferenceuLinuxConfigurationuSshConfigurationuSshPublicKeyuNetworkInterfaceReferenceuNetworkProfileuOSDisku	OSProfileuStorageProfileuVirtualHardDiskuVirtualMachineuVirtualMachineSizeTypesusubscription_idR@udriveruazurearmulocationuresource_groupunameRuactionRuiduiface_idu{0}-vol0ussh_usernametdefaultuwin_usernameussh_publickeyfileurNu,Failed to read ssh publickey file '{0}': {1}i����udisable_password_authenticationu
win_installertkey_datatpathu/home/{0}/.ssh/authorized_keystpublic_keystdisable_password_authenticationtsshulinux_configurationussh_passworduwin_passwordu$The admin password must be a string.ii{u9The admin password must be between 8-123 characters long.ics@s|]}|j�VqdS(N(tisdigit(Rmtchar((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pys	<genexpr>4sics@s|]}|j�VqdS(N(tisupper(RmR�((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pys	<genexpr>6scs@s|]}|j�VqdS(N(tislower(RmR�((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pys	<genexpr>8scs@s|]}|tjkVqdS(N(tstringtpunctuation(RmR�((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pys	<genexpr>:siukThe admin password must contain at least 3 of the following types: upper, lower, digits, special charactersuadmin_passworduavailability_setuV/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/availabilitySets/{2}uvolumesu{0}-datadisk{1}udisk_size_gbulogical_disk_size_in_gbusizeiducachinguhost_cachinguReadOnlyiu"Maximum lun count has been reachedulunu
media_linkuvhdu	unmanagedu-https://{0}.blob.{1}/vhds/{2}-datadisk{3}.vhdustorage_accountuimageu
from_imageu
create_optionuattachuemptyuhttpu|R`RYReRhu/subscriptionsR�uWindowsuLinuxtcachingt
create_optionRitvhdu!https://{0}.blob.{1}/vhds/{2}.vhdtos_typetimagetdisk_size_gbuos_disk_size_gbu
userdata_fileuuserdatauuserdata_templateuuserdata_sendkeysukeysizeupriv_keyupub_keyu
append_domainu.upki_diruMicrosoft.ComputeuCustomScriptExtensionu1.8u.ps1u/powershell -ExecutionPolicy Unrestricted -File uuMicrosoft.Azure.ExtensionsuCustomScriptu2.0ucommandToExecuteufileUrisu./u/uvirtual_machine_nameu_custom_userdata_scriptuextension_nameu	publisheruvirtual_machine_extension_typeutype_handler_versionuauto_upgrade_minor_versionusettingsuprotected_settingsuFailed to encode userdata: %sRUtplanthardware_profiletvm_sizetstorage_profiletos_diskt
data_diskstimage_referencet
os_profiletadmin_usernamet
computer_nametnetwork_profileR�tavailability_setucloud.fire_eventueventurequesting instanceusalt/cloud/{0}/requestingtargsucloud.filter_eventu
requestinguprofileuprovidertsock_dirusock_dirt	transportu	transportR�tvm_nameR�uazurearm.log_cloud_error(CRR�tcompute_modelsR=RERR;R
RRRPR0R�R�RARBtfilestfopentreadR�RRRCRDR�tstrRtlentanyRtstring_typest_get_cloud_environmenttsuffixeststorage_endpointtyamlt	safe_loadR^t
setdefaultRR�R�RSt
startswithR.tnonet
from_imagetosR�texiststcloudtgen_keysR_t
accept_keytuserdata_templatetendswithtrfindt	exceptionRQRR�R�RsRnRtcreate_or_update_vmextensionRR(CR�RjtCachingTypestDataDisktDiskCreateOptionTypestHardwareProfiletImageReferencetLinuxConfigurationtSshConfigurationtSshPublicKeytNetworkInterfaceReferencetNetworkProfiletOSDiskt	OSProfiletStorageProfiletVirtualHardDisktVirtualMachinetVirtualMachineSizeTypestsubscription_idt
iface_dataR�R�t	disk_nametvm_usernametssh_publickeyfile_contentstssh_publickeyfiletspkc_R$R�t	os_kwargst
win_installertsshpublickeytsshconfigurationtlinuxconfigurationtvm_passwordt
complexityRRHtstorage_endpoint_suffixtvolumesR�tluntlunstvolumetimg_reftsource_imagetimg_pubtimg_offtimg_skutimg_verR�R�t
userdata_filetuserdataRtfh_tuserdata_sendkeystkey_idtcustom_extensionR`tvirtual_machine_extension_typettype_handler_versiontcommand_prefixtsettingstparamst	vm_createt	vm_result((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytrequest_instance�s�
			
	$




			
&






(						

&
			


	

cC@smy=|dr<tjttpd|dd|�tkr<tSWntk
rPnX|jd�d&krsd|d<ntdddd	j	|d
�dtdd
|d
dddg�dtddtd�td|d
|dd|d�|jd�st
d|�|d<ntjd|d
|d�t
d|�}|sOd|kr�dj	|d
tj|��}tj|�t|��nd�}y~tjjj|d|d
|dfdtjd|tdd3�d!tjd"|tdd�d#tjd$|tdd%��}WnFtttfk
rY}ztj|�Wd&ttj|���XnX||d'<|jd(�s�tjd(|t�|d(<ntjd)|t�|d*<td+|t�}t|d
d,d-�}tjd.|d
�tjd/|d
tj|��|j|�tddd0d1j	|d
�dtdd2|d
dddg�dtddtd�|S(4u.
    Create a single VM from a data dict.
    uprofileuazurearmR�ubootstrap_interfaceupublicucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingunameRucloud.filter_eventucreatinguproviderudriverRusock_dirRu	transportucloud.cachedir_index_addulocationRuCreating Cloud VM %s in %suerroruError creating VM {0}! ({1})cS@spt|dd�}|stSd}|dkr?|dd}n|dkr\|dd}n|dkrltS|S(	u"
        Query node data.
        Ruactionupublicu
public_ipsiuprivateuprivate_ipsN(R�R
R(Ritbootstrap_interfaceRaR�((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt_query_node_data�stupdate_argsttimeoutuwait_for_ip_timeoutR�i
i<tintervaluwait_for_ip_intervaltinterval_multiplieruwait_for_ip_interval_multiplieriNussh_hostussh_usernameussh_passwordupassworducloud.bootstrapRuactionuCreated Cloud VM '%s'u'%s' VM creation details:
%sucreated instanceusalt/cloud/{0}/createducreatediX(R=tis_profile_configuredR;R<R
tAttributeErrorRRRR�RPR�tinfoRXRRR�RRARBRtwait_for_ipRER	RR�R�R�tpprinttpformatRF(R�t
vm_requestterr_messageRZRaR$R+((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytcreateXs�	
	



	



c
C@sv|d.kri}n|dkr0td��ntdd�}t|dd�}|ddjd	�r�|ddd	d
}n|dddd}ii|6}tjd
�|jj|d|�}|j	�t
jdt�tkrt
d|tjd�dt
�ntjdt�t
dtdt�}|r�|jdtjdt�t
dtdt��}	|	r@tjd�|jd�}
|
d}|
d}i|d6|	d6|d6|d6||d<|jd �rtd!i|d6|d6dd�||d"<q@td!i|dd6|d6|d6dd�||d"<n|jd#tjd$t�t
dtdt��}
|
r�tjd%�i||d&<x|dd&D]}|jd	i�jd
�p�|jdi�jd�}|jd�}
|
d}|
d}i|d6|	d6|d6|d6||d&|d'<|jd �rntd!i|d6|d6dd�||d"<q�td!i|dd6|d6|d6dd�||d"<q�Wq�ntjd(t�t
dtdt�}|rri|d(6|dd6gd"6||d)<|d*d+}xb|D]W}|d
jd�d,}||d)d"jtd!i|d6|d'd-6dd��qWn|S(/u�
    Destroy a VM.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -d myminion
        salt-cloud -a destroy myminion service_name=myservice
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.RucomputeRuactionustorage_profileuos_diskumanaged_diskuiduvhduuriuDeleting VMuresource_groupuupdate_cachedirucloud.delete_minion_cachediru:iu
cleanup_disksR@R�u
delete_vhducleanup_vhdsuDeleting vhdu/i����i����udelete_disksu	containerublobudelete_diskuhttpRudataudelete_data_disksucleanup_data_disksuDeleting data_disksu
data_disksunameucleanup_interfacesucleanup_networkunetwork_profileunetwork_interfacesiu
iface_nameN(RRRR�RR�R�R�R�RsR;R
R0RR<R.R=RERRtdelete_blobtdelete_managed_diskRSR�(RiRRRjt	node_dataR�R+Rnt
cleanup_diskstcleanup_vhdstcompst	containertblobtcleanup_data_diskstdisktdatavhdtcleanup_interfacestifacesR�R�((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytdestroy�s�	



	




6


	
cC@s�|dkrtd��ntdd�}i}yB|jj�}td|�}x|D]}|||d<qYWWn7tk
r�}tdd|j�i|jd6}nX|S(	u8
    List storage accounts within the subscription.
    uactionuGThe list_storage_accounts function must be called with -f or --functionRustorageuazurearm.paged_object_to_listunameuazurearm.log_cloud_erroruError(RRtstorage_accountsR^RRR(RtstorconnR+taccounts_querytaccountstaccountR$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytlist_storage_accountsjs
cC@sytjdt�tdt�}y(tjd�}t||p?d�}Wn,tt	fk
rtt
dj|���nX|S(u+
    Get the cloud environment object.
    ucloud_environmentR@umsrestazure.azure_clouduAZURE_PUBLIC_CLOUDu1The azure {0} cloud environment is not available.(R=RERR;R
t	importlibt
import_moduleR�R`tImportErrorRR�(tcloud_environmenttcloud_env_moduleRH((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR�sc	C@sa|jd�p*tjdt�tdt�}|jd�pWtjdt�tdt�}|jd�p�tjdt�tdt�}|jd�p�tjdt�tdt�}|s�td��n|s�td��n|s3tdd	�}|jj	||�}d
�|j
D�}ttj
|��}nt�}|jj}t||d|d|�S(
u-
    Get the block blob storage service.
    uresource_groupR@u	sas_tokenustorage_accountustorage_keyu"A resource group must be specifiedu#A storage account must be specifiedRustoragecS@si|]}|j|j�qS((tvaluetkey_name(RmRp((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pys
<dictcomp>�s	t	sas_tokentendpoint_suffix(RR=RERR;R
RRRvt	list_keysR�tnextRt
itervaluesRRRR
(	RR�R�tstorage_accounttstorage_keyRwtstorage_keysRHR�((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt_get_block_blob_service�s8	cC@s�|dkri}nd|kr0td��nt|�}i}y_xX|j|d�jD]@}i|jjd6|jjj�d6|jj	d6||j
<q\WWn)tk
r�}tj
tj|��nX|S(u
    List blobs.
    u	containeruA container must be specifiedu	blob_typeu
last_modifieduserver_encryptedN(RRR�t
list_blobsR�t
propertiest	blob_typet
last_modifiedt	isoformattserver_encryptedRiR�R�R�RR(RRtstorageserviceR+RoR$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR��s 	
cC@ss|dkri}nd|kr0td��nd|krKtd��nt|�}|j|d|d�tS(u)
    Delete a blob from a container.
    u	containeruA container must be specifiedublobuA blob must be specifiedN(RRR�RhR0(RRR�((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyRh�s	cC@sntdd�}y|jj|d|d�Wn9tk
ri}tjd|jd�tj|��t	SXt
S(u6
    Delete a managed disk from a resource group.
    Rucomputeuresource_groupublobu#Error deleting managed disk %s - %s(RtdisksR�R�R�R�RRRR
R0(RRRjR$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyRi�s%c	C@s�|d
kri}n|dkr0td��ntdd�}t�}i}x�|D]�}y|jjd|�}Wntk
r�i}nXxU|D]M}|j�}|||d<tdi|d6|dd6�||dd	<q�WqUW|S(u 
    List virtual networks.
    uactionu=The avail_sizes function must be called with -f or --functionRunetworkR�unameRuresource_groupusubnetsN(	RRRR�tvirtual_networksR^RRtlist_subnets(	RRR�R�R+R�tnetworkstnetwork_objtnetwork((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytlist_virtual_networkss(		




/c
	C@s�|dkri}n|dkr0td��ntdd�}|jd�pitjdt�tdt�}|r�d|kr�d|kr�|d}n|s�td��n|jd�dkr�tjdt�tdt�|d<nd|ks|ddkrtd	��ni}|j	j
||d�}x�|D]�}|j�||j<i||jd
<xd|j
D]Y}|jjd�}|d}	|j�||jd
|	<|j||jd
|	d
<qlW|||jd<q8W|S(u,
    List subnets in a virtual network.
    uactionu=The avail_sizes function must be called with -f or --functionRunetworkuresource_groupR@ugroupu"A resource group must be specifieduA "network" must be specifieduip_configurationsu/i����usubnetN(RRRRR=RERR;R
R�R^RRiR�R�R.(
RRR�R�R+R�R�R�RmRi((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR�)s@	


 cC@sY|d%kri}nd|kr0td��nd|krKtd��ntdd�}ttd�}|jd�p�tjdt�t	d	t
�}|s�td
��n|jd�p�t�}|s�td��n|jd
d�}|jdd�}|jdd�}|jdt�}	|jdi�}
|jd�}t
|
t�s_td��n'd|
kr�d|
kr�td��ntjd|d�i}yr|d|d|d|d|d|	d |
d!|�}
|jj||d|d|
�}|j�}|j�}Wn@tk
rT}td"dd#j|j��i|jd$6}nX|S(&u�
    .. versionadded:: 2019.2.0

    Create or update a VM extension object "inside" of a VM object.

    required kwargs:
      .. code-block:: yaml

        extension_name: myvmextension
        virtual_machine_name: myvm
        settings: {"commandToExecute": "hostname"}

    optional kwargs:
      .. code-block:: yaml

        resource_group: < inferred from cloud configs >
        location: < inferred from cloud configs >
        publisher: < default: Microsoft.Azure.Extensions >
        virtual_machine_extension_type: < default: CustomScript >
        type_handler_version: < default: 2.0 >
        auto_upgrade_minor_version: < default: True >
        protected_settings: < default: None >
    uextension_nameu#An extension name must be specifieduvirtual_machine_nameu(A virtual machine name must be specifiedRucomputeuVirtualMachineExtensionuresource_groupR@u"A resource group must be specifiedulocationuA location must be specifiedu	publisheruMicrosoft.Azure.Extensionsuvirtual_machine_extension_typeuCustomScriptutype_handler_versionu2.0uauto_upgrade_minor_versionusettingsuprotected_settingsu#VM extension settings are not validucommandToExecuteuscriptuYVM extension settings are not valid. Either commandToExecute or script must be specified.uCreating VM extension %sRUR`RQRRtauto_upgrade_minor_versionRTtprotected_settingsuazurearm.log_cloud_erroru0Error attempting to create the VM extension: {0}uerrorN(RRRR�RRR=RERR;R
RPR0R�R�R�Ratvirtual_machine_extensionsR�RnRRRR�R(RRRjtVirtualMachineExtensionR�RUR`RQRRR�RTR�R+RUR�R$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR!]sn				c
C@s�|dkrtd��ntdd�}tjdt�tdt�}i}|s't�}x�|D]�}yB|jj	d|d|�}|j
�|j�}|j�}PWqdt
k
r�}	d	|	jkr�qdq�i|	jd
6}qdXqdW|s�tdddj|��idj|�d
6}q�n�yA|jj	d|d|�}|j
�|j�}|j�}WnCt
k
r�}	tddd
j||	j��i|	jd
6}nX|S(u�
    .. versionadded:: 2019.2.0

    Stop (deallocate) a VM

    CLI Examples:

    .. code-block:: bash

         salt-cloud -a stop myminion
    ufunctionu3The stop action must be called with -a or --action.Rucomputeuresource_groupR@RR�u
was not founduerroruazurearm.log_cloud_erroru-Unable to find virtual machine with name: {0}u!Error attempting to stop {0}: {1}(RRR=RERR;R
R�R�t
deallocateRsRnRRRRR�(
RiRRjR�R+R�R�tinstanceRWR$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pytstop�sJ	
	
	
 c
C@s�|dkrtd��ntdd�}tjdt�tdt�}i}|s't�}x�|D]�}yB|jj	d|d|�}|j
�|j�}|j�}PWqdt
k
r�}	d	|	jkr�qdq�i|	jd
6}qdXqdW|s�tdddj|��idj|�d
6}q�n�yA|jj	d|d|�}|j
�|j�}|j�}WnCt
k
r�}	tddd
j||	j��i|	jd
6}nX|S(u�
    .. versionadded:: 2019.2.0

    Start a VM

    CLI Examples:

    .. code-block:: bash

         salt-cloud -a start myminion
    ufunctionu4The start action must be called with -a or --action.Rucomputeuresource_groupR@RR�u
was not founduerroruazurearm.log_cloud_erroru-Unable to find virtual machine with name: {0}u"Error attempting to start {0}: {1}(RRR=RERR;R
R�R�tstartRsRnRRRRR�(
RiRRjR�R+R�R�R�RWR$((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyR�sJ	
	
	
 (Vt__doc__t
__future__RRRtmultiprocessingRtmultiprocessing.poolRR|tloggingRtos.pathRcR�R�tsalt.extRt
salt.cacheRAtsalt.configR=tsalt.loadertsalt.utils.cloudtsalt.utils.filestsalt.utils.stringutilstsalt.utils.yamltsalt.versiontsalt.exceptionsRRRR	R
R?tazure.mgmt.compute.modelstmgmttcomputetmodelsRtazure.mgmt.network.modelsR�R�t#azure.storage.blob.blockblobserviceR
tmsrestazure.azure_exceptionsRR0R~Rt	getLoggert__name__R�RRR%R-RRRRPRWRxR}R�R~R�R�R�R�R�R�RXRgRuR{RR�R�RhRiR�R�R!R�R�(((s>/usr/lib/python2.7/site-packages/salt/cloud/clouds/azurearm.pyt<module>Ws�"

	#	6	
	7!NU$		#�	��	s�	."4j=

Zerion Mini Shell 1.0