rhevm: Fix validate-modules issues (#52436)

This PR includes:

* Adding parameter types
* Fix validate-modules issue
* Improve parameter types and resulting changes

This PR needs to be verified and tested by maintainer(s).
This commit is contained in:
Dag Wieers 2019-03-06 15:05:14 +01:00 committed by John R Barker
parent 5c6b16edc3
commit c44e83ee13
2 changed files with 197 additions and 177 deletions

View file

@ -1,108 +1,131 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Timothy Vandenbrande <timothy.vandenbrande@gmail.com> # Copyright: (c) 2016, Timothy Vandenbrande <timothy.vandenbrande@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
DOCUMENTATION = r'''
DOCUMENTATION = '''
--- ---
module: rhevm module: rhevm
author: Timothy Vandenbrande (@TimothyVandenbrande)
short_description: RHEV/oVirt automation short_description: RHEV/oVirt automation
description: description:
- This module only supports oVirt/RHEV version 3. A newer module M(ovirt_vm) supports oVirt/RHV version 4. - This module only supports oVirt/RHEV version 3.
- A newer module M(ovirt_vm) supports oVirt/RHV version 4.
- Allows you to create/remove/update or powermanage virtual machines on a RHEV/oVirt platform. - Allows you to create/remove/update or powermanage virtual machines on a RHEV/oVirt platform.
version_added: "2.2" version_added: "2.2"
requirements: requirements:
- ovirtsdk - ovirtsdk
author:
- Timothy Vandenbrande (@TimothyVandenbrande)
options: options:
user: user:
description: description:
- The user to authenticate with. - The user to authenticate with.
default: "admin@internal" type: str
default: admin@internal
password:
description:
- The password for user authentication.
type: str
server: server:
description: description:
- The name/ip of your RHEV-m/oVirt instance. - The name/IP of your RHEV-m/oVirt instance.
default: "127.0.0.1" type: str
default: 127.0.0.1
port: port:
description: description:
- The port on which the API is reacheable. - The port on which the API is reacheable.
default: "443" type: int
default: 443
insecure_api: insecure_api:
description: description:
- A boolean switch to make a secure or insecure connection to the server. - A boolean switch to make a secure or insecure connection to the server.
type: bool type: bool
default: 'no' default: no
name: name:
description: description:
- The name of the VM. - The name of the VM.
type: str
cluster: cluster:
description: description:
- The rhev/ovirt cluster in which you want you VM to start. - The RHEV/oVirt cluster in which you want you VM to start.
type: str
datacenter: datacenter:
description: description:
- The rhev/ovirt datacenter in which you want you VM to start. - The RHEV/oVirt datacenter in which you want you VM to start.
default: "Default" type: str
default: Default
state: state:
description: description:
- This serves to create/remove/update or powermanage your VM. - This serves to create/remove/update or powermanage your VM.
default: "present" type: str
choices: ['ping', 'present', 'absent', 'up', 'down', 'restarted', 'cd', 'info'] choices: [ absent, cd, down, info, ping, present, restarted, up ]
default: present
image: image:
description: description:
- The template to use for the VM. - The template to use for the VM.
type: str
type: type:
description: description:
- To define if the VM is a server or desktop. - To define if the VM is a server or desktop.
type: str
choices: [ desktop, host, server ]
default: server default: server
choices: [ 'server', 'desktop', 'host' ]
vmhost: vmhost:
description: description:
- The host you wish your VM to run on. - The host you wish your VM to run on.
type: str
vmcpu: vmcpu:
description: description:
- The number of CPUs you want in your VM. - The number of CPUs you want in your VM.
default: "2" type: int
default: 2
cpu_share: cpu_share:
description: description:
- This parameter is used to configure the cpu share. - This parameter is used to configure the CPU share.
default: "0" type: int
default: 0
vmmem: vmmem:
description: description:
- The amount of memory you want your VM to use (in GB). - The amount of memory you want your VM to use (in GB).
default: "1" type: int
default: 1
osver: osver:
description: description:
- The operationsystem option in RHEV/oVirt. - The operating system option in RHEV/oVirt.
default: "rhel_6x64" type: str
default: rhel_6x64
mempol: mempol:
description: description:
- The minimum amount of memory you wish to reserve for this system. - The minimum amount of memory you wish to reserve for this system.
default: "1" type: int
default: 1
vm_ha: vm_ha:
description: description:
- To make your VM High Available. - To make your VM High Available.
type: bool type: bool
default: 'yes' default: yes
disks: disks:
description: description:
- This option uses complex arguments and is a list of disks with the options name, size and domain. - This option uses complex arguments and is a list of disks with the options name, size and domain.
type: list
ifaces: ifaces:
description: description:
- This option uses complex arguments and is a list of interfaces with the options name and vlan. - This option uses complex arguments and is a list of interfaces with the options name and vlan.
aliases: ['nics', 'interfaces'] type: list
aliases: [ interfaces, nics ]
boot_order: boot_order:
description: description:
- This option uses complex arguments and is a list of items that specify the bootorder. - This option uses complex arguments and is a list of items that specify the bootorder.
default: ["network","hd"] type: list
default: [ hd, network ]
del_prot: del_prot:
description: description:
- This option sets the delete protection checkbox. - This option sets the delete protection checkbox.
@ -111,15 +134,17 @@ options:
cd_drive: cd_drive:
description: description:
- The CD you wish to have mounted on the VM when I(state = 'CD'). - The CD you wish to have mounted on the VM when I(state = 'CD').
type: str
timeout: timeout:
description: description:
- The timeout you wish to define for power actions. - The timeout you wish to define for power actions.
- When I(state = 'up') - When I(state = 'up').
- When I(state = 'down') - When I(state = 'down').
- When I(state = 'restarted') - When I(state = 'restarted').
type: int
''' '''
RETURN = ''' RETURN = r'''
vm: vm:
description: Returns all of the VMs variables and execution. description: Returns all of the VMs variables and execution.
returned: always returned: always
@ -185,116 +210,116 @@ vm:
}' }'
''' '''
EXAMPLES = ''' EXAMPLES = r'''
# basic get info from VM - name: Basic get info from VM
- rhevm: rhevm:
name: "demo" server: rhevm01
user: "{{ rhev.admin.name }}" user: '{{ rhev.admin.name }}'
password: "{{ rhev.admin.pass }}" password: '{{ rhev.admin.pass }}'
server: "rhevm01" name: demo
state: "info" state: info
# basic create example from image - name: Basic create example from image
- rhevm: rhevm:
name: "demo" server: rhevm01
user: "{{ rhev.admin.name }}" user: '{{ rhev.admin.name }}'
password: "{{ rhev.admin.pass }}" password: '{{ rhev.admin.pass }}'
server: "rhevm01" name: demo
state: "present" cluster: centos
image: "centos7_x64" image: centos7_x64
cluster: "centos" state: present
# power management - name: Power management
- rhevm: rhevm:
name: "uptime_server" server: rhevm01
user: "{{ rhev.admin.name }}" user: '{{ rhev.admin.name }}'
password: "{{ rhev.admin.pass }}" password: '{{ rhev.admin.pass }}'
server: "rhevm01" cluster: RH
cluster: "RH" name: uptime_server
state: "down" image: centos7_x64
image: "centos7_x64" state: down
# multi disk, multi nic create example - name: Multi disk, multi nic create example
- rhevm: rhevm:
name: "server007" server: rhevm01
user: "{{ rhev.admin.name }}" user: '{{ rhev.admin.name }}'
password: "{{ rhev.admin.pass }}" password: '{{ rhev.admin.pass }}'
server: "rhevm01" cluster: RH
cluster: "RH" name: server007
state: "present" type: server
type: "server"
vmcpu: 4 vmcpu: 4
vmmem: 2 vmmem: 2
ifaces: ifaces:
- name: "eth0" - name: eth0
vlan: "vlan2202" vlan: vlan2202
- name: "eth1" - name: eth1
vlan: "vlan36" vlan: vlan36
- name: "eth2" - name: eth2
vlan: "vlan38" vlan: vlan38
- name: "eth3" - name: eth3
vlan: "vlan2202" vlan: vlan2202
disks: disks:
- name: "root" - name: root
size: 10 size: 10
domain: "ssd-san" domain: ssd-san
- name: "swap" - name: swap
size: 10 size: 10
domain: "15kiscsi-san" domain: 15kiscsi-san
- name: "opt" - name: opt
size: 10 size: 10
domain: "15kiscsi-san" domain: 15kiscsi-san
- name: "var" - name: var
size: 10 size: 10
domain: "10kiscsi-san" domain: 10kiscsi-san
- name: "home" - name: home
size: 10 size: 10
domain: "sata-san" domain: sata-san
boot_order: boot_order:
- "network" - network
- "hd" - hd
# add a CD to the disk cd_drive
- rhevm:
name: 'server007'
user: "{{ rhev.admin.name }}"
password: "{{ rhev.admin.pass }}"
state: 'cd'
cd_drive: 'rhev-tools-setup.iso'
# new host deployment + host network configuration
- rhevm:
name: "ovirt_node007"
password: "{{ rhevm.admin.pass }}"
type: "host"
state: present state: present
cluster: "rhevm01"
- name: Add a CD to the disk cd_drive
rhevm:
user: '{{ rhev.admin.name }}'
password: '{{ rhev.admin.pass }}'
name: server007
cd_drive: rhev-tools-setup.iso
state: cd
- name: New host deployment + host network configuration
rhevm:
password: '{{ rhevm.admin.pass }}'
name: ovirt_node007
type: host
cluster: rhevm01
ifaces: ifaces:
- name: em1 - name: em1
- name: em2 - name: em2
- name: p3p1 - name: p3p1
ip: '172.31.224.200' ip: 172.31.224.200
netmask: '255.255.254.0' netmask: 255.255.254.0
- name: p3p2 - name: p3p2
ip: '172.31.225.200' ip: 172.31.225.200
netmask: '255.255.254.0' netmask: 255.255.254.0
- name: bond0 - name: bond0
bond: bond:
- em1 - em1
- em2 - em2
network: 'rhevm' network: rhevm
ip: '172.31.222.200' ip: 172.31.222.200
netmask: '255.255.255.0' netmask: 255.255.255.0
management: True management: yes
- name: bond0.36 - name: bond0.36
network: 'vlan36' network: vlan36
ip: '10.2.36.200' ip: 10.2.36.200
netmask: '255.255.254.0' netmask: 255.255.254.0
gateway: '10.2.36.254' gateway: 10.2.36.254
- name: bond0.2202 - name: bond0.2202
network: 'vlan2202' network: vlan2202
- name: bond0.38 - name: bond0.38
network: 'vlan38' network: vlan38
state: present
''' '''
import time import time
@ -313,8 +338,8 @@ RHEV_FAILED = 1
RHEV_SUCCESS = 0 RHEV_SUCCESS = 0
RHEV_UNAVAILABLE = 2 RHEV_UNAVAILABLE = 2
RHEV_TYPE_OPTS = ['server', 'desktop', 'host'] RHEV_TYPE_OPTS = ['desktop', 'host', 'server']
STATE_OPTS = ['ping', 'present', 'absent', 'up', 'down', 'restart', 'cd', 'info'] STATE_OPTS = ['absent', 'cd', 'down', 'info', 'ping', 'present', 'restart', 'up']
msg = [] msg = []
changed = False changed = False
@ -1308,15 +1333,15 @@ def core(module):
memory = module.params.get('vmmem') memory = module.params.get('vmmem')
if memory is not None: if memory is not None:
memory_policy = module.params.get('mempol') memory_policy = module.params.get('mempol')
if int(memory_policy) == 0: if memory_policy == 0:
memory_policy = memory memory_policy = memory
mem_pol_nok = True mem_pol_nok = True
if int(vminfo['mem_pol']) == int(memory_policy): if int(vminfo['mem_pol']) == memory_policy:
setMsg("Memory is correct") setMsg("Memory is correct")
mem_pol_nok = False mem_pol_nok = False
mem_nok = True mem_nok = True
if int(vminfo['memory']) == int(memory): if int(vminfo['memory']) == memory:
setMsg("Memory is correct") setMsg("Memory is correct")
mem_nok = False mem_nok = False
@ -1325,7 +1350,7 @@ def core(module):
return RHEV_FAILED, msg return RHEV_FAILED, msg
if mem_nok and mem_pol_nok: if mem_nok and mem_pol_nok:
if int(memory_policy) > int(vminfo['memory']): if memory_policy > int(vminfo['memory']):
r.setMemory(vminfo['name'], memory) r.setMemory(vminfo['name'], memory)
r.setMemoryPolicy(vminfo['name'], memory_policy) r.setMemoryPolicy(vminfo['name'], memory_policy)
else: else:
@ -1339,7 +1364,7 @@ def core(module):
# Set CPU # Set CPU
cpu = module.params.get('vmcpu') cpu = module.params.get('vmcpu')
if int(vminfo['cpu_cores']) == int(cpu): if int(vminfo['cpu_cores']) == cpu:
setMsg("Number of CPUs is correct") setMsg("Number of CPUs is correct")
else: else:
if r.setCPU(vminfo['name'], cpu) is False: if r.setCPU(vminfo['name'], cpu) is False:
@ -1348,7 +1373,7 @@ def core(module):
# Set CPU SHARE # Set CPU SHARE
cpu_share = module.params.get('cpu_share') cpu_share = module.params.get('cpu_share')
if cpu_share is not None: if cpu_share is not None:
if int(vminfo['cpu_shares']) == int(cpu_share): if int(vminfo['cpu_shares']) == cpu_share:
setMsg("CPU share is correct.") setMsg("CPU share is correct.")
else: else:
if r.setCPUShare(vminfo['name'], cpu_share) is False: if r.setCPUShare(vminfo['name'], cpu_share) is False:
@ -1378,7 +1403,7 @@ def core(module):
# Set VM Host # Set VM Host
vmhost = module.params.get('vmhost') vmhost = module.params.get('vmhost')
if vmhost is not False and vmhost != "False": if vmhost:
if r.setVMHost(vminfo['name'], vmhost) is False: if r.setVMHost(vminfo['name'], vmhost) is False:
return RHEV_FAILED, msg return RHEV_FAILED, msg
@ -1447,37 +1472,35 @@ def main():
global module global module
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
state=dict(default='present', choices=['ping', 'present', 'absent', 'up', 'down', 'restarted', 'cd', 'info']), state=dict(type='str', default='present', choices=['absent', 'cd', 'down', 'info', 'ping', 'present', 'restarted', 'up']),
user=dict(default="admin@internal"), user=dict(type='str', default='admin@internal'),
password=dict(required=True, no_log=True), password=dict(type='str', required=True, no_log=True),
server=dict(default="127.0.0.1"), server=dict(type='str', default='127.0.0.1'),
port=dict(default="443"), port=dict(type='int', default=443),
insecure_api=dict(default=False, type='bool'), insecure_api=dict(type='bool', default=False),
name=dict(), name=dict(type='str'),
image=dict(default=False), image=dict(type='str'),
datacenter=dict(default="Default"), datacenter=dict(type='str', default="Default"),
type=dict(default="server", choices=['server', 'desktop', 'host']), type=dict(type='str', default='server', choices=['desktop', 'host', 'server']),
cluster=dict(default=''), cluster=dict(type='str', default=''),
vmhost=dict(default=False), vmhost=dict(type='str'),
vmcpu=dict(default="2"), vmcpu=dict(type='int', default=2),
vmmem=dict(default="1"), vmmem=dict(type='int', default=1),
disks=dict(), disks=dict(type='list'),
osver=dict(default="rhel_6x64"), osver=dict(type='str', default="rhel_6x64"),
ifaces=dict(aliases=['nics', 'interfaces']), ifaces=dict(type='list', aliases=['interfaces', 'nics']),
timeout=dict(default=False), timeout=dict(type='int'),
mempol=dict(default="1"), mempol=dict(type='int', default=1),
vm_ha=dict(default=True), vm_ha=dict(type='bool', default=True),
cpu_share=dict(default="0"), cpu_share=dict(type='int', default=0),
boot_order=dict(default=["network", "hd"]), boot_order=dict(type='list', default=['hd', 'network']),
del_prot=dict(default=True, type="bool"), del_prot=dict(type='bool', default=True),
cd_drive=dict(default=False) cd_drive=dict(type='str'),
), ),
) )
if not HAS_SDK: if not HAS_SDK:
module.fail_json( module.fail_json(msg="The 'ovirtsdk' module is not importable. Check the requirements.")
msg='The `ovirtsdk` module is not importable. Check the requirements.'
)
rc = RHEV_SUCCESS rc = RHEV_SUCCESS
try: try:
@ -1487,7 +1510,7 @@ def main():
if rc != 0: # something went wrong emit the msg if rc != 0: # something went wrong emit the msg
module.fail_json(rc=rc, msg=result) module.fail_json(rc=rc, msg=result)
else:
module.exit_json(**result) module.exit_json(**result)

View file

@ -174,9 +174,6 @@ lib/ansible/modules/cloud/misc/ovirt.py E326
lib/ansible/modules/cloud/misc/proxmox_kvm.py E322 lib/ansible/modules/cloud/misc/proxmox_kvm.py E322
lib/ansible/modules/cloud/misc/proxmox_kvm.py E324 lib/ansible/modules/cloud/misc/proxmox_kvm.py E324
lib/ansible/modules/cloud/misc/proxmox_template.py E323 lib/ansible/modules/cloud/misc/proxmox_template.py E323
lib/ansible/modules/cloud/misc/rhevm.py E322
lib/ansible/modules/cloud/misc/rhevm.py E324
lib/ansible/modules/cloud/misc/rhevm.py E335
lib/ansible/modules/cloud/misc/terraform.py E324 lib/ansible/modules/cloud/misc/terraform.py E324
lib/ansible/modules/cloud/misc/virt.py E322 lib/ansible/modules/cloud/misc/virt.py E322
lib/ansible/modules/cloud/misc/virt.py E326 lib/ansible/modules/cloud/misc/virt.py E326