mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge pull request #28927 from sjorge/state-smartos-fixes
fix broken smartos state
This commit is contained in:
commit
e3f5e28d67
@ -2,27 +2,74 @@
|
|||||||
'''
|
'''
|
||||||
Management of SmartOS Standalone Compute Nodes
|
Management of SmartOS Standalone Compute Nodes
|
||||||
|
|
||||||
|
:maintainer: Jorge Schrauwen <sjorge@blackdot.be>
|
||||||
|
:maturity: new
|
||||||
|
:depends: vmadm, imgadm
|
||||||
|
:platform: smartos
|
||||||
|
|
||||||
|
.. versionadded:: Boron
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
test.example.org:
|
vmtest.example.org:
|
||||||
|
smartos.vm_present:
|
||||||
|
- config:
|
||||||
|
reprovision: true
|
||||||
|
- vmconfig:
|
||||||
|
image_uuid: c02a2044-c1bd-11e4-bd8c-dfc1db8b0182
|
||||||
|
brand: joyent
|
||||||
|
alias: vmtest
|
||||||
|
quota: 5
|
||||||
|
max_physical_memory: 512
|
||||||
|
tags:
|
||||||
|
label: 'test vm'
|
||||||
|
owner: 'sjorge'
|
||||||
|
nics:
|
||||||
|
"82:1b:8e:49:e9:12"
|
||||||
|
nic_tag: trunk
|
||||||
|
mtu: 1500
|
||||||
|
ips:
|
||||||
|
- 172.16.1.123/16
|
||||||
|
- 192.168.2.123/24
|
||||||
|
vlan_id: 10
|
||||||
|
"82:1b:8e:49:e9:13"
|
||||||
|
nic_tag: trunk
|
||||||
|
mtu: 1500
|
||||||
|
ips:
|
||||||
|
- dhcp
|
||||||
|
vlan_id: 30
|
||||||
|
filesystems:
|
||||||
|
"/bigdata":
|
||||||
|
source: "/bulk/data"
|
||||||
|
type: lofs
|
||||||
|
options:
|
||||||
|
- ro
|
||||||
|
- nodevices
|
||||||
|
|
||||||
|
kvmtest.example.org:
|
||||||
smartos.vm_present:
|
smartos.vm_present:
|
||||||
- vmconfig:
|
- vmconfig:
|
||||||
- image_uuid: c02a2044-c1bd-11e4-bd8c-dfc1db8b0182
|
brand: kvm
|
||||||
- brand: joyent
|
alias: kvmtest
|
||||||
- alias: test
|
cpu_type: host
|
||||||
- quota: 5
|
ram: 512
|
||||||
- max_physical_memory: 512
|
vnc_port: 9
|
||||||
- nics:
|
tags:
|
||||||
- "82:1b:8e:49:e9:12"
|
label: 'test kvm'
|
||||||
- nic_tag: trunk
|
owner: 'sjorge'
|
||||||
- mtu: 1500
|
disks:
|
||||||
- ips: [ "dhcp" ]
|
disk0
|
||||||
- vlan_id: 10
|
size: 2048
|
||||||
- "82:1b:8e:49:e9:13"
|
model: virtio
|
||||||
- nic_tag: trunk
|
compression: lz4
|
||||||
- mtu: 1500
|
boot: true
|
||||||
- ips: [ "dhcp" ]
|
nics:
|
||||||
- vlan_id: 30
|
"82:1b:8e:49:e9:15"
|
||||||
|
nic_tag: trunk
|
||||||
|
mtu: 1500
|
||||||
|
ips:
|
||||||
|
- dhcp
|
||||||
|
vlan_id: 30
|
||||||
|
|
||||||
cleanup_images:
|
cleanup_images:
|
||||||
smartos.image_vacuum
|
smartos.image_vacuum
|
||||||
@ -105,49 +152,23 @@ def _write_config(config):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _parse_state_config(config, default_config):
|
|
||||||
'''
|
|
||||||
Parse vm_present state config
|
|
||||||
'''
|
|
||||||
for cfg_item in config if config else []:
|
|
||||||
for k in cfg_item:
|
|
||||||
if k in default_config:
|
|
||||||
if isinstance(cfg_item[k], (bool)):
|
|
||||||
default_config[k] = cfg_item[k]
|
|
||||||
else:
|
|
||||||
log.warning('smartos.vm_present::config - property {0} must be bool, using default: {1}'.format(k, default_config[k]))
|
|
||||||
else:
|
|
||||||
log.warning('smartos.vm_present::config - property {0} not one of {1}'.format(k, default_config.keys()))
|
|
||||||
|
|
||||||
return default_config
|
|
||||||
|
|
||||||
|
|
||||||
def _parse_vmconfig(config, instances):
|
def _parse_vmconfig(config, instances):
|
||||||
'''
|
'''
|
||||||
Parse vm_present vm config
|
Parse vm_present vm config
|
||||||
'''
|
'''
|
||||||
vmconfig = None
|
vmconfig = None
|
||||||
|
|
||||||
if isinstance(config, (list)):
|
if isinstance(config, (salt.utils.odict.OrderedDict)):
|
||||||
for prop in config:
|
vmconfig = OrderedDict()
|
||||||
# property
|
for prop in config.keys():
|
||||||
if len(prop) == 1 and isinstance(prop, (salt.utils.odict.OrderedDict)):
|
if prop not in instances:
|
||||||
if not vmconfig:
|
vmconfig[prop] = config[prop]
|
||||||
vmconfig = {}
|
else:
|
||||||
for k in prop:
|
vmconfig[prop] = []
|
||||||
if isinstance(prop[k], (list)):
|
for instance in config[prop]:
|
||||||
if k not in instances:
|
instance_config = config[prop][instance]
|
||||||
continue
|
instance_config[instances[prop]] = instance
|
||||||
if k not in vmconfig:
|
vmconfig[prop].append(instance_config)
|
||||||
vmconfig[k] = []
|
|
||||||
for instance in prop[k]:
|
|
||||||
instance_key = instance.keys()[0]
|
|
||||||
instance = _parse_vmconfig(instance[instance_key], instances)
|
|
||||||
if instances[k] not in instance:
|
|
||||||
instance[instances[k]] = instance_key
|
|
||||||
vmconfig[k].append(instance)
|
|
||||||
else:
|
|
||||||
vmconfig[k] = prop[k]
|
|
||||||
else:
|
else:
|
||||||
log.error('smartos.vm_present::parse_vmconfig - failed to parse')
|
log.error('smartos.vm_present::parse_vmconfig - failed to parse')
|
||||||
|
|
||||||
@ -425,15 +446,14 @@ def vm_present(name, vmconfig, config=None):
|
|||||||
'result': None,
|
'result': None,
|
||||||
'comment': ''}
|
'comment': ''}
|
||||||
|
|
||||||
# parse config
|
# config defaults
|
||||||
config = _parse_state_config(
|
state_config = config if config else {}
|
||||||
config,
|
config = {
|
||||||
{
|
'kvm_reboot': True,
|
||||||
'kvm_reboot': True,
|
'auto_import': False,
|
||||||
'auto_import': False,
|
'reprovision': False
|
||||||
'reprovision': False
|
}
|
||||||
}
|
config.update(state_config)
|
||||||
)
|
|
||||||
log.debug('smartos.vm_present::{0}::config - {1}'.format(name, config))
|
log.debug('smartos.vm_present::{0}::config - {1}'.format(name, config))
|
||||||
|
|
||||||
# map special vmconfig parameters
|
# map special vmconfig parameters
|
||||||
@ -464,23 +484,6 @@ def vm_present(name, vmconfig, config=None):
|
|||||||
if 'hostname' not in vmconfig:
|
if 'hostname' not in vmconfig:
|
||||||
vmconfig['hostname'] = name
|
vmconfig['hostname'] = name
|
||||||
|
|
||||||
# ensure instances have ids
|
|
||||||
for instance_type in vmconfig_type['instance']:
|
|
||||||
# skip if instance type not in vmconfig
|
|
||||||
if instance_type not in vmconfig:
|
|
||||||
continue
|
|
||||||
# ensure we have unique id
|
|
||||||
for instance in vmconfig[instance_type]:
|
|
||||||
# skip if we have the id
|
|
||||||
if vmconfig_type['instance'][instance_type] in instance:
|
|
||||||
continue
|
|
||||||
ret['result'] = False
|
|
||||||
ret['comment'] = 'one or more {0} is missing unique id {1}'.format(
|
|
||||||
instance_type,
|
|
||||||
vmconfig_type['instance'][instance_type]
|
|
||||||
)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
# check if vm exists
|
# check if vm exists
|
||||||
if vmconfig['hostname'] in __salt__['vmadm.list'](order='hostname'):
|
if vmconfig['hostname'] in __salt__['vmadm.list'](order='hostname'):
|
||||||
# update vm
|
# update vm
|
||||||
@ -602,6 +605,10 @@ def vm_present(name, vmconfig, config=None):
|
|||||||
|
|
||||||
# handle new properties
|
# handle new properties
|
||||||
for prop in state_cfg:
|
for prop in state_cfg:
|
||||||
|
# skip empty props like ips, options,..
|
||||||
|
if isinstance(state_cfg[prop], (list)) and len(state_cfg[prop]) == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
if prop not in current_cfg:
|
if prop not in current_cfg:
|
||||||
update_cfg[prop] = state_cfg[prop]
|
update_cfg[prop] = state_cfg[prop]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user