mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
kubevirt: Simplify VM parameters (#53340)
This commit is contained in:
parent
a4b2ce5e13
commit
272fa9ead4
3 changed files with 115 additions and 1 deletions
|
@ -42,12 +42,22 @@ VM_COMMON_ARG_SPEC = {
|
|||
'wait': {'type': 'bool', 'default': True},
|
||||
'wait_timeout': {'type': 'int', 'default': 120},
|
||||
'memory': {'type': 'str'},
|
||||
'memory_limit': {'type': 'str'},
|
||||
'cpu_cores': {'type': 'int'},
|
||||
'disks': {'type': 'list'},
|
||||
'labels': {'type': 'dict'},
|
||||
'interfaces': {'type': 'list'},
|
||||
'machine_type': {'type': 'str'},
|
||||
'cloud_init_nocloud': {'type': 'dict'},
|
||||
'bootloader': {'type': 'str'},
|
||||
'smbios_uuid': {'type': 'str'},
|
||||
'cpu_model': {'type': 'str'},
|
||||
'headless': {'type': 'str'},
|
||||
'hugepage_size': {'type': 'str'},
|
||||
'tablets': {'type': 'list'},
|
||||
'cpu_limit': {'type': 'int'},
|
||||
'cpu_shares': {'type': 'int'},
|
||||
'cpu_features': {'type': 'list'},
|
||||
}
|
||||
|
||||
|
||||
|
@ -283,27 +293,69 @@ class KubeVirtRawModule(KubernetesRawModule):
|
|||
|
||||
disks = params.get('disks', [])
|
||||
memory = params.get('memory')
|
||||
memory_limit = params.get('memory_limit')
|
||||
cpu_cores = params.get('cpu_cores')
|
||||
cpu_model = params.get('cpu_model')
|
||||
cpu_features = params.get('cpu_features')
|
||||
labels = params.get('labels')
|
||||
datavolumes = params.get('datavolumes')
|
||||
interfaces = params.get('interfaces')
|
||||
bootloader = params.get('bootloader')
|
||||
cloud_init_nocloud = params.get('cloud_init_nocloud')
|
||||
machine_type = params.get('machine_type')
|
||||
headless = params.get('headless')
|
||||
smbios_uuid = params.get('smbios_uuid')
|
||||
hugepage_size = params.get('hugepage_size')
|
||||
tablets = params.get('tablets')
|
||||
cpu_shares = params.get('cpu_shares')
|
||||
cpu_limit = params.get('cpu_limit')
|
||||
template_spec = template['spec']
|
||||
|
||||
# Merge additional flat parameters:
|
||||
if memory:
|
||||
template_spec['domain']['resources']['requests']['memory'] = memory
|
||||
|
||||
if cpu_shares:
|
||||
template_spec['domain']['resources']['requests']['cpu'] = cpu_shares
|
||||
|
||||
if cpu_limit:
|
||||
template_spec['domain']['resources']['limits']['cpu'] = cpu_limit
|
||||
|
||||
if tablets:
|
||||
for tablet in tablets:
|
||||
tablet['type'] = 'tablet'
|
||||
template_spec['domain']['devices']['inputs'] = tablets
|
||||
|
||||
if memory_limit:
|
||||
template_spec['domain']['resources']['limits']['memory'] = memory_limit
|
||||
|
||||
if hugepage_size is not None:
|
||||
template_spec['domain']['memory']['hugepages']['pageSize'] = hugepage_size
|
||||
|
||||
if cpu_features is not None:
|
||||
template_spec['domain']['cpu']['features'] = cpu_features
|
||||
|
||||
if cpu_cores is not None:
|
||||
template_spec['domain']['cpu']['cores'] = cpu_cores
|
||||
|
||||
if cpu_model:
|
||||
template_spec['domain']['cpu']['model'] = cpu_model
|
||||
|
||||
if labels:
|
||||
template['metadata']['labels'] = labels
|
||||
|
||||
if machine_type:
|
||||
template_spec['domain']['machine']['type'] = machine_type
|
||||
|
||||
if bootloader:
|
||||
template_spec['domain']['firmware']['bootloader'] = {bootloader: {}}
|
||||
|
||||
if smbios_uuid:
|
||||
template_spec['domain']['firmware']['uuid'] = smbios_uuid
|
||||
|
||||
if headless is not None:
|
||||
template_spec['domain']['devices']['autoattachGraphicsDevice'] = not headless
|
||||
|
||||
# Define disks
|
||||
self._define_disks(disks, template_spec)
|
||||
|
||||
|
|
|
@ -86,8 +86,18 @@ EXAMPLES = '''
|
|||
state: running
|
||||
name: myvm
|
||||
namespace: vms
|
||||
memory: 64M
|
||||
memory: 64Mi
|
||||
cpu_cores: 1
|
||||
bootloader: efi
|
||||
smbios_uuid: 5d307ca9-b3ef-428c-8861-06e72d69f223
|
||||
cpu_model: Conroe
|
||||
headless: true
|
||||
hugepage_size: 2Mi
|
||||
tablets:
|
||||
- bus: virtio
|
||||
name: tablet1
|
||||
cpu_limit: 3
|
||||
cpu_shares: 2
|
||||
disks:
|
||||
- name: containerdisk
|
||||
volume:
|
||||
|
|
|
@ -43,6 +43,11 @@ options:
|
|||
- The amount of memory to be requested by virtual machine.
|
||||
- For example 1024Mi.
|
||||
type: str
|
||||
memory_limit:
|
||||
description:
|
||||
- The maximum memory to be used by virtual machine.
|
||||
- For example 1024Mi.
|
||||
type: str
|
||||
machine_type:
|
||||
description:
|
||||
- QEMU machine type is the actual chipset of the virtual machine.
|
||||
|
@ -61,9 +66,56 @@ options:
|
|||
is simply C(strategic-merge).
|
||||
type: list
|
||||
choices: [ json, merge, strategic-merge ]
|
||||
cpu_shares:
|
||||
description:
|
||||
- "Specify CPU shares."
|
||||
type: int
|
||||
cpu_limit:
|
||||
description:
|
||||
- "Is converted to its millicore value and multiplied by 100. The resulting value is the total amount of CPU time that a container can use
|
||||
every 100ms. A virtual machine cannot use more than its share of CPU time during this interval."
|
||||
type: int
|
||||
cpu_cores:
|
||||
description:
|
||||
- "Number of CPU cores."
|
||||
type: int
|
||||
cpu_model:
|
||||
description:
|
||||
- "CPU model."
|
||||
- "You can check list of available models here: U(https://github.com/libvirt/libvirt/blob/master/src/cpu_map/index.xml)."
|
||||
- "I(Note:) User can define default CPU model via as I(default-cpu-model) in I(kubevirt-config) I(ConfigMap), if not set I(host-model) is used."
|
||||
- "I(Note:) Be sure that node CPU model where you run a VM, has the same or higher CPU family."
|
||||
- "I(Note:) If CPU model wasn't defined, the VM will have CPU model closest to one that used on the node where the VM is running."
|
||||
type: str
|
||||
bootloader:
|
||||
description:
|
||||
- "Specify the bootloader of the virtual machine."
|
||||
- "All virtual machines use BIOS by default for booting."
|
||||
type: str
|
||||
smbios_uuid:
|
||||
description:
|
||||
- "In order to provide a consistent view on the virtualized hardware for the guest OS, the SMBIOS UUID can be set."
|
||||
type: str
|
||||
cpu_features:
|
||||
description:
|
||||
- "List of dictionary to fine-tune features provided by the selected CPU model."
|
||||
- "I(Note): Policy attribute can either be omitted or contain one of the following policies: force, require, optional, disable, forbid."
|
||||
- "I(Note): In case a policy is omitted for a feature, it will default to require."
|
||||
- "More information about policies: U(https://libvirt.org/formatdomain.html#elementsCPU)"
|
||||
type: list
|
||||
headless:
|
||||
description:
|
||||
- "Specify if the virtual machine should have attached a minimal Video and Graphics device configuration."
|
||||
- "By default a minimal Video and Graphics device configuration will be applied to the VirtualMachineInstance. The video device is vga
|
||||
compatible and comes with a memory size of 16 MB."
|
||||
hugepage_size:
|
||||
description:
|
||||
- "Specify huge page size."
|
||||
type: str
|
||||
tablets:
|
||||
description:
|
||||
- "Specify tablets to be used as input devices"
|
||||
type: list
|
||||
requirements:
|
||||
- python >= 2.7
|
||||
- openshift >= 0.8.2
|
||||
|
|
Loading…
Reference in a new issue