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

�
���^c@@sYdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Zddlj
Z
ddlmZddlmZmZmZmZygddlZddlZddlZddlZejjjej�ejjjd�kdfZWnek
r1edfZnXej e!�Z"d	Z#d
�Z$d�Z%d�Z&d
�Z'd�Z(d�Z)ddd�Z+ddd�Z,dd�Z-ddd�Z.ddd�Z/ddd�Z0ddd�Z1ddd�Z2ddd�Z3dddd�Z4d�Z5ddd�Z6d�Z7ddd�Z8dddd�Z9dS( u� 
Openstack Cloud Driver
======================

:depends: `shade>=1.19.0 <https://pypi.python.org/pypi/shade>`_

OpenStack is an open source project that is in use by a number a cloud
providers, each of which have their own ways of using it.

This OpenStack driver uses a the shade python module which is managed by the
OpenStack Infra team.  This module is written to handle all the different
versions of different OpenStack tools for salt, so most commands are just passed
over to the module to handle everything.

Provider
--------

There are two ways to configure providers for this driver.  The first one is to
just let shade handle everything, and configure using os-client-config_ and
setting up `/etc/openstack/clouds.yml`.

.. code-block:: yaml

    clouds:
      democloud:
        region_name: RegionOne
        auth:
          username: 'demo'
          password: secret
          project_name: 'demo'
          auth_url: 'http://openstack/identity'

And then this can be referenced in the salt provider based on the `democloud`
name.

.. code-block:: yaml

    myopenstack:
      driver: openstack
      cloud: democloud
      region_name: RegionOne

This allows for just using one configuration for salt-cloud and for any other
openstack tools which are all using `/etc/openstack/clouds.yml`

The other method allows for specifying everything in the provider config,
instead of using the extra configuration file.  This will allow for passing
salt-cloud configs only through pillars for minions without having to write a
clouds.yml file on each minion.abs

.. code-block:: yaml

    myopenstack:
      driver: openstack
      region_name: RegionOne
      auth:
        username: 'demo'
        password: secret
        project_name: 'demo'
        auth_url: 'http://openstack/identity'

Or if you need to use a profile to setup some extra stuff, it can be passed as a
`profile` to use any of the vendor_ config options.

.. code-block:: yaml

    myrackspace:
      driver: openstack
      profile: rackspace
      auth:
        username: rackusername
        api_key: myapikey
      region_name: ORD
      auth_type: rackspace_apikey

And this will pull in the profile for rackspace and setup all the correct
options for the auth_url and different api versions for services.


Profile
-------

Most of the options for building servers are just passed on to the
create_server_ function from shade.

The salt specific ones are:

  - ssh_key_file: The path to the ssh key that should be used to login to the machine to bootstrap it
  - ssh_key_file: The name of the keypair in openstack
  - userdata_template: The renderer to use if the userdata is a file that is templated. Default: False
  - ssh_interface: The interface to use to login for bootstrapping: public_ips, private_ips, floating_ips, fixed_ips

.. code-block:: yaml

    centos:
      provider: myopenstack
      image: CentOS 7
      size: ds1G
      ssh_key_name: mykey
      ssh_key_file: /root/.ssh/id_rsa

This is the minimum setup required.

If metadata is set to make sure that the host has finished setting up the
`wait_for_metadata` can be set.

.. code-block:: yaml

    centos:
      provider: myopenstack
      image: CentOS 7
      size: ds1G
      ssh_key_name: mykey
      ssh_key_file: /root/.ssh/id_rsa
      meta:
        build_config: rack_user_only
      wait_for_metadata:
        rax_service_level_automation: Complete
        rackconnect_automation_status: DEPLOYED

Anything else from the create_server_ docs can be passed through here.

- **image**: Image dict, name or ID to boot with. image is required
            unless boot_volume is given.
- **flavor**: Flavor dict, name or ID to boot onto.
- **auto_ip**: Whether to take actions to find a routable IP for
              the server. (defaults to True)
- **ips**: List of IPs to attach to the server (defaults to None)
- **ip_pool**: Name of the network or floating IP pool to get an
              address from. (defaults to None)
- **root_volume**: Name or ID of a volume to boot from
                  (defaults to None - deprecated, use boot_volume)
- **boot_volume**: Name or ID of a volume to boot from
                  (defaults to None)
- **terminate_volume**: If booting from a volume, whether it should
                       be deleted when the server is destroyed.
                       (defaults to False)
- **volumes**: (optional) A list of volumes to attach to the server
- **meta**: (optional) A dict of arbitrary key/value metadata to
           store for this server. Both keys and values must be
           <=255 characters.
- **files**: (optional, deprecated) A dict of files to overwrite
            on the server upon boot. Keys are file names (i.e.
            ``/etc/passwd``) and values
            are the file contents (either as a string or as a
            file-like object). A maximum of five entries is allowed,
            and each file must be 10k or less.
- **reservation_id**: a UUID for the set of servers being requested.
- **min_count**: (optional extension) The minimum number of
                servers to launch.
- **max_count**: (optional extension) The maximum number of
                servers to launch.
- **security_groups**: A list of security group names
- **userdata**: user data to pass to be exposed by the metadata
            server this can be a file type object as well or a
            string.
- **key_name**: (optional extension) name of previously created
            keypair to inject into the instance.
- **availability_zone**: Name of the availability zone for instance
                        placement.
- **block_device_mapping**: (optional) A dict of block
            device mappings for this server.
- **block_device_mapping_v2**: (optional) A dict of block
            device mappings for this server.
- **nics**:  (optional extension) an ordered list of nics to be
            added to this server, with information about
            connected networks, fixed IPs, port etc.
- **scheduler_hints**: (optional extension) arbitrary key-value pairs
                  specified by the client to help boot an instance
- **config_drive**: (optional extension) value for config drive
                  either boolean, or volume-id
- **disk_config**: (optional extension) control how the disk is
                  partitioned when the server is created.  possible
                  values are 'AUTO' or 'MANUAL'.
- **admin_pass**: (optional extension) add a user supplied admin
                 password.
- **timeout**: (optional) Seconds to wait, defaults to 60.
              See the ``wait`` parameter.
- **reuse_ips**: (optional) Whether to attempt to reuse pre-existing
                           floating ips should a floating IP be
                           needed (defaults to True)
- **network**: (optional) Network dict or name or ID to attach the
              server to.  Mutually exclusive with the nics parameter.
              Can also be be a list of network names or IDs or
              network dicts.
- **boot_from_volume**: Whether to boot from volume. 'boot_volume'
                       implies True, but boot_from_volume=True with
                       no boot_volume is valid and will create a
                       volume from the image and use that.
- **volume_size**: When booting an image from volume, how big should
                  the created volume be? Defaults to 50.
- **nat_destination**: Which network should a created floating IP
                      be attached to, if it's not possible to
                      infer from the cloud's configuration.
                      (Optional, defaults to None)
- **group**: ServerGroup dict, name or id to boot the server in.
            If a group is provided in both scheduler_hints and in
            the group param, the group param will win.
            (Optional, defaults to None)

.. note::

    If there is anything added, that is not in this list, it can be added to an `extras`
    dictionary for the profile, and that will be to the create_server function.

.. _create_server: https://docs.openstack.org/shade/latest/user/usage.html#shade.OpenStackCloud.create_server
.. _vendor: https://docs.openstack.org/os-client-config/latest/user/vendor-support.html
.. _os-client-config: https://docs.openstack.org/os-client-config/latest/user/configuration.html#config-files
i(tabsolute_importtprint_functiontunicode_literalsN(tsix(tSaltCloudSystemExittSaltCloudExecutionTimeouttSaltCloudExecutionFailuretSaltCloudConfigErroru1.19.0u0Please install newer version of shade: >= 1.19.0u#Install pypi module shade >= 1.19.0u	openstackcC@s*t�tkrtSt�tkr&tStS(u*
    Check for OpenStack dependencies
    (tget_configured_providertFalsetget_dependenciest	HAS_SHADEt__virtualname__(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyt__virtual__�s
cC@s>tjttptd�}|r%|Stjttp7td�S(u/
    Return the first configured instance.
    uauthuregion_nameucloud(uauthuregion_name(uclouduregion_name(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(tprovider((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyRs	cC@srtstjd�tSttd�rFtdrFtjtd�tSitdd6tdd6}tjt|�S(u*
    Warn if dependencies aren't met.
    u"shade" not foundu__len__iiushadeuos_client_config(RtlogtwarningR	thasattrRtcheck_driver_dependenciesR(tdeps((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyR
s
cC@s�tjd|tdddt�}tj}|dkrBtj}nx=|D]5}ytj||�|SWqItk
r}qIqIXqIWtS(uT
    Return the preferred Internet protocol. Either 'ipv4' (default) or 'ipv6'.
    uprotocoltdefaultuipv4t
search_globaluipv6(	Rtget_cloud_config_valueRR	tsockettAF_INETtAF_INET6t	inet_ptont	Exception(tvm_tipstprototfamilytip((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pytpreferred_ip(s	

cC@stjd|tdddt�S(uj
    Return the ssh_interface type to connect to. Either 'public_ips' (default)
    or 'private_ips'.
    u
ssh_interfaceRu
public_ipsR(RRRR	(R ((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyt
ssh_interface<scC@s�ttkrttSt�}|jdd�}|dk	r]tdtjj|�|�}nt	j
jdd|�}tdk	r�|tt<n|S(u5
    Return a conn object for the passed VM data
    uprofileudictupdate.updatetcloud_configN(Rt__context__RtpoptNonet	__utils__tos_client_configtvendorstget_profiletshadetopenstackcloudtOpenStackCloud(R tprofiletconn((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pytget_connDs	"
c
C@s�|dkrtd��ni}xYtd|�j�D]B\}}x3d
D]+}|j|i�j||j|��qJWq7W|S(ux
    Return a list of VMs

    CLI Example

    .. code-block:: bash

        salt-cloud -f list_nodes myopenstack

    uactionu=The list_nodes function must be called with -f or --function.R3uidunameusizeustateuprivate_ipsu
public_ipsufloating_ipsu	fixed_ipsuimage(	uidunameusizeustateuprivate_ipsu
public_ipsufloating_ipsu	fixed_ipsuimage(Rtlist_nodes_fulltitemst
setdefaulttget(R3tcalltrettnodetinfotkey((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyt
list_nodesTs"
-cC@s{|dkrtd��n|dkr3t�}ni}x;|jdt�D]'}i|jd6|jd6||j<qLW|S(u�
    Return a list of VMs with minimal information

    CLI Example

    .. code-block:: bash

        salt-cloud -f list_nodes_min myopenstack

    uactionuAThe list_nodes_min function must be called with -f or --function.tbareuidustateN(RR*R4tlist_serverstTruetidtstatustname(R3R9R:R;((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pytlist_nodes_minks%upubliccC@s�g}x�|jj�D]�\}}x�|D]�}|dkrd||jd�krd|j|d�q)|dkr�td|d�r�|j|d�q)|dkr)td|d�r)|j|d�q)q)WqW|S(	NufloatingufixeduOS-EXT-IPS:typeuaddrupublicucloud.is_public_ipuprivate(ufloatingufixed(t	addressesR6R8tappendR+(R;t	addr_typeR:t_t	interfacetaddr((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyt_get_ips�s
! !cC@s�|dkrtd��n|dkr3t�}ni}xF|jdt�D]2}t|�||j<|j||jd<|j||jd<|jj||jd<|j	||jd<t
|d�||jd	<t
|d
�||jd<t
|d�||jd
<t
|d�||jd<t|jt
j�rL|j||jd<qLt|j|jj�d|jj�||jd<qLW|S(u�
    Return a list of VMs with all the information about them

    CLI Example

    .. code-block:: bash

        salt-cloud -f list_nodes_full myopenstack

    uactionuBThe list_nodes_full function must be called with -f or --function.tdetaileduidunameusizeustateuprivateuprivate_ipsupublicu
public_ipsufloatingufloating_ipsufixedu	fixed_ipsuimageN(RR*R4R@RAtdictRDRBtflavorRCRLt
isinstancetimageRtstring_typestgetattrt	get_image(R3R9R:R;((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyR5�s(6cC@s<|dkrtd��ntdt|d�td|�S(u�
    Return a list of VMs with the fields from `query.selection`

    CLI Example

    .. code-block:: bash

        salt-cloud -f list_nodes_full myopenstack

    uactionuDThe list_nodes_select function must be called with -f or --function.ucloud.list_nodes_selectufunctionuquery.selection(RR+R>R(R3R9((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pytlist_nodes_select�s
cC@s7|dkrtd��n|dkr3t�}n|j|dt�}t|�}|j|d<|j|d<|j|j	j�j|d<|j
|d<t|d�|d	<t|d
�|d<t|d�|d
<t|d�|d<t|j
tj�r|j
|d<n+t|j|j
j�d|j
j�|d<|S(u�
    Get VM on this OpenStack account

    name

        name of the instance

    CLI Example

    .. code-block:: bash

        salt-cloud -a show_instance myserver

    uactionu<The show_instance action must be called with -a or --action.R?uidunameusizeustateuprivateuprivate_ipsupublicu
public_ipsufloatingufloating_ipsufixedu	fixed_ipsuimageN(RR*R4t
get_serverRARNRBRDt
get_flavorRORCRLRPRQRRRRSRT(RDR3R9R;R:((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyt
show_instance�s&


+cC@s=|dkrtd��n|dkr3t�}n|j�S(u�
    List available images for OpenStack

    CLI Example

    .. code-block:: bash

        salt-cloud -f avail_images myopenstack
        salt-cloud --list-images myopenstack

    uactionu`The avail_images function must be called with -f or --function, or with the --list-images optionN(RR*R4tlist_images(R3R9((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pytavail_images�scC@s=|dkrtd��n|dkr3t�}n|j�S(u�
    List available sizes for OpenStack

    CLI Example

    .. code-block:: bash

        salt-cloud -f avail_sizes myopenstack
        salt-cloud --list-sizes myopenstack

    uactionu^The avail_sizes function must be called with -f or --function, or with the --list-sizes optionN(RR*R4tlist_flavors(R3R9((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pytavail_sizesscC@s=|dkrtd��n|dkr3t�}n|j�S(u�
    List networks for OpenStack

    CLI Example

    .. code-block:: bash

        salt-cloud -f list_networks myopenstack

    uactionu?The list_networks function must be called with -f or --functionN(RR*R4t
list_networks(R3R9((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyR]scC@s�|dkrtd��n|dkr3t�}n|dksZt|t�rid|kritd��n|jdi|dd6�S(u�
    List subnets in a virtual network

    network
        network to list subnets of

    .. code-block:: bash

        salt-cloud -f list_subnets myopenstack network=salt-net

    uactionu?The list_subnets function must be called with -f or --function.unetworkuA `network` must be specifiedtfiltersN(RR*R4RPRNtlist_subnets(R3R9tkwargs((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyR_.s'cK@s�i tjd6tjd6tjd6td6td6tjd6tjd6tjd6td	6td
6td6td6tjd
6td6tjd6tjd6td6td6td6td6td6tjd6tjd6td6td6td6td6td6td6tjd6tjd6tjd 6}|jd!i�}xrtj|j��D][\}}||kr�t	|||�riq8nt
jd"||||�n|j|�q8Wtd#||�S($u5
    Sanatize kwargs to be sent to create_server
    unameuimageuflavoruauto_ipuipsuip_pooluroot_volumeuboot_volumeuterminate_volumeuvolumesumetaufilesureservation_idusecurity_groupsukey_nameuavailability_zoneublock_device_mappingublock_device_mapping_v2unicsuscheduler_hintsuconfig_driveudisk_configu
admin_passuwaitutimeoutu	reuse_ipsunetworkuboot_from_volumeuvolume_sizeunat_destinationugroupuuserdatauextrauError %s: %s is not of type %sudictupdate.update(
RRRtbooltlistRNtintR)t	iteritemstcopyRPRterrorR+(R`t
VALID_OPTStextraR=tvalue((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyt_clean_create_kwargsHsR













"c
C@s�|dkrtd��ntj|�}tjd|d�td|dd�t�}tjd|t	dt
d	d
�}|d
k	rtj
j|�ry@td
|d��'}tdt	||j��|d<Wd
QXWqtk
r}tjd||�qXnd|kr)|jd�|d<ntjd|t	dt
d	d
�|d<t|d<y|jt|��Wn_tjjk
r�}tjd|d|�t|dd|dd�ttj|���nXt|dd|dd�S(u)
    Request an instance to be built
    ufunctionu?The request_instance action must be called with -a or --action.uCreating Cloud VM %sunameucloud.check_nameua-zA-Z0-9._-uuserdataRRufiles.fopenurucloud.userdata_templateNu#Failed to read userdata from %s: %susizeuflavorussh_key_nameukey_nameuwaituError creating server %s: %sR3R9uaction(RRetdeepcopyRR<R+R4RRRR	R*tostpathtisfiletreadRt	exceptionR)RAt
create_serverRjR/texctOpenStackCloudExceptionRftdestroyRt	text_typeRX(R R3R9R`tuserdatatfp_Rr((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pytrequest_instancexs:	#
c
@s�tjd|t�}tjd|tdtdd#�}|d#k	rmtjj|�rmtdj	|���n||d<t
ddd	d
j	|d�dt
d
d|ddddg�dtddtd�t��d|krBd|kr[d|kr[tj
d|d�t
dtjd|t��\|d<|d<q[ntd�ddd|�t|jd|d�d�dd�}tj
d ��fd!�}yt
d"|d|�}Wn\ttfk
r}z*yt|d�Wntk
r�nXWd#ttj|���XnXtj
d$|�t
d%|t�}t|||�}tj
d&|�|sstd'��n||d(<||d)<t
d*|t�}	|	j|�tjd+|d�tj
d,|dtj|��i|dd6|dd6|dd6|d-d6|d.d.6|d/d/6|d0d06|d1d16}
t
ddd2d3j	|d�dt
d
d4|
t|
��dtddtd�t
d5|d|dd6|d�|	S(7u-
    Create a single VM from a data dict
    udeployussh_key_fileRRu-The defined ssh_key_file '{0}' does not existukey_filenameucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingunametargsucloud.filter_eventucreatinguprofileuproviderudrivertsock_dirusock_dirt	transportu	transportuinstance_idupub_keyupriv_keyuGenerating minion keys for '%s'ucloud.gen_keysukeysizeR3R9uactionR uVM is now runningc@s�t|dd�dd�}d|kr�xtj|jdi��D]_\}}tjd||�|dj|d�|krDtjd||dj|��tSqDWnt||t	|��S(	NunameR3R9uactionuwait_for_metadatauWaiting for metadata: %s=%sumetadatauMetadata is not ready: %s=%s(
RXRRdR8RtdebugR*R	R%R&(R tdataR=Ri(R3(s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyt__query_node�s( ucloud.wait_for_funNuUsing IP address %sucloud.get_salt_interfaceuSalt interface set to: %su A valid IP address was not foundussh_hostu	salt_hostucloud.bootstrapuCreated Cloud VM '%s'u'%s' VM creation details:
%suidufloating_ipsu	fixed_ipsuprivate_ipsu
public_ipsucreated instanceusalt/cloud/{0}/createducreateducloud.cachedir_index_addunova(RRRR	R*RlRmRnRtformatR+R4RR|RxRXR8RRRtRRRuR%tupdateR<tpprinttpformatRb(R tdeploytkey_filenameR}R~t
ip_addressRrtsalt_interfacetsalt_ip_addressR:t
event_data((R3s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pytcreate�s�
"
	 (
	





#cC@s�|dkrtd��ntddddj|�di|d6d	td
dtd�|skt�}nt|d
|dd�}tjd|�|j|�}|r�tjd|�tddddj|�di|d6d	td
dtd�tj	dt
�tkr8tdt|tj	dd��d�ntj	dt
�tkrttd|t
jd�dt�ntd|�tStjd|�t
S(u
    Delete a single VM
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.ucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingRyunameRzusock_dirR{u	transportR3R9uactionuDestroying VM: %suDestroyed VM: %sudestroyed instanceusalt/cloud/{0}/destroyedudelete_sshkeysucloud.remove_sshkeyu
ssh_interfaceu
public_ipsiuupdate_cachedirucloud.delete_minion_cachediru:ucloud.cachedir_index_deluFailed to Destroy VM: %s(RR+RRR4RXRR<t
delete_serverR8R	RARSRtsplitRf(RDR3R9R;R:((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyRts@



*$cC@s|dkrtd��nd|kr6td��n|dkrNt�}n|jd�}xI|j�D];\}}ytd|�||<Wqjtk
r�qjqjXqjWyt||�|�SWnAtj	j
k
r}tjd||�tt
j|���nXdS(u
    Call function from shade.

    func

        function to call from shade.openstackcloud library

    CLI Example

    .. code-block:: bash

        salt-cloud -f call myopenstack func=list_images
        t sujksalt-cloud -f call myopenstack func=create_network name=mysubnet
    uactionu7The call function must be called with -f or --function.ufuncuNo `func` argument passedu
json.loadsuError running %s: %sN(RR*R4R)R6R+t
ValueErrorRSR/RrRsRRfRRu(R3R9R`tfuncR=RiRr((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyR9@s&
(:t__doc__t
__future__RRRRetloggingRlR�Rtsalt.utils.versionstsalttsalt.configRtsalt.extRtsalt.exceptionsRRRRR/tshade.openstackcloudt	shade.excR,tutilstversionst
_LooseVersiont__version__RtImportErrorR	t	getLoggert__name__RRR
RR
R%R&R4R*R>RERLR5RURXRZR\R]R_RjRxR�RtR9(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/openstack.pyt<module>�sT"*

						
#'	0*	p.

Zerion Mini Shell 1.0