%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/glance.pyo

�
���^c@@s�dZddlmZmZmZddlZddlmZddlm	Z	m
Z
ddlmZe	j
d�Ze
eded�Ze
jd	�ZeZy*dd
lmZddlmZeZWnek
r�nXeZydd
lmZeZWnek
rnXddlZejdej�eje �Z!ddl"Z"d
�Z#iZ$ddd�Z&d�Z'ddddddd�Z(dddd�Z)dddd�Z*dddd�Z+dd�Z,dddd�Z-dd�Z.dd�Z/dS(u�
Module for handling openstack glance calls.

:optdepends:    - glanceclient Python adapter
:configuration: This module is not usable until the following are specified
    either in a pillar or in the minion's config file::

        keystone.user: admin
        keystone.password: verybadpass
        keystone.tenant: admin
        keystone.insecure: False   #(optional)
        keystone.auth_url: 'http://127.0.0.1:5000/v2.0/'

    If configuration for multiple openstack accounts is required, they can be
    set up as different configuration profiles:
    For example::

        openstack1:
          keystone.user: admin
          keystone.password: verybadpass
          keystone.tenant: admin
          keystone.auth_url: 'http://127.0.0.1:5000/v2.0/'

        openstack2:
          keystone.user: admin
          keystone.password: verybadpass
          keystone.tenant: admin
          keystone.auth_url: 'http://127.0.0.2:5000/v2.0/'

    With this configuration in place, any of the glance functions can
    make use of a configuration profile by declaring it explicitly.
    For example::

        salt '*' glance.image_list profile=openstack1
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltInvocationError(t__version__tSaltStackVersion(tsixu.iuBoron(tclient(texctlevelcC@str
dStdfS(uJ
    Only load this module if glance
    is installed on this minion.
    uglanceu_The glance execution module cannot be loaded: the glanceclient python library is not available.(t
HAS_GLANCEtFalse(((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyt__virtual__Usic	@s<tddd�|r$|d�nd�d%��fd�}|dd�}|d	d%�}|d
d�}|d�}|dd
�}|dt�}	|d�}
|d�}|dd�}tdd|�}
tjdd|
d�}
|
r|dkr|rtdd��n�|rhi|d6|d	6|d6|d6|
d6|d6|d6}|	r�t|d<q�n<|dkr�|
r�i|
d6|d6|
d6}ntd��tr,t	j
d d!j||��tj
|�}|j|j�|d<|jd	�t	j
d"d#j||
|��tj
||
|�Std$��d%S(&u�
    Set up glance credentials, returns
    `glanceclient.client.Client`. Optional parameter
    "api_version" defaults to 2.

    Only intended to be used within glance-enabled modules
    uversions.warn_untiluNeonusThe glance module has been deprecated and will be removed in {version}.  Please update to using the glanceng moduleu
:keystone.u	keystone.c@s%�jd|td�||��S(uq
        Checks connection_args, then salt-minion config,
        falls back to specified default value.
        uconnection_u
config.get(tgett__salt__(tkeytdefault(tconnection_argstprefix(s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyR
ws
uuseruadminupasswordutenantu	tenant_iduauth_urluhttp://127.0.0.1:35357/v2.0uinsecureutokenuregionuendpointuhttp://127.0.0.1:9292/ukeystone.endpoint_getuglanceu/v2uuinternalurliu"Only can use keystone admin token uwith Glance API v1uusernameuendpoint_urluregion_nameutenant_nameu$No credentials to authenticate with.u*Calling keystoneclient.v2_0.client.Client(u{0}, **{1})u#Calling glanceclient.client.Client(u{0}, {1}, **{2})u,Can't retrieve a auth_token without keystoneN(t	__utils__tNoneRRtretsubRtTruetHAS_KEYSTONEtlogtdebugtformattkstonetClientt	get_tokentsessiontpopRtNotImplementedError(tprofiletapi_versionRR
tusertpasswordttenantt	tenant_idtauth_urltinsecuretadmin_tokentregiontks_endpointtg_endpoint_urltkwargstkeystone((RRs7/usr/lib/python2.7/site-packages/salt/modules/glance.pyt_authbs`





	
		cC@s/i|jd6|jd6|jd6|jd6|jd6|jd6|jd6|jd6|jd	6|j	d
6|j
d6|jd6}x4d
ddgD]#}||kr�||||<q�q�Wt|�t
kr�|||j<nTt|�tkr�|j|�n2djt|��d}tj|�t|��|S(u'
    Add image to given dictionary
    uidunameu
created_atufileumin_diskumin_ramuowneru	protectedustatusutagsu
updated_atu
visibilityucontainer_formatudisk_formatusizeu"collection" is {0}uinstead of dict or list.(tidtnamet
created_attfiletmin_disktmin_ramtownert	protectedtstatusttagst
updated_att
visibilityttypetdicttlisttappendRRterrort	TypeError(t
collectiontimaget
image_preptattrtmsg((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyt
_add_image�s2












ubareurawc
	C@s�i}ddg}dddddg}	ddddd	d
ddd
g	}
||d<|dk	r�||kr�tddjdj|����q�|dkr�t|d<q�t|d<n
t|d<||	kr�tddjdj|	����n
||d<||
kr+tddjdj|
����n
||d<|dk	rN||d<nt|dd�}|jjd||�}t	|j
d|�S(u�
    Create an image (glance image-create)

    CLI Example, old format:

    .. code-block:: bash

        salt '*' glance.image_create name=f16-jeos \
                 disk_format=qcow2 container_format=ovf

    CLI Example, new format resembling Glance API v2:

    .. code-block:: bash

        salt '*' glance.image_create name=f16-jeos visibility=public \
                 disk_format=qcow2 container_format=ovf

    The parameter 'visibility' defaults to 'public' if not specified.
    upublicuprivateuamiuariuakiubareuovfuvhduvmdkurawuqcow2uvdiuisou	copy_fromu"visibility" needs to be one uof the following: {0}u, u	is_publicu"container_format" needs to be uone of the following: {0}ucontainer_formatu"disk_format" needs to be one udisk_formatu	protectedR#iR2R"N(RRRtjoinRRR0timagestcreatet
image_showR1(
R2tlocationR"R<tcontainer_formattdisk_formatR8R.tv_listtcf_listtdf_listtg_clientRD((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pytimage_create�s6






cC@s9t|�}itd6dd6}|rax8|jj�D]$}|j|kr6|j}q6q6q6Wn|s�itd6dj|�d6S|s�|d}ny|jj|�Wnot	j
k
r�itd6dj|�d6St	jk
r}tj
tj|��itd6tj|�d6SXitd6dj||�d6S(	u'
    Delete an image (glance image-delete)

    CLI Examples:

    .. code-block:: bash

        salt '*' glance.image_delete c2eb2eb0-53e1-4a80-b990-8ec887eae7df
        salt '*' glance.image_delete id=c2eb2eb0-53e1-4a80-b990-8ec887eae7df
        salt '*' glance.image_delete name=f16-jeos
    uidunameuresultu'Unable to resolve image id for name {0}ucommentuNo image with ID {0}uDeleted image '{0}' ({1}).N(R0RRRJR?R2R1RtdeleteRtHTTPNotFoundt
HTTPForbiddenRRARt	text_typeR(R1R2R"RSRDt	forbidden((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pytimage_deletes8	

c	C@sVt|�}i}|rSx8|jj�D]$}|j|kr(|j}q(q(q(Wn|stitd6dj|�d6Sy|jj|�}Wn,tj	k
r�itd6dj|�d6SXt
jdd�j}t
jdj|j||���td|�}t|j��d	kr$|d
}nx+|D]#}||kr+||||<q+q+W|S(u�
    Return details about a specific image (glance image-show)

    CLI Example:

    .. code-block:: bash

        salt '*' glance.image_show
    uresultu)Unable to resolve image ID for name '{0}'ucommentuNo image with ID {0}tindentiuProperties of image {0}:
{1}R"iuimage(R0RJR?R2R1RRR
RRVtpprintt
PrettyPrintertpformatRRtimage_schematlentkeys(	R1R2R"RStretRDR^tschemaR((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyRLMs8
	


cC@s�t|�}g}x�|jj�D]�}|dkrP|dkrPt||�q"|dk	r|||jkr|t||�|S||jkr"||kr�ttkr�it	d6dj
|�d6St||�q"q"Wtjdj
|��|S(u�
    Return a list of available images (glance image-list)

    CLI Example:

    .. code-block:: bash

        salt '*' glance.image_list
    uresultu#More than one image with name "{0}"ucommentuReturning images: {0}N(
R0RJR?RRHR1R2tCUR_VERtBORONRRRR(R1R"R2RSRbRD((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyt
image_listys"

cC@s
td|�S(u�
    Returns names and descriptions of the schema "image"'s
    properties for this profile's instance of glance

    CLI Example:

    .. code-block:: bash

        salt '*' glance.image_schema
    uimage(t
schema_get(R"((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyR_�scK@s�|r^td|d|�}d|kr6|dr6|St|�dkr|j�d}qn�|rtd|d|�}|tkr�d|kr�|St|�dkr�itd6dj|�d6St|�dkry|d}Wqtk
r�||}qXqnt�t	j
d	j|��i}xq|j�D]c\}}|jd
�rVq5n||ksr|||kr5t	j
dj||��|||<q5q5Wt
|�}	|	jj|d|�}
|
S(
uE
    Update properties of given image.
    Known to work for:
    - min_ram (in MB)
    - protected (bool)
    - visibility ('public' or 'private')

    CLI Example:

    .. code-block:: bash

        salt '*' glance.image_update id=c2eb2eb0-53e1-4a80-b990-8ec887eae7df
        salt '*' glance.image_update name=f16-jeos
    R1R"uresultiiR2uNo image with name '{0}' found.ucommentuFound image:
{0}u_uadd <{0}={1}> to to_updateuid(RLR`tvaluesRfR>RRtKeyErrorRRRtitemst
startswithR0RJtupdate(R1R2R"R.RDtimg_listt	to_updateRtvalueRStupdated((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pytimage_update�s@
cC@s�t|�}tjdd�j}i}x-|jj|�jD]}|j||j<q=Wt	j
dj|||���i||6S(u�
    Known valid names of schemas are:
      - image
      - images
      - member
      - members

    CLI Example:

    .. code-block:: bash

        salt '*' glance.schema_get name=f16-jeos
    R[iuProperties of schema {0}:
{1}(R0R\R]R^tschemasR
t
propertiestdescriptionR2RRR(R2R"RSR^tschema_propstprop((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyRg�scC@s@t|�}g}x'|jj�D]}|j|j�q"W|S(u�
    Template for writing list functions
    Return a list of available items (glance items-list)

    CLI Example:

    .. code-block:: bash

        salt '*' glance.item_list
    (R0RjR?R@t__dict__(R"RSRbtitem((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyt
_item_list�s
(0t__doc__t
__future__RRRRtsalt.exceptionsRtsalt.versionRRtsalt.extRtsplitt_version_aryRdt	from_nameReRR
tglanceclientRRRtImportErrorRtkeystoneclient.v2_0RtloggingtbasicConfigtDEBUGt	getLoggert__name__RR\Rt__opts__RR0RHRTRZRLRfR_RqRgRy(((s7/usr/lib/python2.7/site-packages/salt/modules/glance.pyt<module>$sT



	
X	#</,!4

Zerion Mini Shell 1.0