%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/usr/lib/python2.7/site-packages/salt/cloud/clouds/
Upload File :
Create Path :
Current File : //proc/self/root/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pyc

�
���^c@@sZdZddlmZmZmZddlZddlmZddlj	Z	yVddl
Z
ddlmZm
Z
mZmZmZmZmZmZmZeZWnek
r�eZnXeje�ZdZdZd�Zd�Zd	�Z d
�Z!ddd�Z#ddd�Z$dd
�Z%dd�Z&dd�Z'dd�Z(dd�Z)dS(u�
A salt cloud provider that lets you use virtualbox on your machine
and act as a cloud.

:depends: vboxapi

For now this will only clone existing VMs. It's best to create a template
from which we will clone.

Followed
https://docs.saltstack.com/en/latest/topics/cloud/cloud.html#non-libcloud-based-modules
to create this.

Dicts provided by salt:
    __opts__ : contains the options used to run Salt Cloud,
        as well as a set of configuration and environment variables
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltCloudSystemExit(	tvb_list_machinestvb_clone_vmtvb_machine_existstvb_destroy_machinetvb_get_machinet
vb_stop_vmttreat_machine_dicttvb_start_vmtvb_wait_for_network_addressu
virtualboxcC@s-tstdfSt�tkr)tdfStS(u�
    This function determines whether or not
    to make this cloud module available upon execution.
    Most often, it uses get_configured_provider() to determine
     if the necessary configuration has been set up.
    It may also check for necessary imports decide whether to load the module.
    In most cases, it will return a True or False value.
    If the name of the driver used does not match the filename,
     then that name should be returned instead of True.

    @return True|False|str
    uCThe virtualbox driver cannot be loaded: 'vboxapi' is not installed.uPThe virtualbox driver cannot be loaded: 'virtualbox' provider is not configured.(tHAS_VBOXtFalsetget_configured_providert__virtualname__(((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pyt__virtual__8s



cC@stjttptd�}|S(u/
    Return the first configured instance.
    ((tconfigtis_provider_configuredt__opts__t__active_provider_name__R(t
configured((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pyRPs
		cC@syidd6dd6dd6}|s%tSd|kr5tS|d|krQ||dStdjd	j|j�����d
S(ue
    Convert the virtualbox config file values for clone_mode into the integers the API requires
    iustateiuchildiuallu	clonemodeu?Illegal clonemode for virtualbox profile.  Legal values are: {}u,N(tDEFAULT_CLONE_MODERtformattjointkeys(tvm_infotmode_map((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pyt
map_clonemode\s
cC@sy7|dr6tjttpd|d�tkr6tSWntk
rJnX|d}tjd|tdtdt�}tjd|tdd�}tjd	|tdd.�}tjd|tdt�}tjd|tdtdd/�}t	|�}d
|j
�kr|d
nd/}d|j
�kr2|dnd}	tjd�t
ddddj|d�dt
dd|ddddg�dtddtd�i|dd6|dd6|d 6}
t
ddd!d"j|d�dt
dd#|
t|
��dtddtd�t|
�}|r�t|d$|�t|d%|d&|�}|r�||	}
tjd'||
�|r�||d(<|
|d)<t
d*|t�}|j|�q�q�nt
ddd+d,j|d�dt
dd-|t|��dtddtd�|S(0u
    Creates a virtual machine from the given VM information

    This is what is used to request a virtual machine to be created by the
    cloud provider, wait for it to become available, and then (optionally) log
    in and install Salt on it.

    Events fired:

    This function fires the event ``salt/cloud/vm_name/creating``, with the
    payload containing the names of the VM, profile, and provider.

    @param vm_info

    .. code-block:: text

        {
            name: <str>
            profile: <dict>
            driver: <provider>:<profile>
            clonefrom: <vm_name>
            clonemode: <mode> (default: state, choices: state, child, all)
        }

    @type vm_info dict
    @return dict of resulting vm. !!!Passwords can and should be included!!!
    uprofileu
virtualboxunameudeployt
search_globaltdefaultuwait_for_ip_timeouti<uboot_timeouti�upower_onuprivate_keyuwaitforpatternuinterfaceindexiu$Going to fire event: starting createucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingtargsucloud.filter_eventucreatinguproviderudrivertsock_dirusock_dirt	transportu	transportu	clonefromu
clone_fromu
clone_modeurequesting instanceusalt/cloud/{0}/requestingu
requestingttimeouttmachine_nametwait_for_patternu[ %s ] IPv4 is: %sukey_filenameussh_hostucloud.bootstrapucreated machineusalt/cloud/{0}/createducreatedi`�N(Rtis_profile_configuredRRRtAttributeErrortget_cloud_config_valuetTruetNoneRRtlogtdebugt	__utils__RtlistRRRtinfotupdate(Rtvm_nametdeploytwait_for_ip_timeouttboot_timeouttpowertkey_filenamet
clone_modeR%tinterface_indextrequest_kwargst	vm_resulttipstiptres((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pytcreatets|	
	

""
"






cC@sh|dkrtd��ni}x@t�D]5}|jd�}|r+t|�||<|d=q+q+W|S(u#
    All information available about all nodes should be returned in this function.
    The fields in the list_nodes() function should also be returned,
    even if they would not normally be provided by the cloud provider.

    This is because some functions both within Salt and 3rd party will break if an expected field is not present.
    This function is normally called with the -F option:


    .. code-block:: bash

        salt-cloud -F


    @param kwargs:
    @type kwargs:
    @param call:
    @type call:
    @return:
    @rtype:
    uactionuBThe list_nodes_full function must be called with -f or --function.uname(RRtgetR
(tkwargstcalltmachinestmachinetname((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pytlist_nodes_full�scC@sM|dkrtd��nddddddg}td	td
�||�S(u�
    This function returns a list of nodes available on this cloud provider, using the following fields:

    id (str)
    image (str)
    size (str)
    state (str)
    private_ips (list)
    public_ips (list)

    No other fields should be returned in this function, and all of these fields should be returned, even if empty.
    The private_ips and public_ips fields should always be of a list type, even if empty,
    and the other fields should always be of a str type.
    This function is normally called with the -Q option:

    .. code-block:: bash

        salt-cloud -Q


    @param kwargs:
    @type kwargs:
    @param call:
    @type call:
    @return:
    @rtype:
    uactionu=The list_nodes function must be called with -f or --function.uiduimageusizeustateuprivate_ipsu
public_ipsucloud.list_nodes_selectufunction(RR-RE(R@RAt
attributes((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pyt
list_nodess	cC@stdtd�td|�S(uO
    Return a list of the VMs that are on the provider, with select fields
    ucloud.list_nodes_selectufunctionuquery.selection(R-RER(RA((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pytlist_nodes_select>scC@s�tjd|�t|�s)dj|�Stddddj|�di|d6d	td
dtd�t|�tddd
dj|�di|d6d	td
dtd�dS(u&
    This function irreversibly destroys a virtual machine on the cloud provider.
    Before doing so, it should fire an event on the Salt event bus.

    The tag for this event is `salt/cloud/<vm name>/destroying`.
    Once the virtual machine has been destroyed, another event is fired.
    The tag for that event is `salt/cloud/<vm name>/destroyed`.

    Dependencies:
        list_nodes

    @param name:
    @type name: str
    @param call:
    @type call:
    @return: True if all went well, otherwise an error message
    @rtype: bool|str
    u Attempting to delete instance %su&{0} doesn't exist and can't be deleteducloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingR unameR!usock_dirR"u	transportudestroyed instanceusalt/cloud/{0}/destroyedN(R+R/RRR-RR(RDRA((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pytdestroyGs$





cC@sR|dkrtd��ntjd|�t|�t|�}|d=t|�S(u�
    Start a machine.
    @param name: Machine to start
    @type name: str
    @param call: Must be "action"
    @type call: str
    uactionu7The instance action must be called with -a or --action.uStarting machine: %suname(RR+R/RRR
(RDRARC((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pytstartss
cC@sR|dkrtd��ntjd|�t|�t|�}|d=t|�S(u�
    Stop a running machine.
    @param name: Machine to stop
    @type name: str
    @param call: Must be "action"
    @type call: str
    uactionu7The instance action must be called with -a or --action.uStopping machine: %suname(RR+R/R	RR
(RDRARC((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pytstop�s
cC@sc|dkrtd��n|d}tjd|�t|�}it|�|d6}|d=|S(u&
    Show the details of an image
    ufunctionu;The show_image action must be called with -f or --function.uimageuShowing image %suname(RR+R/RR
(R@RARDRCtret((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pyt
show_image�s
(*t__doc__t
__future__RRRtloggingtsalt.exceptionsRtsalt.configRtvboxapitsalt.utils.virtualboxRRRRRR	R
RRR)R
tImportErrorRt	getLoggert__name__R+RRRRRR>R*RERGRHRIRJRKRM(((s@/usr/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.pyt<module>s0@


				s(/	,

Zerion Mini Shell 1.0