Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/module_utils/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/module_utils/ovirt.pyo

�
�Udac@s>ddlZddlZddlZddlmZmZddlmZddlmZddl	m
Z
ddlmZyYddl
mZddlZddljZddljZeej�ed�kZWnek
r�eZnXid	d
d6d	dd
6d	dd6d	dd6d	dd6Zd�Zeeed�Zd�Zd�Z d�Z!d�Z"d�Z#ed�Z$ed�Z%d�Z&ed�Z'e(ed�Z)d �d!e(d"d#�Z*d$�Z+d%�Z,d&�Z-d'�Z.d(�Z/d)�Z0d*�Z1d+e2fd,��YZ3d-�Z4d.e
fd/��YZ5dS(0i����N(tABCMetatabstractmethod(tdatetime(tLooseVersion(t
CloudRetry(tMapping(tEnums4.3.0ii
tkibitmibitgibi(ttibi2tpibcCsts|jdd�ndS(Ntmsgs=ovirtsdk4 version 4.3.0 or higher is required for this module(tHAS_SDKt	fail_json(tmodule((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt	check_sdk3s	cs�i}���fd���fd�������fd��|dk	r�xN|jj�D]:\}}|dkrqan�|�}�|�||<qaWn|S(s2
    Convert SDK Struct type into dictionary.
    csy�j���Wntjk
r/d�nXt��fd��D��}t�dd�|d<t�dd�|d<|S(Nc3sB|]8}t�|d�dk	r|�t�|��fVqdS(N(tgetattrtNone(t.0tattr(t
convert_valuetvalue(s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pys	<genexpr>Gstidthref(tfollow_linktsdktErrorRtdictR(Rt
nested_obj(t
attributest
connectionR(Rs>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytresolve_href@s

cs*|jd�r&|d}�|�n|S(Nt_i(t
startswith(tval(tremove_underscore(s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR$Ns

cs�t}t|tj�r=�s)|jr3t|�S�|�St|t�s[t|t�ret|�St|t	�s�t|tj
�r�t|tj
�r��r�|jr�y�j|�}t}Wq�tj
k
r�g}q�Xng}x�|D]��t�tj�r�|r1�r1�jr1|j����q�|sM|jt���q�t��fd��D��}t�dd�|d<|j|�q�t�t�r�|jt���q�|j��q�W|S|SdS(Nc3s<|]2}t�|d�r|�t�|��fVqdS(N(RR(RR(Rti(s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pys	<genexpr>osR(tFalset
isinstanceRtStructRtget_dict_of_structRRtstrtlisttListRtTrueRtappendRRR(RtnestedtretR(RRRtfetch_nestedR (R%s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRTs>


!!



N(Rt__dict__titems(tstructRR1RtrestkeyR((RRRR1R$R s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR):s(cCs2|j�j�}|jj}d|j|jfS(s?
    Return string representation of oVirt engine version.
    s%s.%s(tsystem_servicetgettproduct_infotversiontmajortminor(Rt
engine_apitengine_version((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR>�scCs�|jd�}|dkrK|jd�dk	rKdj|jd��}ntjd|d|jd�d|jd�d|jdd�d|jdt�d|jdd�d	|jd	d�d
|jd
d��S(sK
    Create a connection to Python SDK, from task `auth` parameter.
    If user doesnt't have SSO token the `auth` dictionary has following parameters mandatory:
     url, username, password

    If user has SSO token the `auth` dictionary has following parameters mandatory:
     url, token

    The `ca_file` parameter is mandatory in case user want to use secure connection,
    in case user want to use insecure connection, it's mandatory to send insecure=True.

    :param auth: dictionary which contains needed values for connection creation
    :return: Python SDK connection
    turlthostnameshttps://{0}/ovirt-engine/apitusernametpasswordtca_filetinsecurettokentkerberostheadersN(R8RtformatRt
ConnectionR&(tauthR?((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytcreate_connection�s!	cCs�|dkrdSdj|j��}t|�dkru|dj�dkrut|d �tj|dj�d	�S|j�r�t|�dSt	dj
d
|���dS(sq
    This method convert units to bytes, which follow IEC standard.

    :param param: value to be converted
    tii����tktmtgtttpiii
s+Unsupported value(IEC supported): '{value}'RN(RMRNRORPRQi(Rtjointsplittlentlowertintt	BYTES_MAPR8tisdigitt
ValueErrorRH(tparam((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytconvert_to_bytes�s((cCs|r|j|�SdSdS(s�
    This method returns the entity of the element which link points to.

    :param connection: connection to the Python SDK
    :param link: link of the entity
    :return: entity which link points to
    N(RR(Rtlink((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR�s	
cCs|r|j|�jSdSdS(s�
    This method returns the name of the element which link points to.

    :param connection: connection to the Python SDK
    :param link: link of the entity
    :return: name of the entity, which link points to
    N(RtnameR(RR\((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt
get_link_name�s	cCs6|dk	r2|r(|j�|j�kS||kStS(s�
    Compare two parameters and return if they are equal.
    This parameter doesn't run equal operation if first parameter is None.
    With this approach we don't run equal operation in case user don't
    specify parameter in their task.

    :param param1: user inputted parameter
    :param param2: value of entity parameter
    :return: True if parameters are equal or first parameter is None, otherwise False
    N(RRUR-(tparam1tparam2tignore_case((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytequal�s

c
Ks�|p	i}dtj|j�dkrY|jddjd�|j�D��|�}nqg|j|�D][}tg|j�D]*\}}t||d�|kr|^q�t|�kri|^qi}|p�dg}|dS(s�
    Search for the entity by attributes. Nested entities don't support search
    via REST, so in case using search for nested entity we return all entities
    and filter them by specified attributes.
    tsearchis and css'|]\}}dj||�VqdS(s	{0}="{1}"N(RH(RRMtv((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pys	<genexpr>sN(tinspectt
getargspecR+RRR3RTRR(tservicetlist_paramstkwargsR5teRMRd((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytsearch_by_attributes�s	=c	Ks�dtj|j�dkr=|jddjd|��}n.g|j�D]}|j|krJ|^qJ}|r�g|j�D][}tg|j�D]*\}}t||d�|kr�|^q��t|�kr~|^q~}n|p�dg}|dS(s>
    Search for the entity by its name. Nested entities don't support search
    via REST, so in case using search for nested entity we return all entities
    and filter them by name.

    :param service: service of the entity
    :param name: name of the entity
    :return: Entity object returned by Python SDK
    Rcis
name="{name}"R]N(	ReRfR+RHR]RTR3RR(RgR]RiR5RjRMRd((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytsearch_by_names	.=cCsOd}y.|dk	r'|j|�}n|j�}Wntjk
rJnX|S(sE
    Ignore SDK Error in case of getting an entity from service.
    N(RR8RR(Rgt
get_paramstentity((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt
get_entity.scCs?t||�}|dk	r"|jS|r;td|��ndS(s+
    Search an entity ID by it's name.
    sEntity '%s' was not found.N(RlRRt	Exception(RgR]traise_errorRaRn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytget_id_by_name?s
cCstS(N(R&(Rj((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt<lambda>Osi�icCs�|r�tj�}xdtj�||krxt|�}||�rGdS||�rbtd��ntjt|��qWtd��ndS(s�
    Wait until entity fulfill expected condition.

    :param service: service of the entity
    :param condition: condition to be fulfilled
    :param fail_condition: if this condition is true, raise Exception
    :param timeout: max time to wait in seconds
    :param wait: if True wait for condition, if False don't wait
    :param poll_interval: Number of seconds we should wait until next condition check
    Ns2Error while waiting on result state of the entity.s;Timeout exceed while waiting on result state of the entity.(ttimeRoRptsleeptfloat(Rgt	conditiontfail_conditionttimeouttwaitt
poll_intervaltstartRn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRzLsc		Cs0tjjd�}tjjd�}tjjd�}tjjd�}tjjd�}tjjd�}|dk}d}|dkr�|dk	r�dj|�}n|r�|r�|s�|r�i|d6|d	6|d
6|d6|d6|d
6}n|dk	rtd|dd�}ntdtdd�}|S(Nt	OVIRT_URLtOVIRT_HOSTNAMEtOVIRT_USERNAMEtOVIRT_PASSWORDtOVIRT_TOKENtOVIRT_CAFILEshttps://{0}/ovirt-engine/apiR?RARBRDRERCtdefaultttypeRtrequired(tostenvironR8RRHRR-(	R}R~RR�R�R�tOVIRT_INSECUREtenv_varsRJ((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt__get_auth_dictos,
cKsPtdt�dtdtdd�dtdddt���}|j|�|S(s�
    Extend parameters of info module with parameters which are common to all
    oVirt info modules.

    :param kwargs: kwargs to be extended
    :return: extended dictionary with common parameters
    RJR1R�R�tbooltnested_attributesR+(RR�R&R+tupdate(Ritspec((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytovirt_info_full_argument_spec�s	
cKs
t|�S(s�
    This is deprecated. Please use ovirt_info_full_argument_spec instead!

    :param kwargs: kwargs to be extended
    :return: extended dictionary with common parameters
    (R�(Ri((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytovirt_facts_full_argument_spec�scKs�tdt�dtdddd�dtdtdd�d	tdd
dd�dtdtdd�dtdd
dt���}|j|�|S(s�
    Extend parameters of module with parameters which are common to all oVirt modules.

    :param kwargs: kwargs to be extended
    :return: extended dictionary with common parameters
    RJRyR�i�R�RVRzR�R{iR1R�R+(RR�R-R&R+R�(RiR�((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytovirt_full_argument_spec�s	
cCsG|jjd�dkrC|jjd�dkrC|jdd�ndS(sA
    Most modules must have either `name` or `id` specified.
    R]RRs"name" or "id" is requiredN(tparamsR8RR(R((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytcheck_params�s0cCstt|��t|�kS(N(RR>(RR:((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytengine_supported�scCsjtt|��}t|�}xE|D]=}|jj|�dk	r%ttj�|koa||kSq%WtS(sb
    Check if parameters used by user are supported by oVirt Python SDK
    and oVirt engine.
    N(RR>R�R8Rtsdk_versiontVERSIONR-(R:RRR�tapi_versionRZ((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt
check_support�s
#t
BaseModulecBs(eZdZeZed�Zed��Zej	d��Ze
d��Zdd�Z
d�Zd�Zd�Zd	�Zd
�Zddd�ddded�Zd
�Zd�Zddd�Zdd�d�d�d�d�dd�Zd�d�Zddd�Zd�Zd�ZRS(s	
    This is base class for oVirt modules. oVirt modules should inherit this
    class and override method to customize specific needs of the module.
    The only abstract method of this class is `build_entity`, which must
    to be implemented in child class.
    cCsE||_||_||_||_it�d6t�d6|_dS(Ntaftertbefore(t_connectiont_modulet_servicet_changedRt_diff(tselfRRRgtchanged((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt__init__�s
				cCs|jS(N(R�(R�((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR��scCs|js||_ndS(N(R�(R�R�((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR��s	cCsdS(sP
        This method should return oVirt Python SDK type, which we want to
        create or update, initialized by values passed by Ansible module.

        For example if we want to create VM, we will return following:
          types.Vm(name=self._module.params['vm_name'])

        :return: Specific instance of sdk.Struct.
        N((R�((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytbuild_entity�scCs|jjj||�S(sC
        Return a module parameter specified by it's name.
        (R�R�R8(R�R]R�((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRZ�scCstS(sA
        This method handle checks whether the entity values are same as values
        passed to ansible module. By default we don't compare any values.

        :param entity: Entity we want to compare with Ansible module values.
        :return: True if values are same, so we don't need to update the entity.
        (R-(R�Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytupdate_checkscCsdS(s�
        This method is called right before entity is created.

        :param entity: Entity to be created or updated.
        N((R�Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt
pre_createscCsdS(sx
        This method is called right after entity is created.

        :param entity: Entity which was created.
        N((R�Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytpost_createscCsdS(sx
        This method is called right after entity is updated.

        :param entity: Entity which was updated.
        N((R�Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytpost_updatescCsfx_|j�D]Q\}}t|t�rP|j|j|t��|�||<q
||||<q
W|S(N(R3R'Rtdiff_updateR8R(R�R�R�RMRd((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR�#s
(cCstS(N(R&(Rj((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRs/scsz|dkr%|r%|j|�}n|j|�|r|jj|j�}	|j|�s]|j�}
|jj	s�|p}i}|	j
|
|�}|j|�n|jjrt
||jdtddg�}|j�}
|j|
t
|
��||jd<|
|jd<nt|_q]n@|jj	sT|jj|j�|�}|j|�nt|_|jj	s�|jj|j�}	d�}�r��fd�}ntd|	d	|d
|d|dk	r�|n
|jjdd|jjdd
|jjd
�ni|jd6t|dd�d6t
d|d|jd|jjjd�d|jjjd��t|�jj�6|jd6S(s�
        Method which is called when state of the entity is 'present'. If user
        don't provide `entity` parameter the entity is searched using
        `search_params` parameter. If entity is found it's updated, whether
        the entity should be updated is checked by `update_check` method.
        The corresponding updated entity is build by `build_entity` method.

        Function executed after entity is created can optionally be specified
        in `post_create` parameter. Function executed after entity is updated
        can optionally be specified in `post_update` parameter.

        :param entity: Entity we want to update, if exists.
        :param result_state: State which should entity has in order to finish task.
        :param fail_condition: Function which checks incorrect state of entity, if it returns `True` Exception is raised.
        :param search_params: Dictionary of parameters to be used for search.
        :param update_params: The params which should be passed to update method.
        :param kwargs: Additional parameters passed when creating entity.
        :return: Dictionary with values returned by Ansible module.
        R1RR]R�R�cSs|S(N((Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytstate_conditionxscs|o|j�kS(N(tstatus(Rn(tresult_state(s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR�}sRgRwRxRzRyR{R�RR4RR�tdiffN(Rt
search_entityR�R�RgRR�R�R�t
check_modeR�R�R�R)R�R-tcopyR�R�taddR�RzR�RR8R�t__name__RU(R�RnR�Rxt
search_paramst
update_paramst_waittforce_createRitentity_servicet
new_entitytupdated_entityR�R�R�((R�s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytcreate+sf
		
					"
	(cCsdS(s
        This method is called right before entity is removed.

        :param entity: Entity which we want to remove.
        N((R�Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt
pre_remove�scCs1djdt|�jj�dt|dd��S(Ns{e_type} '{e_name}'te_typete_nameR](RHR�R�RURR(R�Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytentity_name�s	cKs6|dkr|j|�}n|dkr?i|jd6dd6S|j|�|jj|j�}|jjs�|j	|�t
d|dd�d|jjdd|jjdd	|jjd	�nt|_i|jd6|jd
6t
d|d|jd
|jjjd
�d|jjjd��t|�jj�6S(sb
        Method which is called when state of the entity is 'absent'. If user
        don't provide `entity` parameter the entity is searched using
        `search_params` parameter. If entity is found it's removed.

        Function executed before remove is executed can optionally be specified
        in `pre_remove` parameter.

        :param entity: Entity we want to remove.
        :param search_params: Dictionary of parameters to be used for search.
        :param kwargs: Additional parameters passed when removing entity.
        :return: Dictionary with values returned by Ansible module.
        R�sEntity wasn't found.RRgRwcSs|S(N((Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRs�sRzRyR{RR4RR1RR�N(RR�R�R�R�RgRR�R�tremoveRzR�R-R)R�R8R�R�RU(R�RnR�RiR�((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR��s2


		

	cCs|S(N((Rj((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRs�scCs|S(N((Rj((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRs�scCstS(N(R&(Rj((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRs�scCs|S(N((Rj((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRs�scCsdS(N(R(Rj((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRs�sc	Ks�|dkr|j|�}n||�}|dkrU|jjddj|��n|jj|j�}
|
j�}||�r�|jj	s�t
|
|�|	�nt|_n||�t
d|jj|j�d|d|d|jjdd|jjdd|jjd�i|jd	6|jd
6td|d|jd
|jjjd
�d|jjjd��t|�jj�6|jd6S(s�
        This method is executed when we want to change the state of some oVirt
        entity. The action to be executed on oVirt service is specified by
        `action` parameter. Whether the action should be executed can be
        specified by passing `action_condition` parameter. State which the
        entity should be in after execution of the action can be specified
        by `wait_condition` parameter.

        Function executed before an action on entity can optionally be specified
        in `pre_action` parameter. Function executed after an action on entity can
        optionally be specified in `post_action` parameter.

        :param action: Action which should be executed by service on entity.
        :param entity: Entity we want to run action on.
        :param action_condition: Function which is executed when checking if action should be executed.
        :param fail_condition: Function which checks incorrect state of entity, if it returns `True` Exception is raised.
        :param wait_condition: Function which is executed when waiting on result state.
        :param pre_action: Function which is executed before running the action.
        :param post_action: Function which is executed after running the action.
        :param search_params: Dictionary of parameters to be used for search.
        :param kwargs: Additional parameters passed to action.
        :return: Dictionary with values returned by Ansible module.
        Rs)Entity not found, can't run action '{0}'.RgRwRxRzRyR{R�RR4RR1RR�R�N(RR�R�RRHR�RgRR8R�RR-R�RzR�R)R�R�R�RUR�(R�tactionRntaction_conditiontwait_conditionRxt
pre_actiontpost_actionR�RiR�((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR��s<#



	(cCstS(N(R-(Rj((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyRsscCs�|jjdr�tj�}|jjd}|jjd}xLtj�||kr�|j�}|rw||�rw|Stj|�q?WndS(NRzRyR{(R�R�RtR�Ru(R�RwR|RyR{Rn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytwait_for_importscCs�d}d|jjkrY|jjddk	rYt|jj|jjd�d|�}nj|dk	r�t|jd||�}nC|jjjd�dk	r�t|jd|d|jjd�}n|S(s�
        Always first try to search by `ID`, if ID isn't specified,
        check if user constructed special search in `search_params`,
        if not search by `name`.
        RRmRhR]N(RR�R�RoR�RgRkR8(R�R�RhRn((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR�*s(+(cCsR|dks|dkrdSt|tj�r;t|j�St|jd�d�S(NRLt.i(RR'totypestVersionRVR;RS(R�tfull_version((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt
_get_major;s

cCsR|dks|dkrdSt|tj�r;t|j�St|jd�d�S(NRLR�i(RR'R�R�RVR<RS(R�R�((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt
_get_minorBs

N(R�t
__module__t__doc__Rt
__metaclass__R&R�tpropertyR�tsetterRR�RRZR�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR��sB
	
				
b		3C	cCstr
tjStd�S(s2
    Allow for ovirtsdk4 not being installed.
    N(R
RRR�R(((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt_sdk4_error_maybeJst
OvirtRetrycBs2eZe�Zed��Zedd��ZRS(cCs|jS(N(tcode(terror((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytstatus_code_from_exceptionVscCs)dg}|r|j|�n||kS(Ni�(textend(t
response_codetcatch_extra_error_codestretry_on((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pytfoundZs	N(R�R�R�t
base_clasststaticmethodR�RR�(((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyR�Ss	(6ReR�RttabcRRRtdistutils.versionRtansible.module_utils.cloudRt/ansible.module_utils.common._collections_compatRtenumRt	ovirtsdk4Rtovirtsdk4.versionR:R�tovirtsdk4.typesttypesR�R�R
tImportErrorR&RWRRR)R>RKR[RR^RbRkRlRoR-RrRzR�R�R�R�R�R�R�tobjectR�R�R�(((s>/usr/lib/python2.7/site-packages/ansible/module_utils/ovirt.pyt<module>s`

	M			 							
				�v		

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]