Anons79 Mini Shell

Directory : /proc/self/root/lib/python2.7/site-packages/ansible/module_utils/
Upload File :
Current File : //proc/self/root/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyo

�
�Udac@s�ddlZddlZddlmZddlmZddlmZeZ	y$ddl
mZddlm
Z
Wnek
r�eZeZ	nXdd	d��YZdS(
i����N(tenviron(tstring_types(t
AnsibleModule(tOneException(t	OneServertOpenNebulaModulecBsReZdZededdddgdejd��dedddejd	��d
edddeddgdejd
��dededd�dedddd��Zed#d�Z
d�Zd�Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd#d#d#d �Zd!�Zd"�ZRS($s�
    Base class for all OpenNebula Ansible Modules.
    This is basically a wrapper of the common arguments, the pyone client and
    some utility methods.
    tapi_urlttypetstrtaliasestapi_endpointtdefaulttONE_URLtapi_usernametONE_USERNAMEtapi_passwordtno_logt	api_tokentONE_PASSWORDtvalidate_certstbooltwait_timeouttinti,cCsttj}|j|�td|d|d|�|_tdtdddd�|_|j�|_	|j
�|_dS(Nt
argument_spectsupports_check_modetmutually_exclusivetchangedtoriginal_messagettmessage(Rtcommon_argstupdateRtmoduletdicttFalsetresulttcreate_one_clienttonetresolve_parameterstresolved_parameters(tselfRRRtmodule_args((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyt__init__&s	
cCsAttd�rtj�}nd}ts:|jd�n|jjjd�rg|jjjd�}n
|jd�|jjjd�r�|jjjd�}n
|jd�|jjjd�r�|jjjd�}n
|jd�d	||f}|jjjd
�r0dt	kr0t
|d|d
|�St
||�SdS(sc
        Creates an XMLPRC client to OpenNebula.

        Returns: the new xmlrpc client.

        t_create_unverified_contexts!pyone is required for this moduleRsCEither api_url or the environment variable ONE_URL must be providedR
sMEither api_username or the environment vairable ONE_USERNAME must be providedRsMEither api_password or the environment vairable ONE_PASSWORD must be provideds%s:%sRtPYTHONHTTPSVERIFYtsessiontcontextN(thasattrtsslR+tNonet	HAS_PYONEtfailR tparamstgetRR(R(tno_ssl_validation_contextturltusernametpasswordR-((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyR$5s$	


"cCs|jj�dS(s*
        Close the pyone session.
        N(R%tserver_close(R(((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pytclose_one_client]scCs3t|d�r|j�n|jjd|�dS(s�
        Utility failure method, will ensure pyone is properly closed before failing.
        Args:
            msg: human readable failure reason.
        R%tmsgN(R/R;R t	fail_json(R(R<((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyR3cs
cCs3t|d�r|j�n|jj|j�dS(s\
        Utility exit method, will ensure pyone is properly closed before exiting.

        R%N(R/R;R t	exit_jsonR#(R(((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pytexitms
cCst|jj�}d|jjkr{|jjj�}xB|jD]4}|j|jjjd�kr@|j	|d<q@q@Wn|S(s.
        This method resolves parameters provided by a secondary ID to the primary ID.
        For example if cluster_name is present, cluster_id will be introduced by performing
        the required resolution

        Returns: a copy of the parameters that includes the resolved parameters.

        tcluster_namet
cluster_id(
R!R R4R%tclusterpooltinfotCLUSTERtNAMER5tID(R(tresolved_paramstclusterstcluster((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyR&vs
cCs*||jkr"|j|�dk	StSdS(s�
        Utility method to check if a parameter was provided or is resolved
        Args:
            name: the parameter to check
        N(R't
get_parameterR1R"(R(tname((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pytis_parameter�scCs|jj|�S(s�
        Utility method for accessing parameters that includes resolved ID
        parameters from provided Name parameters.
        (R'R5(R(RK((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyRJ�scCs=|jjj�}x$|jD]}|j|kr|SqWdS(s�
        Returns a host given its name.
        Args:
            name: the name of the host

        Returns: the host object or None if the host is absent.

        N(R%thostpoolRCtHOSTRER1(R(RKthoststh((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pytget_host_by_name�s
	cCs=|jjj�}x$|jD]}|j|kr|SqWdS(s�
        Returns a cluster given its name.
        Args:
            name: the name of the cluster

        Returns: the cluster object or None if the host is absent.
        N(R%RBRCRDRER1(R(RKRHtc((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pytget_cluster_by_name�s
	cCs=|jjj�}x$|jD]}|j|kr|SqWdS(s�
        Returns a template given its name.
        Args:
            name: the name of the template

        Returns: the template object or None if the host is absent.

        N(R%ttemplatepoolRCtTEMPLATERER1(R(RKt	templatestt((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pytget_template_by_name�s
	cCs�x�|D]z}||}t|t�r:|j||�qt|t�r_dj|�||<qt|t�st|�||<qqWdS(s
        OpenNebula handles all template elements as strings
        At some point there is a cast being performed on types provided by the user
        This function mimics that transformation so that required template updates are detected properly
        additionally an array will be converted to a comma separated list,
        which works for labels and hopefully for something more.

        Args:
            template: the template to transform

        Returns: the transformed template with data casts applied.
        s, N(t
isinstanceR!t
cast_templatetlisttjoinRR(R(ttemplatetkeytvalue((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyRZ�s

cCsi|s
tS|j|�t�}x;|j�D]-}||j�krV||||<q-tSq-W||kS(s�
        This function will help decide if a template update is required or not
        If a desired key is missing from the current dictionary an update is required
        If the intersection of both dictionaries is not deep equal, an update is required
        Args:
            current: current template as a dictionary
            desired: desired template as a dictionary

        Returns: True if a template update is required
        (R"RZR!tkeystTrue(R(tcurrenttdesiredtintersectiontdkey((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pytrequires_template_update�s
	c
Cs�|s|jjjd�}ntj�}x�tj�||kr�|�}	|	|krx|jd|||	�f�n|r�|	|kr�|jd|||	�f�q�n|	|kr�tStj|jj��q-W|jdd�dS(sS
        Args:
            element_name: the name of the object we are waiting for: HOST, VM, etc.
            state: lambda that returns the current state, will be queried until target state is reached
            state_name: lambda that returns the readable form of a given state
            target_states: states expected to be reached
            invalid_states: if any of this states is reached, fail
            transition_states: when used, these are the valid states during the transition.
            wait_timeout: timeout period in seconds. Defaults to the provided parameter.
        Rsinvalid %s state %ssinvalid %s transition state %sR<sWait timeout has expired!N(	R R4R5ttimeR3RatsleepR%tserver_retry_interval(
R(telement_nametstatet
state_namet
target_statestinvalid_statesttransition_statesRt
start_timet
current_state((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pytwait_for_state�s	 #cCsNy |j|j|j|j�Wn'tk
rI}|jdd|�nXdS(sU
        trigger the start of the execution of the module.
        Returns:

        R<sOpenNebula Exception: %sN(trunR%R R#RR3(R(te((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyt
run_modules cCstd��dS(s�
        to be implemented by subclass with the actual module actions.
        Args:
            one: the OpenNebula XMLRPC client
            module: the Ansible Module object
            result: the Ansible result
        sMethod requires implementationN(tNotImplementedError(R(R%R R#((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyRs*sN(t__name__t
__module__t__doc__R!RR5RaRR"R1R*R$R;R3R?R&RLRJRQRSRXRZRfRrRuRs(((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyRs0'-	(		
										"	((RgR0tosRtansible.module_utils.sixRtansible.module_utils.basicRRaR2tpyoneRtpyone.serverRtImportErrort	ExceptionR"R(((sC/usr/lib/python2.7/site-packages/ansible/module_utils/opennebula.pyt<module>s



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