|
|
@ -62,6 +62,14 @@ options:
|
|
|
|
launch flow. Without using a DataVolume, users have to prepare a pvc with a disk image before assigning
|
|
|
|
launch flow. Without using a DataVolume, users have to prepare a pvc with a disk image before assigning
|
|
|
|
it to a VM or VMI manifest. With a DataVolume, both the pvc creation and import is automated on behalf of the user."
|
|
|
|
it to a VM or VMI manifest. With a DataVolume, both the pvc creation and import is automated on behalf of the user."
|
|
|
|
type: list
|
|
|
|
type: list
|
|
|
|
|
|
|
|
template:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- "Template to used to create a virtual machine."
|
|
|
|
|
|
|
|
type: str
|
|
|
|
|
|
|
|
parameters:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- "Value of parameters to be replaced in template parameters."
|
|
|
|
|
|
|
|
type: dict
|
|
|
|
|
|
|
|
|
|
|
|
extends_documentation_fragment:
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- k8s_auth_options
|
|
|
|
- k8s_auth_options
|
|
|
@ -234,6 +242,8 @@ VM_ARG_SPEC = {
|
|
|
|
'default': 'present'
|
|
|
|
'default': 'present'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'datavolumes': {'type': 'list'},
|
|
|
|
'datavolumes': {'type': 'list'},
|
|
|
|
|
|
|
|
'template': {'type': 'str'},
|
|
|
|
|
|
|
|
'parameters': {'type': 'dict'},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -308,6 +318,7 @@ class KubeVirtVM(KubeVirtRawModule):
|
|
|
|
|
|
|
|
|
|
|
|
def execute_module(self):
|
|
|
|
def execute_module(self):
|
|
|
|
# Parse parameters specific for this module:
|
|
|
|
# Parse parameters specific for this module:
|
|
|
|
|
|
|
|
self.client = self.get_api_client()
|
|
|
|
definition = virtdict()
|
|
|
|
definition = virtdict()
|
|
|
|
ephemeral = self.params.get('ephemeral')
|
|
|
|
ephemeral = self.params.get('ephemeral')
|
|
|
|
state = self.params.get('state')
|
|
|
|
state = self.params.get('state')
|
|
|
@ -315,10 +326,31 @@ class KubeVirtVM(KubeVirtRawModule):
|
|
|
|
if not ephemeral:
|
|
|
|
if not ephemeral:
|
|
|
|
definition['spec']['running'] = state == 'running'
|
|
|
|
definition['spec']['running'] = state == 'running'
|
|
|
|
|
|
|
|
|
|
|
|
# Execute the CURD of VM:
|
|
|
|
# Construct the API object definition:
|
|
|
|
|
|
|
|
vm_template = self.params.get('template')
|
|
|
|
|
|
|
|
processedtemplate = {}
|
|
|
|
|
|
|
|
if vm_template:
|
|
|
|
|
|
|
|
# Find the template the VM should be created from:
|
|
|
|
|
|
|
|
template_resource = self.client.resources.get(api_version='template.openshift.io/v1', kind='Template', name='templates')
|
|
|
|
|
|
|
|
proccess_template = template_resource.get(name=vm_template, namespace=self.params.get('namespace'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set proper template values set by Ansible parameter 'parameters':
|
|
|
|
|
|
|
|
for k, v in self.params.get('parameters', {}).items():
|
|
|
|
|
|
|
|
for parameter in proccess_template.parameters:
|
|
|
|
|
|
|
|
if parameter.name == k:
|
|
|
|
|
|
|
|
parameter.value = v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Proccess the template:
|
|
|
|
|
|
|
|
processedtemplates_res = self.client.resources.get(api_version='template.openshift.io/v1', kind='Template', name='processedtemplates')
|
|
|
|
|
|
|
|
processedtemplate = processedtemplates_res.create(proccess_template.to_dict()).to_dict()['objects'][0]
|
|
|
|
|
|
|
|
|
|
|
|
template = definition if ephemeral else definition['spec']['template']
|
|
|
|
template = definition if ephemeral else definition['spec']['template']
|
|
|
|
kind = 'VirtualMachineInstance' if ephemeral else 'VirtualMachine'
|
|
|
|
kind = 'VirtualMachineInstance' if ephemeral else 'VirtualMachine'
|
|
|
|
|
|
|
|
template['labels']['vm.cnv.io/name'] = self.params.get('name')
|
|
|
|
dummy, definition = self.construct_vm_definition(kind, definition, template)
|
|
|
|
dummy, definition = self.construct_vm_definition(kind, definition, template)
|
|
|
|
|
|
|
|
definition = dict(self.merge_dicts(processedtemplate, definition))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create the VM:
|
|
|
|
result = self.execute_crud(kind, definition)
|
|
|
|
result = self.execute_crud(kind, definition)
|
|
|
|
changed = result['changed']
|
|
|
|
changed = result['changed']
|
|
|
|
|
|
|
|
|
|
|
|