mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Remove unneeded checks for binaries in SmartOS modules
This tidies the actual command string building and makes the code more readable in general. The required binaries are not likely to disappear after __virtual__ has been evaluated. Use correct nomenclature when referring to 'compute nodes'.
This commit is contained in:
parent
58c8ff18e2
commit
e703254990
4 changed files with 54 additions and 172 deletions
|
@ -11,7 +11,6 @@ import logging
|
|||
import salt.utils.json
|
||||
import salt.utils.path
|
||||
import salt.utils.platform
|
||||
import salt.utils.decorators as decorators
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -26,14 +25,6 @@ __func_alias__ = {
|
|||
__virtualname__ = 'imgadm'
|
||||
|
||||
|
||||
@decorators.memoize
|
||||
def _check_imgadm():
|
||||
'''
|
||||
Looks to see if imgadm is present on the system
|
||||
'''
|
||||
return salt.utils.path.which('imgadm')
|
||||
|
||||
|
||||
def _exit_status(retcode):
|
||||
'''
|
||||
Translate exit status of imgadm
|
||||
|
@ -70,11 +61,12 @@ def __virtual__():
|
|||
'''
|
||||
Provides imgadm only on SmartOS
|
||||
'''
|
||||
if salt.utils.platform.is_smartos_globalzone() and _check_imgadm():
|
||||
if salt.utils.platform.is_smartos_globalzone() and \
|
||||
salt.utils.path.which('imgadm'):
|
||||
return __virtualname__
|
||||
return (
|
||||
False,
|
||||
'{0} module can only be loaded on SmartOS computed nodes'.format(
|
||||
'{0} module can only be loaded on SmartOS compute nodes'.format(
|
||||
__virtualname__
|
||||
)
|
||||
)
|
||||
|
@ -91,8 +83,7 @@ def version():
|
|||
salt '*' imgadm.version
|
||||
'''
|
||||
ret = {}
|
||||
imgadm = _check_imgadm()
|
||||
cmd = '{0} --version'.format(imgadm)
|
||||
cmd = 'imgadm --version'
|
||||
res = __salt__['cmd.run'](cmd).splitlines()
|
||||
ret = res[0].split()
|
||||
return ret[-1]
|
||||
|
@ -111,10 +102,8 @@ def update_installed(uuid=''):
|
|||
|
||||
salt '*' imgadm.update [uuid]
|
||||
'''
|
||||
imgadm = _check_imgadm()
|
||||
if imgadm:
|
||||
cmd = '{0} update {1}'.format(imgadm, uuid).rstrip()
|
||||
__salt__['cmd.run'](cmd)
|
||||
cmd = 'imgadm update {0}'.format(uuid).rstrip()
|
||||
__salt__['cmd.run'](cmd)
|
||||
return {}
|
||||
|
||||
|
||||
|
@ -135,8 +124,7 @@ def avail(search=None, verbose=False):
|
|||
salt '*' imgadm.avail verbose=True
|
||||
'''
|
||||
ret = {}
|
||||
imgadm = _check_imgadm()
|
||||
cmd = '{0} avail -j'.format(imgadm)
|
||||
cmd = 'imgadm avail -j'
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
retcode = res['retcode']
|
||||
result = {}
|
||||
|
@ -169,8 +157,7 @@ def list_installed(verbose=False):
|
|||
salt '*' imgadm.list [verbose=True]
|
||||
'''
|
||||
ret = {}
|
||||
imgadm = _check_imgadm()
|
||||
cmd = '{0} list -j'.format(imgadm)
|
||||
cmd = 'imgadm list -j'
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
retcode = res['retcode']
|
||||
result = {}
|
||||
|
@ -198,8 +185,7 @@ def show(uuid):
|
|||
salt '*' imgadm.show e42f8c84-bbea-11e2-b920-078fab2aab1f
|
||||
'''
|
||||
ret = {}
|
||||
imgadm = _check_imgadm()
|
||||
cmd = '{0} show {1}'.format(imgadm, uuid)
|
||||
cmd = 'imgadm show {0}'.format(uuid)
|
||||
res = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0:
|
||||
|
@ -223,8 +209,7 @@ def get(uuid):
|
|||
salt '*' imgadm.get e42f8c84-bbea-11e2-b920-078fab2aab1f
|
||||
'''
|
||||
ret = {}
|
||||
imgadm = _check_imgadm()
|
||||
cmd = '{0} get {1}'.format(imgadm, uuid)
|
||||
cmd = 'imgadm get {0}'.format(uuid)
|
||||
res = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0:
|
||||
|
@ -250,8 +235,7 @@ def import_image(uuid, verbose=False):
|
|||
salt '*' imgadm.import e42f8c84-bbea-11e2-b920-078fab2aab1f [verbose=True]
|
||||
'''
|
||||
ret = {}
|
||||
imgadm = _check_imgadm()
|
||||
cmd = '{0} import {1}'.format(imgadm, uuid)
|
||||
cmd = 'imgadm import {0}'.format(uuid)
|
||||
res = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0:
|
||||
|
@ -275,8 +259,7 @@ def delete(uuid):
|
|||
salt '*' imgadm.delete e42f8c84-bbea-11e2-b920-078fab2aab1f
|
||||
'''
|
||||
ret = {}
|
||||
imgadm = _check_imgadm()
|
||||
cmd = '{0} delete {1}'.format(imgadm, uuid)
|
||||
cmd = 'imgadm delete {0}'.format(uuid)
|
||||
res = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0:
|
||||
|
@ -305,8 +288,7 @@ def vacuum(verbose=False):
|
|||
salt '*' imgadm.vacuum [verbose=True]
|
||||
'''
|
||||
ret = {}
|
||||
imgadm = _check_imgadm()
|
||||
cmd = '{0} vacuum -f'.format(imgadm)
|
||||
cmd = 'imgadm vacuum -f'
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0:
|
||||
|
|
|
@ -17,7 +17,6 @@ import logging
|
|||
# Import Salt libs
|
||||
import salt.utils.path
|
||||
import salt.utils.platform
|
||||
import salt.utils.decorators as decorators
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -30,31 +29,17 @@ __func_alias__ = {
|
|||
__virtualname__ = 'nictagadm'
|
||||
|
||||
|
||||
@decorators.memoize
|
||||
def _check_nictagadm():
|
||||
'''
|
||||
Looks to see if nictagadm is present on the system
|
||||
'''
|
||||
return salt.utils.path.which('nictagadm')
|
||||
|
||||
|
||||
def _check_dladm():
|
||||
'''
|
||||
Looks to see if dladm is present on the system
|
||||
'''
|
||||
return salt.utils.path.which('dladm')
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Provides nictagadm on SmartOS
|
||||
'''
|
||||
if salt.utils.platform.is_smartos_globalzone() \
|
||||
and _check_nictagadm() and _check_dladm():
|
||||
if salt.utils.platform.is_smartos_globalzone() and \
|
||||
salt.utils.path.which('dladm') and \
|
||||
salt.utils.path.which('nictagadm'):
|
||||
return __virtualname__
|
||||
return (
|
||||
False,
|
||||
'{0} module can only be loaded on SmartOS computed nodes'.format(
|
||||
'{0} module can only be loaded on SmartOS compute nodes'.format(
|
||||
__virtualname__
|
||||
)
|
||||
)
|
||||
|
@ -74,10 +59,8 @@ def list_nictags(include_etherstubs=True):
|
|||
salt '*' nictagadm.list
|
||||
'''
|
||||
ret = {}
|
||||
nictagadm = _check_nictagadm()
|
||||
cmd = '{nictagadm} list -d "|" -p{estubs}'.format(
|
||||
nictagadm=nictagadm,
|
||||
estubs=' -L' if not include_etherstubs else ''
|
||||
cmd = 'nictagadm list -d "|" -p{0}'.format(
|
||||
' -L' if not include_etherstubs else ''
|
||||
)
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
retcode = res['retcode']
|
||||
|
@ -109,11 +92,7 @@ def vms(nictag):
|
|||
salt '*' nictagadm.vms admin
|
||||
'''
|
||||
ret = {}
|
||||
nictagadm = _check_nictagadm()
|
||||
cmd = '{nictagadm} vms {nictag}'.format(
|
||||
nictagadm=nictagadm,
|
||||
nictag=nictag
|
||||
)
|
||||
cmd = 'nictagadm vms {0}'.format(nictag)
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0:
|
||||
|
@ -139,14 +118,10 @@ def exists(*nictag, **kwargs):
|
|||
salt '*' nictagadm.exists admin
|
||||
'''
|
||||
ret = {}
|
||||
nictagadm = _check_nictagadm()
|
||||
if len(nictag) == 0:
|
||||
return {'Error': 'Please provide at least one nictag to check.'}
|
||||
|
||||
cmd = '{nictagadm} exists -l {nictags}'.format(
|
||||
nictagadm=nictagadm,
|
||||
nictags=' '.join(nictag)
|
||||
)
|
||||
cmd = 'nictagadm exists -l {0}'.format(' '.join(nictag))
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
|
||||
if not kwargs.get('verbose', False):
|
||||
|
@ -178,29 +153,23 @@ def add(name, mac, mtu=1500):
|
|||
salt '*' nictagadm.add trunk 'DE:AD:OO:OO:BE:EF' 9000
|
||||
'''
|
||||
ret = {}
|
||||
nictagadm = _check_nictagadm()
|
||||
dladm = _check_dladm()
|
||||
|
||||
if mtu > 9000 or mtu < 1500:
|
||||
return {'Error': 'mtu must be a value between 1500 and 9000.'}
|
||||
if mac != 'etherstub':
|
||||
cmd = '{dladm} show-phys -m -p -o address'.format(
|
||||
dladm=dladm
|
||||
)
|
||||
cmd = 'dladm show-phys -m -p -o address'
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
if mac not in res['stdout'].splitlines():
|
||||
return {'Error': '{0} is not present on this system.'.format(mac)}
|
||||
|
||||
if mac == 'etherstub':
|
||||
cmd = '{nictagadm} add -l -p mtu={mtu} {name}'.format(
|
||||
nictagadm=nictagadm,
|
||||
cmd = 'nictagadm add -l -p mtu={mtu} {name}'.format(
|
||||
mtu=mtu,
|
||||
name=name
|
||||
)
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
else:
|
||||
cmd = '{nictagadm} add -p mtu={mtu},mac={mac} {name}'.format(
|
||||
nictagadm=nictagadm,
|
||||
cmd = 'nictagadm add -p mtu={mtu},mac={mac} {name}'.format(
|
||||
mtu=mtu,
|
||||
mac=mac,
|
||||
name=name
|
||||
|
@ -231,8 +200,6 @@ def update(name, mac=None, mtu=None):
|
|||
salt '*' nictagadm.update trunk mtu=9000
|
||||
'''
|
||||
ret = {}
|
||||
nictagadm = _check_nictagadm()
|
||||
dladm = _check_dladm()
|
||||
|
||||
if name not in list_nictags():
|
||||
return {'Error': 'nictag {0} does not exists.'.format(name)}
|
||||
|
@ -245,9 +212,7 @@ def update(name, mac=None, mtu=None):
|
|||
if mac == 'etherstub':
|
||||
return {'Error': 'cannot update a nic with "etherstub".'}
|
||||
else:
|
||||
cmd = '{dladm} show-phys -m -p -o address'.format(
|
||||
dladm=dladm
|
||||
)
|
||||
cmd = 'dladm show-phys -m -p -o address'
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
if mac not in res['stdout'].splitlines():
|
||||
return {'Error': '{0} is not present on this system.'.format(mac)}
|
||||
|
@ -259,8 +224,7 @@ def update(name, mac=None, mtu=None):
|
|||
elif mtu:
|
||||
properties = "mtu={0}".format(mtu) if mtu else ""
|
||||
|
||||
cmd = '{nictagadm} update -p {properties} {name}'.format(
|
||||
nictagadm=nictagadm,
|
||||
cmd = 'nictagadm update -p {properties} {name}'.format(
|
||||
properties=properties,
|
||||
name=name
|
||||
)
|
||||
|
@ -288,13 +252,11 @@ def delete(name, force=False):
|
|||
salt '*' nictagadm.exists admin
|
||||
'''
|
||||
ret = {}
|
||||
nictagadm = _check_nictagadm()
|
||||
|
||||
if name not in list_nictags():
|
||||
return True
|
||||
|
||||
cmd = '{nictagadm} delete {force}{name}'.format(
|
||||
nictagadm=nictagadm,
|
||||
cmd = 'nictagadm delete {force}{name}'.format(
|
||||
force="-f " if force else "",
|
||||
name=name
|
||||
)
|
||||
|
|
|
@ -27,7 +27,7 @@ def __virtual__():
|
|||
return __virtualname__
|
||||
return (
|
||||
False,
|
||||
'{0} module can only be loaded on SmartOS computed nodes'.format(
|
||||
'{0} module can only be loaded on SmartOS compute nodes'.format(
|
||||
__virtualname__
|
||||
)
|
||||
)
|
||||
|
|
|
@ -14,7 +14,6 @@ except ImportError:
|
|||
|
||||
# Import Salt libs
|
||||
import salt.utils.args
|
||||
import salt.utils.decorators as decorators
|
||||
import salt.utils.files
|
||||
import salt.utils.json
|
||||
import salt.utils.path
|
||||
|
@ -36,30 +35,17 @@ __func_alias__ = {
|
|||
__virtualname__ = 'vmadm'
|
||||
|
||||
|
||||
@decorators.memoize
|
||||
def _check_vmadm():
|
||||
'''
|
||||
Looks to see if vmadm is present on the system
|
||||
'''
|
||||
return salt.utils.path.which('vmadm')
|
||||
|
||||
|
||||
def _check_zfs():
|
||||
'''
|
||||
Looks to see if zfs is present on the system
|
||||
'''
|
||||
return salt.utils.path.which('zfs')
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Provides vmadm on SmartOS
|
||||
'''
|
||||
if salt.utils.platform.is_smartos_globalzone() and _check_vmadm():
|
||||
if salt.utils.platform.is_smartos_globalzone() and \
|
||||
salt.utils.path.which('vmadm') and \
|
||||
salt.utils.path.which('zfs'):
|
||||
return __virtualname__
|
||||
return (
|
||||
False,
|
||||
'{0} module can only be loaded on SmartOS computed nodes'.format(
|
||||
'{0} module can only be loaded on SmartOS compute nodes'.format(
|
||||
__virtualname__
|
||||
)
|
||||
)
|
||||
|
@ -80,13 +66,11 @@ def _create_update_from_file(mode='create', uuid=None, path=None):
|
|||
Create vm from file
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if not os.path.isfile(path) or path is None:
|
||||
ret['Error'] = 'File ({0}) does not exists!'.format(path)
|
||||
return ret
|
||||
# vmadm validate create|update [-f <filename>]
|
||||
cmd = '{vmadm} validate {mode} {brand} -f {path}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm validate {mode} {brand} -f {path}'.format(
|
||||
mode=mode,
|
||||
brand=get(uuid)['brand'] if uuid is not None else '',
|
||||
path=path
|
||||
|
@ -102,8 +86,7 @@ def _create_update_from_file(mode='create', uuid=None, path=None):
|
|||
ret['Error'] = res['stderr']
|
||||
return ret
|
||||
# vmadm create|update [-f <filename>]
|
||||
cmd = '{vmadm} {mode} {uuid} -f {path}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm {mode} {uuid} -f {path}'.format(
|
||||
mode=mode,
|
||||
uuid=uuid if uuid is not None else '',
|
||||
path=path
|
||||
|
@ -129,7 +112,6 @@ def _create_update_from_cfg(mode='create', uuid=None, vmcfg=None):
|
|||
Create vm from configuration
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
|
||||
# write json file
|
||||
vmadm_json_file = __salt__['temp.file'](prefix='vmadm-')
|
||||
|
@ -137,8 +119,7 @@ def _create_update_from_cfg(mode='create', uuid=None, vmcfg=None):
|
|||
salt.utils.json.dump(vmcfg, vmadm_json)
|
||||
|
||||
# vmadm validate create|update [-f <filename>]
|
||||
cmd = '{vmadm} validate {mode} {brand} -f {vmadm_json_file}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm validate {mode} {brand} -f {vmadm_json_file}'.format(
|
||||
mode=mode,
|
||||
brand=get(uuid)['brand'] if uuid is not None else '',
|
||||
vmadm_json_file=vmadm_json_file
|
||||
|
@ -154,8 +135,7 @@ def _create_update_from_cfg(mode='create', uuid=None, vmcfg=None):
|
|||
ret['Error'] = res['stderr']
|
||||
return ret
|
||||
# vmadm create|update [-f <filename>]
|
||||
cmd = '{vmadm} {mode} {uuid} -f {vmadm_json_file}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm {mode} {uuid} -f {vmadm_json_file}'.format(
|
||||
mode=mode,
|
||||
uuid=uuid if uuid is not None else '',
|
||||
vmadm_json_file=vmadm_json_file
|
||||
|
@ -202,7 +182,6 @@ def start(vm, options=None, key='uuid'):
|
|||
salt '*' vmadm.start vm=nina.example.org key=hostname
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -210,8 +189,7 @@ def start(vm, options=None, key='uuid'):
|
|||
if 'Error' in vm:
|
||||
return vm
|
||||
# vmadm start <uuid> [option=value ...]
|
||||
cmd = '{vmadm} start {uuid} {options}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm start {uuid} {options}'.format(
|
||||
uuid=vm,
|
||||
options=options if options else ''
|
||||
)
|
||||
|
@ -244,7 +222,6 @@ def stop(vm, force=False, key='uuid'):
|
|||
salt '*' vmadm.stop vm=nina.example.org key=hostname
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -252,8 +229,7 @@ def stop(vm, force=False, key='uuid'):
|
|||
if 'Error' in vm:
|
||||
return vm
|
||||
# vmadm stop <uuid> [-F]
|
||||
cmd = '{vmadm} stop {force} {uuid}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm stop {force} {uuid}'.format(
|
||||
force='-F' if force else '',
|
||||
uuid=vm
|
||||
)
|
||||
|
@ -286,7 +262,6 @@ def reboot(vm, force=False, key='uuid'):
|
|||
salt '*' vmadm.reboot vm=nina.example.org key=hostname
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -294,8 +269,7 @@ def reboot(vm, force=False, key='uuid'):
|
|||
if 'Error' in vm:
|
||||
return vm
|
||||
# vmadm reboot <uuid> [-F]
|
||||
cmd = '{vmadm} reboot {force} {uuid}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm reboot {force} {uuid}'.format(
|
||||
force='-F' if force else '',
|
||||
uuid=vm
|
||||
)
|
||||
|
@ -331,10 +305,8 @@ def list_vms(search=None, sort=None, order='uuid,type,ram,state,alias', keyed=Tr
|
|||
salt '*' vmadm.list search='type=KVM'
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
# vmadm list [-p] [-H] [-o field,...] [-s field,...] [field=value ...]
|
||||
cmd = '{vmadm} list -p -H {order} {sort} {search}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm list -p -H {order} {sort} {search}'.format(
|
||||
order='-o {0}'.format(order) if order else '',
|
||||
sort='-s {0}'.format(sort) if sort else '',
|
||||
search=search if search else ''
|
||||
|
@ -387,10 +359,8 @@ def lookup(search=None, order=None, one=False):
|
|||
salt '*' vmadm.lookup search='alias=nacl' one=True
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
# vmadm lookup [-j|-1] [-o field,...] [field=value ...]
|
||||
cmd = '{vmadm} lookup {one} {order} {search}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm lookup {one} {order} {search}'.format(
|
||||
one='-1' if one else '-j',
|
||||
order='-o {0}'.format(order) if order else '',
|
||||
search=search if search else ''
|
||||
|
@ -431,7 +401,6 @@ def sysrq(vm, action='nmi', key='uuid'):
|
|||
salt '*' vmadm.sysrq nacl nmi key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -442,8 +411,7 @@ def sysrq(vm, action='nmi', key='uuid'):
|
|||
if 'Error' in vm:
|
||||
return vm
|
||||
# vmadm sysrq <uuid> <nmi|screenshot>
|
||||
cmd = '{vmadm} sysrq {uuid} {action}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm sysrq {uuid} {action}'.format(
|
||||
uuid=vm,
|
||||
action=action
|
||||
)
|
||||
|
@ -472,7 +440,6 @@ def delete(vm, key='uuid'):
|
|||
salt '*' vmadm.delete nacl key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -480,10 +447,7 @@ def delete(vm, key='uuid'):
|
|||
if 'Error' in vm:
|
||||
return vm
|
||||
# vmadm delete <uuid>
|
||||
cmd = '{vmadm} delete {uuid}'.format(
|
||||
vmadm=vmadm,
|
||||
uuid=vm
|
||||
)
|
||||
cmd = 'vmadm delete {0}'.format(vm)
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0:
|
||||
|
@ -509,7 +473,6 @@ def get(vm, key='uuid'):
|
|||
salt '*' vmadm.get nacl key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -517,10 +480,7 @@ def get(vm, key='uuid'):
|
|||
if 'Error' in vm:
|
||||
return vm
|
||||
# vmadm get <uuid>
|
||||
cmd = '{vmadm} get {uuid}'.format(
|
||||
vmadm=vmadm,
|
||||
uuid=vm
|
||||
)
|
||||
cmd = 'vmadm get {0}'.format(vm)
|
||||
res = __salt__['cmd.run_all'](cmd)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0:
|
||||
|
@ -550,7 +510,6 @@ def info(vm, info_type='all', key='uuid'):
|
|||
salt '*' vmadm.info nacl vnc key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if info_type not in ['all', 'block', 'blockstats', 'chardev', 'cpus', 'kvm', 'pci', 'spice', 'version', 'vnc']:
|
||||
ret['Error'] = 'Requested info_type is not available'
|
||||
return ret
|
||||
|
@ -561,8 +520,7 @@ def info(vm, info_type='all', key='uuid'):
|
|||
if 'Error' in vm:
|
||||
return vm
|
||||
# vmadm info <uuid> [type,...]
|
||||
cmd = '{vmadm} info {uuid} {type}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm info {uuid} {type}'.format(
|
||||
uuid=vm,
|
||||
type=info_type
|
||||
)
|
||||
|
@ -596,7 +554,6 @@ def create_snapshot(vm, name, key='uuid'):
|
|||
salt '*' vmadm.create_snapshot nacl baseline key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -614,8 +571,7 @@ def create_snapshot(vm, name, key='uuid'):
|
|||
ret['Error'] = 'VM must be running to take a snapshot'
|
||||
return ret
|
||||
# vmadm create-snapshot <uuid> <snapname>
|
||||
cmd = '{vmadm} create-snapshot {uuid} {snapshot}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm create-snapshot {uuid} {snapshot}'.format(
|
||||
snapshot=name,
|
||||
uuid=vm
|
||||
)
|
||||
|
@ -649,7 +605,6 @@ def delete_snapshot(vm, name, key='uuid'):
|
|||
salt '*' vmadm.delete_snapshot nacl baseline key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -664,8 +619,7 @@ def delete_snapshot(vm, name, key='uuid'):
|
|||
ret['Error'] = 'VM must be of type OS'
|
||||
return ret
|
||||
# vmadm delete-snapshot <uuid> <snapname>
|
||||
cmd = '{vmadm} delete-snapshot {uuid} {snapshot}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm delete-snapshot {uuid} {snapshot}'.format(
|
||||
snapshot=name,
|
||||
uuid=vm
|
||||
)
|
||||
|
@ -699,7 +653,6 @@ def rollback_snapshot(vm, name, key='uuid'):
|
|||
salt '*' vmadm.rollback_snapshot nacl baseline key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -714,8 +667,7 @@ def rollback_snapshot(vm, name, key='uuid'):
|
|||
ret['Error'] = 'VM must be of type OS'
|
||||
return ret
|
||||
# vmadm rollback-snapshot <uuid> <snapname>
|
||||
cmd = '{vmadm} rollback-snapshot {uuid} {snapshot}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm rollback-snapshot {uuid} {snapshot}'.format(
|
||||
snapshot=name,
|
||||
uuid=vm
|
||||
)
|
||||
|
@ -746,7 +698,6 @@ def reprovision(vm, image, key='uuid'):
|
|||
salt '*' vmadm.reprovision nacl c02a2044-c1bd-11e4-bd8c-dfc1db8b0182 key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -757,8 +708,7 @@ def reprovision(vm, image, key='uuid'):
|
|||
ret['Error'] = 'Image ({0}) is not present on this host'.format(image)
|
||||
return ret
|
||||
# vmadm reprovision <uuid> [-f <filename>]
|
||||
cmd = six.text_type('echo {image} | {vmadm} reprovision {uuid}').format(
|
||||
vmadm=salt.utils.stringutils.to_unicode(vmadm),
|
||||
cmd = six.text_type('echo {image} | vmadm reprovision {uuid}').format(
|
||||
uuid=salt.utils.stringutils.to_unicode(vm),
|
||||
image=_quote_args(salt.utils.json.dumps({'image_uuid': image}))
|
||||
)
|
||||
|
@ -821,7 +771,6 @@ def update(vm, from_file=None, key='uuid', **kwargs):
|
|||
salt '*' vmadm.update vm=186da9ab-7392-4f55-91a5-b8f1fe770543 max_physical_memory=1024
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
# prepare vmcfg
|
||||
vmcfg = {}
|
||||
kwargs = salt.utils.args.clean_kwargs(**kwargs)
|
||||
|
@ -860,8 +809,6 @@ def send(vm, target, key='uuid'):
|
|||
salt '*' vmadm.send vm=nacl target=/opt/backups key=alias
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
zfs = _check_zfs()
|
||||
if key not in ['uuid', 'alias', 'hostname']:
|
||||
ret['Error'] = 'Key must be either uuid, alias or hostname'
|
||||
return ret
|
||||
|
@ -872,8 +819,7 @@ def send(vm, target, key='uuid'):
|
|||
if 'Error' in vm:
|
||||
return vm
|
||||
# vmadm send <uuid> [target]
|
||||
cmd = '{vmadm} send {uuid} > {target}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm send {uuid} > {target}'.format(
|
||||
uuid=vm,
|
||||
target=os.path.join(target, '{0}.vmdata'.format(vm))
|
||||
)
|
||||
|
@ -890,8 +836,7 @@ def send(vm, target, key='uuid'):
|
|||
for dataset in vmobj['datasets']:
|
||||
name = dataset.split('/')
|
||||
name = name[-1]
|
||||
cmd = '{zfs} send {dataset} > {target}'.format(
|
||||
zfs=zfs,
|
||||
cmd = 'zfs send {dataset} > {target}'.format(
|
||||
dataset=dataset,
|
||||
target=os.path.join(target, '{0}-{1}.zfsds'.format(vm, name))
|
||||
)
|
||||
|
@ -919,8 +864,6 @@ def receive(uuid, source):
|
|||
salt '*' vmadm.receive 186da9ab-7392-4f55-91a5-b8f1fe770543 /opt/backups
|
||||
'''
|
||||
ret = {}
|
||||
vmadm = _check_vmadm()
|
||||
zfs = _check_zfs()
|
||||
if not os.path.isdir(source):
|
||||
ret['Error'] = 'Source must be a directory or host'
|
||||
return ret
|
||||
|
@ -928,8 +871,7 @@ def receive(uuid, source):
|
|||
ret['Error'] = 'Unknow vm with uuid in {0}'.format(source)
|
||||
return ret
|
||||
# vmadm receive
|
||||
cmd = '{vmadm} receive < {source}'.format(
|
||||
vmadm=vmadm,
|
||||
cmd = 'vmadm receive < {source}'.format(
|
||||
source=os.path.join(source, '{0}.vmdata'.format(uuid))
|
||||
)
|
||||
res = __salt__['cmd.run_all'](cmd, python_shell=True)
|
||||
|
@ -945,8 +887,7 @@ def receive(uuid, source):
|
|||
for dataset in vmobj['datasets']:
|
||||
name = dataset.split('/')
|
||||
name = name[-1]
|
||||
cmd = '{zfs} receive {dataset} < {source}'.format(
|
||||
zfs=zfs,
|
||||
cmd = 'zfs receive {dataset} < {source}'.format(
|
||||
dataset=dataset,
|
||||
source=os.path.join(source, '{0}-{1}.zfsds'.format(uuid, name))
|
||||
)
|
||||
|
@ -955,10 +896,7 @@ def receive(uuid, source):
|
|||
if retcode != 0:
|
||||
ret['Error'] = res['stderr'] if 'stderr' in res else _exit_status(retcode)
|
||||
return ret
|
||||
cmd = '{vmadm} install {uuid}'.format(
|
||||
vmadm=vmadm,
|
||||
uuid=uuid
|
||||
)
|
||||
cmd = 'vmadm install {0}'.format(uuid)
|
||||
res = __salt__['cmd.run_all'](cmd, python_shell=True)
|
||||
retcode = res['retcode']
|
||||
if retcode != 0 and not res['stderr'].endswith('datasets'):
|
||||
|
|
Loading…
Add table
Reference in a new issue