%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/linode.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
jZddlm
Z
ddlmZddlmZmZmZmZeje�Zeeje	j	j�j���aiidd6d	d
6d6idd6d
d
6d6idd6dd
6d6idd6dd
6d6idd6dd
6d6idd6dd
6d6idd6dd
6d6ZdZd�Zd�Z dd �Z"dd!�Z#dd"�Z$dddd#�Z%ddd$�Z&d%�Z'ddd&�Z(dd'�Z)dd(�Z*dddd)�Z+d*�Z,dd+�Z-ddd,�Z.d-�Z/d.�Z0d/�Z1d0�Z2dd1�Z3ddd2�Z4d3�Z5d4�Z6d5�Z7ddd6�Z8d7�Z9d8�Z:d9�Z;d:�Z<d;�Z=dd<�Z>dd=�Z?dd>�Z@dd?�ZAdd@�ZBddA�ZCdddB�ZDddC�ZEddD�ZFddE�ZGdF�ZHeIdG�ZJddddHdddIdJ�ZKdKeLdL�ZMddKeLdM�ZNdN�ZOdO�ZPdP�ZQdQ�ZRdS(Ru%
Linode Cloud Module using Linode's REST API
===========================================

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

Use of this module only requires the ``apikey`` parameter. However, the default root password for new instances
also needs to be set. The password needs to be 8 characters and contain lowercase, uppercase, and numbers.

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

.. code-block:: yaml

    my-linode-provider:
      apikey: f4ZsmwtB1c7f85Jdu43RgXVDFlNjuJaeIYV8QMftTqKScEB2vSosFSr...
      password: F00barbaz
      driver: linode

    linode-profile:
      provider: my-linode-provider
      size: Linode 1024
      image: CentOS 7
      location: London, England, UK

i(tabsolute_importtprint_functiontunicode_literalsN(tsix(trange(tSaltCloudConfigErrortSaltCloudExceptiontSaltCloudNotFoundtSaltCloudSystemExiti����ucodeuBoot Failed (not in use)udescruboot_failedi����u
Being Createdubeeing_createdu	Brand Newu	brand_newiuRunningurunningiuPowered OffupoweroffiuShutting Down (not in use)ushutdowniuSaved to Disk (not in use)usave_to_diskulinodecC@st�tkrtStS(u#
    Check for Linode configs.
    (tget_configured_providertFalset__virtualname__(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyt__virtual__YscC@stjttptd�S(u/
    Return the first configured instance.
    uapikeyupassword(uapikeyupassword(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR	cs	cC@s]|dkrtd��ntdd�}i}x&|dD]}|d}|||<q;W|S(u�
    Return available Linode images.

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-images my-linode-config
        salt-cloud -f avail_images my-linode-config
    uactionu?The avail_images function must be called with -f or --function.uavailu
distributionsuDATAuLABEL(Rt_query(tcalltresponsetrettitemtname((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytavail_imagesns
cC@s]|dkrtd��ntdd�}i}x&|dD]}|d}|||<q;W|S(u�
    Return available Linode datacenter locations.

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-locations my-linode-config
        salt-cloud -f avail_locations my-linode-config
    uactionuBThe avail_locations function must be called with -f or --function.uavailudatacentersuDATAuLOCATION(RR(RRRRR((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytavail_locations�s
cC@s]|dkrtd��ntdd�}i}x&|dD]}|d}|||<q;W|S(u�
    Return available Linode sizes.

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-sizes my-linode-config
        salt-cloud -f avail_sizes my-linode-config
    uactionuBThe avail_locations function must be called with -f or --function.uavailuLinodePlansuDATAuLABEL(RR(RRRRR((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytavail_sizes�s
c
	C@s�|dkr'|dkr'td��n|dkr<i}n|jdd�}|jdd�}|jdt�}|dkr�|jdd�}n|dkr�|dkr�td��n|dkr�td	��n|dkr�t|�}|}n|}|tkrItd
i|d6�d}|dkrItd
j|���qIntdddi|d6|d6�d}|d}	t||	�s�t	j
d|�tStS(u3
    Boot a Linode.

    name
        The name of the Linode to boot. Can be used instead of ``linode_id``.

    linode_id
        The ID of the Linode to boot. If provided, will be used as an
        alternative to ``name`` and reduces the number of API calls to
        Linode by one. Will be preferred over ``name``.

    config_id
        The ID of the Config to boot. Required.

    check_running
        Defaults to True. If set to False, overrides the call to check if
        the VM is running before calling the linode.boot API call. Change
        ``check_running`` to True is useful during the boot call in the
        create function, since the new VM will not be running yet.

    Can be called as an action (which requires a name):

    .. code-block:: bash

        salt-cloud -a boot my-instance config_id=10

    ...or as a function (which requires either a name or linode_id):

    .. code-block:: bash

        salt-cloud -f boot my-linode-config name=my-instance config_id=10
        salt-cloud -f boot my-linode-config linode_id=1225876 config_id=10
    uactionu"The boot action requires a 'name'.u	linode_idu	config_idu
check_runningufunctionunameu<The boot function requires either a 'name' or a 'linode_id'.u)The boot function requires a 'config_id'.tkwargsuSTATUSu1u6Cannot boot Linode {0}. Linode {0} is already running.ulinodeuboottargsuLinodeIDuConfigIDuDATAuJobIDuBoot failed for Linode %s.N(tNoneRtgettTruetget_linode_id_from_namet
get_linodetformatRt
_wait_for_jobtlogterrorR
(
RRRt	linode_idt	config_idt
check_runningtlinode_itemtstatusRtboot_job_id((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytboot�sD"		

cC@s�|dkrtd��n|d
kr0i}n|jdd
�}|jdd
�}|jdd
�}|||g}x)|D]!}|d
kr|td��q|q|Wi|d6|d6|d	6}td
dd|�S(u�
    Clone a Linode.

    linode_id
        The ID of the Linode to clone. Required.

    datacenter_id
        The ID of the Datacenter where the Linode will be placed. Required.

    plan_id
        The ID of the plan (size) of the Linode. Required.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f clone my-linode-config linode_id=1234567 datacenter_id=2 plan_id=5
    uactionu8The clone function must be called with -f or --function.u	linode_idu
datacenter_iduplan_iduYThe clone function requires a 'linode_id', 'datacenter_id', and 'plan_id' to be provided.uLinodeIDuDatacenterIDuPlanIDulinodeucloneRN(RRRR(RRR%t
datacenter_idtplan_idtrequired_paramsRt
clone_args((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytclones$	

cC@s�|d}y=|drFtjttp)d|dd|�tkrFtSWntk
rZnXt|�tkrqtStddddj|�d	td
d|dddd
g�dtddtd�t	j
d|�i}i|d6}dJ}|jd�}|r%||d<t
di|d6�}ndJ}|jd�}|rmyt|�}Wqmtk
rid}qmXn|jd�}|r�tnt}	|	rwt|�}
tdi|
d6�}i|d6dj|�d6}|dJkr|d}||d<|d}n|dJkr|d}ny(tdi|
d6|d6|d 6�}Wq�tk
rs}
t	jd!||
d"tj�tSXnh|d|d<y'tdd#d	i|d6|d6�}Wn0tk
r�}
t	jd$||
d"tj�tSXd%|krx-|d%D]}t	jd&||d'�tSWntddd(d)j|�d	td
d*|dddd
g�dtddtd�t|�d+}||d,<t|d-td.��s�t	jd/|d"tj�nt|d0i|d16�t	jd2||�t|�}|rt|�nt |�}|d3kr<|tkr<t|�t}n|	r_t!di|d6�d4}net	jd5|�t"||�d6}t#||�d6}t$di|d6|d6|d76|d86�d9}t%di|d6|d46td:6�tdi|d6�}t&|�}t'|d;�}|d|d<||d<||d<t(|�|d<<|d3|d3<|d=|d=<|d3kr�|d3d>|d?<n|d=d>|d?<t)|�|d@<|d=|d=<|d3|d3<tdddAdBj|�dtdd	i|d?dC6dtd�tdD|t�}|j*|�t	j
dE|�t	jdF|t+j,|��tdddGdHj|�d	td
dI|dddd
g�dtddtd�|S(Ku$
    Create a single Linode VM.
    unameuprofileulinodetvm_ucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingRucloud.filter_eventucreatinguproviderudrivertsock_dirusock_dirt	transportu	transportuCreating Cloud VM %susizeRulabelulocationiu	clonefromu	linode_iduClone of {0}uimageuTOTALRAMuPLANIDuDATACENTERIDu
datacenter_iduplan_iduzError cloning '%s' on Linode.

The following exception was thrown by Linode when trying to clone the specified machine:
%stexc_info_on_loglevelucreateuwError creating %s on Linode

The following exception was thrown by Linode when trying to run the initial deployment:
%su
ERRORARRAYuGError creating %s on Linode

The Linode API returned the following: %s
uERRORMESSAGEurequesting instanceusalt/cloud/{0}/requestingu
requestinguLinodeIDuidR)u	brand_newuCError creating %s on LINODE

while waiting for initial ready statustupdate_argsuLabeluSet name for %s - was linode%s.uprivate_ipsu	config_iduCreating disks for %suDiskIDuroot_disk_iduswap_disk_iduConfigIDu
check_runninguSTATUSustateu
public_ipsiussh_hostupassworduwaiting for sshusalt/cloud/{0}/waiting_for_sshu
ip_addressucloud.bootstrapuCreated Cloud VM '%s'u'%s' VM creation details:
%sucreated instanceusalt/cloud/{0}/createducreatedN(-R
tis_profile_configuredRRR
tAttributeErrort_validate_namet	__utils__R!R#tinfoRRtget_plan_idtget_datacenter_idtKeyErrorRRR R0t	ExceptionR$tloggingtDEBUGRt_clean_datat_wait_for_statust_get_status_id_by_namet
update_linodetdebugtget_private_iptcreate_private_ipt_get_ssh_interfacet
get_config_idtcreate_disk_from_distrotcreate_swap_diskt
create_configR+tget_ipstintt_get_status_descr_by_idtget_passwordtupdatetpprinttpformat(R1RtdataRR-tsizeR,tlocationtclonefrom_nametcloningR%tclone_sourcetresultterrt
error_datatnode_idtprivate_ip_assignmentt
ssh_interfaceR&troot_disk_idtswap_disk_idt	node_datatipststateR((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytcreateCs
	

"








"



	



"
c
C@sf|dkrtd��n|dkr0i}n|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}|dkr�d	}n||||g}x)|D]!}	|	dkr�td
��q�q�Wdj||�}
|dk	r%dj|||�}
ni|d
6|d6|d6|
d6}tddd|�}t|�S(u
    Creates a Linode Configuration Profile.

    name
        The name of the VM to create the config for.

    linode_id
        The ID of the Linode to create the configuration for.

    root_disk_id
        The Root Disk ID to be used for this config.

    swap_disk_id
        The Swap Disk ID to be used for this config.

    data_disk_id
        The Data Disk ID to be used for this config.

    .. versionadded:: 2016.3.0

    kernel_id
        The ID of the kernel to use for this configuration profile.
    uactionu@The create_config function must be called with -f or --function.unameu	linode_iduroot_disk_iduswap_disk_idudata_disk_idu	kernel_idi�u_The create_config functions requires a 'name', 'linode_id', 'root_disk_id', and 'swap_disk_id'.u{0},{1}u{0},{1},{2}uLinodeIDuKernelIDuLabeluDiskListulinodeu
config.createRN(RRRR!RRA(
RRRR%R`Ratdata_disk_idt	kernel_idR.Rtdisklisttconfig_argsRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRLs6		


cC@s�i}|dkr!t|�}nt|�}t|�}|rV|ji|d6�n|rs|ji|d6�ntd��|ji|d6t|�d6|dd6t|||�d6�td	d
d|�}t	|�S(
u	
    Creates the disk for the Linode from the distribution.

    vm\_
        The VM profile to create the disk for.

    linode_id
        The ID of the Linode to create the distribution disk for. Required.

    swap_size
        The size of the disk, in MB.

    u
rootSSHKeyurootPassu&The Linode driver requires a password.uLinodeIDuDistributionIDunameuLabeluSizeulinodeudisk.createfromdistributionRN(
Rt
get_swap_sizetget_pub_keyRPRQRtget_distribution_idt
get_disk_sizeRRA(R1R%t	swap_sizeRtpub_keyt
root_passwordRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRJ^s"	
cC@sgi}|st|�}n|ji|d6|dd6dd6|d6�tddd	|�}t|�S(
u�
    Creates the disk for the specified Linode.

    vm\_
        The VM profile to create the swap disk for.

    linode_id
        The ID of the Linode to create the swap disk for.

    swap_size
        The size of the disk, in MB.
    uLinodeIDunameuLabeluswapuTypeuSizeulinodeudisk.createR(RjRQRRA(R1R%RnRRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRK�s
cC@sVi}|ji|d6|ddd6dd6|d6�tdd	d
|�}t|�S(u1
    Create a data disk for the linode (type is hardcoded to ext4 at the moment)

    .. versionadded:: 2016.3.0

    vm\_
        The VM profile to create the data disk for.

    linode_id
        The ID of the Linode to create the data disk for.

    data_size
        The size of the disk, in MB.

    uLinodeIDunameu_datauLabeluext4uTypeuSizeulinodeudisk.createR(RQRRA(R1R%t	data_sizeRRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytcreate_data_disk�scC@s,i|d6}tddd|�}t|�S(u�
    Creates a private IP for the specified Linode.

    linode_id
        The ID of the Linode to create the IP address for.
    uLinodeIDulinodeu
ip.addprivateR(RRA(R%RRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRG�s
cC@s|dkrtd��ntddddj|�di|d6d	td
dtd�t|�}td
ddi|d6td6�}tddddj|�di|d6d	td
dtd�tjdt�tkrtd|t	j
d�dt�n|S(u�
    Destroys a Linode by name.

    name
        The name of VM to be be destroyed.

    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}/destroyingRunameR2usock_dirR3u	transportulinodeudeleteuLinodeIDu
skipChecksudestroyed instanceusalt/cloud/{0}/destroyeduupdate_cachedirucloud.delete_minion_cachediru:i(RR9R!RRRRRR
Rtsplit(RRR%R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytdestroy�s,


#

$cC@s�|dkrtd��n|dkr0i}n|jdd�}|jdd�}|dkr{|dkr{td��n|dkr�t|�}ntdddi|d	6�d
}i|ddd
6}|S(u�
    Returns a config_id for a given linode.

    .. versionadded:: 2015.8.0

    name
        The name of the Linode for which to get the config_id. Can be used instead
        of ``linode_id``.h

    linode_id
        The ID of the Linode for which to get the config_id. Can be used instead
        of ``name``.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f get_config_id my-linode-config name=my-linode
        salt-cloud -f get_config_id my-linode-config linode_id=1234567
    uactionu@The get_config_id function must be called with -f or --function.unameu	linode_iduTThe get_config_id function requires either a 'name' or a 'linode_id' to be provided.ulinodeuconfig.listRuLinodeIDuDATAiuConfigIDu	config_idN(RRRRRR(RRRR%RR&((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRI�s	 cC@st�|dS(u~
    Returns the Linode Datacenter ID.

    location
        The location, or name, of the datacenter to get the ID from.
    uDATACENTERID(R(RV((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR<)scC@s7tdi|d6�d}tjd|td||�S(uh
    Returns the size of of the root disk in MB.

    vm\_
        The VM to get the disk size for.
    Ru	linode_iduTOTALHDu	disk_sizetdefault(R R
tget_cloud_config_valueR(R1tswapR%t	disk_size((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRm4scC@sEtdi|d6�d}tjd|td||�}|||S(uS
    Return the size of of the data disk in MB

    .. versionadded:: 2016.3.0
    Ru	linode_iduTOTALHDu	disk_sizeRu(R R
RvR(R1RwR%Rxtroot_disk_size((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytget_data_disk_sizeAsc
C@s�tdd�d}tjd|t�}d}x,|D]$}||dkr5|d}|Sq5W|s�tdj||d	tjtg|D]}|djt	�^q������nd
S(uf
    Returns the distribution ID for a VM

    vm\_
        The VM to get the distribution ID for
    uavailu
distributionsuDATAuimageuuLABELuDISTRIBUTIONIDu�The DistributionID for the '{0}' profile could not be found.
The '{1}' instance could not be provisioned. The following distributions are available:
{2}unameN(
RR
RvRRR!RRtsortedtencodet__salt_system_encoding__(R1t
distributionst
vm_image_namet	distro_idtdistro((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRlNs

cC@s>|r%tdddi|d6�}ntdd�}|d}i}x�|D]�}tj|d�}|ddkr}d	}nd
}|j|�dkr�|jiigd	6gd
6|6�n|||j|d�qKW|r:igd	6gd
6}|jtj|��}|r1|d
|d
<|d	|d	<n|}n|S(
u�
    Returns public and private IP addresses.

    linode_id
        Limits the IP addresses returned to the specified Linode ID.
    ulinodeuip.listRuLinodeIDuDATAuLINODEIDuISPUBLICiu
public_ipsuprivate_ipsu	IPADDRESSN(RRt	text_typeRRRQtappend(R%RcRRR]tkeyt_all_ipstmatching_id((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRMks*

	%	cC@s�|dkrtd��n|dkr0i}n|jdd�}|jdd�}|dkr{|dkr{td��n|dkr�t|�}ntdddi|d	6�}|d
dS(
u
    Returns data for a single named Linode.

    name
        The name of the Linode for which to get data. Can be used instead
        ``linode_id``. Note this will induce an additional API call
        compared to using ``linode_id``.

    linode_id
        The ID of the Linode for which to get data. Can be used instead of
        ``name``.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f get_linode my-linode-config name=my-instance
        salt-cloud -f get_linode my-linode-config linode_id=1234567
    uactionu=The get_linode function must be called with -f or --function.unameu	linode_iduBThe get_linode function requires either a 'name' or a 'linode_id'.ulinodeulistRuLinodeIDuDATAiN(RRRRR(RRRR%RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR �s	cC@sjtdd�d}d}x,|D]$}||dkr |d}|Sq W|sftdj|���ndS(	u�
    Returns the Linode ID for a VM from the provided name.

    name
        The name of the Linode from which to get the Linode ID. Required.
    ulinodeulistuDATAuuLABELuLINODEIDu,The specified name, {0}, could not be found.N(RRR!(RtnodesR%tnode((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR�s

cC@s4tjd|tdtjd|tdt�dt�S(uo
    Return the password to use for a VM.

    vm\_
        The configuration to obtain the password from.
    upasswordRuupasswdt
search_global(R
RvRR
(R1((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRP�s	cC@s@t�}||kr4d|kr9tdj|���q4|j�}t|�dkrotdj|���n|d}yt|d�}Wn'tk
r�d}tjd|�nX|dkr�|dkr�d	}n|d}d
j||�}||krtdj|���ntj	d||�|}n||dS(
u�
    Attempts to decode a user-supplied Linode plan label
    into the format in Linode API output

    label
        The label, or name, of the plan to decode.

    Example:
        `Linode 2048` will decode to `Linode 2GB`
    uGBuQInvalid Linode plan ({}) specified - call avail_sizes() for all available optionsiiiu7Failed to decode Linode plan label in Cloud Profile: %suLinodeiuNanodeu{} {}GBu�An outdated Linode plan label was detected in your Cloud Profile (%s). Please update the profile to use the new label format (%s) for the requested Linode plan size.uPLANID(
RRR!RstlenRNt	TypeErrorR#REtwarning(tlabeltsizestplant	plan_typet	plan_sizet	new_label((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyt_decode_linode_plan_label�s6	

	

	cC@sm|dkrtd��n|dkr0i}n|jdd�}|dkr]td��nt|�}|S(u�
    Returns the Linode Plan ID.

    label
        The label, or name, of the plan to get the ID from.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f get_plan_id linode label="Linode 1024"
    uactionu>The show_instance action must be called with -f or --function.ulabelu,The get_plan_id function requires a 'label'.N(RRRR�(RRR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR;s
	cC@stjd|tdt�S(u:
    Return True if a private ip address is requested
    uassign_private_ipRu(R
RvRR
(R1((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRF<scC@stjd|tdt�S(uQ
    Return True if a data disk is requested

    .. versionadded:: 2016.3.0
    uallocate_data_diskRu(R
RvRR
(R1((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyt
get_data_diskEscC@stjd|tdt�S(uc
    Return the SSH pubkey.

    vm\_
        The configuration to obtain the public key from.
    u
ssh_pubkeyR�(R
RvRR
(R1((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRkPscC@stjd|tdd�S(u{
    Returns the amoutn of swap space to be used in MB.

    vm\_
        The VM profile to obtain the swap size from.
    uswapRui�(R
RvR(R1((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRj\scC@sytjd|t�}t�|d}|jd�rJ|jdd�}n|t|�kr`|Stdj|���dS(uN
    Returns the VM's size.

    vm\_
        The VM to get the size for.
    usizeuRAMuLinodeuLinode uu,The specified size, {0}, could not be found.N(	R
RvRRt
startswithtreplaceRNRR!(R1tvm_sizetram((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytget_vm_sizehscC@s(|dkrtd��ntdt�S(u�
    Returns a list of linodes, keeping only a brief listing.

    CLI Example:

    .. code-block:: bash

        salt-cloud -Q
        salt-cloud --query
        salt-cloud -f list_nodes my-linode-config

    .. note::

        The ``image`` label only displays information about the VM's distribution vendor,
        such as "Debian" or "RHEL" and does not display the actual image name. This is
        due to a limitation of the Linode API.
    uactionu=The list_nodes function must be called with -f or --function.tfull(Rt
_list_linodesR
(R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyt
list_nodes}scC@s(|dkrtd��ntdt�S(u�
    List linodes, with all available information.

    CLI Example:

    .. code-block:: bash

        salt-cloud -F
        salt-cloud --full-query
        salt-cloud -f list_nodes_full my-linode-config

    .. note::

        The ``image`` label only displays information about the VM's distribution vendor,
        such as "Debian" or "RHEL" and does not display the actual image name. This is
        due to a limitation of the Linode API.
    uactionuBThe list_nodes_full function must be called with -f or --function.R�(RR�R(R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytlist_nodes_full�scC@s�|dkrtd��ni}tdd�d}xS|D]K}|d}itj|d�d6tt|d	��d
6}|||<q;W|S(u�
    Return a list of the VMs that are on the provider. Only a list of VM names and
    their state is returned. This is the minimum amount of information needed to
    check for existing VMs.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_nodes_min my-linode-config
        salt-cloud --function list_nodes_min my-linode-config
    uactionuAThe list_nodes_min function must be called with -f or --function.ulinodeulistuDATAuLABELuLINODEIDuiduSTATUSustate(RRRR�RORN(RRR�R�Rt	this_node((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytlist_nodes_min�s

cC@stdt�td|�S(uP
    Return a list of the VMs that are on the provider, with select fields.
    ucloud.list_nodes_selectuquery.selection(R9R�R(R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytlist_nodes_select�scC@s�|dkrtd��nt|�}tdddi|d6�}t|�}|d}t||�s|tjd|�tS|S(	u�
    Reboot a linode.

    .. versionadded:: 2015.8.0

    name
        The name of the VM to reboot.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a reboot vm_name
    uactionu<The show_instance action must be called with -a or --action.ulinodeurebootRuLinodeIDuJobIDuReboot failed for %s.(RRRRAR"R#R$R
(RRR]RRTt
reboot_jid((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytreboot�s
cC@s�|dkrtd��nt|�}tdi|d6�}t|�}t|d�}i|dd6|dd	6|d
d6|dd
6t|�d6|dd6|dd6}|S(u
    Displays details about a particular Linode VM. Either a name or a linode_id must
    be provided.

    .. versionadded:: 2015.8.0

    name
        The name of the VM for which to display details.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a show_instance vm_name

    .. note::

        The ``image`` label only displays information about the VM's distribution vendor,
        such as "Debian" or "RHEL" and does not display the actual image name. This is
        due to a limitation of the Linode API.
    uactionu<The show_instance action must be called with -a or --action.Ru	linode_iduSTATUSuLINODEIDuiduDISTRIBUTIONVENDORuimageuLABELunameuTOTALRAMusizeustateuprivate_ipsu
public_ips(RRR RMRNRO(RRR]RbRcRdR((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyt
show_instance�s
cC@sA|dkrtd��ntdj|di�}|sJtd��n|jdd�}|jd�}t|�d	ks�|d
dkr�td��ntd
i|dd6�}tdddi|d6�dd}i}|d|d<|dd|d<|dd|d<|d|d<|dd|d<i||d6S( u
    Show pricing for a particular profile. This is only an estimate, based on
    unofficial pricing sources.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt-cloud -f show_pricing my-linode-config profile=my-linode-profile
    ufunctionu>The show_instance action must be called with -f or --function.uprofilesuprofileu$The requested profile was not found.uprovideru0:0u:iiulinodeu0The requested profile does not belong to Linode.RusizeulabeluavailulinodeplansRuPlanIDuDATAiuHOURLYuper_houriuper_dayiuper_weekuPRICEu	per_monthiuper_year(RRRRRsR�R;R(RRtprofiletprovidertcompsR-RR((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytshow_pricing&s*
"$cC@s�|dkrtd��nt|�}tdi|d6�}|ddkrmitd6dd6d	d
6dd6Std
ddi|d6�d}t||d�r�id	d
6dd6td6Sidd6td6SdS(u�
    Start a VM in Linode.

    name
        The name of the VM to start.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a stop vm_name
    uactionu4The start action must be called with -a or --action.Ru	linode_iduSTATUSiusuccessustartuRunningustateuMachine already runningumsgulinodeubootRuLinodeIDuDATAuJobIDN(RRR RRR"R
(RRR]R�R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytstartSs"

 

cC@s�|dkrtd��nt|�}tdi|d6�}|ddkrfitd6dd	6d
d6Stdd
di|d6�d}t||d�r�idd	6dd6td6Sidd6td6SdS(u�
    Stop a VM in Linode.

    name
        The name of the VM to stop.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a stop vm_name
    uactionu3The stop action must be called with -a or --action.Ru	linode_iduSTATUSiusuccessuStoppedustateuMachine already stoppedumsgulinodeushutdownRuLinodeIDuDATAuJobIDustopN(RRR RRR"R
(RRR]R�R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pytstopys 

 

cC@s3|ji|d6�tddd|�}t|�S(u�
    Updates a Linode's properties.

    linode_id
        The ID of the Linode to shutdown. Required.

    update_args
        The args to update the Linode with. Must be in dictionary form.
    uLinodeIDulinodeuupdateR(RQRRA(R%R5RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRD�s
cC@s;i}|j|d�|s7|d}|j|�n|S(u�
    Returns the DATA response from a Linode API query as a single pre-formatted dictionary

    api_response
        The query to be cleaned.
    uDATA(RQ(tapi_responseRTt
response_data((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRA�s
c
C@stdd�d}t�}i}x�|D]�}i}tj|d�}||d<|d|d<|d|d	<|d
|d<t|d�}t|�|d
<xHtj|�D]7\}}	||kr�|	d|d<|	d|d<q�q�W|r�||d<n|||d<q)W|S(u9
    Helper function to format and parse linode data
    ulinodeulistuDATAuLINODEIDuiduDISTRIBUTIONVENDORuimageuLABELunameuTOTALRAMusizeuSTATUSustateuprivate_ipsu
public_ipsuextra(RRMRR�RNROt	iteritems(
R�R�RcRR�R�R%RdR�tval((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR��s(	


uGETuhttps://api.linode.com/cC@sXt�}tjd|tdtdd�}tjd|tdt�}	t|t�s]i}nd|j�kr||	|d<n|r�d|j�kr�dj||�|d<n|d"kr�i}n|d	kr�d
|d<nt
}
|dkr�t}
nttj
tjj�j���}t|kr6tj|�ntd
||d|d|d|d|
dddt
dt
dddgdt�	}d|dkr|ddrg}
xH|ddD]8}|d}|dkr�td��q�|
j|�q�Wtdjdj|
����qnttj
tjj�j���atjd |d!�|dS(#u,
    Make a web call to the Linode API.
    uratelimit_sleepR�Ruiuapikeyuapi_keyu
api_actionu{0}.{1}uPOSTuapplication/jsonuAcceptuDELETEu
http.querytparamsRTtheader_dicttdecodetdecode_typeujsonttextR)thide_fieldsurootPasstoptsu
ERRORARRAYudictuERRORMESSAGEuAuthentication failedu$Linode API Key is expired or invalidu Linode API reported error(s): {}u, uLinode Response Status Code: %sustatusN(R	R
RvRR
t
isinstancetdicttkeysR!RRRNttimetmktimetdatetimetnowt	timetupletLASTCALLtsleepR9RR�RtjoinR#RE(tactiontcommandRtmethodR�RTturlR1tratelimit_sleeptapikeyR�R�RZt
error_listR$tmsg((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR�s^		
	
	$	
!$i,cC@s�d}t||�}x�td|�D]�}tdddi|d6�d}|dd|krx|dd	d
krxtStj|�tj|s�tjntj	d||�q&Wt
S(u8
    Wait for a Job to return.

    linode_id
        The ID of the Linode to wait on. Required.

    job_id
        The ID of the job to wait for.

    timeout
        The amount of time to wait for a status to update.

    quiet
        Log status updates to debug logs when True. Otherwise, logs to info.
    iiulinodeujob.listRuLinodeIDuDATAuJOBIDuHOST_SUCCESSiu&Still waiting on Job %s for Linode %s.(RNRRRR�R�R#R?tINFOR@R
(R%tjob_idttimeouttquiettintervalt
iterationstitjobs_result((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR"1s(
c
C@s�|dkrtd�}nt|�}d}t||�}x�td|�D]x}tdi|d6�}|d|kr}tSt|d�}	tj|�t	j	|s�t
jnt
jd||	|�qMWt
S(	uI
    Wait for a certain status from Linode.

    linode_id
        The ID of the Linode to wait on. Required.

    status
        The status to look for to update.

    timeout
        The amount of time to wait for a status to update.

    quiet
        Log status updates to debug logs when False. Otherwise, logs to info.
    u	brand_newiiRu	linode_iduSTATUSu/Status for Linode %s is '%s', waiting for '%s'.N(RRCRORNRR RR�R�R#R?R�R@R
(
R%R)R�R�tstatus_desc_waitingR�R�R�RZtstatus_desc_result((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRBSs 
cC@sNx;tjt�D]*\}}|dt|�kr|dSqWtj|d�S(uO
    Return linode status by ID

    status_id
        linode VM status ID
    ucodeudescrN(RR�t
LINODE_STATUSRNRR(t	status_idtstatus_nametstatus_data((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRO}scC@stj|i�jdd�S(uy
    Return linode status description by internalstatus name

    status_name
        internal linode VM status name
    ucodeN(R�RR(R�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRC�scC@s�tj|�}t|�}tjd�}|dksB|dkrKt}n!tj||�sft}nt}|tkr�tj	d�n|S(u�
    Checks if the provided name fits Linode's labeling parameters.

    .. versionadded:: 2015.5.6

    name
        The VM name to validate
    u&^[a-zA-Z0-9][A-Za-z0-9_-]*[a-zA-Z0-9]$ii0u�A Linode label may only contain ASCII letters or numbers, dashes, and underscores, must begin and end with letters or numbers, and be at least three characters in length.(
RR�R�tretcompileR
tmatchRR#R�(Rtname_lengthtregexR((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyR8�s			
cC@stjd|tdddt�S(uj
    Return the ssh_interface type to connect to. Either 'public_ips' (default)
    or 'private_ips'.
    u
ssh_interfaceRuu
public_ipsR�(R
RvRR
(R1((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyRH�s(St__doc__t
__future__RRRR?RRR�R�R�tsalt.configR
tsalt.extRtsalt.ext.six.movesRtsalt.exceptionsRRRRt	getLoggert__name__R#RNR�R�R�R�R�RRR	RRRRR+R0ReRLRJRKRrRGRtRIR<RmRzRlRMR RRPR�R;RFR�RkRjR�R�R�R�R�R�R�R�R�R�RDRAR
R�RRR"RBRORCR8RH(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.pyt<module>s�"$	
	W0	�B)	
/-		
	
	(+			8 						#	 +-&%	!J"*	
	
	

Zerion Mini Shell 1.0