Clean up scheduling code
This commit is contained in:
parent
47827208f9
commit
0087d22295
@ -15,18 +15,19 @@ class ActionModule(ActionBase):
|
|||||||
"""
|
"""
|
||||||
Schedule specifications of VMs by flavour onto hypervisors.
|
Schedule specifications of VMs by flavour onto hypervisors.
|
||||||
|
|
||||||
:param hypervisor_vars: A dict of hostvars for each hypervisor, keyed
|
The following task vars are accepted:
|
||||||
by hypervisor hostname.
|
:hypervisor_vars: A dict of hostvars for each hypervisor, keyed
|
||||||
:param specs: A dict mapping flavour names to the number of VMs
|
by hypervisor hostname. Required.
|
||||||
required of that flavour.
|
:specs: A dict mapping flavour names to the number of VMs
|
||||||
:param flavours: A dict mapping flavour names to a dict of properties
|
required of that flavour. Required.
|
||||||
of that flavour.
|
:flavours: A dict mapping flavour names to a dict of properties
|
||||||
:param vm_name_prefix: A string with with to prefix all sequential VM
|
of that flavour.
|
||||||
names.
|
:vm_name_prefix: A string with with to prefix all sequential VM
|
||||||
|
names.
|
||||||
|
:vol_name_prefix: A string with with to prefix all sequential
|
||||||
|
volume names.
|
||||||
:returns: A dict containing lists of VM details, keyed by the
|
:returns: A dict containing lists of VM details, keyed by the
|
||||||
hostname of the hypervisor to which they are scheduled.
|
hostname of the hypervisor to which they are scheduled.
|
||||||
:raises: AnsibleError if insufficient hypervisors exist to host the
|
|
||||||
requested VMs.
|
|
||||||
"""
|
"""
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
result = super(ActionModule, self).run(tmp, task_vars)
|
||||||
del tmp # tmp no longer has any effect
|
del tmp # tmp no longer has any effect
|
||||||
@ -37,8 +38,11 @@ class ActionModule(ActionBase):
|
|||||||
for flav, cnt in iteritems(task_vars['specs']):
|
for flav, cnt in iteritems(task_vars['specs']):
|
||||||
for _ in xrange(cnt):
|
for _ in xrange(cnt):
|
||||||
vm = deepcopy(task_vars['flavours'][flav])
|
vm = deepcopy(task_vars['flavours'][flav])
|
||||||
# Sequentially number the VM names.
|
# Sequentially number the VM and volume names.
|
||||||
vm['name'] = "%s%d" % (task_vars['vm_name_prefix'], idx)
|
vm['name'] = "%s%d" % (task_vars['vm_name_prefix'], idx)
|
||||||
|
for vol_idx, vol in enumerate(vm['volumes']):
|
||||||
|
vol['name'] = "%s%d" % (task_vars['vol_name_prefix'],
|
||||||
|
vol_idx)
|
||||||
vms.append(vm)
|
vms.append(vm)
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
@ -53,7 +57,11 @@ class ActionModule(ActionBase):
|
|||||||
task_vars = {}
|
task_vars = {}
|
||||||
|
|
||||||
REQUIRED_TASK_VARS = {'hypervisor_vars', 'specs', 'flavours'}
|
REQUIRED_TASK_VARS = {'hypervisor_vars', 'specs', 'flavours'}
|
||||||
OPTIONAL_TASK_VARS = {('vm_name_prefix', 'vm')}
|
# Var names and their defaults.
|
||||||
|
OPTIONAL_TASK_VARS = {
|
||||||
|
('vm_name_prefix', 'vm'),
|
||||||
|
('vol_name_prefix', 'vol'),
|
||||||
|
}
|
||||||
for var in REQUIRED_TASK_VARS:
|
for var in REQUIRED_TASK_VARS:
|
||||||
if var not in task_vars:
|
if var not in task_vars:
|
||||||
e = "The parameter '%s' must be specified." % var
|
e = "The parameter '%s' must be specified." % var
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
set_fact:
|
set_fact:
|
||||||
hypervisor_vars: >
|
hypervisor_vars: >
|
||||||
{{ hypervisor_vars | default({}) | combine({item: hostvars[item]}) }}
|
{{ hypervisor_vars | default({}) | combine({item: hostvars[item]}) }}
|
||||||
with_items: "{{ groups['controllers'] }}"
|
loop: "{{ groups['controllers'] }}"
|
||||||
|
|
||||||
- name: Schedule VMs to hypervisors
|
- name: Schedule VMs to hypervisors
|
||||||
tenks_schedule:
|
tenks_schedule:
|
||||||
@ -26,4 +26,4 @@
|
|||||||
# tenks_schedule lookup plugin outputs a dict. Pretty-print this to persist
|
# tenks_schedule lookup plugin outputs a dict. Pretty-print this to persist
|
||||||
# it in a YAML file.
|
# it in a YAML file.
|
||||||
content: "{{ allocations.result | to_nice_yaml }}"
|
content: "{{ allocations.result | to_nice_yaml }}"
|
||||||
dest: "{{ base_path }}/allocations.yml"
|
dest: "{{ allocations_file_path }}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user