mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Update kubevirt_vm with new feautures (#52311)
This commit is contained in:
parent
664e6fb9c8
commit
435e0c5dba
3 changed files with 143 additions and 32 deletions
|
@ -81,6 +81,7 @@ EXAMPLES = '''
|
|||
name: myvm
|
||||
namespace: vms
|
||||
memory: 64M
|
||||
cpu_cores: 1
|
||||
disks:
|
||||
- name: containerdisk
|
||||
volume:
|
||||
|
@ -158,6 +159,7 @@ EXAMPLES = '''
|
|||
namespace: vms
|
||||
memory: 1024M
|
||||
cloud_init_nocloud:
|
||||
#cloud-config
|
||||
userData: |-
|
||||
password: fedora
|
||||
chpasswd: { expire: False }
|
||||
|
@ -180,9 +182,9 @@ EXAMPLES = '''
|
|||
RETURN = '''
|
||||
kubevirt_vm:
|
||||
description:
|
||||
- The virtual machine dictionary specification returned by the API.
|
||||
- "This dictionary contains all values returned by the KubeVirt API all options
|
||||
are described here U(https://kubevirt.io/api-reference/master/definitions.html#_v1_virtualmachine)"
|
||||
- The virtual machine dictionary specification returned by the API.
|
||||
- "This dictionary contains all values returned by the KubeVirt API all options
|
||||
are described here U(https://kubevirt.io/api-reference/master/definitions.html#_v1_virtualmachine)"
|
||||
returned: success
|
||||
type: complex
|
||||
contains: {}
|
||||
|
@ -192,6 +194,8 @@ kubevirt_vm:
|
|||
import copy
|
||||
import traceback
|
||||
|
||||
from ansible.module_utils.k8s.common import AUTH_ARG_SPEC, COMMON_ARG_SPEC
|
||||
|
||||
try:
|
||||
from openshift.dynamic.client import ResourceInstance
|
||||
except ImportError:
|
||||
|
@ -203,10 +207,8 @@ from ansible.module_utils.kubevirt import (
|
|||
virtdict,
|
||||
KubeVirtRawModule,
|
||||
VM_COMMON_ARG_SPEC,
|
||||
API_VERSION,
|
||||
)
|
||||
|
||||
|
||||
VM_ARG_SPEC = {
|
||||
'ephemeral': {'type': 'bool', 'default': False},
|
||||
'state': {
|
||||
|
@ -224,7 +226,8 @@ class KubeVirtVM(KubeVirtRawModule):
|
|||
@property
|
||||
def argspec(self):
|
||||
""" argspec property builder """
|
||||
argument_spec = copy.deepcopy(AUTH_ARG_SPEC)
|
||||
argument_spec = copy.deepcopy(COMMON_ARG_SPEC)
|
||||
argument_spec.update(copy.deepcopy(AUTH_ARG_SPEC))
|
||||
argument_spec.update(VM_COMMON_ARG_SPEC)
|
||||
argument_spec.update(VM_ARG_SPEC)
|
||||
return argument_spec
|
||||
|
@ -234,7 +237,7 @@ class KubeVirtVM(KubeVirtRawModule):
|
|||
self.patch_resource(resource, definition, existing, self.name, self.namespace, merge_type='merge')
|
||||
|
||||
if wait:
|
||||
resource = self.find_resource('VirtualMachineInstance', self.api_version, fail=True)
|
||||
resource = self.find_supported_resource('VirtualMachineInstance')
|
||||
w, stream = self._create_stream(resource, self.namespace, wait_timeout)
|
||||
|
||||
if wait and stream is not None:
|
||||
|
@ -264,13 +267,13 @@ class KubeVirtVM(KubeVirtRawModule):
|
|||
wait_timeout = self.params.get('wait_timeout')
|
||||
resource_version = self.params.get('resource_version')
|
||||
|
||||
resource_vm = self.find_resource('VirtualMachine', self.api_version)
|
||||
resource_vm = self.find_supported_resource('VirtualMachine')
|
||||
existing = self.get_resource(resource_vm)
|
||||
if resource_version and resource_version != existing.metadata.resourceVersion:
|
||||
return False
|
||||
|
||||
existing_running = False
|
||||
resource_vmi = self.find_resource('VirtualMachineInstance', self.api_version)
|
||||
resource_vmi = self.find_supported_resource('VirtualMachineInstance')
|
||||
existing_running_vmi = self.get_resource(resource_vmi)
|
||||
if existing_running_vmi and hasattr(existing_running_vmi.status, 'phase'):
|
||||
existing_running = existing_running_vmi.status.phase == 'Running'
|
||||
|
@ -300,7 +303,8 @@ class KubeVirtVM(KubeVirtRawModule):
|
|||
# Execute the CURD of VM:
|
||||
template = definition['spec']['template']
|
||||
kind = 'VirtualMachineInstance' if ephemeral else 'VirtualMachine'
|
||||
result = self.execute_crud(kind, definition, template)
|
||||
dummy, definition = self.construct_vm_definition(kind, definition, template)
|
||||
result = self.execute_crud(kind, definition)
|
||||
changed = result['changed']
|
||||
|
||||
# Manage state of the VM:
|
||||
|
@ -320,7 +324,6 @@ class KubeVirtVM(KubeVirtRawModule):
|
|||
def main():
|
||||
module = KubeVirtVM()
|
||||
try:
|
||||
module.api_version = API_VERSION
|
||||
module.execute_module()
|
||||
except Exception as e:
|
||||
module.fail_json(msg=str(e), exception=traceback.format_exc())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue