%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddlZddlmZej	e
�ZiZd�Z
dd�Zdd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�ZdS(u=
Spacewalk Runner
================

.. versionadded:: 2016.3.0

Runner to interact with Spacewalk using Spacewalk API

:codeauthor: Nitin Madhok <nmadhok@clemson.edu>, Joachim Werner <joe@suse.com>, Benedikt Werner <1benediktwerner@gmail.com>
:maintainer: Benedikt Werner <1benediktwerner@gmail.com>

To use this runner, set up the Spacewalk URL, username and password in the
master configuration at ``/etc/salt/master`` or ``/etc/salt/master.d/spacewalk.conf``:

.. code-block:: yaml

    spacewalk:
      spacewalk01.domain.com:
        username: 'testuser'
        password: 'verybadpass'
      spacewalk02.domain.com:
        username: 'testuser'
        password: 'verybadpass'

.. note::

    Optionally, ``protocol`` can be specified if the spacewalk server is
    not using the defaults. Default is ``protocol: https``.

i(tabsolute_importtprint_functiontunicode_literalsN(tsixcC@st�stdfStS(uz
    Check for spacewalk configuration in master config file
    or directory and load runner only if it is specified
    u No spacewalk configuration found(t_get_spacewalk_configurationtFalsetTrue(((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pyt__virtual__.s	
uc	C@s$dtkrtdnd}|r y�x�tj|�D]�\}}|jdd�}|jdd�}|jdd�}|s�|r�tjd|�tSidj||�d6|d6|d6}|s�||kr5|Sq5WWn$t	k
r}tjd	|�tSX|r tjd
|�tSntS(u[
    Return the configuration read from the master configuration
    file or directory
    u	spacewalkuusernameupassworduprotocoluhttpsuNUsername or Password has not been specified in the master configuration for %su{0}://{1}/rpc/apiuapi_urluException encountered: %suGConfiguration for %s has not been specified in the master configurationN(
t__opts__tNoneRt	iteritemstgettlogterrorRtformatt	Exception(	t
spacewalk_urltspacewalk_configtspacewalk_servertservice_configtusernametpasswordtprotocoltrettexc((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pyR8s6
cC@sLi}tjjj|d|dt�|d<|djj||�|d<|S(uA
    Return the client object and session key for the client
    tverbosetuse_datetimeuclientukey(Rtmovest
xmlrpc_clienttServerRtauthtlogin(turltuserRRtsession((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pyt_get_client_and_keycs%cC@s|djj|d�dS(u#
    Disconnect API connection
    uclientukeyN(Rtlogout(R"((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pyt_disconnect_sessionnscC@s�|tkrt|St|�}|s>tdj|���nt|d|d|d�}tjt|�|d}|d}||ft|<||fS(u
    Get session and key
    u#No config for '{0}' found on masteruapi_urluusernameupassworduclientukey(t	_sessionsRRRR#tatexittregisterR%(tservertconfigR"tclienttkey((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pyt_get_sessionus

cO@s�d|kr|d}n|}dj||�}yt|�\}}Wn:tk
r�}dj||�}	tj|	�i|	|6SX|jd�\}
}tt||
�|�}y|||�}
Wn"tk
r�}dj|�}
nXi|
|6S(uD
    Call the Spacewalk xmlrpc api.

    CLI Example:

    .. code-block:: bash

        salt-run spacewalk.api spacewalk01.domain.com systemgroup.create MyGroup Description
        salt-run spacewalk.api spacewalk01.domain.com systemgroup.create arguments='["MyGroup", "Description"]'

    State Example:

    .. code-block:: yaml

        create_group:
          salt.runner:
            - name: spacewalk.api
            - server: spacewalk01.domain.com
            - command: systemgroup.create
            - arguments:
              - MyGroup
              - Description
    u	argumentsu{0} {1}u?Exception raised when connecting to spacewalk server ({0}): {1}u.uAPI call failed: {0}(RR-RRR
tsplittgetattr(R)tcommandtargstkwargst	argumentstcallR+R,Rterr_msgt	namespacetmethodtendpointtoutputte((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pytapi�s"

c
C@s�yt|�\}}Wn:tk
rR}dj||�}tj|�i|d6SX|jj|�}g}x2|D]*}	|	d|krr|j|	d�qrqrW|jj	|||�dkr�i||6Sid|6SdS(u�
    Add server groups to a activation key

    CLI Example:

    .. code-block:: bash

        salt-run spacewalk.addGroupsToKey spacewalk01.domain.com 1-my-key '[group1, group2]'
    u?Exception raised when connecting to spacewalk server ({0}): {1}uErrorunameuidiu&Failed to add groups to activation keyN(
R-RRRR
tsystemgroupt
listAllGroupstappendt
activationkeytaddServerGroups(
R)tactivation_keytgroupsR+R,RR5t
all_groupstgroupIdstgroup((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pytaddGroupsToKey�s

c
C@s�yt|�\}}Wn:tk
rR}dj||�}tj|�i|d6SX|jj|�}g}g}xR|D]J}|jj||d�dkr�|j|d�qx|j|d�qxWi|d6}	|r�||	d<n|	S(u1
    Delete all server groups from Spacewalk
    u?Exception raised when connecting to spacewalk server ({0}): {1}uErrorunameiudeletedufailed(	R-RRRR
R<R=tdeleteR>(
R)R+R,RR5RBtdeleted_groupst
failed_groupsRER((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pytdeleteAllGroups�s"



c	C@s�yt|�\}}Wn:tk
rR}dj||�}tj|�i|d6SX|jj|�}g}g}x0|D](}|j|d�|j|d�qxW|jj||�dkr�i|d6Sidd6SdS(	u�
    Delete all systems from Spacewalk

    CLI Example:

    .. code-block:: bash

        salt-run spacewalk.deleteAllSystems spacewalk01.domain.com
    u?Exception raised when connecting to spacewalk server ({0}): {1}uErroruidunameiudeleteduFailed to delete all systemsN(	R-RRRR
tsystemtlistSystemsR>t
deleteSystems(	R)R+R,RR5tsystemstidstnamesRK((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pytdeleteAllSystems�s

c
C@s�yt|�\}}Wn:tk
rR}dj||�}tj|�i|d6SX|jj|�}g}g}xR|D]J}|jj||d�dkr�|j|d�qx|j|d�qxWi|d6}	|r�||	d<n|	S(u�
    Delete all activation keys from Spacewalk

    CLI Example:

    .. code-block:: bash

        salt-run spacewalk.deleteAllActivationKeys spacewalk01.domain.com
    u?Exception raised when connecting to spacewalk server ({0}): {1}uErrorukeyiudeletedufailed(	R-RRRR
R?tlistActivationKeysRGR>(
R)R+R,RR5tactivation_keystdeleted_keystfailed_keystaKeyR((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pytdeleteAllActivationKeyss"



c	C@s�yt|�\}}Wn:tk
rR}dj||�}tj|�i||6SX|jj||�}|r�xr|D]S}|jj||d�}|dkr�idj|�|6Sidj|�|6SquWnidj|�|6SdS(u�
    Unregister specified server from Spacewalk

    CLI Example:

    .. code-block:: bash

        salt-run spacewalk.unregister my-test-vm spacewalk01.domain.com
    u?Exception raised when connecting to spacewalk server ({0}): {1}uidiu"Successfully unregistered from {0}uFailed to unregister from {0}u/System does not exist in spacewalk server ({0})N(R-RRRR
RKtgetIdtdeleteSystem(	tnamet
server_urlR+R,RR5tsystems_listRKtout((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pyt
unregister8s

(t__doc__t
__future__RRRR'tloggingtsalt.extRt	getLoggert__name__RR&RRR#R%R-R;RFRJRQRWR^(((s:/usr/lib/python2.7/site-packages/salt/runners/spacewalk.pyt<module>s"	
+			0			 	#

Zerion Mini Shell 1.0