%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddlZddlZyddlZe	Z
Wnek
rueZ
nXddl
jZddlmZddlmZmZddlZddlmZmZmZmZddlmZeee��Zeee��Zeee��Zeee��Zeje�Z dZ!d	�Z"d
�Z#dd�Z%dd�Z&dd
�Z'dd�Z(dde	d�Z)d�Z*d�Z+dd�Z,dd�Z-dd�Z.d�Z/dd�Z0dd�Z1d�Z2dS(u�
Packet Cloud Module Using Packet's Python API Client
===========================================

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

Use of this module only requires the ``token`` parameter.

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

The Packet profile requires ``size``, ``image``, ``location``,  ``project_id``

Optional profile parameters:

 - ``storage_size`` -  min value is 10, defines Gigabytes of storage that will be attached to device.
 - ``storage_tier`` - storage_1 - Standard Plan, storage_2 - Performance Plan
 - ``snapshot_count`` - int
 - ``snapshot_frequency`` - string - possible values:
    - 1min
    - 15min
    - 1hour
    - 1day
    - 1week
    - 1month
    - 1year

This driver requires Packet's client library: https://pypi.python.org/pypi/packet-python

.. code-block:: yaml

    packet-provider:
        minion:
            master: 192.168.50.10
        driver: packet
        token: ewr23rdf35wC8oNjJrhmHa87rjSXzJyi
        private_key: /root/.ssh/id_rsa

    packet-profile:
        provider: packet-provider
        size: baremetal_0
        image: ubuntu_16_04_image
        location: ewr1
        project_id: a64d000b-d47c-4d26-9870-46aac43010a6
        storage_size: 10
        storage_tier: storage_1
        storage_snapshot_count: 1
        storage_snapshot_frequency: 15min
i(tabsolute_importtprint_functiontunicode_literalsN(trange(tSaltCloudExceptiontSaltCloudSystemExit(tget_sizet	get_imagetscriptt
show_instance(tnamespaced_functionupacketcC@s-ttkrtdfSt�tkr)tStS(u#
    Check for Packet configs.
    u*The packet python library is not installed(t
HAS_PACKETtFalsetget_configured_providert__virtualname__(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyt__virtual__^s

cC@stjttptd�S(u/
    Return the first configured instance.
    utoken(utoken(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyR
js	cC@sq|dkrtd��ni}t�}tjd|d�}i}x$|j�D]}|j||j<qSW|S(u�
    Return available Packet os images.

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-images packet-provider
        salt-cloud -f avail_images packet-provider
    uactionu?The avail_images function must be called with -f or --function.t
auth_tokenutoken(RR
tpackettManagertlist_operating_systemst__dict__tname(tcalltrettvm_tmanagert	os_system((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pytavail_imagesus	cC@sk|dkrtd��nt�}tjd|d�}i}x$|j�D]}|j||j<qMW|S(u�
    Return available Packet datacenter locations.

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-locations packet-provider
        salt-cloud -f avail_locations packet-provider
    uactionuBThe avail_locations function must be called with -f or --function.Rutoken(RR
RRtlist_facilitiesRR(RRRRtfacility((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pytavail_locations�s	cC@sk|dkrtd��nt�}tjd|d�}i}x$|j�D]}|j||j<qMW|S(u�
    Return available Packet sizes.

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-sizes packet-provider
        salt-cloud -f avail_sizes packet-provider
    uactionuBThe avail_locations function must be called with -f or --function.Rutoken(RR
RRt
list_plansRR(RRRRtplan((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pytavail_sizes�s	cC@sk|dkrtd��nt�}tjd|d�}i}x$|j�D]}|j||j<qMW|S(u�
    Return available Packet projects.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f avail_projects packet-provider
    uactionuAThe avail_projects function must be called with -f or --function.Rutoken(RR
RRt
list_projectsRR(RRRRtproject((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pytavail_projects�s
	i�cC@s�|d	krd}nd}t||�}t�}tjd|d�}x�td|�D]{}	t|djd|��}
|
|�}|j|kr�|St	j
|�tj|s�tj
ntjd||j|�qZW|S(
uu
    Wait for a certain status from Packet.
    status_type
        device or volume
    object_id
        The ID of the Packet device or volume to wait on. Required.
    status
        The status to wait for.
    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.
    uokiRutokeniuget_{status_type}tstatus_typeu/Status for Packet %s is '%s', waiting for '%s'.N(tNonetintR
RRRtgetattrtformattstatettimetsleeptlogtloggingtINFOtDEBUG(R)t	object_idtstatusttimeouttquiettintervalt
iterationsRRtit
get_objecttobj((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyt_wait_for_status�s"		
c	C@s�y�|dr<tjttpt|dd|�tkr<tStjd�\}}td||d|d}|jd�s�|jd�r@ddg}x;|D]3}|j|�dkr�t	j
d|d�tSq�Wt�}x]|j�D]L}|d	|d
kr�d|dkr9t	j
d
|d	|d�tSq�q�Wn|jd�s^|jd�r�ddg}x>|D]3}|j|�dkrqt	j
d|d�tSqqWnWnt
k
r�nXtS(NuprofileRu:u	providersuprofilesustorage_sizeustorage_tierucboth storage_size and storage_tier required for profile %s. Please check your profile configurationucodeulocationustorageufeaturesukChosen location %s for profile %s does not support storage feature. Please check your profile configurationustorage_snapshot_countustorage_snapshot_frequencyu{both storage_snapshot_count and storage_snapshot_frequency required for profile %s. Please check your profile configuration(Rtis_profile_configuredRRRRtsplittgetR*R1terrorR"tvaluestAttributeErrortTrue(Rtaliastdrivertprofile_datat
required_keystkeyt	locationstlocation((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyR?sF	

	

c	
C@s�|d}t|�stStddddj|�dtdd|dd	d
dg�dtd
dtd�tjd|�tjd|d�}tddddj|d�dtdd|dd	d
dg�dtd
dtd�|j	d|dd|d|dd|dd|d�}t
d|jd d!�}|jd!krgtj
d"|d#tj�nt|�}|d$kr�xl|jD](}|d%tkr�|d&|d'<Pq�q�Wn6x3|jD](}|d%tkr�|d&|d'<Pq�q�Wtjd(|td)td*d;�}||d+<||d(<td,|t�}|ji|jd6�|jd-�r<|jd.�r<|j|dd/j|�|jd-�|jd.�|jd�d0|jd1d2�d3|jd4��}|j|j�t
d5|jd d!�}|jd!kr"tj
d"|d#tj�n|ji|jd56�ntjd6|�tjd7|tj|j��tddd8d9j|�dtdd:|dd	d
dg�dtd
dtd�|S(<u$
    Create a single Packet VM.
    unameucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingtargsucloud.filter_eventucreatinguprofileuproviderudrivertsock_dirusock_dirt	transportu	transportuCreating Packet VM %sRutokenurequesting instanceusalt/cloud/{0}/requestingu
requestingt
project_idu
project_idthostnameR$usizeR!ulocationtoperating_systemuimageudeviceR6uactiveuCError creating %s on PACKET

while waiting for initial ready statustexc_info_on_logleveluprivate_ipsupublicuaddressussh_hostuprivate_keyt
search_globaltdefaultukey_filenameucloud.bootstrapustorage_tierustorage_sizeu{0}_storagetsnapshot_countustorage_snapshot_countitsnapshot_frequencyustorage_snapshot_frequencyuvolumeuCreated Cloud VM '%s'u'%s' VM creation details:
%sucreated instanceusalt/cloud/{0}/createducreatedN(R?Rt	__utils__R-RR1tinfoRRt
create_deviceR>tidR.RBR2R4t_get_ssh_interfacetip_addressesRERtget_cloud_config_valueR*tupdateRRAt
create_volumetattachtdebugtpprinttpformat(	RRRtdevicet
ssh_interfacetiptkey_filenameRtvolume((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pytcreateDs�
"
"



-"
cC@sI|dkrtd��ni}x!t�D]}|j||j<q+W|S(u�
    List devices, with all available information.

    CLI Example:

    .. code-block:: bash

        salt-cloud -F
        salt-cloud --full-query
        salt-cloud -f list_nodes_full packet-provider

    ..
    uactionuBThe list_nodes_full function must be called with -f or --function.(Rtget_devices_by_tokenRRQ(RRRe((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pytlist_nodes_full�scC@sZ|dkrtd��ni}x2t�D]'}i|jd6|jd6||j<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 packet-provider
        salt-cloud --function list_nodes_min packet-provider
    uactionuAThe list_nodes_min function must be called with -f or --function.uidustate(RRkR[R.RQ(RRRe((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pytlist_nodes_min�s%cC@s tjjjt�td|�S(uP
    Return a list of the VMs that are on the provider, with select fields.
    uquery.selection(tsalttutilstcloudtlist_nodes_selectRlR(R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyRq�scC@sft�}tjd|d�}g}x:|dD].}|d|}|j|j|d��q0W|S(NRutokenuprofilesu
project_id(R
RRtextendtlist_devices(RRtdevicestprofile_nametprofile((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyRk�s	cC@sI|dkrtd��ni}x!t�D]}|j||j<q+W|S(u�
    Returns a list of devices, keeping only a brief listing.
    CLI Example:
    .. code-block:: bash
        salt-cloud -Q
        salt-cloud --query
        salt-cloud -f list_nodes packet-provider
    ..
    uactionu=The list_nodes function must be called with -f or --function.(RRkRRQ(RRRe((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyt
list_nodesscC@sO|dkrtd��ntddddj|�di|d6d	td
dtd�t�}tjd
|d�}t�}||}x\|j�D]N}xE|j	|j
�D]1}|j|dkr�|j�|j
�Pq�q�Wq�W|jdjd|d�dd�tddddj|�di|d6d	td
dtd�iS(u�
    Destroys a Packet device by name.

    name
        The hostname of VM to be be destroyed.

    CLI Example:

    .. code-block:: bash

        salt-cloud -d name
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.ucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingRMunameRNusock_dirROu	transportRutokenuidudevices/{id}R[ttypeuDELETEudestroyed instanceusalt/cloud/{0}/destroyed(RRXR-RR
RRRmR&tlist_volumesR[tattached_totdetachtdeletetcall_api(RRRRtnodestnodeR'Ri((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pytdestroys:


		


#

cC@stjd|tdddt�S(uj
    Return the ssh_interface type to connect to. Either 'public_ips' (default)
    or 'private_ips'.
    u
ssh_interfaceRUu
public_ipsRT(RR^RR(R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyR\Ts(3t__doc__t
__future__RRRR2RcR/RRERtImportErrorRtsalt.configRtsalt.ext.six.movesRtsalt.exceptionsRRtsalt.utils.cloudRntsalt.cloud.libcloudfuncsRRRR	tsalt.utils.functoolsR
tglobalst	getLoggert__name__R1RRR
R*RR"R%R(R>R?RjRlRmRqRkRwR�R\(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/packet.pyt<module>1sJ


"		(	9	q		9

Zerion Mini Shell 1.0