mirror of
https://github.com/kubevirt/kubevirt.core.git
synced 2026-03-26 19:03:16 +00:00
Merge pull request #3 from 0xFelix/vm-template-spec
kubevirt_vm: Allow to specify template spec
This commit is contained in:
8
examples/play-create-min.yml
Normal file
8
examples/play-create-min.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
- hosts: localhost
|
||||
tasks:
|
||||
- name: Create VM
|
||||
kubernetes.kubevirt.kubevirt_vm:
|
||||
state: present
|
||||
name: testvm
|
||||
namespace: default
|
||||
running: no
|
||||
@@ -11,26 +11,29 @@
|
||||
name: u1.medium
|
||||
preference:
|
||||
name: fedora
|
||||
interfaces:
|
||||
- name: default
|
||||
masquerade: {}
|
||||
- name: bridge-network
|
||||
bridge: {}
|
||||
networks:
|
||||
- name: default
|
||||
pod: {}
|
||||
- name: bridge-network
|
||||
multus:
|
||||
networkName: kindexgw
|
||||
volumes:
|
||||
- containerDisk:
|
||||
image: quay.io/containerdisks/fedora:latest
|
||||
name: containerdisk
|
||||
- cloudInitNoCloud:
|
||||
userData: |-
|
||||
#cloud-config
|
||||
# The default username is: fedora
|
||||
ssh_authorized_keys:
|
||||
- ssh-ed25519 AAAA...
|
||||
name: cloudinit
|
||||
spec:
|
||||
domain:
|
||||
devices:
|
||||
interfaces:
|
||||
- name: default
|
||||
masquerade: {}
|
||||
- name: bridge-network
|
||||
bridge: {}
|
||||
networks:
|
||||
- name: default
|
||||
pod: {}
|
||||
- name: bridge-network
|
||||
multus:
|
||||
networkName: kindexgw
|
||||
volumes:
|
||||
- containerDisk:
|
||||
image: quay.io/containerdisks/fedora:latest
|
||||
name: containerdisk
|
||||
- cloudInitNoCloud:
|
||||
userData: |-
|
||||
#cloud-config
|
||||
# The default username is: fedora
|
||||
ssh_authorized_keys:
|
||||
- ssh-ed25519 AAAA...
|
||||
name: cloudinit
|
||||
wait: yes
|
||||
|
||||
@@ -65,12 +65,6 @@ options:
|
||||
- Specify whether the VirtualMachine should be running.
|
||||
type: bool
|
||||
default: yes
|
||||
termination_grace_period:
|
||||
description:
|
||||
- Specify the termination grace period of the VirtualMachine to provide
|
||||
time for shutting down the guest.
|
||||
type: int
|
||||
default: 180
|
||||
instancetype:
|
||||
description:
|
||||
- Specify the instancetype matcher of the VirtualMachine.
|
||||
@@ -81,24 +75,11 @@ options:
|
||||
- Specify the preference matcher of the VirtualMachine.
|
||||
- Only used when I(state=present).
|
||||
type: dict
|
||||
interfaces:
|
||||
spec:
|
||||
description:
|
||||
- Specify the interfaces of the VirtualMachine.
|
||||
- 'See: https://kubevirt.io/api-reference/main/definitions.html#_v1_interface'
|
||||
type: list
|
||||
elements: 'dict'
|
||||
networks:
|
||||
description:
|
||||
- Specify the networks of the VirtualMachine.
|
||||
- 'See: https://kubevirt.io/api-reference/main/definitions.html#_v1_network'
|
||||
type: list
|
||||
elements: 'dict'
|
||||
volumes:
|
||||
description:
|
||||
- Specify the volumes of the VirtualMachine.
|
||||
- 'See: https://kubevirt.io/api-reference/main/definitions.html#_v1_volume'
|
||||
type: list
|
||||
elements: 'dict'
|
||||
- Specify the template spec of the VirtualMachine.
|
||||
- 'See: http://kubevirt.io/api-reference/v1.0.0/definitions.html#_v1_virtualmachineinstancespec'
|
||||
type: dict
|
||||
wait:
|
||||
description:
|
||||
- Whether to wait for the VirtualMachine to end up in the ready state.
|
||||
@@ -137,28 +118,31 @@ EXAMPLES = """
|
||||
name: u1.medium
|
||||
preference:
|
||||
name: fedora
|
||||
interfaces:
|
||||
- name: default
|
||||
masquerade: {}
|
||||
- name: bridge-network
|
||||
bridge: {}
|
||||
networks:
|
||||
- name: default
|
||||
pod: {}
|
||||
- name: bridge-network
|
||||
multus:
|
||||
networkName: kindexgw
|
||||
volumes:
|
||||
- containerDisk:
|
||||
image: quay.io/containerdisks/fedora:latest
|
||||
name: containerdisk
|
||||
- cloudInitNoCloud:
|
||||
userData: |-
|
||||
#cloud-config
|
||||
# The default username is: fedora
|
||||
ssh_authorized_keys:
|
||||
- ssh-ed25519 AAAA...
|
||||
name: cloudinit
|
||||
spec:
|
||||
domain:
|
||||
devices:
|
||||
interfaces:
|
||||
- name: default
|
||||
masquerade: {}
|
||||
- name: bridge-network
|
||||
bridge: {}
|
||||
networks:
|
||||
- name: default
|
||||
pod: {}
|
||||
- name: bridge-network
|
||||
multus:
|
||||
networkName: kindexgw
|
||||
volumes:
|
||||
- containerDisk:
|
||||
image: quay.io/containerdisks/fedora:latest
|
||||
name: containerdisk
|
||||
- cloudInitNoCloud:
|
||||
userData: |-
|
||||
#cloud-config
|
||||
# The default username is: fedora
|
||||
ssh_authorized_keys:
|
||||
- ssh-ed25519 AAAA...
|
||||
name: cloudinit
|
||||
|
||||
- name: Delete a VirtualMachine
|
||||
kubernetes.kubevirt.kubevirt_vm:
|
||||
@@ -250,6 +234,7 @@ metadata:
|
||||
{{ labels | to_yaml | indent(4) }}
|
||||
{%- endif %}
|
||||
spec:
|
||||
running: {{ running }}
|
||||
{% if instancetype %}
|
||||
instancetype:
|
||||
{{ instancetype | to_yaml | indent(4) }}
|
||||
@@ -258,7 +243,6 @@ spec:
|
||||
preference:
|
||||
{{ preference | to_yaml | indent(4) }}
|
||||
{% endif %}
|
||||
running: {{ running }}
|
||||
template:
|
||||
{% if annotations or labels %}
|
||||
metadata:
|
||||
@@ -272,23 +256,12 @@ spec:
|
||||
{%- endif %}
|
||||
{% endif %}
|
||||
spec:
|
||||
{% if spec %}
|
||||
{{ spec | to_yaml | indent (6) }}
|
||||
{%- else %}
|
||||
domain:
|
||||
{% if interfaces %}
|
||||
devices:
|
||||
interfaces:
|
||||
{{ interfaces | to_yaml | indent(10) }}
|
||||
{%- else %}
|
||||
devices: {}
|
||||
{% endif %}
|
||||
{% if networks %}
|
||||
networks:
|
||||
{{ networks | to_yaml | indent(6) }}
|
||||
{%- endif %}
|
||||
{% if volumes %}
|
||||
volumes:
|
||||
{{ volumes | to_yaml | indent(6) }}
|
||||
{%- endif %}
|
||||
terminationGracePeriodSeconds: {{ termination_grace_period }}
|
||||
{% endif %}
|
||||
"""
|
||||
|
||||
|
||||
@@ -317,12 +290,9 @@ def arg_spec() -> Dict:
|
||||
"annotations": {"type": "dict"},
|
||||
"labels": {"type": "dict"},
|
||||
"running": {"type": "bool", "default": True},
|
||||
"termination_grace_period": {"type": "int", "default": 180},
|
||||
"instancetype": {"type": "dict"},
|
||||
"preference": {"type": "dict"},
|
||||
"interfaces": {"type": "list", "elements": "dict"},
|
||||
"networks": {"type": "list", "elements": "dict"},
|
||||
"volumes": {"type": "list", "elements": "dict"},
|
||||
"spec": {"type": "dict"},
|
||||
"wait": {"type": "bool", "default": False},
|
||||
"wait_sleep": {"type": "int", "default": 5},
|
||||
"wait_timeout": {"type": "int", "default": 120},
|
||||
@@ -352,7 +322,6 @@ def main() -> None:
|
||||
required_one_of=[
|
||||
("name", "generate_name"),
|
||||
],
|
||||
required_together=[("interfaces", "networks")],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
|
||||
@@ -70,7 +70,8 @@ spec:
|
||||
spec:
|
||||
domain:
|
||||
devices: {}
|
||||
terminationGracePeriodSeconds: 180'''
|
||||
terminationGracePeriodSeconds: 180
|
||||
'''
|
||||
|
||||
FIXTURE2 = {
|
||||
'name': 'testvm',
|
||||
@@ -80,11 +81,17 @@ FIXTURE2 = {
|
||||
'service': 'loadbalancer',
|
||||
'environment': 'staging'
|
||||
},
|
||||
'api_version': 'kubevirt.io/v1', 'running': True, 'termination_grace_period': 180, 'wait': False, 'wait_sleep': 5, 'wait_timeout': 120, 'force': False,
|
||||
'generate_name': None, 'annotations': None, 'instancetype': None, 'preference': None, 'interfaces': None, 'networks': None, 'volumes': None,
|
||||
'kubeconfig': None, 'context': None, 'host': None, 'api_key': None, 'username': None, 'password': None, 'validate_certs': None, 'ca_cert': None,
|
||||
'client_cert': None, 'client_key': None, 'proxy': None, 'no_proxy': None, 'proxy_headers': None, 'persist_config': None, 'impersonate_user': None,
|
||||
'impersonate_groups': None, 'delete_options': None,
|
||||
'spec': {
|
||||
'domain': {
|
||||
'devices': {}
|
||||
},
|
||||
'terminationGracePeriodSeconds': 180
|
||||
},
|
||||
'api_version': 'kubevirt.io/v1', 'running': True, 'wait': False, 'wait_sleep': 5, 'wait_timeout': 120, 'force': False,
|
||||
'generate_name': None, 'annotations': None, 'instancetype': None, 'preference': None,
|
||||
'kubeconfig': None, 'context': None, 'host': None, 'api_key': None, 'username': None, 'password': None, 'validate_certs': None,
|
||||
'ca_cert': None, 'client_cert': None, 'client_key': None, 'proxy': None, 'no_proxy': None, 'proxy_headers': None,
|
||||
'persist_config': None, 'impersonate_user': None, 'impersonate_groups': None, 'delete_options': None,
|
||||
'resource_definition': METADATA,
|
||||
'wait_condition': {
|
||||
'type': 'Ready',
|
||||
@@ -127,6 +134,12 @@ class TestCreateVM(unittest.TestCase):
|
||||
"labels": {
|
||||
"service": "loadbalancer",
|
||||
"environment": "staging"
|
||||
},
|
||||
'spec': {
|
||||
'domain': {
|
||||
'devices': {}
|
||||
},
|
||||
'terminationGracePeriodSeconds': 180
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user