%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@sldZddlmZmZmZddlZddlZddlZddlZddl	j
Z
ddlmZm
Z
mZmZmZddlZddlZddlZddlmZy2ddlmZmZmZmZmZeZWnek
re ZnXej!e"�Z#dZ$d�Z%d	�Z&d
�Z'd�Z(d�Z)d
�Z*ddd�Z,ddd�Z-d�Z.d�Z/ddd�Z0ddd�Z1dd�Z2d�Z3ddd�Z4ddd�Z5ddd�Z6dd�Z7d�Z8d�Z9d�Z:dd�Z;dd�Z<dd�Z=dd �Z>d!�Z?d"�Z@d#�ZAd$�ZBd%�ZCdS(&u�

1&1 Cloud Server Module
=======================

The 1&1 SaltStack cloud module allows a 1&1 server to be automatically deployed
and bootstrapped with Salt. It also has functions to create block storages and
ssh keys.

:depends: 1and1 >= 1.2.0

The module requires the 1&1 api_token to be provided.  The server should also
be assigned a public LAN, a private LAN, or both along with SSH key pairs.

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

.. code-block:: yaml

    my-oneandone-config:
      driver: oneandone
      # The 1&1 api token
      api_token: <your-token>
      # SSH private key filename
      ssh_private_key: /path/to/private_key
      # SSH public key filename
      ssh_public_key: /path/to/public_key

.. code-block:: yaml

    my-oneandone-profile:
      provider: my-oneandone-config
      # Either provide fixed_instance_size_id or vcore, cores_per_processor, ram, and hdds.
      # Size of the ID desired for the server
      fixed_instance_size: S
      # Total amount of processors
      vcore: 2
      # Number of cores per processor
      cores_per_processor: 2
      # RAM memory size in GB
      ram: 4
      # Hard disks
      hdds:
      -
        is_main: true
        size: 20
      -
        is_main: false
        size: 20
      # ID of the appliance image that will be installed on server
      appliance_id: <ID>
      # ID of the datacenter where the server will be created
      datacenter_id: <ID>
      # Description of the server
      description: My server description
      # Password of the server. Password must contain more than 8 characters
      # using uppercase letters, numbers and other special symbols.
      password: P4$$w0rD
      # Power on server after creation - default True
      power_on: true
      # Firewall policy ID. If it is not provided, the server will assign
      # the best firewall policy, creating a new one if necessary.
      # If the parameter is sent with a 0 value, the server will be created with all ports blocked.
      firewall_policy_id: <ID>
      # IP address ID
      ip_id: <ID>
      # Load balancer ID
      load_balancer_id: <ID>
      # Monitoring policy ID
      monitoring_policy_id: <ID>

Set ``deploy`` to False if Salt should not be installed on the node.

.. code-block:: yaml

    my-oneandone-profile:
      deploy: False

Create an SSH key

.. code-block:: bash

    sudo salt-cloud -f create_ssh_key my-oneandone-config name='SaltTest' description='SaltTestDescription'

Create a block storage

.. code-block:: bash

    sudo salt-cloud -f create_block_storage my-oneandone-config name='SaltTest2'
    description='SaltTestDescription' size=50 datacenter_id='5091F6D8CBFEF9C26ACE957C652D5D49'

i(tabsolute_importtprint_functiontunicode_literalsN(tSaltCloudConfigErrortSaltCloudNotFoundtSaltCloudExecutionFailuretSaltCloudExecutionTimeouttSaltCloudSystemExit(tsix(tOneAndOneServicetServertHddtBlockStoragetSshKeyu	oneandonecC@s*t�tkrtSt�tkr&tStS(u'
    Check for 1&1 configurations.
    (tget_configured_providertFalsetget_dependenciest__virtualname__(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt__virtual__�s
cC@stjttptd�S(u/
    Return the first configured instance.
    u	api_token(u	api_token(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR�s	cC@stjtitd6�S(u+
    Warn if dependencies are not met.
    u	oneandone(Rtcheck_driver_dependenciesRt
HAS_ONEANDONE(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR�scC@s%tdtjdt�tdt��S(u5
    Return a conn object for the passed VM data
    t	api_tokenu	api_tokent
search_global(R	Rtget_cloud_config_valueRRR(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytget_conn�sc@s�tjd|tdddt��t�}�sMtd�|D�d�}|St�fd�|D�d�}|rv|Stdj����dS(u%
    Return the VM's size object
    ufixed_instance_sizetdefaultRcs@s%|]}|ddkr|VqdS(unameuSN((t.0titem((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pys	<genexpr>�sc3@s5|]+}|d�ks)|d�kr|VqdS(unameuidN((RR(tvm_size(s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pys	<genexpr>�su.The specified size, '{0}', could not be found.N(	RRRtNoneRtavail_sizestnextRtformat(tvm_tsizestsize((R s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytget_size�s		cC@s�tjd|t�jdd�}t�}xMtj|�D]<\}}|r:|||d||dfkr:||Sq:Wtdj|���dS(u(
    Return the image object to use
    uimageuasciiusalt-cloud-force-asciiuidunameu/The specified image, '{0}', could not be found.N(	RRRtencodetavail_imagesRt	iteritemsRR$(R%tvm_imagetimagestkeytvalue((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt	get_image�s	(cC@sm|dkrtd��ng}|s3t�}nx,|j�D]}|ji||d6�q@Wi|d6S(u6
    List available locations/datacenters for 1&1
    uactionufThe avail_locations function must be called with -f or --function, or with the --list-locations optionucountry_codeu	Locations(RRtlist_datacenterstappend(tconntcalltdatacenterst
datacenter((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytavail_locations�scC@sM|dkrtd��nt�}t|�}|jd|�}i|d6S(u 
    Create a block storage
    uactionufThe avail_locations function must be called with -f or --function, or with the --list-locations optiont
block_storageuBlockStorage(RRt_get_block_storagetcreate_block_storage(tkwargsR4R3R8tdata((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR:�s	cC@s�|dkri}n|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}td|d|�}|r�||_n|r�||_n|r�||_n|S(	uB
    Construct a block storage instance from passed arguments
    unameusizeudescriptionu
datacenter_idu	server_idtnameR'N(R!tgetRtdescriptiont
datacenter_idt	server_id(R;tblock_storage_nametblock_storage_sizetblock_storage_descriptionR@RAR8((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR9s"		cC@sO|jdd�}|jdd�}|jdd�}td|d|d|�S(u<
    Construct an SshKey instance from passed arguments
    unameudescriptionu
public_keyR=R?t
public_keyN(R>R!R
(R;tssh_key_nametssh_key_descriptionRE((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt_get_ssh_key#scC@sM|dkrtd��nt�}t|�}|jd|�}i|d6S(u
    Create an ssh key
    uactionufThe avail_locations function must be called with -f or --function, or with the --list-locations optiontssh_keyuSshKey(RRRHtcreate_ssh_key(R;R4R3RIR<((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyRJ2s	cC@s\|dkrtd��n|s-t�}ni}x"|j�D]}|||d<q@W|S(uI
    Return a list of the server appliances that are on the provider
    uactionu`The avail_images function must be called with -f or --function, or with the --list-images optionuname(RRtlist_appliances(R3R4trett	appliance((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR*FscC@s4|dkrtd��nt�}|j�}|S(u_
    Return a dict of all available VM sizes on the cloud provider with
    relevant data.
    uactionu^The avail_sizes function must be called with -f or --function, or with the --list-sizes option(RRtfixed_server_flavors(R4R3R&((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR"[s	cC@sLtjjjtjd|t�|ttjjjtjjjt|���S(u-
    Return the script deployment object
    uscript(	tsalttutilstcloudt	os_scriptRRRtsalt_config_to_yamlt
minion_config(R%((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytscriptmscC@s?|dkrtd��n|s-t�}ni}|j�}x�|D]�}g}g}i}|jd�jdd�}|jd�r�x"|dD]}|j|�q�Wn|jd�r�x&|dD]}	|j|	d�q�Wni|d	d	6|d
d	d
6|d6|dd
d
6|d6|d6}
|
||d<qFW|S(u7
    Return a list of VMs that are on the provider
    uactionu=The list_nodes function must be called with -f or --function.uhardwareufixed_instance_size_iduCustom sizeuprivate_networksuipsuipuiduimageusizeustatusustateuprivate_ipsu
public_ipsuname(RRtlist_serversR>R2(R3R4RLtnodestnodet
public_ipstprivate_ipsR't
private_ipt	public_iptserver((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt
list_nodes{s6

cC@sb|dkrtd��n|s-t�}ni}|j�}x|D]}|||d<qFW|S(uL
    Return a list of the VMs that are on the provider, with all fields
    uactionuBThe list_nodes_full function must be called with -f or --function.uname(RRRV(R3R4RLRWRX((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytlist_nodes_full�s
cC@s8|st�}ntjjjt|d�td|�S(uO
    Return a list of the VMs that are on the provider, with select fields
    ufunctionuquery.selection(RRORPRQtlist_nodes_selectR_R(R3R4((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR`�scC@sD|dkrtd��nt�}td||tt�||S(uC
    Show the details from the provider concerning an instance
    uactionu<The show_instance action must be called with -a or --action.ucloud.cache_node(RR_t	__utils__RR(R=R4RW((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt
show_instance�s	c&C@s�tjd|tdd'dt�}t|�}d'}d'}d'}d'}d|krjt|�}|d}n�|dr�|dr�|dr�|d	r�tjd|tdd'dt�}tjd|tdd'dt�}tjd|tdd'dt�}ntd
��tjd|tdd'dt�}tjd|tdd'dt�}	tjd
|tdd'dt�}
tjd|tdd'dt�}tjd|tdd'dt�}tjd|tdd'dt�}
tjd|tdd'dt�}tjd|tdd'dt�}tjd|tdtdt�}tjd|tdtdt�}t	d|dd|d|d|d|d|d|d|	d|d|
d |d!|d"|
d#|d$|d%|d&|�S((u=
    Construct server instance from cloud profile config
    udescriptionRRufixed_instance_sizeuiduvcoreucores_per_processoruramuhddsuZ'fixed_instance_size' or 'vcore','cores_per_processor', 'ram', and 'hdds'must be provided.uappliance_idupasswordufirewall_policy_iduip_iduload_balancer_idumonitoring_policy_idu
datacenter_iduprivate_network_idupower_onupublic_key_idsR=unameR?tfixed_instance_size_idtvcoretcores_per_processortramtappliance_idtpasswordtpower_ontfirewall_policy_idtip_idtload_balancer_idtmonitoring_policy_idR@trsa_keytprivate_network_idREN(
RRRR!Rtload_public_keyR(RtTrueR
(R%R?RIRdReRfRctfixed_instance_sizeRgRhRjRkRlRmR@RoRiRE((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt_get_server�s�	
												
cC@s`tjd|tdddt�}g}x2|D]*}|jtd|dd|d��q.W|S(	u5
    Construct VM hdds from cloud profile config
    uhddsRRR'usizetis_mainuis_mainN(RRRR!RR2R(R%t_hddsthddsthdd((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt	_get_hddsJs	

c	C@sy7|dr6tjttpd|d�tkr6tSWntk
rJnXd}t�}g}t|�}t	|j
dd�s�t|�}ntddddj
|d	�d
i|d	d	6dtdd
td�y6|jd|d|�}t|t|�|d�Wn4tk
rD}tjd|d	|dtj�tSX|d|d<|d}d�}y[tjjj|d||fdtjd|tdd,�dtjd|tdd��}Wn_ttfk
r"}z*yt|d	�Wntk
rnXWdttj |j!���XnXtj"d �tj#d!|�tj"d"|t$j%|��tddd#d$j
|d	�d
i|d	d	6|dd6|d%d&6dtdd
td�d'|kr||d(<t&|�|d)<td*|t�}|j'|�|Std+��dS(-u-
    Create a single VM from a data dict
    uprofileu	oneandoneuhardwareufixed_instance_size_iducloud.fire_eventueventurequesting instanceusalt/cloud/{0}/requestingunametargstsock_dirusock_dirt	transportu	transportR]Rvuidu�Error creating %s on 1and1

The following exception was thrown by the 1and1 library when trying to run the initial deployment: 
%stexc_info_on_loglevelu	server_idufirst_passwordcS@s�t}yPt|dd�}|s&tStjd|dtj|d�|dd�Wn-tk
r�}tjd|dtj	�tSX|ddj
�dk}|s�d	S|d
dd|d
<|S(u?
        Query node data until node becomes available.
        unameuactionu+Loaded node data for %s:
name: %s
state: %sustatusustateuFailed to get nodes list: %sR|u
powered_onNuipsiuipussh_host(RRbtlogtdebugtpprinttpformatt	ExceptionterrortloggingtDEBUGtlower(R%R<trunningterr((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt__query_node_data�s(	
tupdate_argsttimeoutuwait_for_ip_timeoutRi
i<tintervaluwait_for_ip_intervalNuVM is now runninguCreated Cloud VM %su%s VM creation details:
%sucreated instanceusalt/cloud/{0}/createdudriveruproviderussh_hostupasswordukey_filenameucloud.bootstrapu!A valid IP address was not found.iX((Rtis_profile_configuredRRRtAttributeErrorR!RRstbooltspecsRxRaR$t
create_servert_wait_for_completiontget_wait_timeoutR�R}R�R�R�RORPRQtwait_for_ipRRRtdestroyRRt	text_typetmessageR~tinfoRR�tget_key_filenametupdate(	R%R<R3RvR]texcRhR�RL((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytcreate`s�
	
	
	
	!




cC@s|dkrtd��ntddddj|�di|d6d	td
dtd�t�}t||�}|jd
|d�tddddj|�di|d6d	td
dtd�tjdt�t	kr�td|t
jd�dt�nt	S(u:
    destroy a server by name

    :param name: name given to the server
    :param call: call value in this case is 'action'
    :return: array of booleans , true if successfully stopped and true if
             successfully removed

    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}/destroyingRyunameRzusock_dirR{u	transportRAuidudestroyed instanceusalt/cloud/{0}/destroyeduupdate_cachedirucloud.delete_minion_cachediru:i(RRaR$RRtget_nodet
delete_serverR>RRqRtsplit(R=R4R3RX((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR��s4

	


cC@s6t�}t||�}|jd|ddd�tS(u�
    reboot a server by name
    :param name: name given to the machine
    :param call: call value in this case is 'action'
    :return: true if successful

    CLI Example:

    .. code-block:: bash

        salt-cloud -a reboot vm_name
    RAuidtactionuREBOOT(RR�tmodify_server_statusRq(R=R4R3RX((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytreboots
	cC@s0t�}t||�}|jd|d�tS(u�
    stop a server by name
    :param name: name given to the machine
    :param call: call value in this case is 'action'
    :return: true if successful

    CLI Example:

    .. code-block:: bash

        salt-cloud -a stop vm_name
    RAuid(RR�tstop_serverRq(R=R4R3RX((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytstop/s
	cC@s0t�}t||�}|jd|d�tS(u�
    start a server by name
    :param name: name given to the machine
    :param call: call value in this case is 'action'
    :return: true if successful


    CLI Example:

    .. code-block:: bash

        salt-cloud -a start vm_name
    RAuid(RR�tstart_serverRq(R=R4R3RX((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pytstartDs	cC@s5x.|jdd�D]}|d|kr|SqWdS(u(
    Return a node for the named VM
    tper_pagei�unameN(RV(R3R=RX((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR�ZscC@sqtjd|tdtdd�}|dk	rmtjj|�}tjj|�sit	dj
|���n|SdS(uH
    Check SSH private key file and return absolute path if exists.
    ussh_private_keyRRu0The defined ssh_private_key '{0}' does not existN(RRRRR!tostpatht
expandusertisfileRR$(R%tkey_filename((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR�cscC@s�tjd|tdtdd�}|dk	r�tjj|�}tjj|�sit	dj
|���ntjj
j|d��2}tjjj|j�jdd��}|SWdQXndS(	u-
    Load the public key file if exists.
    ussh_public_keyRRu/The defined ssh_public_key '{0}' does not existuru
uN(RRRRR!R�R�R�R�RR$RORPtfilestfopentstringutilst
to_unicodetreadtreplace(R%tpublic_key_filenameRER.((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyRpvs'cC@stjd|tdddt�S(u@
    Return the wait_for_timeout for resource provisioning.
    uwait_for_timeoutRii<Ri�(RRRR(R%((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR��scC@s�tj�|}x�|tj�kr�tjd�|j|�}|ddj�}|dkredS|dkr�tdj|���q|dkr�qqtdj|���qWtd
j|���dS(u<
    Poll request status until resource is provisioned.
    iustatusustateu
powered_onNufaileduServer creation failed for {0}uactiveuenabledu	deployinguconfiguringuUnknown server state {0}u6Timed out waiting for server create completion for {0}(uactiveuenabledu	deployinguconfiguring(ttimetsleept
get_serverR�R�R$(R3twait_timeoutRAR]tserver_state((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyR��s$
	(Dt__doc__t
__future__RRRR�R�RR�tsalt.configRtsalt.exceptionsRRRRRtsalt.utils.filesROtsalt.utils.cloudtsalt.utils.stringutilstsalt.extRtoneandone.clientR	R
RRR
RqRtImportErrorRt	getLoggert__name__R}RRRRRR(R0R!R7R:R9RHRJR*R"RUR^R_R`RbRsRxR�R�R�R�R�R�R�RpR�R�(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/oneandone.pyt<module>\s`((


	
		
						+	n		�7					

Zerion Mini Shell 1.0