<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import os <EOL> import salt . utils <EOL> import salt . utils . files <EOL> import salt . utils . atomicfile <EOL> from salt . utils . odict import OrderedDict <EOL> log = logging . getLogger ( __name__ ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in __salt__ and '<STR_LIT>' in __salt__ : <EOL> return True <EOL> else : <EOL> return ( <EOL> False , <EOL> '<STR_LIT>' . format ( <EOL> __virtualname__ <EOL> ) <EOL> ) <EOL> def _load_config ( ) : <EOL> '''<STR_LIT>''' <EOL> config = { } <EOL> if os . path . isfile ( '<STR_LIT>' ) : <EOL> with salt . utils . fopen ( '<STR_LIT>' , '<STR_LIT:r>' ) as config_file : <EOL> for optval in config_file : <EOL> if optval [ <NUM_LIT:0> ] == '<STR_LIT:#>' : <EOL> continue <EOL> if '<STR_LIT:=>' not in optval : <EOL> continue <EOL> optval = optval . split ( '<STR_LIT:=>' ) <EOL> config [ optval [ <NUM_LIT:0> ] . lower ( ) ] = optval [ <NUM_LIT:1> ] . strip ( ) . strip ( '<STR_LIT:">' ) <EOL> log . debug ( '<STR_LIT>' . format ( config ) ) <EOL> return config <EOL> def _write_config ( config ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> with salt . utils . atomicfile . atomic_open ( '<STR_LIT>' , '<STR_LIT:w>' ) as config_file : <EOL> config_file . write ( "<STR_LIT>" ) <EOL> for prop in OrderedDict ( sorted ( config . items ( ) ) ) : <EOL> if '<STR_LIT:U+0020>' in str ( config [ prop ] ) : <EOL> if not config [ prop ] . startswith ( '<STR_LIT:">' ) or not config [ prop ] . endswith ( '<STR_LIT:">' ) : <EOL> config [ prop ] = '<STR_LIT>' . format ( config [ prop ] ) <EOL> config_file . write ( "<STR_LIT>" . format ( prop , config [ prop ] ) ) <EOL> log . debug ( '<STR_LIT>' . format ( config ) ) <EOL> except IOError : <EOL> return False <EOL> return True <EOL> def _parse_vmconfig ( config , instances ) : <EOL> '''<STR_LIT>''' <EOL> vmconfig = None <EOL> if isinstance ( config , ( salt . utils . odict . OrderedDict ) ) : <EOL> vmconfig = OrderedDict ( ) <EOL> for prop in config . keys ( ) : <EOL> if prop not in instances : <EOL> vmconfig [ prop ] = config [ prop ] <EOL> else : <EOL> if not isinstance ( config [ prop ] , ( salt . utils . odict . OrderedDict ) ) : <EOL> continue <EOL> vmconfig [ prop ] = [ ] <EOL> for instance in config [ prop ] : <EOL> instance_config = config [ prop ] [ instance ] <EOL> instance_config [ instances [ prop ] ] = instance <EOL> vmconfig [ prop ] . append ( instance_config ) <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> return vmconfig <EOL> def _get_instance_changes ( current , state ) : <EOL> '''<STR_LIT>''' <EOL> current_keys = set ( current . keys ( ) ) <EOL> state_keys = set ( state . keys ( ) ) <EOL> changed = salt . utils . compare_dicts ( current , state ) <EOL> for change in changed . keys ( ) : <EOL> if change in changed and changed [ change ] [ '<STR_LIT>' ] == "<STR_LIT>" : <EOL> del changed [ change ] <EOL> if change in changed and changed [ change ] [ '<STR_LIT>' ] == "<STR_LIT>" : <EOL> del changed [ change ] <EOL> return changed <EOL> def config_present ( name , value ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> config = _load_config ( ) <EOL> if isinstance ( value , ( bool ) ) : <EOL> value = '<STR_LIT:true>' if value else '<STR_LIT:false>' <EOL> if not value : <EOL> value = "<STR_LIT>" <EOL> if name in config : <EOL> if str ( config [ name ] ) == str ( value ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name , value ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name , value ) <EOL> ret [ '<STR_LIT>' ] [ name ] = value <EOL> config [ name ] = value <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name , value ) <EOL> ret [ '<STR_LIT>' ] [ name ] = value <EOL> config [ name ] = value <EOL> if not __opts__ [ '<STR_LIT:test>' ] and len ( ret [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> ret [ '<STR_LIT:result>' ] = _write_config ( config ) <EOL> return ret <EOL> def config_absent ( name ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> config = _load_config ( ) <EOL> if name in config : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> ret [ '<STR_LIT>' ] [ name ] = None <EOL> del config [ name ] <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> if not __opts__ [ '<STR_LIT:test>' ] and len ( ret [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> ret [ '<STR_LIT:result>' ] = _write_config ( config ) <EOL> return ret <EOL> def image_present ( name ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if name in __salt__ [ '<STR_LIT>' ] ( ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> available_images = __salt__ [ '<STR_LIT>' ] ( ) <EOL> if name in available_images : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> else : <EOL> __salt__ [ '<STR_LIT>' ] ( name ) <EOL> ret [ '<STR_LIT:result>' ] = ( name in __salt__ [ '<STR_LIT>' ] ( ) ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> ret [ '<STR_LIT>' ] [ name ] = available_images [ name ] <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> def image_absent ( name ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if name not in __salt__ [ '<STR_LIT>' ] ( ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> if name in __salt__ [ '<STR_LIT>' ] ( order = '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> else : <EOL> __salt__ [ '<STR_LIT>' ] ( name ) <EOL> ret [ '<STR_LIT:result>' ] = name not in __salt__ [ '<STR_LIT>' ] ( ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> ret [ '<STR_LIT>' ] [ name ] = None <EOL> return ret <EOL> def image_vacuum ( name ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> images = [ ] <EOL> for state in __salt__ [ '<STR_LIT>' ] ( ) : <EOL> if '<STR_LIT:state>' not in state : <EOL> continue <EOL> if state [ '<STR_LIT:state>' ] != __virtualname__ : <EOL> continue <EOL> if state [ '<STR_LIT>' ] not in [ '<STR_LIT>' ] : <EOL> continue <EOL> if '<STR_LIT:name>' in state : <EOL> images . append ( state [ '<STR_LIT:name>' ] ) <EOL> for image_uuid in __salt__ [ '<STR_LIT>' ] ( order = '<STR_LIT>' ) : <EOL> if image_uuid in images : <EOL> continue <EOL> images . append ( image_uuid ) <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> for image_uuid in __salt__ [ '<STR_LIT>' ] ( ) : <EOL> if image_uuid in images : <EOL> continue <EOL> if image_uuid in __salt__ [ '<STR_LIT>' ] ( image_uuid ) : <EOL> ret [ '<STR_LIT>' ] [ image_uuid ] = None <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if ret [ '<STR_LIT:result>' ] and len ( ret [ '<STR_LIT>' ] ) == <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> elif ret [ '<STR_LIT:result>' ] and len ( ret [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return ret <EOL> def vm_present ( name , vmconfig , config = None ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> state_config = config if config else { } <EOL> config = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> config . update ( state_config ) <EOL> log . debug ( '<STR_LIT>' . format ( name , config ) ) <EOL> vmconfig_type = { <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:path>' , <EOL> '<STR_LIT>' : '<STR_LIT:target>' <EOL> } , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' <EOL> ] <EOL> } <EOL> vmconfig = _parse_vmconfig ( vmconfig , vmconfig_type [ '<STR_LIT>' ] ) <EOL> log . debug ( '<STR_LIT>' . format ( name , vmconfig ) ) <EOL> if '<STR_LIT>' not in vmconfig : <EOL> vmconfig [ '<STR_LIT>' ] = name <EOL> if vmconfig [ '<STR_LIT>' ] in __salt__ [ '<STR_LIT>' ] ( order = '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> vmconfig = { <EOL> '<STR_LIT:state>' : vmconfig , <EOL> '<STR_LIT>' : __salt__ [ '<STR_LIT>' ] ( vmconfig [ '<STR_LIT>' ] , key = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : None <EOL> } <EOL> if '<STR_LIT>' in vmconfig [ '<STR_LIT:state>' ] : <EOL> vmconfig [ '<STR_LIT>' ] = vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] <EOL> vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] = vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in vmconfig [ '<STR_LIT:state>' ] : <EOL> new_disks = [ ] <EOL> for disk in vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] : <EOL> path = False <EOL> if '<STR_LIT>' in vmconfig [ '<STR_LIT>' ] : <EOL> for cdisk in vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> if cdisk [ '<STR_LIT:path>' ] . endswith ( disk [ '<STR_LIT:path>' ] ) : <EOL> path = cdisk [ '<STR_LIT:path>' ] <EOL> break <EOL> if not path : <EOL> del disk [ '<STR_LIT:path>' ] <EOL> else : <EOL> disk [ '<STR_LIT:path>' ] = path <EOL> new_disks . append ( disk ) <EOL> vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] = new_disks <EOL> for prop in vmconfig [ '<STR_LIT:state>' ] : <EOL> if prop in vmconfig_type [ '<STR_LIT>' ] or prop in vmconfig_type [ '<STR_LIT>' ] or prop in vmconfig_type [ '<STR_LIT>' ] : <EOL> continue <EOL> if prop in vmconfig [ '<STR_LIT>' ] : <EOL> if isinstance ( vmconfig [ '<STR_LIT>' ] [ prop ] , ( list ) ) or isinstance ( vmconfig [ '<STR_LIT>' ] [ prop ] , ( dict ) ) : <EOL> if vmconfig [ '<STR_LIT>' ] [ prop ] == vmconfig [ '<STR_LIT:state>' ] [ prop ] : <EOL> continue <EOL> else : <EOL> if "<STR_LIT>" . format ( vmconfig [ '<STR_LIT>' ] [ prop ] ) == "<STR_LIT>" . format ( vmconfig [ '<STR_LIT:state>' ] [ prop ] ) : <EOL> continue <EOL> vmconfig [ '<STR_LIT>' ] [ prop ] = vmconfig [ '<STR_LIT:state>' ] [ prop ] <EOL> for collection in vmconfig_type [ '<STR_LIT>' ] : <EOL> if collection in vmconfig_type [ '<STR_LIT>' ] : <EOL> continue <EOL> if collection in vmconfig [ '<STR_LIT:state>' ] and vmconfig [ '<STR_LIT:state>' ] [ collection ] is not None : <EOL> for prop in vmconfig [ '<STR_LIT:state>' ] [ collection ] : <EOL> if prop in vmconfig [ '<STR_LIT>' ] [ collection ] and vmconfig [ '<STR_LIT>' ] [ collection ] [ prop ] == vmconfig [ '<STR_LIT:state>' ] [ collection ] [ prop ] : <EOL> continue <EOL> if '<STR_LIT>' . format ( collection ) not in vmconfig [ '<STR_LIT>' ] : <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( collection ) ] = { } <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( collection ) ] [ prop ] = vmconfig [ '<STR_LIT:state>' ] [ collection ] [ prop ] <EOL> if collection in vmconfig [ '<STR_LIT>' ] and vmconfig [ '<STR_LIT>' ] [ collection ] is not None : <EOL> for prop in vmconfig [ '<STR_LIT>' ] [ collection ] : <EOL> if collection in vmconfig [ '<STR_LIT:state>' ] and vmconfig [ '<STR_LIT:state>' ] [ collection ] is not None : <EOL> if prop in vmconfig [ '<STR_LIT:state>' ] [ collection ] : <EOL> continue <EOL> if '<STR_LIT>' . format ( collection ) not in vmconfig [ '<STR_LIT>' ] : <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( collection ) ] = [ ] <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( collection ) ] . append ( prop ) <EOL> for instance in vmconfig_type [ '<STR_LIT>' ] : <EOL> if instance in vmconfig_type [ '<STR_LIT>' ] : <EOL> continue <EOL> if instance in vmconfig [ '<STR_LIT:state>' ] and vmconfig [ '<STR_LIT:state>' ] [ instance ] is not None : <EOL> for state_cfg in vmconfig [ '<STR_LIT:state>' ] [ instance ] : <EOL> add_instance = True <EOL> for current_cfg in vmconfig [ '<STR_LIT>' ] [ instance ] : <EOL> if vmconfig_type [ '<STR_LIT>' ] [ instance ] not in state_cfg : <EOL> continue <EOL> if state_cfg [ vmconfig_type [ '<STR_LIT>' ] [ instance ] ] == current_cfg [ vmconfig_type [ '<STR_LIT>' ] [ instance ] ] : <EOL> add_instance = False <EOL> changed = _get_instance_changes ( current_cfg , state_cfg ) <EOL> update_cfg = { } <EOL> if len ( changed ) > <NUM_LIT:0> : <EOL> for prop in changed : <EOL> update_cfg [ prop ] = state_cfg [ prop ] <EOL> for prop in state_cfg : <EOL> if isinstance ( state_cfg [ prop ] , ( list ) ) and len ( state_cfg [ prop ] ) == <NUM_LIT:0> : <EOL> continue <EOL> if prop not in current_cfg : <EOL> update_cfg [ prop ] = state_cfg [ prop ] <EOL> if len ( update_cfg ) > <NUM_LIT:0> : <EOL> if '<STR_LIT>' . format ( instance ) not in vmconfig [ '<STR_LIT>' ] : <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( instance ) ] = [ ] <EOL> update_cfg [ vmconfig_type [ '<STR_LIT>' ] [ instance ] ] = state_cfg [ vmconfig_type [ '<STR_LIT>' ] [ instance ] ] <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( instance ) ] . append ( update_cfg ) <EOL> if add_instance : <EOL> if '<STR_LIT>' . format ( instance ) not in vmconfig [ '<STR_LIT>' ] : <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( instance ) ] = [ ] <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( instance ) ] . append ( state_cfg ) <EOL> if instance in vmconfig [ '<STR_LIT>' ] and vmconfig [ '<STR_LIT>' ] [ instance ] is not None : <EOL> for current_cfg in vmconfig [ '<STR_LIT>' ] [ instance ] : <EOL> remove_instance = True <EOL> if instance in vmconfig [ '<STR_LIT:state>' ] and vmconfig [ '<STR_LIT:state>' ] [ instance ] is not None : <EOL> for state_cfg in vmconfig [ '<STR_LIT:state>' ] [ instance ] : <EOL> if vmconfig_type [ '<STR_LIT>' ] [ instance ] not in state_cfg : <EOL> continue <EOL> if state_cfg [ vmconfig_type [ '<STR_LIT>' ] [ instance ] ] == current_cfg [ vmconfig_type [ '<STR_LIT>' ] [ instance ] ] : <EOL> remove_instance = False <EOL> if remove_instance : <EOL> if '<STR_LIT>' . format ( instance ) not in vmconfig [ '<STR_LIT>' ] : <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( instance ) ] = [ ] <EOL> vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' . format ( instance ) ] . append ( <EOL> current_cfg [ vmconfig_type [ '<STR_LIT>' ] [ instance ] ] <EOL> ) <EOL> kvm_needs_start = False <EOL> if not __opts__ [ '<STR_LIT:test>' ] and len ( vmconfig [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> if vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' and config [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in vmconfig [ '<STR_LIT>' ] or '<STR_LIT>' in vmconfig [ '<STR_LIT>' ] or '<STR_LIT>' in vmconfig [ '<STR_LIT>' ] : <EOL> if vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] in __salt__ [ '<STR_LIT>' ] ( order = '<STR_LIT>' , search = '<STR_LIT>' ) : <EOL> kvm_needs_start = True <EOL> __salt__ [ '<STR_LIT>' ] ( vm = vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] , key = '<STR_LIT>' ) <EOL> rret = __salt__ [ '<STR_LIT>' ] ( vm = vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] , key = '<STR_LIT>' , ** vmconfig [ '<STR_LIT>' ] ) <EOL> if not isinstance ( rret , ( bool ) ) and '<STR_LIT>' in rret : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = "<STR_LIT>" . format ( rret [ '<STR_LIT>' ] ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] [ vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ] = vmconfig [ '<STR_LIT>' ] <EOL> if ret [ '<STR_LIT:result>' ] : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT>' ] [ vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ] = vmconfig [ '<STR_LIT>' ] <EOL> if vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] in ret [ '<STR_LIT>' ] and len ( ret [ '<STR_LIT>' ] [ vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ] ) > <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ) <EOL> if config [ '<STR_LIT>' ] and vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' and not __opts__ [ '<STR_LIT:test>' ] : <EOL> if vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] in __salt__ [ '<STR_LIT>' ] ( order = '<STR_LIT>' , search = '<STR_LIT>' ) : <EOL> __salt__ [ '<STR_LIT>' ] ( vm = vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] , key = '<STR_LIT>' ) <EOL> if kvm_needs_start : <EOL> __salt__ [ '<STR_LIT>' ] ( vm = vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] , key = '<STR_LIT>' ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] = { } <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in vmconfig [ '<STR_LIT>' ] and vmconfig [ '<STR_LIT>' ] != vmconfig [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> if config [ '<STR_LIT>' ] : <EOL> if vmconfig [ '<STR_LIT>' ] not in __salt__ [ '<STR_LIT>' ] ( ) : <EOL> if config [ '<STR_LIT>' ] : <EOL> available_images = __salt__ [ '<STR_LIT>' ] ( ) <EOL> if vmconfig [ '<STR_LIT>' ] in available_images and not __opts__ [ '<STR_LIT:test>' ] : <EOL> __salt__ [ '<STR_LIT>' ] ( vmconfig [ '<STR_LIT>' ] ) <EOL> rret = __salt__ [ '<STR_LIT>' ] ( <EOL> vm = vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] , <EOL> key = '<STR_LIT>' , <EOL> image = vmconfig [ '<STR_LIT>' ] <EOL> ) <EOL> if not isinstance ( rret , ( bool ) ) and '<STR_LIT>' in rret : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> if vmconfig [ '<STR_LIT>' ] not in __salt__ [ '<STR_LIT>' ] ( ) : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] , <EOL> vmconfig [ '<STR_LIT>' ] <EOL> ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] <EOL> ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ) <EOL> if vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] not in ret [ '<STR_LIT>' ] : <EOL> ret [ '<STR_LIT>' ] [ vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ] = { } <EOL> ret [ '<STR_LIT>' ] [ vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ] [ '<STR_LIT>' ] = vmconfig [ '<STR_LIT>' ] <EOL> else : <EOL> log . warning ( '<STR_LIT>' . format ( <EOL> name <EOL> ) ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( vmconfig [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] ) <EOL> if not isinstance ( rret , ( bool ) ) and '<STR_LIT>' in rret : <EOL> ret [ '<STR_LIT>' ] = "<STR_LIT>" . format ( rret [ '<STR_LIT>' ] ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> if '<STR_LIT>' in vmconfig and vmconfig [ '<STR_LIT>' ] not in __salt__ [ '<STR_LIT>' ] ( ) : <EOL> if config [ '<STR_LIT>' ] : <EOL> available_images = __salt__ [ '<STR_LIT>' ] ( ) <EOL> if vmconfig [ '<STR_LIT>' ] not in available_images : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( vmconfig [ '<STR_LIT>' ] ) <EOL> elif not __opts__ [ '<STR_LIT:test>' ] : <EOL> if vmconfig [ '<STR_LIT>' ] not in __salt__ [ '<STR_LIT>' ] ( vmconfig [ '<STR_LIT>' ] ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( vmconfig [ '<STR_LIT>' ] ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( vmconfig [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in vmconfig : <EOL> new_disks = [ ] <EOL> for disk in vmconfig [ '<STR_LIT>' ] : <EOL> if '<STR_LIT:path>' in disk : <EOL> del disk [ '<STR_LIT:path>' ] <EOL> new_disks . append ( disk ) <EOL> vmconfig [ '<STR_LIT>' ] = new_disks <EOL> if ret [ '<STR_LIT:result>' ] : <EOL> uuid = __salt__ [ '<STR_LIT>' ] ( ** vmconfig ) if not __opts__ [ '<STR_LIT:test>' ] else True <EOL> if not isinstance ( uuid , ( bool ) ) and '<STR_LIT>' in uuid : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = "<STR_LIT>" . format ( uuid [ '<STR_LIT>' ] ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] [ vmconfig [ '<STR_LIT>' ] ] = vmconfig <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( vmconfig [ '<STR_LIT>' ] ) <EOL> return ret <EOL> def vm_absent ( name , archive = False ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if name not in __salt__ [ '<STR_LIT>' ] ( order = '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> if not __opts__ [ '<STR_LIT:test>' ] : <EOL> if archive : <EOL> __salt__ [ '<STR_LIT>' ] ( vm = name , key = '<STR_LIT>' , archive_on_delete = True ) <EOL> ret [ '<STR_LIT:result>' ] = __salt__ [ '<STR_LIT>' ] ( name , key = '<STR_LIT>' ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> if not isinstance ( ret [ '<STR_LIT:result>' ] , bool ) and ret [ '<STR_LIT:result>' ] . get ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> ret [ '<STR_LIT>' ] [ name ] = None <EOL> return ret <EOL> def vm_running ( name ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if name in __salt__ [ '<STR_LIT>' ] ( order = '<STR_LIT>' , search = '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True if __opts__ [ '<STR_LIT:test>' ] else __salt__ [ '<STR_LIT>' ] ( name , key = '<STR_LIT>' ) <EOL> if not isinstance ( ret [ '<STR_LIT:result>' ] , bool ) and ret [ '<STR_LIT:result>' ] . get ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] [ name ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> def vm_stopped ( name ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if name in __salt__ [ '<STR_LIT>' ] ( order = '<STR_LIT>' , search = '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True if __opts__ [ '<STR_LIT:test>' ] else __salt__ [ '<STR_LIT>' ] ( name , key = '<STR_LIT>' ) <EOL> if not isinstance ( ret [ '<STR_LIT:result>' ] , bool ) and ret [ '<STR_LIT:result>' ] . get ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] [ name ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret </s>
