%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/lib/python2.7/site-packages/salt/cloud/clouds/
Upload File :
Create Path :
Current File : //proc/self/root/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyc

�
���^c@@s&dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
ZddlZddljZddlmZmZmZmZmZmZddlmZddlmZyddlZeZWnek
re ZnXej!e"�Z#dZ$dd	fZ%d
�Z&d�Z'd�Z(e)d
�Z*e)d�Z+e)d�Z,e)d�Z-e)ed�Z.e)d�Z/d�Z0d�Z1d�Z2d�Z3d�Z4de)e)e)dd�Z5d�Z6e)d�Z7d�Z8e)d�Z9e)e)d�Z:e)e)d �Z;e)e)d!�Z<e)e)d"�Z=d#�Z>e)d$�Z?d%�Z@d&�ZAe)e)d'�ZBe)d(�ZCe)e)d)�ZDe)e)d*�ZEe)e)d+�ZFe)e)d,�ZGe)e)d-�ZHe e d.�ZIe)d/�ZJe)d0�ZKe)d1�ZLe d2�ZMd3�ZNdS(4ud
DigitalOcean Cloud Module
=========================

The DigitalOcean cloud module is used to control access to the DigitalOcean VPS system.

Use of this module requires a requires a ``personal_access_token``, an ``ssh_key_file``,
and at least one SSH key name in ``ssh_key_names``. More ``ssh_key_names`` can be added
by separating each key with a comma. The ``personal_access_token`` can be found in the
DigitalOcean web interface in the "Apps & API" section. The SSH key name can be found
under the "SSH Keys" section.

.. code-block:: yaml

    # Note: This example is for /etc/salt/cloud.providers or any file in the
    # /etc/salt/cloud.providers.d/ directory.

    my-digital-ocean-config:
      personal_access_token: xxx
      ssh_key_file: /path/to/ssh/key/file
      ssh_key_names: my-key-name,my-key-name-2
      driver: digitalocean

:depends: requests
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltCloudConfigErrortSaltInvocationErrortSaltCloudNotFoundtSaltCloudSystemExittSaltCloudExecutionFailuretSaltCloudExecutionTimeout(tsix(tzipudigitaloceanu
digital_oceanudocC@s*t�tkrtSt�tkr&tStS(u/
    Check for DigitalOcean configurations
    (tget_configured_providertFalsetget_dependenciest__virtualname__(((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyt__virtual__Ds
c
C@s(tjdtdtptdtdd�S(u/
    Return the first configured instance.
    toptstprovidertaliasest
required_keysupersonal_access_token(upersonal_access_token(tconfigtis_provider_configuredt__opts__t__active_provider_name__Rt__virtual_aliases__(((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyRQs
	cC@stjtitd6�S(u*
    Warn if dependencies aren't met.
    urequests(Rtcheck_driver_dependenciesRtHAS_REQUESTS(((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR
]scC@s�|dkrtd��ntdd�}i}xY|dD]M}i||d<x6tj|�D]%}tj||�||d|<q_Wq;W|S(ub
    Return a dict of all available VM locations on the cloud provider with
    relevant data
    uactionufThe avail_locations function must be called with -f or --function, or with the --list-locations optiontmethoduregionsuname(RtqueryR	titerkeyst	text_type(tcalltitemstrettregiontitem((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytavail_locationsgs'cC@s�|dkrtd��nt}d}i}x�|r�tddddtj|�d�}xP|dD]D}i||d	<x-tj|�D]}||||d	|<q�WqgW|d7}yd
|ddk}Wq0tk
r�t}q0Xq0W|S(
u>
    Return a list of the images that are on the provider
    uactionu`The avail_images function must be called with -f or --function, or with the --list-images optioniRuimagestcommandu?page=u
&per_page=200unameunextulinksupages(RtTrueRR	RRtKeyErrorR(RtfetchtpageR!R timageR#((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytavail_images|s$	&

cC@s�|dkrtd��ntdddd�}i}xY|dD]M}i||d<x6tj|�D]%}tj||�||d|<qeWqAW|S(uC
    Return a list of the image sizes that are on the provider
    uactionu^The avail_sizes function must be called with -f or --function, or with the --list-sizes optionRusizesR%u
?per_page=100uslug(RRR	RR(RR R!tsizeR#((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytavail_sizes�s'cC@s"|dkrtd��nt�S(u;
    Return a list of the VMs that are on the provider
    uactionu=The list_nodes function must be called with -f or --function.(Rt_list_nodes(R((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyt
list_nodes�scC@s.|dkrtd��ntdtd|�S(u;
    Return a list of the VMs that are on the provider
    uactionuBThe list_nodes_full function must be called with -f or --function.tfullt
for_output(RR.R&(RR1((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytlist_nodes_full�scC@s#tjjjtd�td|�S(uO
    Return a list of the VMs that are on the provider, with select fields
    ufunctionuquery.selection(tsalttutilstcloudtlist_nodes_selectR2R(R((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR6�scC@s�t�}tjd|tdt�}t|tj�sHtj|�}nxm|D]e}|||d||d||dfkrO||ddk	r�||dSt
||d�SqOWtdj|���dS(u(
    Return the image object to use
    uimaget
search_globalunameusluguidu/The specified image, '{0}', could not be found.N(
R+Rtget_cloud_config_valueRRt
isinstanceR	tstring_typesRtNonetintRtformat(tvm_timagestvm_imageR*((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyt	get_image�s	
cC@s}t�}tjtjd|tdt��}x4|D],}|j�||dkr4||dSq4Wtdj	|���dS(u6
    Return the VM's size. Used by create_node().
    usizeR7uslugu.The specified size, '{0}', could not be found.N(
R-R	RRR8RRtlowerRR=(R>tsizestvm_sizeR,((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytget_size�s	
cC@s�t�}tjtjd|tdt��}x<|D]4}|||d||dfkr4||dSq4Wtdj|���dS(u"
    Return the VM's location
    ulocationR7unameuslugu2The specified location, '{0}', could not be found.N(	R$R	RRR8RRRR=(R>t	locationstvm_locationtlocation((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytget_location�s	
cC@stddd|dd�}|S(u
    Create a node
    Rudropletstargsthttp_methodupost(R(RJtnode((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytcreate_node	sc@s	y=|dr<tjttpd|dd|�tkr<tSWntk
rPnXtddddj|d�d	td
d|dddd
g�dtddtd�tj	d|d�i|dd6t
|�d6t|�d6t|�d6gd6gd6}tj
d|tdt�}|r=|djt|��ntj
d|tdtdt�}|r�x1|jd�D]}|djt|��qtWntj
d|tdtdd3�}|d3k	r�tjj|�r�tdj|���ntjdt�r|d3krtd ��ntj
d!|tdtdd"�}|dckrhtj	d$|�||d!<ntd%��tj
d&|tdtdd3�}|d3k	r�t|t�s�td'��n||d&<n|r�|d#kr�td(��ntj
d)|tdtdd3�}|d3k	rFt|t�s9td*��n||d+<ntj
d,|tdtdd3�}	|	d3k	r�t|	t�s�td-��n|	|d,<ntj
d.|tdtdd3�}
|
d3k	r�t|
t�s�td/��n|
|d.<ntj
d|tdtdt�|d<tj
d0|tdtdd3�}|d3k	r�yYtjjj|d1��;}tjjjt|tjjj |j!���|d2<Wd3QXWq�t"k
r�}
tj#d4||
�q�Xntj
d5|tdtdd3�}|r"tj	d6�d3}|djd7�}t$|�d8krbtj%d9�d7j&|d: �}d7j&|d:�}ntj%d;|d�|d<}tj
d=|tdtd|��tj
d>|tdtd|���r�rtj	d?�����fd@�}tj%dA|�q"tj'dB�tdC��ntdddDdEj|d�d	td
dF|t(|��dtddtd�yt)|�}Wn4t"k
r�}
tj'dG|d|
dHt*j+�tSXdI�}y\tjjj,|dJ|dfdKtj
dL|tddd�dOtj
dP|tddM��}Wn\t-t.fk
r}}
z*yt/|d�Wnt0k
r_nXWd3t0t1j2|
���XnX|jdQ�s�d3|dQ<ndedf}}t3t(t4||���}x�g|D]2}|dV|D]}|dW||dXf^q�q�D]z\}}}tj	dY|||�||}|d"krV|rV|||�qVn||kr|dQs|||dQ<q|qqW|dQd3kr�t0dZjt5|dV����ntj%d[|dQ�||d\<td]|t�}|j6|�tj	d^|d�tj%d_|dt7j8|��tddd`daj|d�d	td
db|dddd
g�dtddtd�|S(gu-
    Create a single VM from a data dict
    uprofileudigitaloceanR>ucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingunameRJucloud.filter_eventucreatinguproviderudrivertsock_dirusock_dirt	transportu	transportuCreating Cloud VM %susizeuimageuregionussh_keysutagsussh_key_nameR7u
ssh_key_namestdefaultu,ussh_key_fileu-The defined key_filename '{0}' does not existu	ssh_agentu�The DigitalOcean driver requires an ssh_key_file and an ssh_key_name because it does not supply a root password upon building the server.u
ssh_interfaceupublicuprivateu.ssh_interface: Setting interface for ssh to %suVThe DigitalOcean driver requires ssh_interface to be defined as 'public' or 'private'.uprivate_networkingu/'private_networking' should be a boolean value.uwThe DigitalOcean driver requires ssh_interface if defined as 'private' then private_networking should be set as 'True'.ubackups_enabledu,'backups_enabled' should be a boolean value.ubackupsuipv6u!'ipv6' should be a boolean value.u
monitoringu''monitoring' should be a boolean value.u
userdata_fileuru	user_dataNu#Failed to read userdata from %s: %sucreate_dns_recordu4create_dns_record: will attempt to write DNS recordsu.iuVcreate_dns_record: inferring default dns_hostname, dns_domain from minion name as FQDNi����u1create_dns_record: can't infer dns_domain from %siudns_hostnameu
dns_domainu;create_dns_record: using dns_hostname="%s", dns_domain="%s"c	@std�d�d|d|�S(Nt
dns_domaintnametrecord_typetrecord_data(tpost_dns_record(tttd(RQtdns_hostname(sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyt<lambda>�sucreate_dns_record: %suEcreate_dns_record: could not determine dns_hostname and/or dns_domainui'create_dns_record' must be a dict specifying "domain" and "hostname" or the minion name must be an FQDN.urequesting instanceusalt/cloud/{0}/requestingu
requestingusError creating %s on DIGITALOCEAN

The following exception was thrown when trying to run the initial deployment: %stexc_info_on_loglevelcS@s`t|d�}|stS|djd�r\x-|ddD]}|ddkr;|Sq;WntS(Nuactionunetworksuv4utypeupublic(t
show_instanceRtget(tvm_nametdatatnetwork((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyt__query_node_data�stupdate_argsttimeoutuwait_for_ip_timeouti
i<tintervaluwait_for_ip_intervalussh_hostuv4uv6uAuAAAAunetworksutypeu
ip_addressu found %s IP%s interface for "%s"u@No suitable IP addresses found for ssh minion bootstrapping: {0}u?Found public IP address to use for ssh minion bootstrapping: %sukey_filenameucloud.bootstrapuCreated Cloud VM '%s'u'%s' VM creation details:
%sucreated instanceusalt/cloud/{0}/createducreated(uprivateupubliciX(uv4uv6(uAuAAAA(9Rtis_profile_configuredRRRtAttributeErrort	__utils__R=tlogtinfoRERARIR8tappendt	get_keyidtsplitR;tostpathtisfileRR\R9tboolR3R4tfilestfopenR5tuserdata_templatetstringutilst
to_unicodetreadt	Exceptiont	exceptiontlentdebugtjointerrortlistRMtloggingtDEBUGtwait_for_ipRRtdestroyRR	RtdictR
treprtupdatetpprinttpformat(R>tkwargstssh_key_namet
ssh_key_namestkeytkey_filenamet
ssh_interfacetprivate_networkingtbackups_enabledtipv6t
monitoringt
userdata_filetfp_texctcreate_dns_recordtdefault_dns_domaintdns_domain_nametdefault_dns_hostnamet__add_dns_addr__R!R`R^t
addr_familiestdns_arec_typestarec_maptfamilytnettfacingtaddr_familyt
ip_addresstdns_rec_type((RQRXsB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytcreatesb	

"





	



2






	




?



"
udropletsugetc
	C@s�tjtjdt�tdtdd��}dj||�}|r[|dj|�7}n|rn||7}nt|t	�s�i}ntjdt�tdt�}t
jjj
|�}tt|�}	|	|d|d	id
|d6dd
6�}
|
jdkr"tdj|
j|
j���ntj|
j�|
jdkrEtS|
j}t
jjj|�}|jdd�j�dkr�ttj|jdi����n|S(u)
    Make a web call to DigitalOcean
    uapi_rootR7RPuhttps://api.digitalocean.com/v2u{0}/{1}/u{0}/upersonal_access_tokenR^theadersuBearer u
Authorizationuapplication/jsonuContent-Typei+uKAn error occurred while querying DigitalOcean. HTTP Code: {0}  Error: '{1}'i�ustatusuuerroru
error_message(R	RRR8RRRR=R9R�R3R4tjsontdumpstgetattrtrequestststatus_codeRttextRgRyturlR&tloadsR\RBR�R�(
Rt
droplet_idR%RJRKt	base_pathRmtpersonal_access_tokenR^t	requestertrequesttcontenttresult((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR%s@
	*	!cC@sRtjjjtjd|t�|ttjjjtjjjt|���}|S(u-
    Return the script deployment object
    uscript(	R3R4R5t	os_scriptRR8Rtsalt_config_to_yamlt
minion_config(R>t
deploy_script((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytscript_scC@s?|dkrtd��nt|�}td|tt�|S(uA
    Show the details from DigitalOcean concerning a droplet
    uactionu<The show_instance action must be called with -a or --action.ucloud.cache_node(Rt	_get_nodeRfRR(RRRRL((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR[nscC@spd}xc|dkrkytdt�|SWq	tk
rg|d8}tjd||�tjd�q	Xq	WiS(Ni
iR1iu<Failed to get the data for node '%s'. Remaining attempts: %sg�?(R2RR'RgRyttimetsleep(RRtattempts((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR�{s


cC@s$|dkrtjd�tSt}d}i}x�|rtddddtj|�d�}x|d	D]s}|d
}||kr�tdj|���ni||<x2tj	|�D]!}tj||�|||<q�WqiW|d7}yd|d
dk}Wq2t
k
rt}q2Xq2W|S(ub
    Return a dict of all available VM locations on the cloud provider with
    relevant data
    ufunctionu@The list_keypairs function must be called with -f or --function.iRuaccount/keysR%u?page=u
&per_page=100ussh_keysunameu�A duplicate key pair name, '{0}', was found in DigitalOcean's key pair list. Please change the key name stored by DigitalOcean. Be sure to adjust the value of 'ssh_key_file' in your cloud profile or provider configuration, if necessary.unextulinksupages(RgR{RR&RR	RRR=RR'(RR(R)R!R tkey_pairRRR#((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyt
list_keypairs�s2	


#

cC@s�|dkrtjd�tS|s,i}nd|krItjd�tStdd�}||dd}tjd|�tdd	d
|�}|S(u,
    Show the details of an SSH keypair
    ufunctionu?The show_keypair function must be called with -f or --function.ukeynameuA keyname is required.RuiduKey ID is %sRuaccount/keysR%(RgR{RR�RyR(R�Rtkeypairstkeyidtdetails((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytshow_keypair�s	
cC@sntjjj|dd��"}tjjj|j��}WdQXi|dd6|d6}t|d|�}|S(u�
    Upload public key to cloud provider.
    Similar to EC2 import_keypair.

    .. versionadded:: 2016.11.0

    kwargs
        file(mandatory): public key file-name
        keyname(mandatory): public key name in the provider
    ufileurNukeynameunameu
public_keyR(R3R4RpRqRsRtRut
create_key(R�Rtpublic_key_filenametpublic_key_contenttdigitalocean_kwargstcreated_result((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytimport_keypair�s!
c	C@s~|dkrtjd�tSy;tdddddi|dd6|d	d	6d
d�}Wntk
rytjd�tSX|S(
u
    Upload a public key
    ufunctionu=The create_key function must be called with -f or --function.RuaccountR%ukeysRJunameu
public_keyRKupostu3`name` and `public_key` arguments must be specified(RgR{RRR'Rh(R�RR�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR��s


cC@sj|dkrtjd�tSy'tdddd|ddd	�}Wntk
retjd
�tSX|S(u
    Delete public key
    ufunctionu=The create_key function must be called with -f or --function.RuaccountR%ukeys/uidRKudeleteu`id` argument must be specified(RgR{RRR'Rh(R�RR�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyt
remove_keys


cC@sA|s
dStdd�}||d}|r1|Std��dS(u&
    Return the ID of the keyname
    Rufunctionuidu)The specified ssh key could not be found.N(R;R�R(tkeynameR�R�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyRjscC@sF|dkrtd��ntddddj|�di|d6d	td
dtd�t|d
d�}tddd|ddd�}t}t|t�s�t	d��nt
jd|�t|�tddddj|�di|d6d	td
dtd�tj
dt�tkrBtd|tjd�dt�n|S(u�
    Destroy a node. Will check termination protection and warn if enabled.

    CLI Example:

    .. code-block:: bash

        salt-cloud --destroy mymachine
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.ucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingRJunameRNusock_dirROu	transportRuactionRudropletsR�uidRKudeleteu.'delete_dns_record' should be a boolean value.uDeleting DNS records for %s.udestroyed instanceusalt/cloud/{0}/destroyeduupdate_cachedirucloud.delete_minion_cachediru:i(RRfR=RR[RR&R9RoRRgRytdestroy_dns_recordsR\RRRk(RRRR^RLtdelete_dns_record((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR�$s8






$cK@s�d|kr-|d}|d=|j|�nd}x@|D]8}||rMq:dj||||�}t|��q:Wtddd	|d�}|r�tddd	|dd
ddi|dd
6|dd6|dd6dd�}|StS(uS
    Creates a DNS record for the given name if the domain is managed with DO.
    ukwargsu
dns_domainunameurecord_typeurecord_datau5{0}="{1}" ## all mandatory args must be provided: {2}RudomainsR�R%urecordsRJutypeudataRKupost(u
dns_domainunameurecord_typeurecord_data(R�R=RRR(R�tf_kwargstmandatory_kwargstiR{tdomainR�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyRUjs(



'	c	
C@s{dj|jd�d�}dj|jd�d �}ytddd|dd�}Wntk
rxtjd�tSXtjd	tj|��|d
}|rwg|D]&}|dj	�|kr�|d^q�}tjd
|�x�|D]�}y>tj
d|�tddd|ddj|�dd�}Wn$tk
rVtjd||�nXtjdtj|��q�WntS(uV
    Deletes DNS records for the given hostname if the domain is managed with DO.
    u.i����RudomainsR�R%urecordsuFailed to find domains.ufound DNS records: %sudomain_recordsunameuidudeleting DNS record IDs: %sudeleting DNS record %surecords/{0}RKudeleteu,failed to delete DNS domain %s record ID %s.u#DNS deletion REST call returned: %s(
RzRkRRRgRyRR�R�tdecodeRhR=R{(	tfqdnR�thostnametresponsetrecordstrt
record_idstid_R!((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR��s0


3


 cC@s0tdj|di�}|s+idd6S|jdd�}|jd�}t|�dksn|d	d
kryidd6Si}i}t�}tj||dd
�|d<|dd|d<|dd|d<tj||dd�|d<|dd|d<|jdt�r!||d<ni||d6S(u
    Show pricing for a particular profile. This is only an estimate, based on
    unofficial pricing sources.

    .. versionadded:: 2015.8.0

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f show_pricing my-digitalocean-config profile=my-profile
    uprofilesuprofileu#The requested profile was not founduErroruprovideru0:0u:iiudigitaloceanu5The requested profile does not belong to DigitalOceanusizeuprice_hourlyuper_houriuper_dayiuper_weeku
price_monthlyu	per_monthi4uper_yearurawu_raw(RR\RkRxR-tdecimaltDecimalR(R�RtprofileRtcompstrawR!RC((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytshow_pricing�s$
"	
cC@s�|dkrtd��nt}d}i}x�|r�tddddtj|�d�}xP|dD]D}i||d	<x-tj|�D]}||||d	|<q�WqgW|d7}yd
|ddk}Wq0tk
r�t}q0Xq0W|S(
u�
    Return a list of the floating ips that are on the provider

    .. versionadded:: 2016.3.0

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f list_floating_ips my-digitalocean-config
    uactionukThe list_floating_ips function must be called with -f or --function, or with the --list-floating-ips optioniRufloating_ipsR%u?page=u
&per_page=200uipunextulinksupages(RR&RR	RRR'R(RR(R)R!R tfloating_ipR#((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytlist_floating_ips�s&	

cC@s||dkrtjd�tS|s,i}nd|krItjd�tS|d}tjd|�tddd|�}|S(	u�
    Show the details of a floating IP

    .. versionadded:: 2016.3.0

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f show_floating_ip my-digitalocean-config floating_ip='45.55.96.47'
    ufunctionuCThe show_floating_ip function must be called with -f or --function.ufloating_ipuA floating IP is required.uFloating ip is %sRufloating_ipsR%(RgR{RRyR(R�RR�R�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytshow_floating_ip�s	

cC@s�|dkrtjd�tS|s,i}nd|krbtdddi|dd6dd�}|Sd	|kr�tdddi|d	d	6dd�}|Stjd
�tSdS(u
    Create a new floating IP

    .. versionadded:: 2016.3.0

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f create_floating_ip my-digitalocean-config region='NYC2'

        salt-cloud -f create_floating_ip my-digitalocean-config droplet_id='1234567'
    ufunctionuEThe create_floating_ip function must be called with -f or --function.u
droplet_idRufloating_ipsRJRKuposturegionu#A droplet_id or region is required.N(RgR{RR(R�RR�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytcreate_floating_ips$			
cC@s�|dkrtjd�tS|s,i}nd|krItjd�tS|d}tjd|d�tddd|d	d
�}|S(u�
    Delete a floating IP

    .. versionadded:: 2016.3.0

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f delete_floating_ip my-digitalocean-config floating_ip='45.55.96.47'
    ufunctionuEThe delete_floating_ip function must be called with -f or --function.ufloating_ipuA floating IP is required.uFloating ip is %sRufloating_ipsR%RKudelete(RgR{RRyR(R�RR�R�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytdelete_floating_ipEs	

	c
C@s�|dkrtjd�tS|s,i}ndrOd|krOtjd�tStddd|dd	d
i|dd6dd6d
d�}|S(u�
    Assign a floating IP

    .. versionadded:: 2016.3.0

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f assign_floating_ip my-digitalocean-config droplet_id=1234567 floating_ip='45.55.96.47'
    ufunctionuEThe assign_floating_ip function must be called with -f or --function.ufloating_ipu
droplet_idu)A floating IP and droplet_id is required.Rufloating_ipsR%u/actionsRJuassignutypeRKupost(RgR{RR(R�RR�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytassign_floating_iphs	
	c	C@s}|dkrtjd�tS|s,i}nd|krItjd�tStddd|ddd	id
d6dd
�}|S(u�
    Unassign a floating IP

    .. versionadded:: 2016.3.0

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f unassign_floating_ip my-digitalocean-config floating_ip='45.55.96.47'
    ufunctionuGThe inassign_floating_ip function must be called with -f or --function.ufloating_ipuA floating IP is required.Rufloating_ipsR%u/actionsRJuunassignutypeRKupost(RgR{RR(R�RR�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytunassign_floating_ip�s	

	c
C@s;t}d}i}x"|r6tddddtj|�d�}x�|dD]�}|d}i||<|r�t|d|�||<qLt|d	�\}}	i|d
d
6|ddd6|d6|	d6|d
6|dd6tj|d�d6||<qLW|d7}yd|ddk}Wqtk
r2t}qXqW|S(u8
    Helper function to format and parse node data.
    iRudropletsR%u?page=u
&per_page=200unameR1unetworksuiduimageuprivate_ipsu
public_ipsu	size_slugusizeustatusustateunextulinksupages(R&RR	Rt_get_full_outputt_get_ipsR'R(
R0R1R(R)R!R RLRRt
public_ipstprivate_ips((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR.�s4	



c	C@s�|dkrtd��nt|dd�}|jd�dkrbitd6dd6dd6dd	6Std
|ddd
didd6dd�}itd6|ddd6|ddd6S(u�
    Reboot a droplet in DigitalOcean.

    .. versionadded:: 2015.8.8

    name
        The name of the droplet to restart.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a reboot droplet_name
    uactionu6The restart action must be called with -a or --action.RustatusuoffusuccessustopuMachine is already off.umsgR�uidR%uactionsRJurebootutypeRKupostustate(RR[R\R&R(RRRR^R!((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytreboot�s 

	
c	C@s�|dkrtd��nt|dd�}|jd�dkrbitd6dd6dd6dd	6Std
|ddd
didd6dd�}itd6|ddd6|ddd6S(u�
    Start a droplet in DigitalOcean.

    .. versionadded:: 2015.8.8

    name
        The name of the droplet to start.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a start droplet_name
    uactionu4The start action must be called with -a or --action.RustatusuactiveusuccessustartuMachine is already running.umsgR�uidR%uactionsRJupower_onutypeRKupostustate(RR[R\R&R(RRRR^R!((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytstart�s 

	
c	C@s�|dkrtd��nt|dd�}|jd�dkrbitd6dd6dd6dd	6Std
|ddd
didd6dd�}itd6|ddd6|ddd6S(u�
    Stop a droplet in DigitalOcean.

    .. versionadded:: 2015.8.8

    name
        The name of the droplet to stop.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a stop droplet_name
    uactionu3The stop action must be called with -a or --action.RustatusuoffusuccessustopuMachine is already off.umsgR�uidR%uactionsRJushutdownutypeRKupostustate(RR[R\R&R(RRRR^R!((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pytstops 

	
cC@s\i}xOtj|�D]>}||}|dk	rJ|rJtj|�}n|||<qW|S(u�
    Helper function for _list_nodes to loop through all node information.
    Returns a dictionary containing the full information of a node.
    N(R	RR;R(RLR1R!R#tvalue((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR�>s
cC@s|jd�}|jd�}g}g}|r�xg|D]\}|jd�}|jd�}|dkrw|j|�n|dkr7|j|�q7q7Wn|r
xg|D]\}|jd�}|jd�}|dkr�|j|�n|dkr�|j|�q�q�Wn||fS(uv
    Helper function for list_nodes. Returns public and private ip lists based on a
    given network dictionary.
    uv4uv6utypeu
ip_addressupublicuprivate(R\Ri(tnetworkstv4stv6sR�R�R#tip_typeR�((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyR�Ls*

(Ot__doc__t
__future__RRRR�R}RlR�R�tsalt.utils.cloudR3tsalt.utils.filestsalt.utils.jsontsalt.utils.stringutilstsalt.configRtsalt.exceptionsRRRRRRtsalt.extR	tsalt.ext.six.movesR
R�R&RtImportErrorRt	getLoggert__name__RgRRRRR
R;R$R+R-R/R2R6RARERIRMR�RR�R[R�R�R�R�R�R�RjR�RUR�R�R�R�R�R�R�R�R.R�R�R�R�R�(((sB/usr/lib/python2.7/site-packages/salt/cloud/clouds/digitalocean.pyt<module>s~.


	
		
						�:	
	+	
F		"'(!*#!!%%%%

Zerion Mini Shell 1.0