<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import , print_function <EOL> import datetime <EOL> import copy <EOL> import textwrap <EOL> import difflib <EOL> import logging <EOL> import tempfile <EOL> import os <EOL> import pipes <EOL> import time <EOL> import shutil <EOL> import re <EOL> import random <EOL> import distutils . version <EOL> import salt <EOL> import salt . utils . odict <EOL> import salt . utils <EOL> import salt . utils . dictupdate <EOL> import salt . utils . network <EOL> from salt . exceptions import CommandExecutionError , SaltInvocationError <EOL> import salt . utils . cloud <EOL> import salt . config <EOL> import salt . ext . six as six <EOL> from salt . ext . six . moves import range <EOL> from salt . ext . six . moves . urllib . parse import urlparse as _urlparse <EOL> log = logging . getLogger ( __name__ ) <EOL> __func_alias__ = { <EOL> '<STR_LIT>' : '<STR_LIT:list>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> __virtualname__ = '<STR_LIT>' <EOL> DEFAULT_NIC = '<STR_LIT>' <EOL> DEFAULT_BR = '<STR_LIT>' <EOL> SEED_MARKER = '<STR_LIT>' <EOL> EXEC_DRIVER = '<STR_LIT>' <EOL> DEFAULT_PATH = '<STR_LIT>' <EOL> _marker = object ( ) <EOL> def __virtual__ ( ) : <EOL> if salt . utils . which ( '<STR_LIT>' ) : <EOL> return __virtualname__ <EOL> return ( False , '<STR_LIT>' ) <EOL> def get_root_path ( path ) : <EOL> '''<STR_LIT>''' <EOL> if not path : <EOL> path = __opts__ . get ( '<STR_LIT>' , DEFAULT_PATH ) <EOL> return path <EOL> def version ( ) : <EOL> '''<STR_LIT>''' <EOL> k = '<STR_LIT>' <EOL> if not __context__ . get ( k , None ) : <EOL> cversion = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> if not cversion [ '<STR_LIT>' ] : <EOL> ver = distutils . version . LooseVersion ( cversion [ '<STR_LIT>' ] ) <EOL> if ver < distutils . version . LooseVersion ( '<STR_LIT:1.0>' ) : <EOL> raise CommandExecutionError ( '<STR_LIT>' ) <EOL> __context__ [ k ] = "<STR_LIT>" . format ( ver ) <EOL> return __context__ . get ( k , None ) <EOL> def _clear_context ( ) : <EOL> '''<STR_LIT>''' <EOL> for var in [ x for x in __context__ if x . startswith ( '<STR_LIT>' ) ] : <EOL> log . trace ( '<STR_LIT>' . format ( var ) ) <EOL> __context__ . pop ( var , None ) <EOL> def _ip_sort ( ip ) : <EOL> '''<STR_LIT>''' <EOL> idx = '<STR_LIT>' <EOL> if ip == '<STR_LIT:127.0.0.1>' : <EOL> idx = '<STR_LIT>' <EOL> if ip == '<STR_LIT>' : <EOL> idx = '<STR_LIT>' <EOL> elif '<STR_LIT>' in ip : <EOL> idx = '<STR_LIT:100>' <EOL> return '<STR_LIT>' . format ( idx , ip ) <EOL> def search_lxc_bridges ( ) : <EOL> '''<STR_LIT>''' <EOL> bridges = __context__ . get ( '<STR_LIT>' , None ) <EOL> if not bridges : <EOL> bridges = set ( ) <EOL> running_bridges = set ( ) <EOL> bridges . add ( DEFAULT_BR ) <EOL> try : <EOL> output = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> for line in output [ '<STR_LIT>' ] . splitlines ( ) [ <NUM_LIT:1> : ] : <EOL> if not line . startswith ( '<STR_LIT:U+0020>' ) : <EOL> running_bridges . add ( line . split ( ) [ <NUM_LIT:0> ] . strip ( ) ) <EOL> except ( SaltInvocationError , CommandExecutionError ) : <EOL> pass <EOL> for ifc , ip in six . iteritems ( <EOL> __grains__ . get ( '<STR_LIT>' , { } ) <EOL> ) : <EOL> if ifc in running_bridges : <EOL> bridges . add ( ifc ) <EOL> elif os . path . exists ( <EOL> '<STR_LIT>' . format ( ifc ) <EOL> ) : <EOL> bridges . add ( ifc ) <EOL> bridges = list ( bridges ) <EOL> def sort_bridges ( a ) : <EOL> pref = '<STR_LIT:z>' <EOL> if '<STR_LIT>' in a : <EOL> pref = '<STR_LIT:a>' <EOL> elif '<STR_LIT>' == a : <EOL> pref = '<STR_LIT:c>' <EOL> return '<STR_LIT>' . format ( pref , a ) <EOL> bridges . sort ( key = sort_bridges ) <EOL> __context__ [ '<STR_LIT>' ] = bridges <EOL> return bridges <EOL> def search_lxc_bridge ( ) : <EOL> '''<STR_LIT>''' <EOL> return search_lxc_bridges ( ) [ <NUM_LIT:0> ] <EOL> def _get_salt_config ( config , ** kwargs ) : <EOL> if not config : <EOL> config = kwargs . get ( '<STR_LIT>' , { } ) <EOL> if not config : <EOL> config = { } <EOL> config . setdefault ( '<STR_LIT>' , <EOL> kwargs . get ( '<STR_LIT>' , <EOL> __opts__ . get ( '<STR_LIT>' , <EOL> __opts__ [ '<STR_LIT:id>' ] ) ) ) <EOL> config . setdefault ( <EOL> '<STR_LIT>' , <EOL> kwargs . get ( '<STR_LIT>' , <EOL> __opts__ . get ( '<STR_LIT>' , <EOL> __opts__ . get ( '<STR_LIT>' , <EOL> __opts__ . get ( '<STR_LIT>' ) ) ) ) ) <EOL> if not config [ '<STR_LIT>' ] : <EOL> config = { } <EOL> return config <EOL> def cloud_init_interface ( name , vm_ = None , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if vm_ is None : <EOL> vm_ = { } <EOL> vm_ = copy . deepcopy ( vm_ ) <EOL> vm_ = salt . utils . dictupdate . update ( vm_ , kwargs ) <EOL> profile_data = copy . deepcopy ( <EOL> vm_ . get ( '<STR_LIT>' , <EOL> vm_ . get ( '<STR_LIT>' , { } ) ) ) <EOL> if not isinstance ( profile_data , ( dict , six . string_types ) ) : <EOL> profile_data = { } <EOL> profile = get_container_profile ( profile_data ) <EOL> def _cloud_get ( k , default = None ) : <EOL> return vm_ . get ( k , profile . get ( k , default ) ) <EOL> if name is None : <EOL> name = vm_ [ '<STR_LIT:name>' ] <EOL> default_template = '<STR_LIT>' <EOL> if __grains__ . get ( '<STR_LIT>' , '<STR_LIT>' ) in [ '<STR_LIT>' ] : <EOL> default_template = '<STR_LIT>' <EOL> image = _cloud_get ( '<STR_LIT:image>' ) <EOL> if not image : <EOL> _cloud_get ( '<STR_LIT>' , default_template ) <EOL> backing = _cloud_get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if image : <EOL> profile [ '<STR_LIT>' ] = image <EOL> vgname = _cloud_get ( '<STR_LIT>' , None ) <EOL> if vgname : <EOL> profile [ '<STR_LIT>' ] = vgname <EOL> if backing : <EOL> profile [ '<STR_LIT>' ] = backing <EOL> snapshot = _cloud_get ( '<STR_LIT>' , False ) <EOL> autostart = bool ( _cloud_get ( '<STR_LIT>' , True ) ) <EOL> dnsservers = _cloud_get ( '<STR_LIT>' , [ ] ) <EOL> if not dnsservers : <EOL> dnsservers = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> password = _cloud_get ( '<STR_LIT:password>' , '<STR_LIT>' ) <EOL> password_encrypted = _cloud_get ( '<STR_LIT>' , False ) <EOL> fstype = _cloud_get ( '<STR_LIT>' , None ) <EOL> lvname = _cloud_get ( '<STR_LIT>' , None ) <EOL> pub_key = _cloud_get ( '<STR_LIT>' , None ) <EOL> priv_key = _cloud_get ( '<STR_LIT>' , None ) <EOL> size = _cloud_get ( '<STR_LIT:size>' , '<STR_LIT>' ) <EOL> script = _cloud_get ( '<STR_LIT>' , None ) <EOL> script_args = _cloud_get ( '<STR_LIT>' , None ) <EOL> users = _cloud_get ( '<STR_LIT>' , None ) <EOL> if users is None : <EOL> users = [ ] <EOL> ssh_username = _cloud_get ( '<STR_LIT>' , None ) <EOL> if ssh_username and ( ssh_username not in users ) : <EOL> users . append ( ssh_username ) <EOL> network_profile = _cloud_get ( '<STR_LIT>' , None ) <EOL> nic_opts = kwargs . get ( '<STR_LIT>' , None ) <EOL> netmask = _cloud_get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> path = _cloud_get ( '<STR_LIT:path>' , None ) <EOL> bridge = _cloud_get ( '<STR_LIT>' , None ) <EOL> gateway = _cloud_get ( '<STR_LIT>' , None ) <EOL> unconditional_install = _cloud_get ( '<STR_LIT>' , False ) <EOL> force_install = _cloud_get ( '<STR_LIT>' , True ) <EOL> config = _get_salt_config ( _cloud_get ( '<STR_LIT>' , { } ) , ** vm_ ) <EOL> default_nic = _cloud_get ( '<STR_LIT>' , DEFAULT_NIC ) <EOL> if not isinstance ( nic_opts , dict ) : <EOL> nic_opts = salt . utils . odict . OrderedDict ( ) <EOL> eth0 = nic_opts . setdefault ( default_nic , <EOL> salt . utils . odict . OrderedDict ( ) ) <EOL> if not isinstance ( nic_opts , salt . utils . odict . OrderedDict ) : <EOL> bnic_opts = salt . utils . odict . OrderedDict ( ) <EOL> bnic_opts . update ( nic_opts ) <EOL> nic_opts = bnic_opts <EOL> gw = None <EOL> bridge = _cloud_get ( '<STR_LIT>' , None ) <EOL> ip = _cloud_get ( '<STR_LIT>' , None ) <EOL> mac = _cloud_get ( '<STR_LIT>' , None ) <EOL> if ip : <EOL> fullip = ip <EOL> if netmask : <EOL> fullip += '<STR_LIT>' . format ( netmask ) <EOL> eth0 [ '<STR_LIT>' ] = fullip <EOL> if mac is not None : <EOL> eth0 [ '<STR_LIT>' ] = mac <EOL> for ix , iopts in enumerate ( _cloud_get ( "<STR_LIT>" , [ ] ) ) : <EOL> ifh = "<STR_LIT>" . format ( ix + <NUM_LIT:1> ) <EOL> ethx = nic_opts . setdefault ( ifh , { } ) <EOL> if gw is None : <EOL> gw = iopts . get ( '<STR_LIT>' , ethx . get ( '<STR_LIT>' , None ) ) <EOL> if gw : <EOL> eth0 . pop ( '<STR_LIT>' , None ) <EOL> gateway = None <EOL> ethx [ '<STR_LIT>' ] = gw <EOL> elink = iopts . get ( '<STR_LIT>' , ethx . get ( '<STR_LIT>' , None ) ) <EOL> if elink : <EOL> ethx [ '<STR_LIT>' ] = elink <EOL> aip = iopts . get ( '<STR_LIT>' , iopts . get ( '<STR_LIT>' , None ) ) <EOL> if aip : <EOL> ethx [ '<STR_LIT>' ] = aip <EOL> nm = iopts . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if nm : <EOL> ethx [ '<STR_LIT>' ] += '<STR_LIT>' . format ( nm ) <EOL> for i in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if i in iopts : <EOL> ethx [ '<STR_LIT>' ] = iopts [ i ] <EOL> break <EOL> if '<STR_LIT>' not in ethx : <EOL> ethx [ '<STR_LIT>' ] = salt . utils . gen_mac ( ) <EOL> gw = None <EOL> for ethx in [ a for a in nic_opts ] : <EOL> ndata = nic_opts [ ethx ] <EOL> if gw : <EOL> ndata . pop ( '<STR_LIT>' , None ) <EOL> if '<STR_LIT>' in ndata : <EOL> gw = ndata [ '<STR_LIT>' ] <EOL> gateway = None <EOL> if bridge : <EOL> eth0 [ '<STR_LIT>' ] = bridge <EOL> if gateway : <EOL> eth0 [ '<STR_LIT>' ] = gateway <EOL> lxc_init_interface = { } <EOL> lxc_init_interface [ '<STR_LIT:name>' ] = name <EOL> lxc_init_interface [ '<STR_LIT>' ] = config <EOL> lxc_init_interface [ '<STR_LIT>' ] = _cloud_get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> lxc_init_interface [ '<STR_LIT>' ] = pub_key <EOL> lxc_init_interface [ '<STR_LIT>' ] = priv_key <EOL> lxc_init_interface [ '<STR_LIT>' ] = nic_opts <EOL> for clone_from in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> lxc_init_interface [ '<STR_LIT>' ] = _cloud_get ( clone_from , None ) <EOL> if lxc_init_interface [ '<STR_LIT>' ] is not None : <EOL> break <EOL> lxc_init_interface [ '<STR_LIT>' ] = profile <EOL> lxc_init_interface [ '<STR_LIT>' ] = snapshot <EOL> lxc_init_interface [ '<STR_LIT>' ] = dnsservers <EOL> lxc_init_interface [ '<STR_LIT>' ] = fstype <EOL> lxc_init_interface [ '<STR_LIT:path>' ] = path <EOL> lxc_init_interface [ '<STR_LIT>' ] = vgname <EOL> lxc_init_interface [ '<STR_LIT:size>' ] = size <EOL> lxc_init_interface [ '<STR_LIT>' ] = lvname <EOL> lxc_init_interface [ '<STR_LIT>' ] = force_install <EOL> lxc_init_interface [ '<STR_LIT>' ] = ( <EOL> unconditional_install <EOL> ) <EOL> lxc_init_interface [ '<STR_LIT>' ] = script <EOL> lxc_init_interface [ '<STR_LIT>' ] = script_args <EOL> lxc_init_interface [ '<STR_LIT>' ] = _cloud_get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> lxc_init_interface [ '<STR_LIT>' ] = _cloud_get ( '<STR_LIT>' , None ) <EOL> lxc_init_interface [ '<STR_LIT>' ] = autostart <EOL> lxc_init_interface [ '<STR_LIT>' ] = users <EOL> lxc_init_interface [ '<STR_LIT:password>' ] = password <EOL> lxc_init_interface [ '<STR_LIT>' ] = password_encrypted <EOL> lxc_init_interface [ '<STR_LIT>' ] = network_profile <EOL> for i in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if _cloud_get ( i , None ) : <EOL> try : <EOL> lxc_init_interface [ i ] = vm_ [ i ] <EOL> except KeyError : <EOL> lxc_init_interface [ i ] = profile [ i ] <EOL> return lxc_init_interface <EOL> def _get_profile ( key , old_key , name , ** kwargs ) : <EOL> if isinstance ( name , dict ) : <EOL> profilename = name . pop ( '<STR_LIT:name>' , None ) <EOL> return _get_profile ( key , old_key , profilename , ** name ) <EOL> if name is None : <EOL> profile_match = { } <EOL> else : <EOL> profile_match = __salt__ [ '<STR_LIT>' ] ( <EOL> '<STR_LIT>' . format ( name , key ) , <EOL> default = None , <EOL> merge = '<STR_LIT>' <EOL> ) <EOL> if profile_match is None : <EOL> profile_match = __salt__ [ '<STR_LIT>' ] ( <EOL> '<STR_LIT>' . format ( name , old_key ) , None ) <EOL> if profile_match is not None : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> key , old_key ) ) <EOL> else : <EOL> profile_match = { } <EOL> if not isinstance ( profile_match , dict ) : <EOL> raise CommandExecutionError ( '<STR_LIT>' . format ( key ) ) <EOL> overrides = salt . utils . clean_kwargs ( ** copy . deepcopy ( kwargs ) ) <EOL> profile_match = salt . utils . dictupdate . update ( <EOL> copy . deepcopy ( profile_match ) , <EOL> overrides <EOL> ) <EOL> return profile_match <EOL> def get_container_profile ( name = None , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> profile = _get_profile ( '<STR_LIT>' , '<STR_LIT>' , name , ** kwargs ) <EOL> return profile <EOL> def get_network_profile ( name = None , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> profile = _get_profile ( '<STR_LIT>' , '<STR_LIT>' , name , ** kwargs ) <EOL> return profile <EOL> def _rand_cpu_str ( cpu ) : <EOL> '''<STR_LIT>''' <EOL> cpu = int ( cpu ) <EOL> avail = __salt__ [ '<STR_LIT>' ] ( ) <EOL> if cpu < avail : <EOL> return '<STR_LIT>' . format ( avail ) <EOL> to_set = set ( ) <EOL> while len ( to_set ) < cpu : <EOL> choice = random . randint ( <NUM_LIT:0> , avail - <NUM_LIT:1> ) <EOL> if choice not in to_set : <EOL> to_set . add ( str ( choice ) ) <EOL> return '<STR_LIT:U+002C>' . join ( sorted ( to_set ) ) <EOL> def _network_conf ( conf_tuples = None , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> nic = kwargs . get ( '<STR_LIT>' , None ) <EOL> ret = [ ] <EOL> nic_opts = kwargs . get ( '<STR_LIT>' , { } ) <EOL> if nic_opts is None : <EOL> nic_opts = { } <EOL> if not conf_tuples : <EOL> conf_tuples = [ ] <EOL> old = _get_veths ( conf_tuples ) <EOL> if not old : <EOL> old = { } <EOL> if nic and isinstance ( nic , ( six . string_types , dict ) ) : <EOL> nicp = get_network_profile ( nic ) <EOL> else : <EOL> nicp = { } <EOL> if DEFAULT_NIC not in nicp : <EOL> nicp [ DEFAULT_NIC ] = { } <EOL> kwargs = copy . deepcopy ( kwargs ) <EOL> gateway = kwargs . pop ( '<STR_LIT>' , None ) <EOL> bridge = kwargs . get ( '<STR_LIT>' , None ) <EOL> if nic_opts : <EOL> for dev , args in six . iteritems ( nic_opts ) : <EOL> ethx = nicp . setdefault ( dev , { } ) <EOL> try : <EOL> ethx = salt . utils . dictupdate . update ( ethx , args ) <EOL> except AttributeError : <EOL> raise SaltInvocationError ( '<STR_LIT>' ) <EOL> ifs = [ a for a in nicp ] <EOL> ifs += [ a for a in old if a not in nicp ] <EOL> ifs . sort ( ) <EOL> gateway_set = False <EOL> for dev in ifs : <EOL> args = nicp . get ( dev , { } ) <EOL> opts = nic_opts . get ( dev , { } ) if nic_opts else { } <EOL> old_if = old . get ( dev , { } ) <EOL> disable = opts . get ( '<STR_LIT>' , args . get ( '<STR_LIT>' , False ) ) <EOL> if disable : <EOL> continue <EOL> mac = opts . get ( '<STR_LIT>' , <EOL> opts . get ( '<STR_LIT>' , <EOL> args . get ( '<STR_LIT>' , <EOL> args . get ( '<STR_LIT>' , '<STR_LIT>' ) ) ) ) <EOL> type_ = opts . get ( '<STR_LIT:type>' , args . get ( '<STR_LIT:type>' , '<STR_LIT>' ) ) <EOL> flags = opts . get ( '<STR_LIT>' , args . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> link = opts . get ( '<STR_LIT>' , args . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ipv4 = opts . get ( '<STR_LIT>' , args . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ipv6 = opts . get ( '<STR_LIT>' , args . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> infos = salt . utils . odict . OrderedDict ( [ <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT:test>' : not type_ , <EOL> '<STR_LIT:value>' : type_ , <EOL> '<STR_LIT>' : old_if . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:default>' : '<STR_LIT>' } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT:test>' : False , <EOL> '<STR_LIT:value>' : dev , <EOL> '<STR_LIT>' : dev , <EOL> '<STR_LIT:default>' : dev } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT:test>' : not flags , <EOL> '<STR_LIT:value>' : flags , <EOL> '<STR_LIT>' : old_if . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:default>' : '<STR_LIT>' } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT:test>' : not link , <EOL> '<STR_LIT:value>' : link , <EOL> '<STR_LIT>' : old_if . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:default>' : search_lxc_bridge ( ) } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT:test>' : not mac , <EOL> '<STR_LIT:value>' : mac , <EOL> '<STR_LIT>' : old_if . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:default>' : salt . utils . gen_mac ( ) } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT:test>' : not ipv4 , <EOL> '<STR_LIT:value>' : ipv4 , <EOL> '<STR_LIT>' : old_if . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:default>' : None } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT:test>' : not ipv6 , <EOL> '<STR_LIT:value>' : ipv6 , <EOL> '<STR_LIT>' : old_if . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:default>' : None } ) ] ) <EOL> for info in list ( infos . keys ( ) ) : <EOL> bundle = infos [ info ] <EOL> if bundle [ '<STR_LIT:test>' ] : <EOL> if bundle [ '<STR_LIT>' ] : <EOL> bundle [ '<STR_LIT:value>' ] = bundle [ '<STR_LIT>' ] <EOL> elif bundle [ '<STR_LIT:default>' ] : <EOL> bundle [ '<STR_LIT:value>' ] = bundle [ '<STR_LIT:default>' ] <EOL> for info , data in six . iteritems ( infos ) : <EOL> if data [ '<STR_LIT:value>' ] : <EOL> ret . append ( { info : data [ '<STR_LIT:value>' ] } ) <EOL> for key , val in six . iteritems ( args ) : <EOL> if key == '<STR_LIT>' and bridge : <EOL> val = bridge <EOL> val = opts . get ( key , val ) <EOL> if key in [ <EOL> '<STR_LIT:type>' , '<STR_LIT>' , '<STR_LIT:name>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] : <EOL> continue <EOL> ret . append ( { '<STR_LIT>' . format ( key ) : val } ) <EOL> if not gateway : <EOL> gateway = args . get ( '<STR_LIT>' , None ) <EOL> if gateway is not None and not gateway_set : <EOL> ret . append ( { '<STR_LIT>' : gateway } ) <EOL> gateway_set = True <EOL> if gateway is not None and not gateway_set : <EOL> ret . append ( { '<STR_LIT>' : gateway } ) <EOL> gateway_set = True <EOL> new = _get_veths ( ret ) <EOL> for iface in [ a for a in new ] : <EOL> ndata = new [ iface ] <EOL> nmac = ndata . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ntype = ndata . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> omac , otype = '<STR_LIT>' , '<STR_LIT>' <EOL> if iface in old : <EOL> odata = old [ iface ] <EOL> omac = odata . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> otype = odata . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if otype and not ntype : <EOL> ntype = otype <EOL> if not ntype : <EOL> ntype = '<STR_LIT>' <EOL> new [ iface ] [ '<STR_LIT>' ] = ntype <EOL> if omac and not nmac : <EOL> new [ iface ] [ '<STR_LIT>' ] = omac <EOL> ret = [ ] <EOL> for val in six . itervalues ( new ) : <EOL> for row in val : <EOL> ret . append ( salt . utils . odict . OrderedDict ( [ ( row , val [ row ] ) ] ) ) <EOL> if ( <EOL> distutils . version . LooseVersion ( version ( ) ) <= '<STR_LIT>' and <EOL> True not in [ '<STR_LIT>' in a for a in ret ] and <EOL> True in [ '<STR_LIT>' in a for a in ret ] <EOL> ) : <EOL> ret . append ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> return ret <EOL> def _get_lxc_default_data ( ** kwargs ) : <EOL> kwargs = copy . deepcopy ( kwargs ) <EOL> ret = { } <EOL> for k in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> val = kwargs . get ( k , None ) <EOL> if val is not None : <EOL> ret [ '<STR_LIT>' . format ( k ) ] = val <EOL> autostart = kwargs . get ( '<STR_LIT>' ) <EOL> if autostart is None : <EOL> autostart = True <EOL> if autostart != '<STR_LIT>' : <EOL> if autostart : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> else : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT:0>' <EOL> memory = kwargs . get ( '<STR_LIT>' ) <EOL> if memory is not None : <EOL> ret [ '<STR_LIT>' ] = memory * <NUM_LIT> <EOL> cpuset = kwargs . get ( '<STR_LIT>' ) <EOL> if cpuset : <EOL> ret [ '<STR_LIT>' ] = cpuset <EOL> cpushare = kwargs . get ( '<STR_LIT>' ) <EOL> cpu = kwargs . get ( '<STR_LIT>' ) <EOL> if cpushare : <EOL> ret [ '<STR_LIT>' ] = cpushare <EOL> if cpu and not cpuset : <EOL> ret [ '<STR_LIT>' ] = _rand_cpu_str ( cpu ) <EOL> return ret <EOL> def _config_list ( conf_tuples = None , only_net = False , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> only_net = bool ( only_net ) <EOL> if not conf_tuples : <EOL> conf_tuples = [ ] <EOL> kwargs = copy . deepcopy ( kwargs ) <EOL> ret = [ ] <EOL> if not only_net : <EOL> default_data = _get_lxc_default_data ( ** kwargs ) <EOL> for k , val in six . iteritems ( default_data ) : <EOL> ret . append ( { k : val } ) <EOL> net_datas = _network_conf ( conf_tuples = conf_tuples , ** kwargs ) <EOL> ret . extend ( net_datas ) <EOL> return ret <EOL> def _get_veths ( net_data ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( net_data , dict ) : <EOL> net_data = list ( net_data . items ( ) ) <EOL> nics = salt . utils . odict . OrderedDict ( ) <EOL> current_nic = salt . utils . odict . OrderedDict ( ) <EOL> no_names = True <EOL> for item in net_data : <EOL> if item and isinstance ( item , dict ) : <EOL> item = list ( item . items ( ) ) [ <NUM_LIT:0> ] <EOL> elif isinstance ( item , six . string_types ) : <EOL> sitem = item . strip ( ) <EOL> if sitem . startswith ( '<STR_LIT:#>' ) or not sitem : <EOL> continue <EOL> elif '<STR_LIT:=>' in item : <EOL> item = tuple ( [ a . strip ( ) for a in item . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) ] ) <EOL> if item [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> current_nic = salt . utils . odict . OrderedDict ( ) <EOL> if item [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> no_names = False <EOL> nics [ item [ <NUM_LIT:1> ] . strip ( ) ] = current_nic <EOL> current_nic [ item [ <NUM_LIT:0> ] . strip ( ) ] = item [ <NUM_LIT:1> ] . strip ( ) <EOL> if no_names and current_nic : <EOL> nics [ DEFAULT_NIC ] = current_nic <EOL> return nics <EOL> class _LXCConfig ( object ) : <EOL> '''<STR_LIT>''' <EOL> pattern = re . compile ( r'<STR_LIT>' ) <EOL> non_interpretable_pattern = re . compile ( r'<STR_LIT>' ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> kwargs = copy . deepcopy ( kwargs ) <EOL> self . name = kwargs . pop ( '<STR_LIT:name>' , None ) <EOL> path = get_root_path ( kwargs . get ( '<STR_LIT:path>' , None ) ) <EOL> self . data = [ ] <EOL> if self . name : <EOL> self . path = os . path . join ( path , self . name , '<STR_LIT>' ) <EOL> if os . path . isfile ( self . path ) : <EOL> with salt . utils . fopen ( self . path ) as fhr : <EOL> for line in fhr . readlines ( ) : <EOL> match = self . pattern . findall ( ( line . strip ( ) ) ) <EOL> if match : <EOL> self . data . append ( ( match [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , match [ <NUM_LIT:0> ] [ - <NUM_LIT:1> ] ) ) <EOL> match = self . non_interpretable_pattern . findall ( <EOL> ( line . strip ( ) ) ) <EOL> if match : <EOL> self . data . append ( ( '<STR_LIT>' , match [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> self . path = None <EOL> def _replace ( key , val ) : <EOL> if val : <EOL> self . _filter_data ( key ) <EOL> self . data . append ( ( key , val ) ) <EOL> default_data = _get_lxc_default_data ( ** kwargs ) <EOL> for key , val in six . iteritems ( default_data ) : <EOL> _replace ( key , val ) <EOL> old_net = self . _filter_data ( '<STR_LIT>' ) <EOL> net_datas = _network_conf ( conf_tuples = old_net , ** kwargs ) <EOL> if net_datas : <EOL> for row in net_datas : <EOL> self . data . extend ( list ( row . items ( ) ) ) <EOL> for idx in [ '<STR_LIT>' ] : <EOL> if not default_data . get ( idx ) : <EOL> self . _filter_data ( idx ) <EOL> def as_string ( self ) : <EOL> chunks = ( '<STR_LIT>' . format ( item , ( '<STR_LIT>' if item [ <NUM_LIT:0> ] else '<STR_LIT>' ) ) for item in self . data ) <EOL> return '<STR_LIT:\n>' . join ( chunks ) + '<STR_LIT:\n>' <EOL> def write ( self ) : <EOL> if self . path : <EOL> content = self . as_string ( ) <EOL> with salt . utils . fopen ( self . path , '<STR_LIT:w>' ) as fic : <EOL> fic . write ( content ) <EOL> fic . flush ( ) <EOL> def tempfile ( self ) : <EOL> ntf = tempfile . NamedTemporaryFile ( ) <EOL> ntf . write ( self . as_string ( ) ) <EOL> ntf . flush ( ) <EOL> return ntf <EOL> def _filter_data ( self , pattern ) : <EOL> '''<STR_LIT>''' <EOL> removed = [ ] <EOL> filtered = [ ] <EOL> for param in self . data : <EOL> if not param [ <NUM_LIT:0> ] . startswith ( pattern ) : <EOL> filtered . append ( param ) <EOL> else : <EOL> removed . append ( param ) <EOL> self . data = filtered <EOL> return removed <EOL> def _get_base ( ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> profile = get_container_profile ( copy . deepcopy ( kwargs . get ( '<STR_LIT>' ) ) ) <EOL> kw_overrides = copy . deepcopy ( kwargs ) <EOL> def select ( key , default = None ) : <EOL> kw_overrides_match = kw_overrides . pop ( key , _marker ) <EOL> profile_match = profile . pop ( key , default ) <EOL> if kw_overrides_match is _marker : <EOL> return profile_match <EOL> return kw_overrides_match <EOL> template = select ( '<STR_LIT>' ) <EOL> image = select ( '<STR_LIT:image>' ) <EOL> vgname = select ( '<STR_LIT>' ) <EOL> path = kwargs . get ( '<STR_LIT:path>' , None ) <EOL> for param in ( '<STR_LIT:path>' , '<STR_LIT:image>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> kwargs . pop ( param , None ) <EOL> if image : <EOL> proto = _urlparse ( image ) . scheme <EOL> img_tar = __salt__ [ '<STR_LIT>' ] ( image ) <EOL> img_name = os . path . basename ( img_tar ) <EOL> hash_ = salt . utils . get_hash ( <EOL> img_tar , <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) ) <EOL> name = '<STR_LIT>' . format ( proto , img_name , hash_ ) <EOL> if not exists ( name , path = path ) : <EOL> create ( name , template = template , image = image , <EOL> path = path , vgname = vgname , ** kwargs ) <EOL> if vgname : <EOL> rootfs = os . path . join ( '<STR_LIT>' , vgname , name ) <EOL> edit_conf ( info ( name , path = path ) [ '<STR_LIT>' ] , <EOL> out_format = '<STR_LIT>' , ** { '<STR_LIT>' : rootfs } ) <EOL> return name <EOL> elif template : <EOL> name = '<STR_LIT>' . format ( template ) <EOL> if not exists ( name , path = path ) : <EOL> create ( name , template = template , image = image , path = path , <EOL> vgname = vgname , ** kwargs ) <EOL> if vgname : <EOL> rootfs = os . path . join ( '<STR_LIT>' , vgname , name ) <EOL> edit_conf ( info ( name , path = path ) [ '<STR_LIT>' ] , <EOL> out_format = '<STR_LIT>' , ** { '<STR_LIT>' : rootfs } ) <EOL> return name <EOL> return '<STR_LIT>' <EOL> def init ( name , <EOL> config = None , <EOL> cpuset = None , <EOL> cpushare = None , <EOL> memory = None , <EOL> profile = None , <EOL> network_profile = None , <EOL> nic = _marker , <EOL> nic_opts = None , <EOL> cpu = None , <EOL> autostart = True , <EOL> password = None , <EOL> password_encrypted = None , <EOL> users = None , <EOL> dnsservers = None , <EOL> searchdomains = None , <EOL> bridge = None , <EOL> gateway = None , <EOL> pub_key = None , <EOL> priv_key = None , <EOL> force_install = False , <EOL> unconditional_install = False , <EOL> bootstrap_delay = None , <EOL> bootstrap_args = None , <EOL> bootstrap_shell = None , <EOL> bootstrap_url = None , <EOL> ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } } <EOL> profile = get_container_profile ( copy . deepcopy ( profile ) ) <EOL> if bool ( nic ) and nic is not _marker : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> network_profile = nic <EOL> if not network_profile : <EOL> network_profile = profile . get ( '<STR_LIT>' ) <EOL> if not network_profile : <EOL> network_profile = DEFAULT_NIC <EOL> try : <EOL> kwargs [ '<STR_LIT>' ] = kwargs . pop ( '<STR_LIT>' ) <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> changes_dict = { '<STR_LIT>' : [ ] } <EOL> changes = changes_dict . get ( '<STR_LIT>' ) <EOL> if users is None : <EOL> users = [ ] <EOL> dusers = [ '<STR_LIT:root>' ] <EOL> for user in dusers : <EOL> if user not in users : <EOL> users . append ( user ) <EOL> kw_overrides = copy . deepcopy ( kwargs ) <EOL> def select ( key , default = None ) : <EOL> kw_overrides_match = kw_overrides . pop ( key , _marker ) <EOL> profile_match = profile . pop ( key , default ) <EOL> if kw_overrides_match is _marker : <EOL> return profile_match <EOL> return kw_overrides_match <EOL> path = select ( '<STR_LIT:path>' ) <EOL> bpath = get_root_path ( path ) <EOL> state_pre = state ( name , path = path ) <EOL> tvg = select ( '<STR_LIT>' ) <EOL> vgname = tvg if tvg else __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> start_ = select ( '<STR_LIT:start>' , True ) <EOL> autostart = select ( '<STR_LIT>' , autostart ) <EOL> seed = select ( '<STR_LIT>' , True ) <EOL> install = select ( '<STR_LIT>' , True ) <EOL> seed_cmd = select ( '<STR_LIT>' ) <EOL> salt_config = _get_salt_config ( config , ** kwargs ) <EOL> approve_key = select ( '<STR_LIT>' , True ) <EOL> clone_from = select ( '<STR_LIT>' ) <EOL> if password and password_encrypted is None : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> password_encrypted = False <EOL> if vgname and not clone_from : <EOL> try : <EOL> kwargs [ '<STR_LIT>' ] = vgname <EOL> clone_from = _get_base ( profile = profile , ** kwargs ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = exc . strerror <EOL> if changes : <EOL> ret [ '<STR_LIT>' ] = changes_dict <EOL> return ret <EOL> if not kwargs . get ( '<STR_LIT>' ) is False : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> does_exist = exists ( name , path = path ) <EOL> to_reboot = False <EOL> remove_seed_marker = False <EOL> if does_exist : <EOL> pass <EOL> elif clone_from : <EOL> remove_seed_marker = True <EOL> try : <EOL> clone ( name , clone_from , profile = profile , ** kwargs ) <EOL> changes . append ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> if '<STR_LIT>' in exc . strerror : <EOL> changes . append ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = exc . strerror <EOL> if changes : <EOL> ret [ '<STR_LIT>' ] = changes_dict <EOL> return ret <EOL> cfg = _LXCConfig ( name = name , network_profile = network_profile , <EOL> nic_opts = nic_opts , bridge = bridge , path = path , <EOL> gateway = gateway , autostart = autostart , <EOL> cpuset = cpuset , cpushare = cpushare , memory = memory ) <EOL> old_chunks = read_conf ( cfg . path , out_format = '<STR_LIT>' ) <EOL> cfg . write ( ) <EOL> chunks = read_conf ( cfg . path , out_format = '<STR_LIT>' ) <EOL> if old_chunks != chunks : <EOL> to_reboot = True <EOL> else : <EOL> remove_seed_marker = True <EOL> cfg = _LXCConfig ( network_profile = network_profile , <EOL> nic_opts = nic_opts , cpuset = cpuset , path = path , <EOL> bridge = bridge , gateway = gateway , <EOL> autostart = autostart , <EOL> cpushare = cpushare , memory = memory ) <EOL> with cfg . tempfile ( ) as cfile : <EOL> try : <EOL> create ( name , config = cfile . name , profile = profile , ** kwargs ) <EOL> changes . append ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> if '<STR_LIT>' in exc . strerror : <EOL> changes . append ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] = exc . strerror <EOL> if changes : <EOL> ret [ '<STR_LIT>' ] = changes_dict <EOL> return ret <EOL> cpath = os . path . join ( bpath , name , '<STR_LIT>' ) <EOL> old_chunks = [ ] <EOL> if os . path . exists ( cpath ) : <EOL> old_chunks = read_conf ( cpath , out_format = '<STR_LIT>' ) <EOL> new_cfg = _config_list ( conf_tuples = old_chunks , <EOL> cpu = cpu , <EOL> network_profile = network_profile , <EOL> nic_opts = nic_opts , bridge = bridge , <EOL> cpuset = cpuset , cpushare = cpushare , <EOL> memory = memory ) <EOL> if new_cfg : <EOL> edit_conf ( cpath , out_format = '<STR_LIT>' , lxc_config = new_cfg ) <EOL> chunks = read_conf ( cpath , out_format = '<STR_LIT>' ) <EOL> if old_chunks != chunks : <EOL> to_reboot = True <EOL> cfg = _LXCConfig ( name = name , network_profile = network_profile , <EOL> nic_opts = nic_opts , bridge = bridge , path = path , <EOL> gateway = gateway , autostart = autostart , <EOL> cpuset = cpuset , cpushare = cpushare , memory = memory ) <EOL> old_chunks = [ ] <EOL> if os . path . exists ( cfg . path ) : <EOL> old_chunks = read_conf ( cfg . path , out_format = '<STR_LIT>' ) <EOL> cfg . write ( ) <EOL> chunks = read_conf ( cfg . path , out_format = '<STR_LIT>' ) <EOL> if old_chunks != chunks : <EOL> changes . append ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> to_reboot = True <EOL> if to_reboot : <EOL> try : <EOL> stop ( name , path = path ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( exc ) <EOL> if changes : <EOL> ret [ '<STR_LIT>' ] = changes_dict <EOL> return ret <EOL> if not does_exist or ( does_exist and state ( name , path = path ) != '<STR_LIT>' ) : <EOL> try : <EOL> start ( name , path = path ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( exc ) <EOL> if changes : <EOL> ret [ '<STR_LIT>' ] = changes_dict <EOL> return ret <EOL> if remove_seed_marker : <EOL> run ( name , <EOL> '<STR_LIT>' . format ( SEED_MARKER ) , <EOL> path = path , <EOL> chroot_fallback = False , <EOL> python_shell = False ) <EOL> if ret . get ( '<STR_LIT:result>' , True ) and password : <EOL> gid = '<STR_LIT>' <EOL> gids = [ gid , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( name ) ] <EOL> if not any ( retcode ( name , <EOL> '<STR_LIT>' . format ( x ) , <EOL> chroot_fallback = True , <EOL> path = path , <EOL> ignore_retcode = True ) == <NUM_LIT:0> <EOL> for x in gids ) : <EOL> for default_user in [ '<STR_LIT>' ] : <EOL> if ( <EOL> default_user not in users and <EOL> retcode ( name , <EOL> '<STR_LIT>' . format ( default_user ) , <EOL> python_shell = False , <EOL> path = path , <EOL> chroot_fallback = True , <EOL> ignore_retcode = True ) == <NUM_LIT:0> <EOL> ) : <EOL> users . append ( default_user ) <EOL> for user in users : <EOL> try : <EOL> cret = set_password ( name , <EOL> users = [ user ] , <EOL> path = path , <EOL> password = password , <EOL> encrypted = password_encrypted ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> msg = '<STR_LIT>' . format ( <EOL> user ) + exc . strerror <EOL> if user == '<STR_LIT:root>' : <EOL> ret [ '<STR_LIT>' ] = msg <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> else : <EOL> log . debug ( msg ) <EOL> if ret . get ( '<STR_LIT:result>' , True ) : <EOL> changes . append ( { '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> if retcode ( name , <EOL> ( '<STR_LIT>' <EOL> . format ( gid ) ) , <EOL> path = path , <EOL> chroot_fallback = True , <EOL> ignore_retcode = True ) != <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> changes [ - <NUM_LIT:1> ] [ '<STR_LIT:password>' ] += '<STR_LIT>' + ret [ '<STR_LIT>' ] + '<STR_LIT:.>' <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> if ret . get ( '<STR_LIT:result>' , True ) and dnsservers : <EOL> gid = '<STR_LIT>' <EOL> gids = [ gid , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( name ) ] <EOL> if not any ( retcode ( name , <EOL> '<STR_LIT>' . format ( x ) , <EOL> chroot_fallback = True , <EOL> path = path , <EOL> ignore_retcode = True ) == <NUM_LIT:0> <EOL> for x in gids ) : <EOL> try : <EOL> set_dns ( name , <EOL> path = path , <EOL> dnsservers = dnsservers , <EOL> searchdomains = searchdomains ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' + exc . strerror <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> else : <EOL> changes . append ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> if retcode ( name , <EOL> ( '<STR_LIT>' <EOL> . format ( gid ) ) , <EOL> chroot_fallback = True , <EOL> path = path , <EOL> ignore_retcode = True ) != <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> changes [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] += '<STR_LIT>' + ret [ '<STR_LIT>' ] + '<STR_LIT:.>' <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> if remove_seed_marker : <EOL> run ( name , <EOL> '<STR_LIT>' . format ( SEED_MARKER ) , <EOL> path = path , <EOL> python_shell = False ) <EOL> gid = '<STR_LIT>' <EOL> gids = [ gid , '<STR_LIT>' ] <EOL> if ( <EOL> any ( retcode ( name , <EOL> '<STR_LIT>' . format ( x ) , <EOL> path = path , <EOL> chroot_fallback = True , <EOL> ignore_retcode = True ) == <NUM_LIT:0> <EOL> for x in gids ) or not ret . get ( '<STR_LIT:result>' , True ) <EOL> ) : <EOL> pass <EOL> elif seed or seed_cmd : <EOL> if seed : <EOL> try : <EOL> result = bootstrap ( <EOL> name , config = salt_config , path = path , <EOL> approve_key = approve_key , <EOL> pub_key = pub_key , priv_key = priv_key , <EOL> install = install , <EOL> force_install = force_install , <EOL> unconditional_install = unconditional_install , <EOL> bootstrap_delay = bootstrap_delay , <EOL> bootstrap_url = bootstrap_url , <EOL> bootstrap_shell = bootstrap_shell , <EOL> bootstrap_args = bootstrap_args ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' + exc . strerror <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> else : <EOL> if not result : <EOL> ret [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> else : <EOL> changes . append ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> elif seed_cmd : <EOL> try : <EOL> result = __salt__ [ seed_cmd ] ( info ( name , path = path ) [ '<STR_LIT>' ] , <EOL> name , <EOL> salt_config ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> . format ( seed_cmd , exc . strerror ) ) <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> else : <EOL> if not result : <EOL> ret [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( seed_cmd ) ) <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> else : <EOL> changes . append ( <EOL> { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( seed_cmd ) } <EOL> ) <EOL> if ret . get ( '<STR_LIT:result>' , True ) and not start_ : <EOL> try : <EOL> stop ( name , path = path ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( exc ) <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> state_post = state ( name , path = path ) <EOL> if state_pre != state_post : <EOL> changes . append ( { '<STR_LIT:state>' : { '<STR_LIT>' : state_pre , '<STR_LIT>' : state_post } } ) <EOL> if ret . get ( '<STR_LIT:result>' , True ) : <EOL> ret [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> . format ( name ) ) <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> if changes : <EOL> ret [ '<STR_LIT>' ] = changes_dict <EOL> return ret <EOL> def cloud_init ( name , vm_ = None , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> init_interface = cloud_init_interface ( name , vm_ , ** kwargs ) <EOL> name = init_interface . pop ( '<STR_LIT:name>' , name ) <EOL> return init ( name , ** init_interface ) <EOL> def images ( dist = None ) : <EOL> '''<STR_LIT>''' <EOL> out = __salt__ [ '<STR_LIT>' ] ( <EOL> '<STR_LIT>' , <EOL> ignore_retcode = True <EOL> ) <EOL> if '<STR_LIT>' not in out : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> ret = { } <EOL> passed_header = False <EOL> for line in out . splitlines ( ) : <EOL> try : <EOL> distro , release , arch , variant , build_time = line . split ( ) <EOL> except ValueError : <EOL> continue <EOL> if not passed_header : <EOL> if distro == '<STR_LIT>' : <EOL> passed_header = True <EOL> continue <EOL> dist_list = ret . setdefault ( distro , [ ] ) <EOL> dist_list . append ( { <EOL> '<STR_LIT>' : release , <EOL> '<STR_LIT>' : arch , <EOL> '<STR_LIT>' : variant , <EOL> '<STR_LIT>' : build_time , <EOL> } ) <EOL> if dist is not None : <EOL> return dict ( [ ( dist , ret . get ( dist , [ ] ) ) ] ) <EOL> return ret <EOL> def templates ( ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> template_scripts = os . listdir ( '<STR_LIT>' ) <EOL> except OSError : <EOL> return [ ] <EOL> else : <EOL> return [ x [ <NUM_LIT:4> : ] for x in template_scripts if x . startswith ( '<STR_LIT>' ) ] <EOL> def _after_ignition_network_profile ( cmd , <EOL> ret , <EOL> name , <EOL> network_profile , <EOL> path , <EOL> nic_opts ) : <EOL> _clear_context ( ) <EOL> if ret [ '<STR_LIT>' ] == <NUM_LIT:0> and exists ( name , path = path ) : <EOL> if network_profile : <EOL> network_changes = apply_network_profile ( name , <EOL> network_profile , <EOL> path = path , <EOL> nic_opts = nic_opts ) <EOL> if network_changes : <EOL> log . info ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( network_profile , name , network_changes ) <EOL> ) <EOL> c_state = state ( name , path = path ) <EOL> return { '<STR_LIT:result>' : True , <EOL> '<STR_LIT:state>' : { '<STR_LIT>' : None , '<STR_LIT>' : c_state } } <EOL> else : <EOL> if exists ( name , path = path ) : <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> cmd += '<STR_LIT>' . format ( name ) <EOL> __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' <EOL> . format ( cmd , ret [ '<STR_LIT>' ] ) <EOL> ) <EOL> def create ( name , <EOL> config = None , <EOL> profile = None , <EOL> network_profile = None , <EOL> nic_opts = None , <EOL> ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> download_template_deps = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> cmd = '<STR_LIT>' . format ( name ) <EOL> profile = get_container_profile ( copy . deepcopy ( profile ) ) <EOL> kw_overrides = copy . deepcopy ( kwargs ) <EOL> def select ( key , default = None ) : <EOL> kw_overrides_match = kw_overrides . pop ( key , None ) <EOL> profile_match = profile . pop ( key , default ) <EOL> if kw_overrides_match is None : <EOL> return profile_match <EOL> return kw_overrides_match <EOL> path = select ( '<STR_LIT:path>' ) <EOL> if exists ( name , path = path ) : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> tvg = select ( '<STR_LIT>' ) <EOL> vgname = tvg if tvg else __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> template = select ( '<STR_LIT>' ) <EOL> image = select ( '<STR_LIT:image>' ) <EOL> if template and image : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> elif not any ( ( template , image , profile ) ) : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> options = select ( '<STR_LIT>' ) or { } <EOL> backing = select ( '<STR_LIT>' ) <EOL> if vgname and not backing : <EOL> backing = '<STR_LIT>' <EOL> lvname = select ( '<STR_LIT>' ) <EOL> fstype = select ( '<STR_LIT>' ) <EOL> size = select ( '<STR_LIT:size>' , '<STR_LIT>' ) <EOL> if backing in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> fstype = None <EOL> size = None <EOL> if backing in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> lvname = vgname = None <EOL> if image : <EOL> img_tar = __salt__ [ '<STR_LIT>' ] ( image ) <EOL> template = os . path . join ( <EOL> os . path . dirname ( salt . __file__ ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> options [ '<STR_LIT>' ] = img_tar <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> if not os . path . exists ( path ) : <EOL> os . makedirs ( path ) <EOL> if config : <EOL> cmd += '<STR_LIT>' . format ( config ) <EOL> if template : <EOL> cmd += '<STR_LIT>' . format ( template ) <EOL> if backing : <EOL> backing = backing . lower ( ) <EOL> cmd += '<STR_LIT>' . format ( backing ) <EOL> if backing in ( '<STR_LIT>' , ) : <EOL> if lvname : <EOL> cmd += '<STR_LIT>' . format ( lvname ) <EOL> if vgname : <EOL> cmd += '<STR_LIT>' . format ( vgname ) <EOL> if backing not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if fstype : <EOL> cmd += '<STR_LIT>' . format ( fstype ) <EOL> if size : <EOL> cmd += '<STR_LIT>' . format ( size ) <EOL> if options : <EOL> if template == '<STR_LIT>' : <EOL> missing_deps = [ x for x in download_template_deps <EOL> if x not in options ] <EOL> if missing_deps : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' <EOL> . format ( '<STR_LIT:U+002CU+0020>' . join ( missing_deps ) ) <EOL> ) <EOL> cmd += '<STR_LIT>' <EOL> for key , val in six . iteritems ( options ) : <EOL> cmd += '<STR_LIT>' . format ( key , val ) <EOL> ret = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> return _after_ignition_network_profile ( cmd , <EOL> ret , <EOL> name , <EOL> network_profile , <EOL> path , <EOL> nic_opts ) <EOL> def clone ( name , <EOL> orig , <EOL> profile = None , <EOL> network_profile = None , <EOL> nic_opts = None , <EOL> ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> profile = get_container_profile ( copy . deepcopy ( profile ) ) <EOL> kw_overrides = copy . deepcopy ( kwargs ) <EOL> def select ( key , default = None ) : <EOL> kw_overrides_match = kw_overrides . pop ( key , None ) <EOL> profile_match = profile . pop ( key , default ) <EOL> if kw_overrides_match is None : <EOL> return profile_match <EOL> return kw_overrides_match <EOL> path = select ( '<STR_LIT:path>' ) <EOL> if exists ( name , path = path ) : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> _ensure_exists ( orig , path = path ) <EOL> if state ( orig , path = path ) != '<STR_LIT>' : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( orig ) <EOL> ) <EOL> backing = select ( '<STR_LIT>' ) <EOL> snapshot = select ( '<STR_LIT>' ) <EOL> if backing in ( '<STR_LIT>' , ) : <EOL> snapshot = False <EOL> if not snapshot : <EOL> snapshot = '<STR_LIT>' <EOL> else : <EOL> snapshot = '<STR_LIT>' <EOL> size = select ( '<STR_LIT:size>' , '<STR_LIT>' ) <EOL> if backing in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> size = None <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> if not os . path . exists ( path ) : <EOL> os . makedirs ( path ) <EOL> cmd += '<STR_LIT>' . format ( snapshot , orig , name ) <EOL> if backing : <EOL> backing = backing . lower ( ) <EOL> cmd += '<STR_LIT>' . format ( backing ) <EOL> if backing not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if size : <EOL> cmd += '<STR_LIT>' . format ( size ) <EOL> ret = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> return _after_ignition_network_profile ( cmd , <EOL> ret , <EOL> name , <EOL> network_profile , <EOL> path , <EOL> nic_opts ) <EOL> def ls_ ( active = None , cache = True , path = None ) : <EOL> '''<STR_LIT>''' <EOL> contextvar = '<STR_LIT>' . format ( path ) <EOL> if active : <EOL> contextvar += '<STR_LIT>' <EOL> if cache and ( contextvar in __context__ ) : <EOL> return __context__ [ contextvar ] <EOL> else : <EOL> ret = [ ] <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> if active : <EOL> cmd += '<STR_LIT>' <EOL> output = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> for line in output . splitlines ( ) : <EOL> ret . extend ( line . split ( ) ) <EOL> __context__ [ contextvar ] = ret <EOL> return ret <EOL> def list_ ( extra = False , limit = None , path = None ) : <EOL> '''<STR_LIT>''' <EOL> ctnrs = ls_ ( path = path ) <EOL> if extra : <EOL> stopped = { } <EOL> frozen = { } <EOL> running = { } <EOL> else : <EOL> stopped = [ ] <EOL> frozen = [ ] <EOL> running = [ ] <EOL> ret = { '<STR_LIT>' : running , <EOL> '<STR_LIT>' : stopped , <EOL> '<STR_LIT>' : frozen } <EOL> for container in ctnrs : <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> cmd += '<STR_LIT>' . format ( container ) <EOL> c_info = __salt__ [ '<STR_LIT>' ] ( <EOL> cmd , <EOL> python_shell = False , <EOL> output_loglevel = '<STR_LIT>' <EOL> ) <EOL> c_state = None <EOL> for line in c_info . splitlines ( ) : <EOL> stat = line . split ( '<STR_LIT::>' ) <EOL> if stat [ <NUM_LIT:0> ] in ( '<STR_LIT>' , '<STR_LIT:state>' ) : <EOL> c_state = stat [ <NUM_LIT:1> ] . strip ( ) <EOL> break <EOL> if not c_state or ( limit is not None and c_state . lower ( ) != limit ) : <EOL> continue <EOL> if extra : <EOL> infos = info ( container , path = path ) <EOL> method = '<STR_LIT>' <EOL> value = { container : infos } <EOL> else : <EOL> method = '<STR_LIT>' <EOL> value = container <EOL> if c_state == '<STR_LIT>' : <EOL> getattr ( stopped , method ) ( value ) <EOL> continue <EOL> if c_state == '<STR_LIT>' : <EOL> getattr ( frozen , method ) ( value ) <EOL> continue <EOL> if c_state == '<STR_LIT>' : <EOL> getattr ( running , method ) ( value ) <EOL> continue <EOL> if limit is not None : <EOL> return ret . get ( limit , { } if extra else [ ] ) <EOL> return ret <EOL> def _change_state ( cmd , <EOL> name , <EOL> expected , <EOL> stdin = _marker , <EOL> stdout = _marker , <EOL> stderr = _marker , <EOL> with_communicate = _marker , <EOL> use_vt = _marker , <EOL> path = None ) : <EOL> pre = state ( name , path = path ) <EOL> if pre == expected : <EOL> return { '<STR_LIT:result>' : True , <EOL> '<STR_LIT:state>' : { '<STR_LIT>' : expected , '<STR_LIT>' : expected } , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> . format ( name , expected ) } <EOL> if cmd == '<STR_LIT>' : <EOL> scmd = '<STR_LIT>' <EOL> if path : <EOL> scmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> scmd += '<STR_LIT>' . format ( name ) <EOL> __salt__ [ '<STR_LIT>' ] ( scmd , <EOL> python_shell = False ) <EOL> if path and '<STR_LIT>' not in cmd : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> cmd += '<STR_LIT>' . format ( name ) <EOL> pkwargs = { '<STR_LIT>' : False , <EOL> '<STR_LIT>' : with_communicate , <EOL> '<STR_LIT>' : use_vt , <EOL> '<STR_LIT>' : stdin , <EOL> '<STR_LIT>' : stdout , <EOL> '<STR_LIT>' : stderr } <EOL> for i in [ a for a in pkwargs ] : <EOL> val = pkwargs [ i ] <EOL> if val is _marker : <EOL> pkwargs . pop ( i , None ) <EOL> error = __salt__ [ '<STR_LIT>' ] ( cmd , ** pkwargs ) <EOL> if error : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( name , cmd , error ) <EOL> ) <EOL> if expected is not None : <EOL> rcmd = '<STR_LIT>' <EOL> if path : <EOL> rcmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> rcmd += '<STR_LIT>' . format ( name , expected . upper ( ) ) <EOL> __salt__ [ '<STR_LIT>' ] ( rcmd , python_shell = False , timeout = <NUM_LIT:30> ) <EOL> _clear_context ( ) <EOL> post = state ( name , path = path ) <EOL> ret = { '<STR_LIT:result>' : post == expected , <EOL> '<STR_LIT:state>' : { '<STR_LIT>' : pre , '<STR_LIT>' : post } } <EOL> return ret <EOL> def _ensure_exists ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> if not exists ( name , path = path ) : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> def _ensure_running ( name , no_start = False , path = None ) : <EOL> '''<STR_LIT>''' <EOL> _ensure_exists ( name , path = path ) <EOL> pre = state ( name , path = path ) <EOL> if pre == '<STR_LIT>' : <EOL> return start ( name , path = path ) <EOL> elif pre == '<STR_LIT>' : <EOL> if no_start : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> return start ( name , path = path ) <EOL> elif pre == '<STR_LIT>' : <EOL> if no_start : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> return unfreeze ( name , path = path ) <EOL> def restart ( name , path = None , lxc_config = None , force = False ) : <EOL> '''<STR_LIT>''' <EOL> _ensure_exists ( name , path = path ) <EOL> orig_state = state ( name , path = path ) <EOL> if orig_state != '<STR_LIT>' : <EOL> stop ( name , kill = force , path = path ) <EOL> ret = start ( name , path = path , lxc_config = lxc_config ) <EOL> ret [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] = orig_state <EOL> if orig_state != '<STR_LIT>' : <EOL> ret [ '<STR_LIT>' ] = True <EOL> return ret <EOL> def start ( name , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> path = kwargs . get ( '<STR_LIT:path>' , None ) <EOL> cpath = get_root_path ( path ) <EOL> lxc_config = kwargs . get ( '<STR_LIT>' , None ) <EOL> cmd = '<STR_LIT>' <EOL> if not lxc_config : <EOL> lxc_config = os . path . join ( cpath , name , '<STR_LIT>' ) <EOL> if os . path . exists ( lxc_config ) : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( lxc_config ) ) <EOL> cmd += '<STR_LIT>' <EOL> _ensure_exists ( name , path = path ) <EOL> if kwargs . get ( '<STR_LIT>' , False ) : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> return restart ( name , path = path ) <EOL> if state ( name , path = path ) == '<STR_LIT>' : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> use_vt = kwargs . get ( '<STR_LIT>' , None ) <EOL> with_communicate = kwargs . get ( '<STR_LIT>' , False ) <EOL> return _change_state ( cmd , name , '<STR_LIT>' , <EOL> stdout = None , <EOL> stderr = None , <EOL> stdin = None , <EOL> with_communicate = with_communicate , <EOL> path = path , <EOL> use_vt = use_vt ) <EOL> def stop ( name , kill = False , path = None , use_vt = None ) : <EOL> '''<STR_LIT>''' <EOL> _ensure_exists ( name , path = path ) <EOL> orig_state = state ( name , path = path ) <EOL> if orig_state == '<STR_LIT>' and not kill : <EOL> unfreeze ( name , path = path ) <EOL> cmd = '<STR_LIT>' <EOL> if kill : <EOL> cmd += '<STR_LIT>' <EOL> ret = _change_state ( cmd , name , '<STR_LIT>' , use_vt = use_vt , path = path ) <EOL> ret [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] = orig_state <EOL> return ret <EOL> def freeze ( name , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> use_vt = kwargs . get ( '<STR_LIT>' , None ) <EOL> path = kwargs . get ( '<STR_LIT:path>' , None ) <EOL> _ensure_exists ( name , path = path ) <EOL> orig_state = state ( name , path = path ) <EOL> start_ = kwargs . get ( '<STR_LIT:start>' , False ) <EOL> if orig_state == '<STR_LIT>' : <EOL> if not start_ : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> start ( name , path = path ) <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> ret = _change_state ( cmd , name , '<STR_LIT>' , use_vt = use_vt , path = path ) <EOL> if orig_state == '<STR_LIT>' and start_ : <EOL> ret [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] = orig_state <EOL> ret [ '<STR_LIT>' ] = True <EOL> ret [ '<STR_LIT:state>' ] [ '<STR_LIT>' ] = state ( name , path = path ) <EOL> return ret <EOL> def unfreeze ( name , path = None , use_vt = None ) : <EOL> '''<STR_LIT>''' <EOL> _ensure_exists ( name , path = path ) <EOL> if state ( name , path = path ) == '<STR_LIT>' : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> return _change_state ( cmd , name , '<STR_LIT>' , path = path , use_vt = use_vt ) <EOL> def destroy ( name , stop = False , path = None ) : <EOL> '''<STR_LIT>''' <EOL> _ensure_exists ( name , path = path ) <EOL> if not stop and state ( name , path = path ) != '<STR_LIT>' : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> return _change_state ( '<STR_LIT>' , name , None , path = path ) <EOL> remove = salt . utils . alias_function ( destroy , '<STR_LIT>' ) <EOL> def exists ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> _exists = name in ls_ ( path = path ) <EOL> if not _exists : <EOL> _exists = name in ls_ ( cache = False , path = path ) <EOL> return _exists <EOL> def state ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> cachekey = '<STR_LIT>' . format ( name , path ) <EOL> try : <EOL> return __context__ [ cachekey ] <EOL> except KeyError : <EOL> if not exists ( name , path = path ) : <EOL> __context__ [ cachekey ] = None <EOL> else : <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> cmd += '<STR_LIT>' . format ( name ) <EOL> ret = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> if ret [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> _clear_context ( ) <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) <EOL> ) <EOL> c_infos = ret [ '<STR_LIT>' ] . splitlines ( ) <EOL> c_state = None <EOL> for c_info in c_infos : <EOL> stat = c_info . split ( '<STR_LIT::>' ) <EOL> if stat [ <NUM_LIT:0> ] . lower ( ) == '<STR_LIT:state>' : <EOL> c_state = stat [ <NUM_LIT:1> ] . strip ( ) . lower ( ) <EOL> break <EOL> __context__ [ cachekey ] = c_state <EOL> return __context__ [ cachekey ] <EOL> def get_parameter ( name , parameter , path = None ) : <EOL> '''<STR_LIT>''' <EOL> _ensure_exists ( name , path = path ) <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> cmd += '<STR_LIT>' . format ( name , parameter ) <EOL> ret = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> if ret [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( parameter ) <EOL> ) <EOL> return ret [ '<STR_LIT>' ] . strip ( ) <EOL> def set_parameter ( name , parameter , value , path = None ) : <EOL> '''<STR_LIT>''' <EOL> if not exists ( name , path = path ) : <EOL> return None <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> cmd += '<STR_LIT>' . format ( name , parameter , value ) <EOL> ret = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> if ret [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> return False <EOL> else : <EOL> return True <EOL> def info ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> cachekey = '<STR_LIT>' . format ( name , path ) <EOL> try : <EOL> return __context__ [ cachekey ] <EOL> except KeyError : <EOL> _ensure_exists ( name , path = path ) <EOL> cpath = get_root_path ( path ) <EOL> try : <EOL> conf_file = os . path . join ( cpath , name , '<STR_LIT>' ) <EOL> except AttributeError : <EOL> conf_file = os . path . join ( cpath , str ( name ) , '<STR_LIT>' ) <EOL> if not os . path . isfile ( conf_file ) : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( conf_file ) <EOL> ) <EOL> ret = { } <EOL> config = [ ] <EOL> with salt . utils . fopen ( conf_file ) as fp_ : <EOL> for line in fp_ : <EOL> comps = [ x . strip ( ) for x in <EOL> line . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . strip ( ) . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) ] <EOL> if len ( comps ) == <NUM_LIT:2> : <EOL> config . append ( tuple ( comps ) ) <EOL> ifaces = [ ] <EOL> current = None <EOL> for key , val in config : <EOL> if key == '<STR_LIT>' : <EOL> current = { '<STR_LIT:type>' : val } <EOL> ifaces . append ( current ) <EOL> elif not current : <EOL> continue <EOL> elif key . startswith ( '<STR_LIT>' ) : <EOL> current [ key . replace ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) ] = val <EOL> if ifaces : <EOL> ret [ '<STR_LIT>' ] = ifaces <EOL> ret [ '<STR_LIT>' ] = next ( <EOL> ( x [ <NUM_LIT:1> ] for x in config if x [ <NUM_LIT:0> ] == '<STR_LIT>' ) , <EOL> None <EOL> ) <EOL> ret [ '<STR_LIT:state>' ] = state ( name , path = path ) <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> ret [ '<STR_LIT:size>' ] = None <EOL> ret [ '<STR_LIT>' ] = conf_file <EOL> if ret [ '<STR_LIT:state>' ] == '<STR_LIT>' : <EOL> try : <EOL> limit = int ( get_parameter ( name , '<STR_LIT>' ) ) <EOL> except ( CommandExecutionError , TypeError , ValueError ) : <EOL> limit = <NUM_LIT:0> <EOL> try : <EOL> usage = int ( get_parameter ( name , '<STR_LIT>' ) ) <EOL> except ( CommandExecutionError , TypeError , ValueError ) : <EOL> usage = <NUM_LIT:0> <EOL> free = limit - usage <EOL> ret [ '<STR_LIT>' ] = limit <EOL> ret [ '<STR_LIT>' ] = free <EOL> size = run_stdout ( name , '<STR_LIT>' , path = path , python_shell = False ) <EOL> ret [ '<STR_LIT:size>' ] = size . splitlines ( ) [ - <NUM_LIT:1> ] . split ( ) [ <NUM_LIT:1> ] <EOL> ip_cmd = run_all ( <EOL> name , '<STR_LIT>' , path = path , python_shell = False ) <EOL> if ip_cmd [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> ip_data = ip_cmd [ '<STR_LIT>' ] <EOL> ip_cmd = run_all ( <EOL> name , '<STR_LIT>' , path = path , python_shell = False ) <EOL> ip_data += '<STR_LIT:\n>' + ip_cmd [ '<STR_LIT>' ] <EOL> ip_data = salt . utils . network . _interfaces_ip ( ip_data ) <EOL> else : <EOL> ip_cmd = run_all ( <EOL> name , '<STR_LIT>' , path = path , python_shell = False ) <EOL> if ip_cmd [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> ip_data = salt . utils . network . _interfaces_ifconfig ( <EOL> ip_cmd [ '<STR_LIT>' ] ) <EOL> else : <EOL> log . warning ( <EOL> '<STR_LIT>' <EOL> . format ( name ) <EOL> ) <EOL> ip_data = { } <EOL> ret [ '<STR_LIT>' ] = salt . utils . network . ip_addrs ( <EOL> include_loopback = True , <EOL> interface_data = ip_data <EOL> ) <EOL> ret [ '<STR_LIT>' ] = salt . utils . network . ip_addrs6 ( <EOL> include_loopback = True , <EOL> interface_data = ip_data <EOL> ) <EOL> ret [ '<STR_LIT>' ] = ret [ '<STR_LIT>' ] + ret [ '<STR_LIT>' ] <EOL> for address in ret [ '<STR_LIT>' ] : <EOL> if address == '<STR_LIT:127.0.0.1>' : <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> elif salt . utils . cloud . is_public_ip ( address ) : <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> for address in ret [ '<STR_LIT>' ] : <EOL> if address == '<STR_LIT>' or address . startswith ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> ret [ '<STR_LIT>' ] . append ( address ) <EOL> for key in [ x for x in ret if x == '<STR_LIT>' or x . endswith ( '<STR_LIT>' ) ] : <EOL> ret [ key ] . sort ( key = _ip_sort ) <EOL> __context__ [ cachekey ] = ret <EOL> return __context__ [ cachekey ] <EOL> def set_password ( name , users , password , encrypted = True , path = None ) : <EOL> '''<STR_LIT>''' <EOL> def _bad_user_input ( ) : <EOL> raise SaltInvocationError ( '<STR_LIT>' ) <EOL> if not isinstance ( users , list ) : <EOL> try : <EOL> users = users . split ( '<STR_LIT:U+002C>' ) <EOL> except AttributeError : <EOL> _bad_user_input ( ) <EOL> if not users : <EOL> _bad_user_input ( ) <EOL> failed_users = [ ] <EOL> for user in users : <EOL> result = retcode ( name , <EOL> '<STR_LIT>' . format ( '<STR_LIT>' if encrypted else '<STR_LIT>' ) , <EOL> stdin = '<STR_LIT::>' . join ( ( user , password ) ) , <EOL> python_shell = False , <EOL> path = path , <EOL> chroot_fallback = True , <EOL> output_loglevel = '<STR_LIT>' ) <EOL> if result != <NUM_LIT:0> : <EOL> failed_users . append ( user ) <EOL> if failed_users : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' <EOL> . format ( '<STR_LIT:U+002CU+0020>' . join ( failed_users ) ) <EOL> ) <EOL> return True <EOL> set_pass = salt . utils . alias_function ( set_password , '<STR_LIT>' ) <EOL> def update_lxc_conf ( name , lxc_conf , lxc_conf_unset , path = None ) : <EOL> '''<STR_LIT>''' <EOL> _ensure_exists ( name , path = path ) <EOL> cpath = get_root_path ( path ) <EOL> lxc_conf_p = os . path . join ( cpath , name , '<STR_LIT>' ) <EOL> if not os . path . exists ( lxc_conf_p ) : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' . format ( lxc_conf_p ) <EOL> ) <EOL> changes = { '<STR_LIT>' : [ ] , '<STR_LIT>' : [ ] , '<STR_LIT>' : [ ] } <EOL> ret = { '<STR_LIT>' : changes , '<STR_LIT:result>' : True , '<STR_LIT>' : '<STR_LIT>' } <EOL> with open ( lxc_conf_p , '<STR_LIT:r>' ) as fic : <EOL> filtered_lxc_conf = [ ] <EOL> for row in lxc_conf : <EOL> if not row : <EOL> continue <EOL> for conf in row : <EOL> filtered_lxc_conf . append ( ( conf . strip ( ) , <EOL> row [ conf ] . strip ( ) ) ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> lines = [ ] <EOL> orig_config = fic . read ( ) <EOL> for line in orig_config . splitlines ( ) : <EOL> if line . startswith ( '<STR_LIT:#>' ) or not line . strip ( ) : <EOL> lines . append ( [ line , '<STR_LIT>' ] ) <EOL> else : <EOL> line = line . split ( '<STR_LIT:=>' ) <EOL> index = line . pop ( <NUM_LIT:0> ) <EOL> val = ( index . strip ( ) , '<STR_LIT:=>' . join ( line ) . strip ( ) ) <EOL> if val not in lines : <EOL> lines . append ( val ) <EOL> for key , item in filtered_lxc_conf : <EOL> matched = False <EOL> for idx , line in enumerate ( lines [ : ] ) : <EOL> if line [ <NUM_LIT:0> ] == key : <EOL> matched = True <EOL> lines [ idx ] = ( key , item ) <EOL> if '<STR_LIT:=>' . join ( line [ <NUM_LIT:1> : ] ) . strip ( ) != item . strip ( ) : <EOL> changes [ '<STR_LIT>' ] . append ( <EOL> ( { line [ <NUM_LIT:0> ] : line [ <NUM_LIT:1> : ] } , { key : item } ) ) <EOL> break <EOL> if not matched : <EOL> if ( key , item ) not in lines : <EOL> lines . append ( ( key , item ) ) <EOL> changes [ '<STR_LIT>' ] . append ( { key : item } ) <EOL> dest_lxc_conf = [ ] <EOL> if lxc_conf_unset : <EOL> for line in lines : <EOL> for opt in lxc_conf_unset : <EOL> if ( <EOL> not line [ <NUM_LIT:0> ] . startswith ( opt ) and <EOL> line not in dest_lxc_conf <EOL> ) : <EOL> dest_lxc_conf . append ( line ) <EOL> else : <EOL> changes [ '<STR_LIT>' ] . append ( opt ) <EOL> else : <EOL> dest_lxc_conf = lines <EOL> conf = '<STR_LIT>' <EOL> for key , val in dest_lxc_conf : <EOL> if not val : <EOL> conf += '<STR_LIT>' . format ( key ) <EOL> else : <EOL> conf += '<STR_LIT>' . format ( key . strip ( ) , val . strip ( ) ) <EOL> conf_changed = conf != orig_config <EOL> chrono = datetime . datetime . now ( ) . strftime ( '<STR_LIT>' ) <EOL> if conf_changed : <EOL> with open ( '<STR_LIT>' . format ( lxc_conf_p , chrono ) , '<STR_LIT:w>' ) as wfic : <EOL> wfic . write ( conf ) <EOL> with open ( lxc_conf_p , '<STR_LIT:w>' ) as wfic : <EOL> wfic . write ( conf ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> if not any ( changes [ x ] for x in changes ) : <EOL> ret [ '<STR_LIT>' ] = { } <EOL> return ret <EOL> def set_dns ( name , dnsservers = None , searchdomains = None , path = None ) : <EOL> '''<STR_LIT>''' <EOL> if dnsservers is None : <EOL> dnsservers = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> elif not isinstance ( dnsservers , list ) : <EOL> try : <EOL> dnsservers = dnsservers . split ( '<STR_LIT:U+002C>' ) <EOL> except AttributeError : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> if searchdomains is None : <EOL> searchdomains = [ ] <EOL> elif not isinstance ( searchdomains , list ) : <EOL> try : <EOL> searchdomains = searchdomains . split ( '<STR_LIT:U+002C>' ) <EOL> except AttributeError : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> dns = [ '<STR_LIT>' . format ( x ) for x in dnsservers ] <EOL> dns . extend ( [ '<STR_LIT>' . format ( x ) for x in searchdomains ] ) <EOL> dns = '<STR_LIT:\n>' . join ( dns ) + '<STR_LIT:\n>' <EOL> rstr = __salt__ [ '<STR_LIT>' ] ( ) <EOL> script = '<STR_LIT>' . format ( rstr ) <EOL> DNS_SCRIPT = "<STR_LIT:\n>" . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> dns , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> dns , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> result = run_all ( <EOL> name , '<STR_LIT>' . format ( script ) , path = path , <EOL> stdin = DNS_SCRIPT , python_shell = True ) <EOL> if result [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> result = run_all ( <EOL> name , '<STR_LIT>' . format ( script ) , <EOL> path = path , python_shell = True ) <EOL> run_all ( name , <EOL> '<STR_LIT>' . format ( script ) , <EOL> path = path , python_shell = True ) <EOL> if result [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> error = ( '<STR_LIT>' <EOL> . format ( name ) ) <EOL> if result [ '<STR_LIT>' ] : <EOL> error += '<STR_LIT>' . format ( result [ '<STR_LIT>' ] ) <EOL> raise CommandExecutionError ( error ) <EOL> return True <EOL> def running_systemd ( name , cache = True , path = None ) : <EOL> '''<STR_LIT>''' <EOL> k = '<STR_LIT>' . format ( name , path ) <EOL> ret = __context__ . get ( k , None ) <EOL> if ret is None or not cache : <EOL> rstr = __salt__ [ '<STR_LIT>' ] ( ) <EOL> script = '<STR_LIT>' . format ( rstr ) <EOL> _script = textwrap . dedent ( <EOL> '''<STR_LIT>''' ) <EOL> result = run_all ( <EOL> name , '<STR_LIT>' . format ( script ) , path = path , <EOL> stdin = _script , python_shell = True ) <EOL> if result [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> result = run_all ( name , <EOL> '<STR_LIT>' '<STR_LIT>' . format ( script ) , <EOL> path = path , <EOL> python_shell = True ) <EOL> else : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) ) <EOL> run_all ( name , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( script ) , <EOL> path = path , <EOL> ignore_retcode = True , <EOL> python_shell = True ) <EOL> if result [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> error = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( name ) ) <EOL> if result [ '<STR_LIT>' ] : <EOL> error += '<STR_LIT>' . format ( result [ '<STR_LIT>' ] ) <EOL> if result [ '<STR_LIT>' ] in ( <NUM_LIT:0> , <NUM_LIT:2> ) : <EOL> __context__ [ k ] = ret = not result [ '<STR_LIT>' ] <EOL> return ret <EOL> def systemd_running_state ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> ret = run_all ( name , <EOL> '<STR_LIT>' , <EOL> path = path , <EOL> ignore_retcode = True ) [ '<STR_LIT>' ] <EOL> except CommandExecutionError : <EOL> ret = '<STR_LIT>' <EOL> return ret <EOL> def test_sd_started_state ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> qstate = systemd_running_state ( name , path = path ) <EOL> if qstate in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return False <EOL> elif qstate == '<STR_LIT>' : <EOL> return None <EOL> else : <EOL> return True <EOL> def test_bare_started_state ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> ret = run_all ( <EOL> name , '<STR_LIT>' , path = path , ignore_retcode = True <EOL> ) [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> except ( CommandExecutionError , ) : <EOL> ret = None <EOL> return ret <EOL> def wait_started ( name , path = None , timeout = <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> if not exists ( name , path = path ) : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) ) <EOL> if not state ( name , path = path ) == '<STR_LIT>' : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) ) <EOL> ret = False <EOL> if running_systemd ( name , path = path ) : <EOL> test_started = test_sd_started_state <EOL> logger = log . error <EOL> else : <EOL> test_started = test_bare_started_state <EOL> logger = log . debug <EOL> now = time . time ( ) <EOL> expire = now + timeout <EOL> now = time . time ( ) <EOL> started = test_started ( name , path = path ) <EOL> while time . time ( ) < expire and not started : <EOL> time . sleep ( <NUM_LIT> ) <EOL> started = test_started ( name , path = path ) <EOL> if started is None : <EOL> logger ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( name ) ) <EOL> ret = True <EOL> else : <EOL> ret = started <EOL> return ret <EOL> def _needs_install ( name , path = None ) : <EOL> ret = <NUM_LIT:0> <EOL> has_minion = retcode ( name , <EOL> '<STR_LIT>' , <EOL> path = path , <EOL> ignore_retcode = True ) <EOL> if has_minion : <EOL> processes = run_stdout ( name , "<STR_LIT>" , path = path ) <EOL> if '<STR_LIT>' not in processes : <EOL> ret = <NUM_LIT:1> <EOL> else : <EOL> retcode ( name , '<STR_LIT>' ) <EOL> else : <EOL> ret = <NUM_LIT:1> <EOL> return ret <EOL> def bootstrap ( name , <EOL> config = None , <EOL> approve_key = True , <EOL> install = True , <EOL> pub_key = None , <EOL> priv_key = None , <EOL> bootstrap_url = None , <EOL> force_install = False , <EOL> unconditional_install = False , <EOL> path = None , <EOL> bootstrap_delay = None , <EOL> bootstrap_args = None , <EOL> bootstrap_shell = None ) : <EOL> '''<STR_LIT>''' <EOL> wait_started ( name , path = path ) <EOL> if bootstrap_delay is not None : <EOL> try : <EOL> log . info ( '<STR_LIT>' . format ( <EOL> name , bootstrap_delay ) ) <EOL> time . sleep ( bootstrap_delay ) <EOL> except TypeError : <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> c_info = info ( name , path = path ) <EOL> if not c_info : <EOL> return None <EOL> if bootstrap_args : <EOL> if '<STR_LIT>' not in bootstrap_args : <EOL> bootstrap_args += '<STR_LIT>' <EOL> else : <EOL> bootstrap_args = '<STR_LIT>' <EOL> if not bootstrap_shell : <EOL> bootstrap_shell = '<STR_LIT>' <EOL> orig_state = _ensure_running ( name , path = path ) <EOL> if not orig_state : <EOL> return orig_state <EOL> if not force_install : <EOL> needs_install = _needs_install ( name , path = path ) <EOL> else : <EOL> needs_install = True <EOL> seeded = retcode ( name , <EOL> '<STR_LIT>' . format ( SEED_MARKER ) , <EOL> path = path , <EOL> chroot_fallback = True , <EOL> ignore_retcode = True ) == <NUM_LIT:0> <EOL> tmp = tempfile . mkdtemp ( ) <EOL> if seeded and not unconditional_install : <EOL> ret = True <EOL> else : <EOL> ret = False <EOL> cfg_files = __salt__ [ '<STR_LIT>' ] ( <EOL> config , tmp = tmp , id_ = name , approve_key = approve_key , <EOL> pub_key = pub_key , priv_key = priv_key ) <EOL> if needs_install or force_install or unconditional_install : <EOL> if install : <EOL> rstr = __salt__ [ '<STR_LIT>' ] ( ) <EOL> configdir = '<STR_LIT>' . format ( rstr ) <EOL> cmd = '<STR_LIT>' . format ( configdir ) <EOL> if run ( name , cmd , python_shell = False ) : <EOL> log . error ( '<STR_LIT>' <EOL> . format ( configdir , cmd ) ) <EOL> return False <EOL> bs_ = __salt__ [ '<STR_LIT>' ] ( <EOL> bootstrap = bootstrap_url ) <EOL> script = '<STR_LIT>' . format ( rstr ) <EOL> copy_to ( name , bs_ , script , path = path ) <EOL> result = run_all ( name , <EOL> '<STR_LIT>' . format ( script ) , <EOL> python_shell = True ) <EOL> copy_to ( name , cfg_files [ '<STR_LIT>' ] , <EOL> os . path . join ( configdir , '<STR_LIT>' ) , <EOL> path = path ) <EOL> copy_to ( name , cfg_files [ '<STR_LIT>' ] , <EOL> os . path . join ( configdir , '<STR_LIT>' ) , <EOL> path = path ) <EOL> copy_to ( name , cfg_files [ '<STR_LIT>' ] , <EOL> os . path . join ( configdir , '<STR_LIT>' ) , <EOL> path = path ) <EOL> bootstrap_args = bootstrap_args . format ( configdir ) <EOL> cmd = ( '<STR_LIT>' <EOL> . format ( bootstrap_shell , <EOL> bootstrap_args . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) , <EOL> script ) ) <EOL> log . info ( '<STR_LIT>' <EOL> . format ( cmd , name ) ) <EOL> ret = retcode ( name , cmd , output_loglevel = '<STR_LIT:info>' , <EOL> path = path , use_vt = True ) == <NUM_LIT:0> <EOL> run_all ( name , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( script ) , <EOL> ignore_retcode = True , <EOL> python_shell = True ) <EOL> else : <EOL> ret = False <EOL> else : <EOL> minion_config = salt . config . minion_config ( cfg_files [ '<STR_LIT>' ] ) <EOL> pki_dir = minion_config [ '<STR_LIT>' ] <EOL> copy_to ( name , <EOL> cfg_files [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> path = path ) <EOL> copy_to ( name , <EOL> cfg_files [ '<STR_LIT>' ] , <EOL> os . path . join ( pki_dir , '<STR_LIT>' ) , <EOL> path = path ) <EOL> copy_to ( name , <EOL> cfg_files [ '<STR_LIT>' ] , <EOL> os . path . join ( pki_dir , '<STR_LIT>' ) , <EOL> path = path ) <EOL> run ( name , <EOL> '<STR_LIT>' , <EOL> path = path , <EOL> python_shell = False ) <EOL> ret = True <EOL> shutil . rmtree ( tmp ) <EOL> if orig_state == '<STR_LIT>' : <EOL> stop ( name , path = path ) <EOL> elif orig_state == '<STR_LIT>' : <EOL> freeze ( name , path = path ) <EOL> if ret : <EOL> run ( name , <EOL> '<STR_LIT>' . format ( SEED_MARKER ) , <EOL> path = path , <EOL> python_shell = False ) <EOL> return ret <EOL> def attachable ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> cachekey = '<STR_LIT>' . format ( name , path ) <EOL> try : <EOL> return __context__ [ cachekey ] <EOL> except KeyError : <EOL> _ensure_exists ( name , path = path ) <EOL> log . debug ( '<STR_LIT>' . format ( name ) ) <EOL> cmd = '<STR_LIT>' <EOL> if path : <EOL> cmd += '<STR_LIT>' . format ( pipes . quote ( path ) ) <EOL> cmd += '<STR_LIT>' . format ( name ) <EOL> result = __salt__ [ '<STR_LIT>' ] ( cmd , <EOL> python_shell = False , <EOL> output_loglevel = '<STR_LIT>' , <EOL> ignore_retcode = True ) == <NUM_LIT:0> <EOL> __context__ [ cachekey ] = result <EOL> return __context__ [ cachekey ] <EOL> def _run ( name , <EOL> cmd , <EOL> output = None , <EOL> no_start = False , <EOL> preserve_state = True , <EOL> stdin = None , <EOL> python_shell = True , <EOL> output_loglevel = '<STR_LIT>' , <EOL> use_vt = False , <EOL> path = None , <EOL> ignore_retcode = False , <EOL> chroot_fallback = None , <EOL> keep_env = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> orig_state = state ( name , path = path ) <EOL> try : <EOL> if attachable ( name , path = path ) : <EOL> ret = __salt__ [ '<STR_LIT>' ] ( <EOL> name , <EOL> cmd , <EOL> path = path , <EOL> container_type = __virtualname__ , <EOL> exec_driver = EXEC_DRIVER , <EOL> output = output , <EOL> no_start = no_start , <EOL> stdin = stdin , <EOL> python_shell = python_shell , <EOL> output_loglevel = output_loglevel , <EOL> ignore_retcode = ignore_retcode , <EOL> use_vt = use_vt , <EOL> keep_env = keep_env ) <EOL> else : <EOL> if not chroot_fallback : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( name ) ) <EOL> rootfs = info ( name , path = path ) . get ( '<STR_LIT>' ) <EOL> __context__ [ '<STR_LIT>' ] = __salt__ [ '<STR_LIT>' ] <EOL> ret = __salt__ [ '<STR_LIT>' ] ( rootfs , <EOL> cmd , <EOL> stdin = stdin , <EOL> python_shell = python_shell , <EOL> output_loglevel = output_loglevel , <EOL> ignore_retcode = ignore_retcode ) <EOL> except Exception : <EOL> raise <EOL> finally : <EOL> new_state = state ( name , path = path ) <EOL> if preserve_state : <EOL> if orig_state == '<STR_LIT>' and new_state != '<STR_LIT>' : <EOL> stop ( name , path = path ) <EOL> elif orig_state == '<STR_LIT>' and new_state != '<STR_LIT>' : <EOL> freeze ( name , start = True , path = path ) <EOL> if output in ( None , '<STR_LIT:all>' ) : <EOL> return ret <EOL> else : <EOL> return ret [ output ] <EOL> def run_cmd ( name , <EOL> cmd , <EOL> no_start = False , <EOL> preserve_state = True , <EOL> stdin = None , <EOL> stdout = True , <EOL> stderr = False , <EOL> python_shell = True , <EOL> path = None , <EOL> output_loglevel = '<STR_LIT>' , <EOL> use_vt = False , <EOL> ignore_retcode = False , <EOL> chroot_fallback = False , <EOL> keep_env = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> if stdout and stderr : <EOL> output = '<STR_LIT:all>' <EOL> elif stdout : <EOL> output = '<STR_LIT>' <EOL> elif stderr : <EOL> output = '<STR_LIT>' <EOL> else : <EOL> output = '<STR_LIT>' <EOL> return _run ( name , <EOL> cmd , <EOL> output = output , <EOL> no_start = no_start , <EOL> preserve_state = preserve_state , <EOL> stdin = stdin , <EOL> python_shell = python_shell , <EOL> path = path , <EOL> output_loglevel = output_loglevel , <EOL> use_vt = use_vt , <EOL> ignore_retcode = ignore_retcode , <EOL> keep_env = keep_env ) <EOL> def run ( name , <EOL> cmd , <EOL> no_start = False , <EOL> preserve_state = True , <EOL> stdin = None , <EOL> python_shell = True , <EOL> output_loglevel = '<STR_LIT>' , <EOL> use_vt = False , <EOL> path = None , <EOL> ignore_retcode = False , <EOL> chroot_fallback = False , <EOL> keep_env = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> return _run ( name , <EOL> cmd , <EOL> path = path , <EOL> output = None , <EOL> no_start = no_start , <EOL> preserve_state = preserve_state , <EOL> stdin = stdin , <EOL> python_shell = python_shell , <EOL> output_loglevel = output_loglevel , <EOL> use_vt = use_vt , <EOL> ignore_retcode = ignore_retcode , <EOL> chroot_fallback = chroot_fallback , <EOL> keep_env = keep_env ) <EOL> def run_stdout ( name , <EOL> cmd , <EOL> no_start = False , <EOL> preserve_state = True , <EOL> stdin = None , <EOL> python_shell = True , <EOL> output_loglevel = '<STR_LIT>' , <EOL> use_vt = False , <EOL> path = None , <EOL> ignore_retcode = False , <EOL> chroot_fallback = False , <EOL> keep_env = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> return _run ( name , <EOL> cmd , <EOL> path = path , <EOL> output = '<STR_LIT>' , <EOL> no_start = no_start , <EOL> preserve_state = preserve_state , <EOL> stdin = stdin , <EOL> python_shell = python_shell , <EOL> output_loglevel = output_loglevel , <EOL> use_vt = use_vt , <EOL> ignore_retcode = ignore_retcode , <EOL> chroot_fallback = chroot_fallback , <EOL> keep_env = keep_env ) <EOL> def run_stderr ( name , <EOL> cmd , <EOL> no_start = False , <EOL> preserve_state = True , <EOL> stdin = None , <EOL> python_shell = True , <EOL> output_loglevel = '<STR_LIT>' , <EOL> use_vt = False , <EOL> path = None , <EOL> ignore_retcode = False , <EOL> chroot_fallback = False , <EOL> keep_env = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> return _run ( name , <EOL> cmd , <EOL> path = path , <EOL> output = '<STR_LIT>' , <EOL> no_start = no_start , <EOL> preserve_state = preserve_state , <EOL> stdin = stdin , <EOL> python_shell = python_shell , <EOL> output_loglevel = output_loglevel , <EOL> use_vt = use_vt , <EOL> ignore_retcode = ignore_retcode , <EOL> chroot_fallback = chroot_fallback , <EOL> keep_env = keep_env ) <EOL> def retcode ( name , <EOL> cmd , <EOL> no_start = False , <EOL> preserve_state = True , <EOL> stdin = None , <EOL> python_shell = True , <EOL> output_loglevel = '<STR_LIT>' , <EOL> use_vt = False , <EOL> path = None , <EOL> ignore_retcode = False , <EOL> chroot_fallback = False , <EOL> keep_env = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> return _run ( name , <EOL> cmd , <EOL> output = '<STR_LIT>' , <EOL> path = path , <EOL> no_start = no_start , <EOL> preserve_state = preserve_state , <EOL> stdin = stdin , <EOL> python_shell = python_shell , <EOL> output_loglevel = output_loglevel , <EOL> use_vt = use_vt , <EOL> ignore_retcode = ignore_retcode , <EOL> chroot_fallback = chroot_fallback , <EOL> keep_env = keep_env ) <EOL> def run_all ( name , <EOL> cmd , <EOL> no_start = False , <EOL> preserve_state = True , <EOL> stdin = None , <EOL> python_shell = True , <EOL> output_loglevel = '<STR_LIT>' , <EOL> use_vt = False , <EOL> path = None , <EOL> ignore_retcode = False , <EOL> chroot_fallback = False , <EOL> keep_env = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> return _run ( name , <EOL> cmd , <EOL> output = '<STR_LIT:all>' , <EOL> no_start = no_start , <EOL> preserve_state = preserve_state , <EOL> stdin = stdin , <EOL> python_shell = python_shell , <EOL> output_loglevel = output_loglevel , <EOL> use_vt = use_vt , <EOL> path = path , <EOL> ignore_retcode = ignore_retcode , <EOL> chroot_fallback = chroot_fallback , <EOL> keep_env = keep_env ) <EOL> def _get_md5 ( name , path ) : <EOL> '''<STR_LIT>''' <EOL> output = run_stdout ( name , '<STR_LIT>' . format ( path ) , <EOL> chroot_fallback = True , <EOL> ignore_retcode = True ) <EOL> try : <EOL> return output . split ( ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> return None <EOL> def copy_to ( name , source , dest , overwrite = False , makedirs = False , path = None ) : <EOL> '''<STR_LIT>''' <EOL> _ensure_running ( name , no_start = True , path = path ) <EOL> return __salt__ [ '<STR_LIT>' ] ( <EOL> name , <EOL> source , <EOL> dest , <EOL> container_type = __virtualname__ , <EOL> path = path , <EOL> exec_driver = EXEC_DRIVER , <EOL> overwrite = overwrite , <EOL> makedirs = makedirs ) <EOL> cp = salt . utils . alias_function ( copy_to , '<STR_LIT>' ) <EOL> def read_conf ( conf_file , out_format = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> ret_commented = [ ] <EOL> ret_simple = { } <EOL> with salt . utils . fopen ( conf_file , '<STR_LIT:r>' ) as fp_ : <EOL> for line in fp_ . readlines ( ) : <EOL> if '<STR_LIT:=>' not in line : <EOL> ret_commented . append ( line ) <EOL> continue <EOL> comps = line . split ( '<STR_LIT:=>' ) <EOL> value = '<STR_LIT:=>' . join ( comps [ <NUM_LIT:1> : ] ) . strip ( ) <EOL> comment = None <EOL> if value . strip ( ) . startswith ( '<STR_LIT:#>' ) : <EOL> vcomps = value . strip ( ) . split ( '<STR_LIT:#>' ) <EOL> value = vcomps [ <NUM_LIT:1> ] . strip ( ) <EOL> comment = '<STR_LIT:#>' . join ( vcomps [ <NUM_LIT:1> : ] ) . strip ( ) <EOL> ret_commented . append ( { comps [ <NUM_LIT:0> ] . strip ( ) : { <EOL> '<STR_LIT:value>' : value , <EOL> '<STR_LIT>' : comment , <EOL> } } ) <EOL> else : <EOL> ret_commented . append ( { comps [ <NUM_LIT:0> ] . strip ( ) : value } ) <EOL> ret_simple [ comps [ <NUM_LIT:0> ] . strip ( ) ] = value <EOL> if out_format == '<STR_LIT>' : <EOL> return ret_simple <EOL> return ret_commented <EOL> def write_conf ( conf_file , conf ) : <EOL> '''<STR_LIT>''' <EOL> if not isinstance ( conf , list ) : <EOL> raise SaltInvocationError ( '<STR_LIT>' ) <EOL> content = '<STR_LIT>' <EOL> for line in conf : <EOL> if isinstance ( line , ( six . text_type , six . string_types ) ) : <EOL> content += line <EOL> elif isinstance ( line , dict ) : <EOL> for key in list ( line . keys ( ) ) : <EOL> out_line = None <EOL> if isinstance ( <EOL> line [ key ] , <EOL> ( six . text_type , six . string_types , six . integer_types , float ) <EOL> ) : <EOL> out_line = '<STR_LIT>' . join ( ( key , "<STR_LIT>" . format ( line [ key ] ) ) ) <EOL> elif isinstance ( line [ key ] , dict ) : <EOL> out_line = '<STR_LIT>' . join ( ( key , line [ key ] [ '<STR_LIT:value>' ] ) ) <EOL> if '<STR_LIT>' in line [ key ] : <EOL> out_line = '<STR_LIT>' . join ( ( out_line , line [ key ] [ '<STR_LIT>' ] ) ) <EOL> if out_line : <EOL> content += out_line <EOL> content += '<STR_LIT:\n>' <EOL> with salt . utils . fopen ( conf_file , '<STR_LIT:w>' ) as fp_ : <EOL> fp_ . write ( content ) <EOL> return { } <EOL> def edit_conf ( conf_file , <EOL> out_format = '<STR_LIT>' , <EOL> read_only = False , <EOL> lxc_config = None , <EOL> ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> data = [ ] <EOL> try : <EOL> conf = read_conf ( conf_file , out_format = out_format ) <EOL> except Exception : <EOL> conf = [ ] <EOL> if not lxc_config : <EOL> lxc_config = [ ] <EOL> lxc_config = copy . deepcopy ( lxc_config ) <EOL> net_config = [ ] <EOL> for lxc_kws in lxc_config + [ kwargs ] : <EOL> net_params = { } <EOL> for kwarg in [ a for a in lxc_kws ] : <EOL> if kwarg . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> if kwarg . startswith ( '<STR_LIT>' ) : <EOL> net_params [ kwarg ] = lxc_kws [ kwarg ] <EOL> lxc_kws . pop ( kwarg , None ) <EOL> if net_params : <EOL> net_config . append ( net_params ) <EOL> nic_opts = salt . utils . odict . OrderedDict ( ) <EOL> for params in net_config : <EOL> dev = params . get ( '<STR_LIT>' , DEFAULT_NIC ) <EOL> dev_opts = nic_opts . setdefault ( dev , salt . utils . odict . OrderedDict ( ) ) <EOL> for param in params : <EOL> opt = param . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> opt = { '<STR_LIT>' : '<STR_LIT>' } . get ( opt , opt ) <EOL> dev_opts [ opt ] = params [ param ] <EOL> net_changes = [ ] <EOL> if nic_opts : <EOL> net_changes = _config_list ( conf , only_net = True , <EOL> ** { '<STR_LIT>' : DEFAULT_NIC , <EOL> '<STR_LIT>' : nic_opts } ) <EOL> if net_changes : <EOL> lxc_config . extend ( net_changes ) <EOL> for line in conf : <EOL> if not isinstance ( line , dict ) : <EOL> data . append ( line ) <EOL> continue <EOL> else : <EOL> for key in list ( line . keys ( ) ) : <EOL> val = line [ key ] <EOL> if net_changes and key . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> found = False <EOL> for ix in range ( len ( lxc_config ) ) : <EOL> kw = lxc_config [ ix ] <EOL> if key in kw : <EOL> found = True <EOL> data . append ( { key : kw [ key ] } ) <EOL> del kw [ key ] <EOL> if not found : <EOL> data . append ( { key : val } ) <EOL> for lxc_kws in lxc_config : <EOL> for kwarg in lxc_kws : <EOL> data . append ( { kwarg : lxc_kws [ kwarg ] } ) <EOL> if read_only : <EOL> return data <EOL> write_conf ( conf_file , data ) <EOL> return read_conf ( conf_file , out_format ) <EOL> def reboot ( name , path = None ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( name ) } <EOL> does_exist = exists ( name , path = path ) <EOL> if does_exist and ( state ( name , path = path ) == '<STR_LIT>' ) : <EOL> try : <EOL> stop ( name , path = path ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( exc ) <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> return ret <EOL> if does_exist and ( state ( name , path = path ) != '<STR_LIT>' ) : <EOL> try : <EOL> start ( name , path = path ) <EOL> except ( SaltInvocationError , CommandExecutionError ) as exc : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( exc ) <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> return ret <EOL> ret [ '<STR_LIT>' ] [ name ] = '<STR_LIT>' <EOL> return ret <EOL> def reconfigure ( name , <EOL> cpu = None , <EOL> cpuset = None , <EOL> cpushare = None , <EOL> memory = None , <EOL> profile = None , <EOL> network_profile = None , <EOL> nic_opts = None , <EOL> bridge = None , <EOL> gateway = None , <EOL> autostart = None , <EOL> utsname = None , <EOL> rootfs = None , <EOL> path = None , <EOL> ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> changes = { } <EOL> cpath = get_root_path ( path ) <EOL> path = os . path . join ( cpath , name , '<STR_LIT>' ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( name ) , <EOL> '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : changes } <EOL> profile = get_container_profile ( copy . deepcopy ( profile ) ) <EOL> kw_overrides = copy . deepcopy ( kwargs ) <EOL> def select ( key , default = None ) : <EOL> kw_overrides_match = kw_overrides . pop ( key , _marker ) <EOL> profile_match = profile . pop ( key , default ) <EOL> if kw_overrides_match is _marker : <EOL> return profile_match <EOL> return kw_overrides_match <EOL> if nic_opts is not None and not network_profile : <EOL> network_profile = DEFAULT_NIC <EOL> if autostart is not None : <EOL> autostart = select ( '<STR_LIT>' , autostart ) <EOL> else : <EOL> autostart = '<STR_LIT>' <EOL> if not utsname : <EOL> utsname = select ( '<STR_LIT>' , utsname ) <EOL> if os . path . exists ( path ) : <EOL> old_chunks = read_conf ( path , out_format = '<STR_LIT>' ) <EOL> make_kw = salt . utils . odict . OrderedDict ( [ <EOL> ( '<STR_LIT>' , utsname ) , <EOL> ( '<STR_LIT>' , rootfs ) , <EOL> ( '<STR_LIT>' , autostart ) , <EOL> ( '<STR_LIT>' , cpu ) , <EOL> ( '<STR_LIT>' , gateway ) , <EOL> ( '<STR_LIT>' , cpuset ) , <EOL> ( '<STR_LIT>' , cpushare ) , <EOL> ( '<STR_LIT>' , network_profile ) , <EOL> ( '<STR_LIT>' , nic_opts ) , <EOL> ( '<STR_LIT>' , bridge ) ] ) <EOL> if memory : <EOL> make_kw [ '<STR_LIT>' ] = memory <EOL> kw = salt . utils . odict . OrderedDict ( ) <EOL> for key , val in six . iteritems ( make_kw ) : <EOL> if val is not None : <EOL> kw [ key ] = val <EOL> new_cfg = _config_list ( conf_tuples = old_chunks , ** kw ) <EOL> if new_cfg : <EOL> edit_conf ( path , out_format = '<STR_LIT>' , lxc_config = new_cfg ) <EOL> chunks = read_conf ( path , out_format = '<STR_LIT>' ) <EOL> if old_chunks != chunks : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> if state ( name , path = path ) == '<STR_LIT>' : <EOL> cret = reboot ( name , path = path ) <EOL> ret [ '<STR_LIT:result>' ] = cret [ '<STR_LIT:result>' ] <EOL> return ret <EOL> def apply_network_profile ( name , network_profile , nic_opts = None , path = None ) : <EOL> '''<STR_LIT>''' <EOL> cpath = get_root_path ( path ) <EOL> cfgpath = os . path . join ( cpath , name , '<STR_LIT>' ) <EOL> before = [ ] <EOL> with salt . utils . fopen ( cfgpath , '<STR_LIT:r>' ) as fp_ : <EOL> for line in fp_ : <EOL> before . append ( line ) <EOL> lxcconfig = _LXCConfig ( name = name , path = path ) <EOL> old_net = lxcconfig . _filter_data ( '<STR_LIT>' ) <EOL> network_params = { } <EOL> for param in _network_conf ( <EOL> conf_tuples = old_net , <EOL> network_profile = network_profile , nic_opts = nic_opts <EOL> ) : <EOL> network_params . update ( param ) <EOL> if network_params : <EOL> edit_conf ( cfgpath , out_format = '<STR_LIT>' , ** network_params ) <EOL> after = [ ] <EOL> with salt . utils . fopen ( cfgpath , '<STR_LIT:r>' ) as fp_ : <EOL> for line in fp_ : <EOL> after . append ( line ) <EOL> diff = '<STR_LIT>' <EOL> for line in difflib . unified_diff ( before , <EOL> after , <EOL> fromfile = '<STR_LIT>' , <EOL> tofile = '<STR_LIT>' ) : <EOL> diff += line <EOL> return diff </s>
