%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/parallels.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlm
Z
mZddlmZdZidd6Zeje�Zejd	ej�Zd
�Zd�Zddd�Zddd
�Zdeedded�Zeedd�Z dd�Z!dd�Z"dd�Z#edd�Z$dd�Z%dd�Z&dd�Z'dd�Z(edd�Z)edd�Z*e+dd�Z,deedd�Z-dddd�Z.ded�Z/dd�Z0dS(u�
Manage Parallels Desktop VMs with ``prlctl`` and ``prlsrvctl``.  Only some of
the prlctl commands implemented so far.  Of those that have been implemented,
not all of the options may have been provided yet.  For a complete reference,
see the `Parallels Desktop Reference Guide
<http://download.parallels.com/desktop/v9/ga/docs/en_US/Parallels%20Command%20Line%20Reference%20Guide.pdf>`_.

This module requires the prlctl binary to be installed to run most functions.
To run parallels.prlsrvctl, the prlsrvctl binary is required.

What has not been implemented yet can be accessed through ``parallels.prlctl``
and ``parallels.prlsrvctl`` (note the preceding double dash ``--`` as
necessary):

.. code-block:: bash

    salt '*' parallels.prlctl installtools macvm runas=macdev
    salt -- '*' parallels.prlctl capture 'macvm --file macvm.display.png' runas=macdev
    salt -- '*' parallels.prlsrvctl set '--mem-limit auto' runas=macdev

.. versionadded:: 2016.3.0
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltInvocationErrortCommandExecutionError(tsixu	parallelsuexecuexec_uB{?([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})}?cC@sht|tj�rtj|�St|ttf�rTg|D]}tj|�^q;Stj|�gSdS(u*
    Return args as a list of strings
    N(t
isinstanceRtstring_typestshlextsplitttupletlistt	text_type(targstarg((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pyt_normalize_args1s

 cC@sgg}xHtjt|�D]4}|j�r|j|jd�jd��qqWttt	|���S(u�
    Return the set of GUIDs found in guid_string

    :param str guid_string:
        String containing zero or more GUIDs.  Each GUID may or may not be
        enclosed in {}

    Example data (this string contains two distinct GUIDs):

    PARENT_SNAPSHOT_ID                      SNAPSHOT_ID
                                            {a5b8999f-5d95-4aff-82de-e515b0101b66}
    {a5b8999f-5d95-4aff-82de-e515b0101b66} *{a7345be5-ab66-478c-946e-a6c2caf14909}
    iu{}(
tretfinditert
GUID_REGEXtgroupstappendtgrouptstriptsortedRtset(tguid_stringtguidst
found_guid((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pyt_find_guids>s
&cC@s`tjjjd�s$td��nd|g}|rL|jt|��ntd|d|�S(u
    Execute a prlsrvctl command

    .. versionadded:: 2016.11.0

    :param str sub_cmd:
        prlsrvctl subcommand to execute

    :param str args:
        The arguments supplied to ``prlsrvctl <sub_cmd>``

    :param str runas:
        The user that the prlsrvctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.prlsrvctl info runas=macdev
        salt '*' parallels.prlsrvctl usb list runas=macdev
        salt -- '*' parallels.prlsrvctl set '--mem-limit auto' runas=macdev
    u	prlsrvctluprlsrvctl utility not availableucmd.runtrunas(tsalttutilstpathtwhichRtextendRt__salt__(tsub_cmdR
Rtcmd((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pyt	prlsrvctlSscC@s`tjjjd�s$td��nd|g}|rL|jt|��ntd|d|�S(u�
    Execute a prlctl command

    :param str sub_cmd:
        prlctl subcommand to execute

    :param str args:
        The arguments supplied to ``prlctl <sub_cmd>``

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.prlctl user list runas=macdev
        salt '*' parallels.prlctl exec 'macvm uname' runas=macdev
        salt -- '*' parallels.prlctl capture 'macvm --file macvm.display.png' runas=macdev
    uprlctluprlctl utility not availableucmd.runR(RRR R!RR"RR#(R$R
RR%((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytprlctlvscC@s�|dkrg}nt|�}|r:|j|g�n|rP|jd�n|rf|jd�n|r||jd�ntd|d|�S(u�
    List information about the VMs

    :param str name:
        Name/ID of VM to list

        .. versionchanged:: 2016.11.0

            No longer implies ``info=True``

    :param str info:
        List extra information

    :param bool all:
        List all non-template VMs

    :param tuple args:
        Additional arguments given to ``prctl list``

    :param str runas:
        The user that the prlctl command will be run as

    :param bool template:
        List the available virtual machine templates.  The real virtual
        machines will not be included in the output

        .. versionadded:: 2016.11.0

    Example:

    .. code-block:: bash

        salt '*' parallels.list_vms runas=macdev
        salt '*' parallels.list_vms name=macvm info=True runas=macdev
        salt '*' parallels.list_vms info=True runas=macdev
        salt '*' parallels.list_vms ' -o uuid,status' all=True runas=macdev
    u--infou--allu
--templateulistRN(tNoneRR"RR'(tnametinfotallR
Rttemplate((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytlist_vms�s'	cC@sltjjj|�dtjjj|�g}|rC|jd�n|rY|jd�ntd|d|�S(uM
    Clone a VM

    .. versionadded:: 2016.11.0

    :param str name:
        Name/ID of VM to clone

    :param str new_name:
        Name of the new VM

    :param bool linked:
        Create a linked virtual machine.

    :param bool template:
        Create a virtual machine template instead of a real virtual machine.

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.clone macvm macvm_new runas=macdev
        salt '*' parallels.clone macvm macvm_templ template=True runas=macdev
    u--nameu--linkedu
--templateucloneR(RRtdatatdecodeRR'(R)tnew_nametlinkedR,RR
((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytclone�s-cC@s"tdtjjj|�d|�S(u*
    Delete a VM

    .. versionadded:: 2016.11.0

    :param str name:
        Name/ID of VM to clone

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.exec macvm 'find /etc/paths.d' runas=macdev
    udeleteR(R'RRR.R/(R)R((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytdelete�scC@sLt|dtd|�j�}x'|D]}dj|�|kr%tSq%WtS(u
    Query whether a VM exists

    .. versionadded:: 2016.11.0

    :param str name:
        Name/ID of VM

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.exists macvm runas=macdev
    R*Ru	Name: {0}(R-tTruet
splitlinestformattFalse(R)Rtvm_infot	info_line((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytexists	s

cC@s"tdtjjj|�d|�S(u�
    Start a VM

    :param str name:
        Name/ID of VM to start

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.start macvm runas=macdev
    ustartR(R'RRR.R/(R)R((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytstart"scC@sAtjjj|�g}|r.|jd�ntd|d|�S(uf
    Stop a VM

    :param str name:
        Name/ID of VM to stop

    :param bool kill:
        Perform a hard shutdown

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.stop macvm runas=macdev
        salt '*' parallels.stop macvm kill=True runas=macdev
    u--killustopR(RRR.R/RR'(R)tkillRR
((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytstop5scC@s"tdtjjj|�d|�S(u5
    Restart a VM by gracefully shutting it down and then restarting
    it

    :param str name:
        Name/ID of VM to restart

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.restart macvm runas=macdev
    urestartR(R'RRR.R/(R)R((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytrestartRscC@s"tdtjjj|�d|�S(u&
    Reset a VM by performing a hard shutdown and then a restart

    :param str name:
        Name/ID of VM to reset

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.reset macvm runas=macdev
    uresetR(R'RRR.R/(R)R((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytresetfscC@s"tdtjjj|�d|�S(u
    Status of a VM

    :param str name:
        Name/ID of VM whose status will be returned

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.status macvm runas=macdev
    ustatusR(R'RRR.R/(R)R((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytstatusyscC@s>tjjj|�g}|jt|��td|d|�S(u`
    Run a command on a VM

    :param str name:
        Name/ID of VM whose exec will be returned

    :param str command:
        Command to run on the VM

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.exec macvm 'find /etc/paths.d' runas=macdev
    uexecR(RRR.R/R"RR'(R)tcommandRR
((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytexec_�scC@sktjjj|�}tjt|�sNtdjtjjj|����nt	d|d|gd|�}t
|�s�tdj||���nytjjj|�}Wn2tjjj
k
r�}tjd|�i}nXt|t�r|jdd�}|dkr0d}q0ntjd	|�d}|rX|rXtd
j||���ntjjj|�S(uY
    Attempt to convert a snapshot ID to a snapshot name.  If the snapshot has
    no name or if the ID is not found or invalid, an empty string will be returned

    :param str name:
        Name/ID of VM whose snapshots are inspected

    :param str snap_id:
        ID of the snapshot

    :param bool strict:
        Raise an exception if a name cannot be found for the given ``snap_id``

    :param str runas:
        The user that the prlctl command will be run as

    Example data

    .. code-block:: yaml

        ID: {a5b8999f-5d95-4aff-82de-e515b0101b66}
        Name: original
        Date: 2016-03-04 10:50:34
        Current: yes
        State: poweroff
        Description: original state

    CLI Example:

    .. code-block:: bash

        salt '*' parallels.snapshot_id_to_name macvm a5b8999f-5d95-4aff-82de-e515b0101b66 runas=macdev
    uSnapshot ID "{0}" is not a GUIDu
snapshot-listu--idRu'No snapshots for VM "{0}" have ID "{1}"u:Could not interpret snapshot data returned from prlctl: %suNameuu^Could not interpret snapshot data returned from prlctl: data is not formed as a dictionary: %su@Could not find a snapshot name for snapshot ID "{0}" of VM "{1}"N(RRR.R/RtmatchRRR6R'tlentyamlt	safe_loadt	YAMLErrortlogtwarningRtdicttgetR((R)tsnap_idtstrictRR*R.terrt	snap_name((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytsnapshot_id_to_name�s6#$


c	C@stjjj|�}tjjj|�}td|d|�}t|�}g}x9|D]1}t||d|�|krX|j|�qXqXWt|�dkr�t	dj
||���nRt|�dkr�|dSdj
||�}|r�t	|��n
tj|�|SdS(ua
    Attempt to convert a snapshot name to a snapshot ID.  If the name is not
    found an empty string is returned.  If multiple snapshots share the same
    name, a list will be returned

    :param str name:
        Name/ID of VM whose snapshots are inspected

    :param str snap_name:
        Name of the snapshot

    :param bool strict:
        Raise an exception if multiple snapshot IDs are found

    :param str runas:
        The user that the prlctl command will be run as

    CLI Example:

    .. code-block:: bash

        salt '*' parallels.snapshot_id_to_name macvm original runas=macdev
    u
snapshot-listRiu)No snapshots for VM "{0}" have name "{1}"iu/Multiple snapshots for VM "{0}" have name "{1}"N(
RRR.R/R'RRPRRDRR6RHRI(	R)RORMRR*tsnap_idst	named_idsRLt	multi_msg((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytsnapshot_name_to_id�s&

cC@sQtjjj|�}tjt|�r4|jd�St||d|d|�SdS(uk
    Validate snapshot name and convert to snapshot ID

    :param str name:
        Name/ID of VM whose snapshot name is being validated

    :param str snap_name:
        Name/ID of snapshot

    :param bool strict:
        Raise an exception if multiple snapshot IDs are found

    :param str runas:
        The user that the prlctl command will be run as
    u{}RMRN(	RRR.R/RRCRRRT(R)RORMR((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pyt_validate_snap_name2s
c
C@s�tjjj|�}|r3t||d|�}n|g}|rR|jd�n|rn|jd|g�ntd|d|�}|r�t|�}dj	dd�}xH|D]@}	t
||	d|�}|dj	|	tjjj|��7}q�W|S|Sd	S(
uc
    List the snapshots

    :param str name:
        Name/ID of VM whose snapshots will be listed

    :param str snap_id:
        Name/ID of snapshot to display information about.  If ``tree=True`` is
        also specified, display the snapshot subtree having this snapshot as
        the root snapshot

    :param bool tree:
        List snapshots in tree format rather than tabular format

    :param bool names:
        List snapshots as ID, name pairs

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.list_snapshots macvm runas=macdev
        salt '*' parallels.list_snapshots macvm tree=True runas=macdev
        salt '*' parallels.list_snapshots macvm snap_name=original runas=macdev
        salt '*' parallels.list_snapshots macvm names=True runas=macdev
    Ru--treeu--idu
snapshot-listu
{0:<38}  {1}
uSnapshot IDu
Snapshot Nameu
{{{0}}}  {1}
N(RRR.R/RURR"R'RR6RP(
R)ROttreetnamesRR
tresRQtretRL((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytlist_snapshotsKs"	
)cC@s�tjjj|�}|r3tjjj|�}n|g}|rX|jd|g�n|rt|jd|g�ntd|d|�S(u
    Create a snapshot

    :param str name:
        Name/ID of VM to take a snapshot of

    :param str snap_name:
        Name of snapshot

    :param str desc:
        Description of snapshot

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.create_snapshot macvm snap_name=macvm-original runas=macdev
        salt '*' parallels.create_snapshot macvm snap_name=macvm-updates desc='clean install with updates' runas=macdev
    u--nameu
--descriptionusnapshotR(RRR.R/R"R'(R)ROtdescRR
((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytsnapshot�s	c
C@s�|}tjjj|�}t||d|d|�}t|tj�rU|g}ni}xE|D]=}|jd�}|d|g}t	d|d|�||<qbWt
|j��}	t|	�dkr�||	dS|SdS(	u�
    Delete a snapshot

    .. note::

        Deleting a snapshot from which other snapshots are dervied will not
        delete the derived snapshots

    :param str name:
        Name/ID of VM whose snapshot will be deleted

    :param str snap_name:
        Name/ID of snapshot to delete

    :param str runas:
        The user that the prlctl command will be run as

    :param bool all:
        Delete all snapshots having the name given

        .. versionadded:: 2016.11.0

    Example:

    .. code-block:: bash

        salt '*' parallels.delete_snapshot macvm 'unneeded snapshot' runas=macdev
        salt '*' parallels.delete_snapshot macvm 'Snapshot for linked clone' all=True runas=macdev
    RMRu{}u--idusnapshot-deleteiiN(
RRR.R/RURRRRR'RtkeysRD(
R)RORR+RMRQRYRLR
tret_keys((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytdelete_snapshot�s
cC@sLtjjj|�}t||d|�}|d|g}td|d|�S(us
    Revert a VM to a snapshot

    :param str name:
        Name/ID of VM to revert to a snapshot

    :param str snap_name:
        Name/ID of snapshot to revert to

    :param str runas:
        The user that the prlctl command will be run as

    Example:

    .. code-block:: bash

        salt '*' parallels.revert_snapshot macvm base-with-updates runas=macdev
    Ru--idusnapshot-switch(RRR.R/RUR'(R)RORR
((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pytrevert_snapshot�s(1t__doc__t
__future__RRRRtloggingRtsalt.utils.dataRtsalt.utils.pathtsalt.utils.yamltsalt.exceptionsRRtsalt.extRt__virtualname__t__func_alias__t	getLoggert__name__RHtcompiletIRRRR(R&R'R7R-R2R3R:R;R=R>R?R@RBRPRTR4RURZR\R_R`(((s:/usr/lib/python2.7/site-packages/salt/modules/parallels.pyt<module>sF
	
	#!9$Q:>'9

Zerion Mini Shell 1.0