diff --git a/lib/ansible/modules/cloud/misc/ovirt.py b/lib/ansible/modules/cloud/misc/ovirt.py index 162999c0586..2edde96056c 100644 --- a/lib/ansible/modules/cloud/misc/ovirt.py +++ b/lib/ansible/modules/cloud/misc/ovirt.py @@ -1,21 +1,20 @@ #!/usr/bin/python -# (c) 2013, Vincent Van der Kussen +# Copyright: (c) 2013, Vincent Van der Kussen # 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 __metaclass__ = type - ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} - DOCUMENTATION = ''' --- module: ovirt -author: "Vincent Van der Kussen (@vincentvdk)" +author: +- Vincent Van der Kussen (@vincentvdk) short_description: oVirt/RHEV platform management description: - This module only supports oVirt/RHEV version 3. A newer module M(ovirt_vms) supports oVirt/RHV version 4. @@ -24,190 +23,141 @@ version_added: "1.4" options: user: description: - - the user to authenticate with - default: null + - The user to authenticate with. required: true - aliases: [] url: description: - - the url of the oVirt instance - default: null + - The url of the oVirt instance. required: true - aliases: [] instance_name: description: - - the name of the instance to use - default: null + - The name of the instance to use. required: true aliases: [ vmname ] password: description: - - password of the user to authenticate with - default: null + - Password of the user to authenticate with. required: true - aliases: [] image: description: - - template to use for the instance - default: null - required: false - aliases: [] + - The template to use for the instance. resource_type: description: - - whether you want to deploy an image or create an instance from scratch. - default: null - required: false - aliases: [] - choices: [ 'new', 'template' ] + - Whether you want to deploy an image or create an instance from scratch. + choices: [ new, template ] zone: description: - - deploy the image to this oVirt cluster - default: null - required: false - aliases: [] + - Deploy the image to this oVirt cluster. instance_disksize: description: - - size of the instance's disk in GB - default: null - required: false + - Size of the instance's disk in GB. aliases: [ vm_disksize] instance_cpus: description: - - the instance's number of cpu's + - The instance's number of CPUs. default: 1 - required: false aliases: [ vmcpus ] instance_nic: description: - - name of the network interface in oVirt/RHEV - default: null - required: false + - The name of the network interface in oVirt/RHEV. aliases: [ vmnic ] instance_network: description: - - the logical network the machine should belong to + - The logical network the machine should belong to. default: rhevm - required: false aliases: [ vmnetwork ] instance_mem: description: - - the instance's amount of memory in MB - default: null - required: false + - The instance's amount of memory in MB. aliases: [ vmmem ] instance_type: description: - - define if the instance is a server or desktop + - Define whether the instance is a server or desktop. + choices: [ desktop, server ] default: server - required: false aliases: [ vmtype ] - choices: [ 'server', 'desktop' ] disk_alloc: description: - - define if disk is thin or preallocated + - Define whether disk is thin or preallocated. + choices: [ preallocated, thin ] default: thin - required: false - aliases: [] - choices: [ 'thin', 'preallocated' ] disk_int: description: - - interface type of the disk + - Interface type of the disk. + choices: [ ide, virtio ] default: virtio - required: false - aliases: [] - choices: [ 'virtio', 'ide' ] instance_os: description: - - type of Operating System - default: null - required: false + - Type of Operating System. aliases: [ vmos ] instance_cores: description: - - define the instance's number of cores + - Define the instance's number of cores. default: 1 - required: false aliases: [ vmcores ] sdomain: description: - - the Storage Domain where you want to create the instance's disk on. - default: null - required: false - aliases: [] + - The Storage Domain where you want to create the instance's disk on. region: description: - - the oVirt/RHEV datacenter where you want to deploy to - default: null - required: false - aliases: [] + - The oVirt/RHEV datacenter where you want to deploy to. instance_dns: description: - - define the instance's Primary DNS server - required: false + - Define the instance's Primary DNS server. aliases: [ dns ] version_added: "2.1" instance_domain: description: - - define the instance's Domain - required: false + - Define the instance's Domain. aliases: [ domain ] version_added: "2.1" instance_hostname: description: - - define the instance's Hostname - required: false + - Define the instance's Hostname. aliases: [ hostname ] version_added: "2.1" instance_ip: description: - - define the instance's IP - required: false + - Define the instance's IP. aliases: [ ip ] version_added: "2.1" instance_netmask: description: - - define the instance's Netmask - required: false + - Define the instance's Netmask. aliases: [ netmask ] version_added: "2.1" instance_rootpw: description: - - define the instance's Root password - required: false + - Define the instance's Root password. aliases: [ rootpw ] version_added: "2.1" instance_key: description: - - define the instance's Authorized key - required: false + - Define the instance's Authorized key. aliases: [ key ] version_added: "2.1" state: description: - - create, terminate or remove instances - default: 'present' - required: false - aliases: [] - choices: ['present', 'absent', 'shutdown', 'started', 'restarted'] - + - Create, terminate or remove instances. + choices: [ absent, present, restarted, shutdown, started ] + default: present requirements: - - "python >= 2.6" - - "ovirt-engine-sdk-python" + - ovirt-engine-sdk-python ''' -EXAMPLES = ''' -# Basic example provisioning from image. -ovirt: +EXAMPLES = ''' +- name: Basic example to provision from image + ovirt: user: admin@internal url: https://ovirt.example.com instance_name: ansiblevm04 password: secret image: centos_64 zone: cluster01 - resource_type: template" + resource_type: template -# Full example to create new instance from scratch -ovirt: +- name: Full example to create new instance from scratch + ovirt: instance_name: testansible resource_type: new instance_type: server @@ -225,26 +175,26 @@ ovirt: sdomain: FIBER01 instance_cores: 1 instance_os: rhel_6x64 - disk_int: virtio" + disk_int: virtio -# stopping an instance -ovirt: +- name: Stopping an existing instance + ovirt: instance_name: testansible state: stopped user: admin@internal password: secret url: https://ovirt.example.com -# starting an instance -ovirt: +- name: Start an existing instance + ovirt: instance_name: testansible state: started user: admin@internal password: secret url: https://ovirt.example.com -# starting an instance with cloud init information -ovirt: +- name: Start an instance with cloud init information + ovirt: instance_name: testansible state: started user: admin@internal @@ -256,8 +206,8 @@ ovirt: netmask: 255.255.255.0 gateway: 192.0.2.1 rootpw: bigsecret - ''' + import time try: @@ -281,6 +231,7 @@ def conn(url, user, password): raise Exception("error connecting to the oVirt API") return api + # ------------------------------------------------------------------- # # Create VM from scratch def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, vmmem, vmdisk_alloc, sdomain, vmcores, vmos, vmdisk_int): @@ -290,8 +241,9 @@ def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, template=conn.templates.get(name="Blank"), memory=1024 * 1024 * int(vmmem), cpu=params.CPU(topology=params.CpuTopology(cores=int(vmcores))), type_=vmtype) # define disk params - vmdisk= params.Disk(size=1024 * 1024 * 1024 * int(vmdisk_size), wipe_after_delete=True, sparse=True, interface=vmdisk_int, type_="System", format='cow', - storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)])) + vmdisk = params.Disk(size=1024 * 1024 * 1024 * int(vmdisk_size), wipe_after_delete=True, sparse=True, interface=vmdisk_int, type_="System", + format='cow', + storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)])) # define network parameters network_net = params.Network(name=vmnetwork) nic_net1 = params.NIC(name='nic1', network=network_net, interface='virtio') @@ -299,10 +251,10 @@ def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, # define VM params vmparams = params.VM(name=vmname, cluster=conn.clusters.get(name=zone), os=params.OperatingSystem(type_=vmos), template=conn.templates.get(name="Blank"), memory=1024 * 1024 * int(vmmem), - cpu=params.CPU(topology=params.CpuTopology(cores=int(vmcores))) ,type_=vmtype) + cpu=params.CPU(topology=params.CpuTopology(cores=int(vmcores))), type_=vmtype) # define disk params - vmdisk= params.Disk(size=1024 * 1024 * 1024 * int(vmdisk_size), wipe_after_delete=True, sparse=False, interface=vmdisk_int, type_="System", - format='raw', storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)])) + vmdisk = params.Disk(size=1024 * 1024 * 1024 * int(vmdisk_size), wipe_after_delete=True, sparse=False, interface=vmdisk_int, type_="System", + format='raw', storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)])) # define network parameters network_net = params.Network(name=vmnetwork) nic_net1 = params.NIC(name=vmnic, network=network_net, interface='virtio') @@ -324,7 +276,7 @@ def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, # create an instance from a template def create_vm_template(conn, vmname, image, zone): - vmparams = params.VM(name=vmname, cluster=conn.clusters.get(name=zone), template=conn.templates.get(name=image),disks=params.Disks(clone=True)) + vmparams = params.VM(name=vmname, cluster=conn.clusters.get(name=zone), template=conn.templates.get(name=image), disks=params.Disks(clone=True)) try: conn.vms.add(vmparams) except: @@ -345,17 +297,19 @@ def vm_start(conn, vmname, hostname=None, ip=None, netmask=None, gateway=None, nic = params.GuestNicConfiguration(name='eth0', boot_protocol='STATIC', ip=ipinfo, on_boot=True) nics = params.Nics() nics = params.GuestNicsConfiguration(nic_configuration=[nic]) - initialization=params.Initialization(regenerate_ssh_keys=True, host_name=hostname, domain=domain, user_name='root', - root_password=rootpw, nic_configurations=nics, dns_servers=dns, - authorized_ssh_keys=key) + initialization = params.Initialization(regenerate_ssh_keys=True, host_name=hostname, domain=domain, user_name='root', + root_password=rootpw, nic_configurations=nics, dns_servers=dns, + authorized_ssh_keys=key) action = params.Action(use_cloud_init=use_cloud_init, vm=params.VM(initialization=initialization)) vm.start(action=action) + # Stop instance def vm_stop(conn, vmname): vm = conn.vms.get(name=vmname) vm.stop() + # restart instance def vm_restart(conn, vmname): state = vm_status(conn, vmname) @@ -365,11 +319,13 @@ def vm_restart(conn, vmname): time.sleep(5) vm.start() + # remove an instance def vm_remove(conn, vmname): vm = conn.vms.get(name=vmname) vm.delete() + # ------------------------------------------------------------------- # # VM statuses # @@ -395,76 +351,75 @@ def get_vm(conn, vmname): # ------------------------------------------------------------------- # # Main -def main(): +def main(): module = AnsibleModule( - argument_spec = dict( - state = dict(default='present', choices=['present', 'absent', 'shutdown', 'started', 'restart']), - #name = dict(required=True), - user = dict(required=True), - url = dict(required=True), - instance_name = dict(required=True, aliases=['vmname']), - password = dict(required=True, no_log=True), - image = dict(), - resource_type = dict(choices=['new', 'template']), - zone = dict(), - instance_disksize = dict(aliases=['vm_disksize']), - instance_cpus = dict(default=1, aliases=['vmcpus']), - instance_nic = dict(aliases=['vmnic']), - instance_network = dict(default='rhevm', aliases=['vmnetwork']), - instance_mem = dict(aliases=['vmmem']), - instance_type = dict(default='server', aliases=['vmtype'], choices=['server', 'desktop']), - disk_alloc = dict(default='thin', choices=['thin', 'preallocated']), - disk_int = dict(default='virtio', choices=['virtio', 'ide']), - instance_os = dict(aliases=['vmos']), - instance_cores = dict(default=1, aliases=['vmcores']), - instance_hostname = dict(aliases=['hostname']), - instance_ip = dict(aliases=['ip']), - instance_netmask = dict(aliases=['netmask']), - instance_gateway = dict(aliases=['gateway']), - instance_domain = dict(aliases=['domain']), - instance_dns = dict(aliases=['dns']), - instance_rootpw = dict(aliases=['rootpw']), - instance_key = dict(aliases=['key']), - sdomain = dict(), - region = dict(), - ) + argument_spec=dict( + state=dict(type='str', default='present', choices=['absent', 'present', 'restart', 'shutdown', 'started']), + user=dict(type='str', required=True), + url=dict(type='str', required=True), + instance_name=dict(type='str', required=True, aliases=['vmname']), + password=dict(type='str', required=True, no_log=True), + image=dict(type='str'), + resource_type=dict(type='str', choices=['new', 'template']), + zone=dict(type='str'), + instance_disksize=dict(type='str', aliases=['vm_disksize']), + instance_cpus=dict(type='str', default=1, aliases=['vmcpus']), + instance_nic=dict(type='str', aliases=['vmnic']), + instance_network=dict(type='str', default='rhevm', aliases=['vmnetwork']), + instance_mem=dict(type='str', aliases=['vmmem']), + instance_type=dict(type='str', default='server', aliases=['vmtype'], choices=['desktop', 'server']), + disk_alloc=dict(type='str', default='thin', choices=['preallocated', 'thin']), + disk_int=dict(type='str', default='virtio', choices=['ide', 'virtio']), + instance_os=dict(type='str', aliases=['vmos']), + instance_cores=dict(type='str', default=1, aliases=['vmcores']), + instance_hostname=dict(type='str', aliases=['hostname']), + instance_ip=dict(type='str', aliases=['ip']), + instance_netmask=dict(type='str', aliases=['netmask']), + instance_gateway=dict(type='str', aliases=['gateway']), + instance_domain=dict(type='str', aliases=['domain']), + instance_dns=dict(type='str', aliases=['dns']), + instance_rootpw=dict(type='str', aliases=['rootpw']), + instance_key=dict(type='str', aliases=['key']), + sdomain=dict(type='str'), + region=dict(type='str'), + ), ) if not HAS_OVIRTSDK: module.fail_json(msg='ovirtsdk required for this module') - state = module.params['state'] - user = module.params['user'] - url = module.params['url'] - vmname = module.params['instance_name'] - password = module.params['password'] - image = module.params['image'] # name of the image to deploy - resource_type = module.params['resource_type'] # template or from scratch - zone = module.params['zone'] # oVirt cluster - vmdisk_size = module.params['instance_disksize'] # disksize - vmcpus = module.params['instance_cpus'] # number of cpu - vmnic = module.params['instance_nic'] # network interface - vmnetwork = module.params['instance_network'] # logical network - vmmem = module.params['instance_mem'] # mem size - vmdisk_alloc = module.params['disk_alloc'] # thin, preallocated - vmdisk_int = module.params['disk_int'] # disk interface virtio or ide - vmos = module.params['instance_os'] # Operating System - vmtype = module.params['instance_type'] # server or desktop - vmcores = module.params['instance_cores'] # number of cores - sdomain = module.params['sdomain'] # storage domain to store disk on - region = module.params['region'] # oVirt Datacenter - hostname = module.params['instance_hostname'] - ip = module.params['instance_ip'] - netmask = module.params['instance_netmask'] - gateway = module.params['instance_gateway'] - domain = module.params['instance_domain'] - dns = module.params['instance_dns'] - rootpw = module.params['instance_rootpw'] - key = module.params['instance_key'] - #initialize connection + state = module.params['state'] + user = module.params['user'] + url = module.params['url'] + vmname = module.params['instance_name'] + password = module.params['password'] + image = module.params['image'] # name of the image to deploy + resource_type = module.params['resource_type'] # template or from scratch + zone = module.params['zone'] # oVirt cluster + vmdisk_size = module.params['instance_disksize'] # disksize + vmcpus = module.params['instance_cpus'] # number of cpu + vmnic = module.params['instance_nic'] # network interface + vmnetwork = module.params['instance_network'] # logical network + vmmem = module.params['instance_mem'] # mem size + vmdisk_alloc = module.params['disk_alloc'] # thin, preallocated + vmdisk_int = module.params['disk_int'] # disk interface virtio or ide + vmos = module.params['instance_os'] # Operating System + vmtype = module.params['instance_type'] # server or desktop + vmcores = module.params['instance_cores'] # number of cores + sdomain = module.params['sdomain'] # storage domain to store disk on + region = module.params['region'] # oVirt Datacenter + hostname = module.params['instance_hostname'] + ip = module.params['instance_ip'] + netmask = module.params['instance_netmask'] + gateway = module.params['instance_gateway'] + domain = module.params['instance_domain'] + dns = module.params['instance_dns'] + rootpw = module.params['instance_rootpw'] + key = module.params['instance_key'] + # initialize connection try: - c = conn(url+"/api", user, password) + c = conn(url + "/api", user, password) except Exception as e: module.fail_json(msg='%s' % e) @@ -475,14 +430,14 @@ def main(): create_vm_template(c, vmname, image, zone) except Exception as e: module.fail_json(msg='%s' % e) - module.exit_json(changed=True, msg="deployed VM %s from template %s" % (vmname,image)) + module.exit_json(changed=True, msg="deployed VM %s from template %s" % (vmname, image)) elif resource_type == 'new': # FIXME: refactor, use keyword args. try: create_vm(c, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, vmmem, vmdisk_alloc, sdomain, vmcores, vmos, vmdisk_int) except Exception as e: module.fail_json(msg='%s' % e) - module.exit_json(changed=True, msg="deployed VM %s from scratch" % vmname) + module.exit_json(changed=True, msg="deployed VM %s from scratch" % vmname) else: module.exit_json(changed=False, msg="You did not specify a resource type") else: @@ -492,7 +447,7 @@ def main(): if vm_status(c, vmname) == 'up': module.exit_json(changed=False, msg="VM %s is already running" % vmname) else: - #vm_start(c, vmname) + # vm_start(c, vmname) vm_start(c, vmname, hostname, ip, netmask, gateway, domain, dns, rootpw, key) module.exit_json(changed=True, msg="VM %s started" % vmname) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_affinity_group.py b/lib/ansible/modules/cloud/ovirt/ovirt_affinity_group.py index 3f115952f1e..53f4a275076 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_affinity_group.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_affinity_group.py @@ -1,85 +1,67 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# Copyright (c) 2016 Red Hat, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# + +# Copyright: (c) 2017, Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} - DOCUMENTATION = ''' --- module: ovirt_affinity_group short_description: Module to manage affinity groups in oVirt/RHV version_added: "2.3" -author: "Ondra Machacek (@machacekondra)" +author: +- Ondra Machacek (@machacekondra) description: - "This module manage affinity groups in oVirt/RHV. It can also manage assignments of those groups to VMs." options: name: description: - - "Name of the affinity group to manage." + - Name of the affinity group to manage. required: true state: description: - - "Should the affinity group be present or absent." - choices: ['present', 'absent'] + - Should the affinity group be present or absent. + choices: [ absent, present ] default: present cluster: description: - - "Name of the cluster of the affinity group." + - Name of the cluster of the affinity group. description: description: - - "Description of the affinity group." + - Description of the affinity group. host_enforcing: description: - - "If I(true) VM cannot start on host if it does not satisfy the C(host_rule)." - - "C(This parameter is support since oVirt/RHV 4.1 version.)" + - If I(yes) VM cannot start on host if it does not satisfy the C(host_rule). + - This parameter is support since oVirt/RHV 4.1 version. + type: bool host_rule: description: - - "If I(positive) I(all) VMs in this group should run on the this host." - - "If I(negative) I(no) VMs in this group should run on the this host." - - "C(This parameter is support since oVirt/RHV 4.1 version.)" - choices: - - positive - - negative + - If I(positive) I(all) VMs in this group should run on the this host. + - If I(negative) I(no) VMs in this group should run on the this host. + - This parameter is support since oVirt/RHV 4.1 version. + choices: [ negative, positive ] vm_enforcing: description: - - "If I(true) VM cannot start if it does not satisfy the C(vm_rule)." + - If I(yes) VM cannot start if it does not satisfy the C(vm_rule). + type: bool vm_rule: description: - - "If I(positive) I(all) VMs in this group should run on the host defined by C(host_rule)." - - "If I(negative) I(no) VMs in this group should run on the host defined by C(host_rule)." - - "If I(disabled) this affinity group doesn't take effect." - choices: - - positive - - negative - - disabled + - If I(positive) I(all) VMs in this group should run on the host defined by C(host_rule). + - If I(negative) I(no) VMs in this group should run on the host defined by C(host_rule). + - If I(disabled) this affinity group doesn't take effect. + choices: [ disabled, negative, positive ] vms: description: - - "List of the VMs names, which should have assigned this affinity group." + - List of the VMs names, which should have assigned this affinity group. hosts: description: - - "List of the hosts names, which should have assigned this affinity group." - - "C(This parameter is support since oVirt/RHV 4.1 version.)" + - List of the hosts names, which should have assigned this affinity group. + - This parameter is support since oVirt/RHV 4.1 version. extends_documentation_fragment: ovirt ''' @@ -87,8 +69,8 @@ EXAMPLES = ''' # Examples don't contain auth parameter for simplicity, # look at ovirt_auth module to see how to reuse authentication: -# Create(if not exists) and assign affinity group to VMs vm1 and vm2 and host host1 -- ovirt_affinity_group: +- name: Create(if not exists) and assign affinity group to VMs vm1 and vm2 and host host1 + ovirt_affinity_group: name: mygroup cluster: mycluster vm_enforcing: true @@ -101,8 +83,8 @@ EXAMPLES = ''' hosts: - host1 -# Detach VMs from affinity group and disable VM rule: -- ovirt_affinity_group: +- name: Detach VMs from affinity group and disable VM rule + ovirt_affinity_group: name: mygroup cluster: mycluster vm_enforcing: false @@ -114,8 +96,8 @@ EXAMPLES = ''' - host1 - host2 -# Remove affinity group -- ovirt_affinity_group: +- name: Remove affinity group + ovirt_affinity_group: state: absent cluster: mycluster name: mygroup @@ -245,13 +227,10 @@ class AffinityGroupsModule(BaseModule): def update_check(self, entity): assigned_vms = self.assigned_vms(entity) do_update = ( - equal(self.param('description'), entity.description) - and equal(self.param('vm_enforcing'), entity.enforcing) - and equal( + equal(self.param('description'), entity.description) and equal(self.param('vm_enforcing'), entity.enforcing) and equal( self.param('vm_rule') == 'positive' if self.param('vm_rule') else None, entity.positive - ) - and equal(self._vm_ids, assigned_vms) + ) and equal(self._vm_ids, assigned_vms) ) # Following attributes is supported since 4.1, # so return if it doesn't exist: @@ -262,32 +241,24 @@ class AffinityGroupsModule(BaseModule): return do_update and ( equal( self.param('host_rule') == 'positive' if self.param('host_rule') else None, - entity.hosts_rule.positive - ) - and equal(self.param('host_enforcing'), entity.hosts_rule.enforcing) - and equal( + entity.hosts_rule.positive) and equal(self.param('host_enforcing'), entity.hosts_rule.enforcing) and equal( self.param('vm_rule') in ['negative', 'positive'] if self.param('vm_rule') else None, - entity.vms_rule.enabled - ) - and equal(self._host_ids, sorted([host.id for host in entity.hosts])) + entity.vms_rule.enabled) and equal(self._host_ids, sorted([host.id for host in entity.hosts])) ) def main(): argument_spec = ovirt_full_argument_spec( - state=dict( - choices=['present', 'absent'], - default='present', - ), - cluster=dict(default=None, required=True), - name=dict(default=None, required=True), - description=dict(default=None), - vm_enforcing=dict(default=None, type='bool'), - vm_rule=dict(default=None, choices=['positive', 'negative', 'disabled']), - host_enforcing=dict(default=None, type='bool'), - host_rule=dict(default=None, choices=['positive', 'negative']), - vms=dict(default=None, type='list'), - hosts=dict(default=None, type='list'), + state=dict(type='str', default='present', choices=['absent', 'present']), + cluster=dict(type='str', required=True), + name=dict(type='str', required=True), + description=dict(type='str'), + vm_enforcing=dict(type='bool'), + vm_rule=dict(type='str', choices=['disabled', 'negative', 'positive']), + host_enforcing=dict(type='bool'), + host_rule=dict(type='str', choices=['negative', 'positive']), + vms=dict(type='list'), + hosts=dict(type='list'), ) module = AnsibleModule( argument_spec=argument_spec, diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_nics.py b/lib/ansible/modules/cloud/ovirt/ovirt_nics.py index 2d6dc607238..0dec47fb38f 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_nics.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_nics.py @@ -1,71 +1,56 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# Copyright (c) 2016 Red Hat, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# + +# Copyright: (c) 2017, Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} - DOCUMENTATION = ''' --- module: ovirt_nics short_description: Module to manage network interfaces of Virtual Machines in oVirt/RHV version_added: "2.3" -author: "Ondra Machacek (@machacekondra)" +author: +- Ondra Machacek (@machacekondra) description: - - "Module to manage network interfaces of Virtual Machines in oVirt/RHV." + - Module to manage network interfaces of Virtual Machines in oVirt/RHV. options: name: description: - - "Name of the network interface to manage." + - Name of the network interface to manage. required: true vm: description: - - "Name of the Virtual Machine to manage." - - "You must provide either C(vm) parameter or C(template) parameter." + - Name of the Virtual Machine to manage. + - You must provide either C(vm) parameter or C(template) parameter. template: description: - - "Name of the template to manage." - - "You must provide either C(vm) parameter or C(template) parameter." + - Name of the template to manage. + - You must provide either C(vm) parameter or C(template) parameter. version_added: "2.4" state: description: - - "Should the Virtual Machine NIC be present/absent/plugged/unplugged." - choices: ['present', 'absent', 'plugged', 'unplugged'] + - Should the Virtual Machine NIC be present/absent/plugged/unplugged. + choices: [ absent, plugged, present, unplugged ] default: present network: description: - - "Logical network to which the VM network interface should use, - by default Empty network is used if network is not specified." + - Logical network to which the VM network interface should use, + by default Empty network is used if network is not specified. profile: description: - - "Virtual network interface profile to be attached to VM network interface." + - Virtual network interface profile to be attached to VM network interface. interface: description: - - "Type of the network interface." - choices: ['virtio', 'e1000', 'rtl8139', 'pci_passthrough', 'rtl8139_virtio', 'spapr_vlan'] - default: 'virtio' + - Type of the network interface. + choices: [ e1000, pci_passthrough, rtl8139, rtl8139_virtio, spapr_vlan, virtio ] + default: virtio mac_address: description: - - "Custom MAC address of the network interface, by default it's obtained from MAC pool." + - Custom MAC address of the network interface, by default it's obtained from MAC pool. extends_documentation_fragment: ovirt ''' @@ -73,8 +58,8 @@ EXAMPLES = ''' # Examples don't contain auth parameter for simplicity, # look at ovirt_auth module to see how to reuse authentication: -# Add NIC to VM -- ovirt_nics: +- name: Add NIC to VM + ovirt_nics: state: present vm: myvm name: mynic @@ -83,21 +68,20 @@ EXAMPLES = ''' profile: ovirtmgmt network: ovirtmgmt -# Plug NIC to VM -- ovirt_nics: +- name: Plug NIC to VM + ovirt_nics: state: plugged vm: myvm name: mynic -# Unplug NIC from VM -- ovirt_nics: +- name: Unplug NIC from VM + ovirt_nics: state: unplugged vm: myvm name: mynic - -# add NIC to template -- ovirt_nics: +- name: Add NIC to template + ovirt_nics: auth: "{{ ovirt_auth }}" state: present template: my_template @@ -106,13 +90,11 @@ EXAMPLES = ''' profile: ovirtmgmt network: ovirtmgmt - -# Remove NIC from VM -- ovirt_nics: +- name: Remove NIC from VM + ovirt_nics: state: absent vm: myvm name: mynic - ''' RETURN = ''' @@ -191,22 +173,19 @@ class EntityNicsModule(BaseModule): def main(): argument_spec = ovirt_full_argument_spec( - state=dict( - choices=['present', 'absent', 'plugged', 'unplugged'], - default='present' - ), - vm=dict(required=False), - template=dict(required=False), - name=dict(required=True), - interface=dict(default=None), - profile=dict(default=None), - network=dict(default=None), - mac_address=dict(default=None), + state=dict(type='str', default='present', choices=['absent', 'plugged', 'present', 'unplugged']), + vm=dict(type='str'), + template=dict(type='str'), + name=dict(type='str', required=True), + interface=dict(type='str'), + profile=dict(type='str'), + network=dict(type='str'), + mac_address=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, - required_one_of=[['vm', 'template']] + required_one_of=[['vm', 'template']], ) check_sdk(module) @@ -249,7 +228,7 @@ def main(): networks_service = dcs_service.service(dc.id).networks_service() network = next( (n for n in networks_service.list() - if n.name == module.params['network']), + if n.name == module.params['network']), None ) if network is None: diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_permissions.py b/lib/ansible/modules/cloud/ovirt/ovirt_permissions.py index fb6b8a92866..7eebb3eebdb 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_permissions.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_permissions.py @@ -1,92 +1,75 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# Copyright (c) 2016 Red Hat, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# + +# Copyright: (c) 2017, Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} - DOCUMENTATION = ''' --- module: ovirt_permissions -short_description: "Module to manage permissions of users/groups in oVirt/RHV" +short_description: Module to manage permissions of users/groups in oVirt/RHV version_added: "2.3" -author: "Ondra Machacek (@machacekondra)" +author: +- Ondra Machacek (@machacekondra) description: - - "Module to manage permissions of users/groups in oVirt/RHV" + - Module to manage permissions of users/groups in oVirt/RHV. options: role: description: - - "Name of the role to be assigned to user/group on specific object." + - Name of the role to be assigned to user/group on specific object. default: UserRole state: description: - - "Should the permission be present/absent." - choices: ['present', 'absent'] + - Should the permission be present/absent. + choices: [ absent, present ] default: present object_id: description: - - "ID of the object where the permissions should be managed." + - ID of the object where the permissions should be managed. object_name: description: - - "Name of the object where the permissions should be managed." + - Name of the object where the permissions should be managed. object_type: description: - - "The object where the permissions should be managed." - default: 'vm' - choices: [ - 'data_center', - 'cluster', - 'host', - 'storage_domain', - 'network', - 'disk', - 'vm', - 'vm_pool', - 'template', - 'cpu_profile', - 'disk_profile', - 'vnic_profile', - 'system', - ] + - The object where the permissions should be managed. + choices: + - cluster + - cpu_profile + - data_center + - disk + - disk_profile + - host + - network + - storage_domain + - system + - template + - vm + - vm_pool + - vnic_profile + default: vm user_name: description: - - "Username of the user to manage. In most LDAPs it's I(uid) of the user, - but in Active Directory you must specify I(UPN) of the user." - - "Note that if user don't exist in the system this module will fail, - you should ensure the user exists by using M(ovirt_users) module." + - Username of the user to manage. In most LDAPs it's I(uid) of the user, + but in Active Directory you must specify I(UPN) of the user. + - Note that if user does not exist in the system this module will fail, + you should ensure the user exists by using M(ovirt_users) module. group_name: description: - - "Name of the group to manage." - - "Note that if group don't exist in the system this module will fail, - you should ensure the group exists by using M(ovirt_groups) module." + - Name of the group to manage. + - Note that if group does not exist in the system this module will fail, + you should ensure the group exists by using M(ovirt_groups) module. authz_name: description: - - "Authorization provider of the user/group. In previous versions of oVirt/RHV known as domain." + - Authorization provider of the user/group. required: true - aliases: ['domain'] + aliases: [ domain ] namespace: description: - - "Namespace of the authorization provider, where user/group resides." - required: false + - Namespace of the authorization provider, where user/group resides. extends_documentation_fragment: ovirt ''' @@ -94,16 +77,16 @@ EXAMPLES = ''' # Examples don't contain auth parameter for simplicity, # look at ovirt_auth module to see how to reuse authentication: -# Add user user1 from authorization provider example.com-authz -- ovirt_permissions: +- name: Add user user1 from authorization provider example.com-authz + ovirt_permissions: user_name: user1 authz_name: example.com-authz object_type: vm object_name: myvm role: UserVmManager -# Remove permission from user -- ovirt_permissions: +- name: Remove permission from user + ovirt_permissions: state: absent user_name: user1 authz_name: example.com-authz @@ -241,35 +224,30 @@ class PermissionsModule(BaseModule): def main(): argument_spec = ovirt_full_argument_spec( - state=dict( - choices=['present', 'absent'], - default='present', - ), - role=dict(default='UserRole'), - object_type=dict( - default='vm', - choices=[ - 'data_center', - 'cluster', - 'host', - 'storage_domain', - 'network', - 'disk', - 'vm', - 'vm_pool', - 'template', - 'cpu_profile', - 'disk_profile', - 'vnic_profile', - 'system', - ] - ), - authz_name=dict(required=True, aliases=['domain']), - object_id=dict(default=None), - object_name=dict(default=None), - user_name=dict(rdefault=None), - group_name=dict(default=None), - namespace=dict(default=None), + state=dict(type='str', default='present', choices=['absent', 'present']), + role=dict(type='str', default='UserRole'), + object_type=dict(type='str', default='vm', + choices=[ + 'cluster', + 'cpu_profile', + 'data_center', + 'disk', + 'disk_profile', + 'host', + 'network', + 'storage_domain', + 'system', + 'template', + 'vm', + 'vm_pool', + 'vnic_profile', + ]), + authz_name=dict(type='str', required=True, aliases=['domain']), + object_id=dict(type='str'), + object_name=dict(type='str'), + user_name=dict(type='str'), + group_name=dict(type='str'), + namespace=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, @@ -277,10 +255,7 @@ def main(): ) check_sdk(module) - if ( - (module.params['object_name'] is None and module.params['object_id'] is None) - and module.params['object_type'] != 'system' - ): + if (module.params['object_name'] is None and module.params['object_id'] is None) and module.params['object_type'] != 'system': module.fail_json(msg='"object_name" or "object_id" is required') if module.params['user_name'] is None and module.params['group_name'] is None: diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py index d21e336c8b6..33073cd05fb 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py @@ -1,360 +1,389 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# Copyright (c) 2016 Red Hat, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# + +# Copyright: (c) 2017, Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} - DOCUMENTATION = ''' --- module: ovirt_vms -short_description: "Module to manage Virtual Machines in oVirt/RHV" +short_description: Module to manage Virtual Machines in oVirt/RHV version_added: "2.2" -author: "Ondra Machacek (@machacekondra)" +author: +- Ondra Machacek (@machacekondra) description: - - "This module manages whole lifecycle of the Virtual Machine(VM) in oVirt/RHV. Since VM can hold many states in oVirt/RHV, - this see notes to see how the states of the VM are handled." + - This module manages whole lifecycle of the Virtual Machine(VM) in oVirt/RHV. + - Since VM can hold many states in oVirt/RHV, this see notes to see how the states of the VM are handled. options: name: description: - - "Name of the Virtual Machine to manage. If VM don't exists C(name) is required. - Otherwise C(id) or C(name) can be used." + - Name of the Virtual Machine to manage. + - If VM don't exists C(name) is required. Otherwise C(id) or C(name) can be used. id: description: - - "ID of the Virtual Machine to manage." + - ID of the Virtual Machine to manage. state: description: - - "Should the Virtual Machine be running/stopped/present/absent/suspended/next_run/registered. - When C(state) is I(registered) and the unregistered VM's name - belongs to an already registered in engine VM in the same DC - then we fail to register the unregistered template." - - "I(present) state will create/update VM and don't change its state if it already exists." - - "I(running) state will create/update VM and start it." - - "I(next_run) state updates the VM and if the VM has next run configuration it will be rebooted." - - "Please check I(notes) to more detailed description of states." - - "I(registered) is supported since 2.4" - choices: ['running', 'stopped', 'present', 'absent', 'suspended', 'next_run', 'registered'] + - Should the Virtual Machine be running/stopped/present/absent/suspended/next_run/registered. + When C(state) is I(registered) and the unregistered VM's name + belongs to an already registered in engine VM in the same DC + then we fail to register the unregistered template. + - I(present) state will create/update VM and don't change its state if it already exists. + - I(running) state will create/update VM and start it. + - I(next_run) state updates the VM and if the VM has next run configuration it will be rebooted. + - Please check I(notes) to more detailed description of states. + - I(registered) is supported since 2.4. + choices: [ absent, next_run, present, registered, running, stopped, suspended ] default: present cluster: description: - - "Name of the cluster, where Virtual Machine should be created. Required if creating VM." + - Name of the cluster, where Virtual Machine should be created. + - Required if creating VM. allow_partial_import: description: - - "Boolean indication whether to allow partial registration of Virtual Machine when C(state) is registered." + - Boolean indication whether to allow partial registration of Virtual Machine when C(state) is registered. version_added: "2.4" template: description: - - "Name of the template, which should be used to create Virtual Machine. Required if creating VM." - - "If template is not specified and VM doesn't exist, VM will be created from I(Blank) template." + - Name of the template, which should be used to create Virtual Machine. + - Required if creating VM. + - If template is not specified and VM doesn't exist, VM will be created from I(Blank) template. template_version: description: - - "Version number of the template to be used for VM." - - "By default the latest available version of the template is used." + - Version number of the template to be used for VM. + - By default the latest available version of the template is used. version_added: "2.3" use_latest_template_version: description: - - "Specify if latest template version should be used, when running a stateless VM." - - "If this parameter is set to I(true) stateless VM is created." + - Specify if latest template version should be used, when running a stateless VM. + - If this parameter is set to I(yes) stateless VM is created. + type: bool version_added: "2.3" storage_domain: description: - - "Name of the storage domain where all template disks should be created." - - "This parameter is considered only when C(template) is provided." - - "C(**IMPORTANT**)" - - "This parameter is not idempotent, if the VM exists and you specfiy different storage domain, - disk won't move." + - Name of the storage domain where all template disks should be created. + - This parameter is considered only when C(template) is provided. + - IMPORTANT - This parameter is not idempotent, if the VM exists and you specfiy different storage domain, + disk won't move. version_added: "2.4" disk_format: description: - - "Specify format of the disk." - - "If (cow) format is used, disk will by created as sparse, so space will be allocated for the volume as needed, also known as I(thin provision)." - - "If (raw) format is used, disk storage will be allocated right away, also known as I(preallocated)." - - "Note that this option isn't idempotent as it's not currently possible to change format of the disk via API." - - "This parameter is considered only when C(template) and C(storage domain) is provided." - choices: ['cow', 'raw'] + - Specify format of the disk. + - If C(cow) format is used, disk will by created as sparse, so space will be allocated for the volume as needed, also known as I(thin provision). + - If C(raw) format is used, disk storage will be allocated right away, also known as I(preallocated). + - Note that this option isn't idempotent as it's not currently possible to change format of the disk via API. + - This parameter is considered only when C(template) and C(storage domain) is provided. + choices: [ cow, raw ] default: cow version_added: "2.4" memory: description: - - "Amount of memory of the Virtual Machine. Prefix uses IEC 60027-2 standard (for example 1GiB, 1024MiB)." - - "Default value is set by engine." + - Amount of memory of the Virtual Machine. Prefix uses IEC 60027-2 standard (for example 1GiB, 1024MiB). + - Default value is set by engine. memory_guaranteed: description: - - "Amount of minimal guaranteed memory of the Virtual Machine. - Prefix uses IEC 60027-2 standard (for example 1GiB, 1024MiB)." - - "C(memory_guaranteed) parameter can't be lower than C(memory) parameter. Default value is set by engine." + - Amount of minimal guaranteed memory of the Virtual Machine. + Prefix uses IEC 60027-2 standard (for example 1GiB, 1024MiB). + - C(memory_guaranteed) parameter can't be lower than C(memory) parameter. + - Default value is set by engine. cpu_shares: description: - - "Set a CPU shares for this Virtual Machine. Default value is set by oVirt/RHV engine." + - Set a CPU shares for this Virtual Machine. + - Default value is set by oVirt/RHV engine. cpu_cores: description: - - "Number of virtual CPUs cores of the Virtual Machine. Default value is set by oVirt/RHV engine." + - Number of virtual CPUs cores of the Virtual Machine. + - Default value is set by oVirt/RHV engine. cpu_sockets: description: - - "Number of virtual CPUs sockets of the Virtual Machine. Default value is set by oVirt/RHV engine." + - Number of virtual CPUs sockets of the Virtual Machine. + - Default value is set by oVirt/RHV engine. type: description: - - "Type of the Virtual Machine. Default value is set by oVirt/RHV engine." - choices: [server, desktop] + - Type of the Virtual Machine. + - Default value is set by oVirt/RHV engine. + choices: [ desktop, server ] operating_system: description: - - "Operating system of the Virtual Machine. Default value is set by oVirt/RHV engine." - choices: [ - rhel_6_ppc64, other, freebsd, windows_2003x64, windows_10, rhel_6x64, rhel_4x64, windows_2008x64, - windows_2008R2x64, debian_7, windows_2012x64, ubuntu_14_04, ubuntu_12_04, ubuntu_13_10, windows_8x64, - other_linux_ppc64, windows_2003, other_linux, windows_10x64, windows_2008, rhel_3, rhel_5, rhel_4, - other_ppc64, sles_11, rhel_6, windows_xp, rhel_7x64, freebsdx64, rhel_7_ppc64, windows_7, rhel_5x64, - ubuntu_14_04_ppc64, sles_11_ppc64, windows_8, windows_2012R2x64, windows_2008r2x64, ubuntu_13_04, - ubuntu_12_10, windows_7x64 - ] + - Operating system of the Virtual Machine. + - Default value is set by oVirt/RHV engine. + choices: + - debian_7 + - freebsd + - freebsdx64 + - other + - other_linux + - other_linux_ppc64 + - other_ppc64 + - rhel_3 + - rhel_4 + - rhel_4x64 + - rhel_5 + - rhel_5x64 + - rhel_6 + - rhel_6x64 + - rhel_6_ppc64 + - rhel_7x64 + - rhel_7_ppc64 + - sles_11 + - sles_11_ppc64 + - ubuntu_12_04 + - ubuntu_12_10 + - ubuntu_13_04 + - ubuntu_13_10 + - ubuntu_14_04 + - ubuntu_14_04_ppc64 + - windows_10 + - windows_10x64 + - windows_2003 + - windows_2003x64 + - windows_2008 + - windows_2008x64 + - windows_2008r2x64 + - windows_2008R2x64 + - windows_2012x64 + - windows_2012R2x64 + - windows_7 + - windows_7x64 + - windows_8 + - windows_8x64 + - windows_xp boot_devices: description: - - "List of boot devices which should be used to boot. Choices I(network), I(hd) and I(cdrom)." - - "For example: ['cdrom', 'hd']. Default value is set by oVirt/RHV engine." + - List of boot devices which should be used to boot. For example C([ cdrom, hd ]). + - Default value is set by oVirt/RHV engine. + choices: [ cdrom, hd, network ] host: description: - - "Specify host where Virtual Machine should be running. By default the host is chosen by engine scheduler." - - "This parameter is used only when C(state) is I(running) or I(present)." + - Specify host where Virtual Machine should be running. By default the host is chosen by engine scheduler. + - This parameter is used only when C(state) is I(running) or I(present). high_availability: description: - - "If I(True) Virtual Machine will be set as highly available." - - "If I(False) Virtual Machine won't be set as highly available." - - "If no value is passed, default value is set by oVirt/RHV engine." + - If I(yes) Virtual Machine will be set as highly available. + - If I(no) Virtual Machine won't be set as highly available. + - If no value is passed, default value is set by oVirt/RHV engine. + type: bool lease: description: - - "Name of the storage domain this virtual machine lease reside on." - - "C(Note): Supported since oVirt 4.1." + - Name of the storage domain this virtual machine lease reside on. + - NOTE - Supported since oVirt 4.1. version_added: "2.4" delete_protected: description: - - "If I(True) Virtual Machine will be set as delete protected." - - "If I(False) Virtual Machine won't be set as delete protected." - - "If no value is passed, default value is set by oVirt/RHV engine." + - If I(yes) Virtual Machine will be set as delete protected. + - If I(no) Virtual Machine won't be set as delete protected. + - If no value is passed, default value is set by oVirt/RHV engine. stateless: description: - - "If I(True) Virtual Machine will be set as stateless." - - "If I(False) Virtual Machine will be unset as stateless." - - "If no value is passed, default value is set by oVirt/RHV engine." + - If I(yes) Virtual Machine will be set as stateless. + - If I(no) Virtual Machine will be unset as stateless. + - If no value is passed, default value is set by oVirt/RHV engine. clone: description: - - "If I(True) then the disks of the created virtual machine will be cloned and independent of the template." - - "This parameter is used only when C(state) is I(running) or I(present) and VM didn't exist before." - default: False + - If I(yes) then the disks of the created virtual machine will be cloned and independent of the template. + - This parameter is used only when C(state) is I(running) or I(present) and VM didn't exist before. + type: bool + default: 'no' clone_permissions: description: - - "If I(True) then the permissions of the template (only the direct ones, not the inherited ones) - will be copied to the created virtual machine." - - "This parameter is used only when C(state) is I(running) or I(present) and VM didn't exist before." - default: False + - If I(yes) then the permissions of the template (only the direct ones, not the inherited ones) + will be copied to the created virtual machine. + - This parameter is used only when C(state) is I(running) or I(present) and VM didn't exist before. + type: bool + default: 'no' cd_iso: description: - - "ISO file from ISO storage domain which should be attached to Virtual Machine." - - "If you pass empty string the CD will be ejected from VM." - - "If used with C(state) I(running) or I(present) and VM is running the CD will be attached to VM." - - "If used with C(state) I(running) or I(present) and VM is down the CD will be attached to VM persistently." + - ISO file from ISO storage domain which should be attached to Virtual Machine. + - If you pass empty string the CD will be ejected from VM. + - If used with C(state) I(running) or I(present) and VM is running the CD will be attached to VM. + - If used with C(state) I(running) or I(present) and VM is down the CD will be attached to VM persistently. force: description: - - "Please check to I(Synopsis) to more detailed description of force parameter, it can behave differently - in different situations." - default: False + - Please check to I(Synopsis) to more detailed description of force parameter, it can behave differently + in different situations. + type: bool + default: 'no' nics: description: - - "List of NICs, which should be attached to Virtual Machine. NIC is described by following dictionary:" - - "C(name) - Name of the NIC." - - "C(profile_name) - Profile name where NIC should be attached." - - "C(interface) - Type of the network interface. One of following: I(virtio), I(e1000), I(rtl8139), default is I(virtio)." - - "C(mac_address) - Custom MAC address of the network interface, by default it's obtained from MAC pool." - - "C(Note:)" - - "This parameter is used only when C(state) is I(running) or I(present) and is able to only create NICs. - To manage NICs of the VM in more depth please use M(ovirt_nics) module instead." + - List of NICs, which should be attached to Virtual Machine. NIC is described by following dictionary. + - C(name) - Name of the NIC. + - C(profile_name) - Profile name where NIC should be attached. + - C(interface) - Type of the network interface. One of following I(virtio), I(e1000), I(rtl8139), default is I(virtio). + - C(mac_address) - Custom MAC address of the network interface, by default it's obtained from MAC pool. + - NOTE - This parameter is used only when C(state) is I(running) or I(present) and is able to only create NICs. + To manage NICs of the VM in more depth please use M(ovirt_nics) module instead. disks: description: - - "List of disks, which should be attached to Virtual Machine. Disk is described by following dictionary:" - - "C(name) - Name of the disk. Either C(name) or C(id) is reuqired." - - "C(id) - ID of the disk. Either C(name) or C(id) is reuqired." - - "C(interface) - Interface of the disk, either I(virtio) or I(IDE), default is I(virtio)." - - "C(bootable) - I(True) if the disk should be bootable, default is non bootable." - - "C(activate) - I(True) if the disk should be activated, default is activated." - - "C(Note:)" - - "This parameter is used only when C(state) is I(running) or I(present) and is able to only attach disks. - To manage disks of the VM in more depth please use M(ovirt_disks) module instead." + - List of disks, which should be attached to Virtual Machine. Disk is described by following dictionary. + - C(name) - Name of the disk. Either C(name) or C(id) is reuqired. + - C(id) - ID of the disk. Either C(name) or C(id) is reuqired. + - C(interface) - Interface of the disk, either I(virtio) or I(IDE), default is I(virtio). + - C(bootable) - I(True) if the disk should be bootable, default is non bootable. + - C(activate) - I(True) if the disk should be activated, default is activated. + - NOTE - This parameter is used only when C(state) is I(running) or I(present) and is able to only attach disks. + To manage disks of the VM in more depth please use M(ovirt_disks) module instead. sysprep: description: - - "Dictionary with values for Windows Virtual Machine initialization using sysprep:" - - "C(host_name) - Hostname to be set to Virtual Machine when deployed." - - "C(active_directory_ou) - Active Directory Organizational Unit, to be used for login of user." - - "C(org_name) - Organization name to be set to Windows Virtual Machine." - - "C(domain) - Domain to be set to Windows Virtual Machine." - - "C(timezone) - Timezone to be set to Windows Virtual Machine." - - "C(ui_language) - UI language of the Windows Virtual Machine." - - "C(system_locale) - System localization of the Windows Virtual Machine." - - "C(input_locale) - Input localization of the Windows Virtual Machine." - - "C(windows_license_key) - License key to be set to Windows Virtual Machine." - - "C(user_name) - Username to be used for set password to Windows Virtual Machine." - - "C(root_password) - Password to be set for username to Windows Virtual Machine." + - Dictionary with values for Windows Virtual Machine initialization using sysprep. + - C(host_name) - Hostname to be set to Virtual Machine when deployed. + - C(active_directory_ou) - Active Directory Organizational Unit, to be used for login of user. + - C(org_name) - Organization name to be set to Windows Virtual Machine. + - C(domain) - Domain to be set to Windows Virtual Machine. + - C(timezone) - Timezone to be set to Windows Virtual Machine. + - C(ui_language) - UI language of the Windows Virtual Machine. + - C(system_locale) - System localization of the Windows Virtual Machine. + - C(input_locale) - Input localization of the Windows Virtual Machine. + - C(windows_license_key) - License key to be set to Windows Virtual Machine. + - C(user_name) - Username to be used for set password to Windows Virtual Machine. + - C(root_password) - Password to be set for username to Windows Virtual Machine. cloud_init: description: - - "Dictionary with values for Unix-like Virtual Machine initialization using cloud init:" - - "C(host_name) - Hostname to be set to Virtual Machine when deployed." - - "C(timezone) - Timezone to be set to Virtual Machine when deployed." - - "C(user_name) - Username to be used to set password to Virtual Machine when deployed." - - "C(root_password) - Password to be set for user specified by C(user_name) parameter." - - "C(authorized_ssh_keys) - Use this SSH keys to login to Virtual Machine." - - "C(regenerate_ssh_keys) - If I(True) SSH keys will be regenerated on Virtual Machine." - - "C(custom_script) - Cloud-init script which will be executed on Virtual Machine when deployed." - - "C(dns_servers) - DNS servers to be configured on Virtual Machine." - - "C(dns_search) - DNS search domains to be configured on Virtual Machine." - - "C(nic_boot_protocol) - Set boot protocol of the network interface of Virtual Machine. Can be one of none, dhcp or static." - - "C(nic_ip_address) - If boot protocol is static, set this IP address to network interface of Virtual Machine." - - "C(nic_netmask) - If boot protocol is static, set this netmask to network interface of Virtual Machine." - - "C(nic_gateway) - If boot protocol is static, set this gateway to network interface of Virtual Machine." - - "C(nic_name) - Set name to network interface of Virtual Machine." - - "C(nic_on_boot) - If I(True) network interface will be set to start on boot." + - Dictionary with values for Unix-like Virtual Machine initialization using cloud init. + - C(host_name) - Hostname to be set to Virtual Machine when deployed. + - C(timezone) - Timezone to be set to Virtual Machine when deployed. + - C(user_name) - Username to be used to set password to Virtual Machine when deployed. + - C(root_password) - Password to be set for user specified by C(user_name) parameter. + - C(authorized_ssh_keys) - Use this SSH keys to login to Virtual Machine. + - C(regenerate_ssh_keys) - If I(True) SSH keys will be regenerated on Virtual Machine. + - C(custom_script) - Cloud-init script which will be executed on Virtual Machine when deployed. + - C(dns_servers) - DNS servers to be configured on Virtual Machine. + - C(dns_search) - DNS search domains to be configured on Virtual Machine. + - C(nic_boot_protocol) - Set boot protocol of the network interface of Virtual Machine. Can be one of C(none), C(dhcp) or C(static). + - C(nic_ip_address) - If boot protocol is static, set this IP address to network interface of Virtual Machine. + - C(nic_netmask) - If boot protocol is static, set this netmask to network interface of Virtual Machine. + - C(nic_gateway) - If boot protocol is static, set this gateway to network interface of Virtual Machine. + - C(nic_name) - Set name to network interface of Virtual Machine. + - C(nic_on_boot) - If I(True) network interface will be set to start on boot. cloud_init_nics: description: - - "List of dictionaries representing network interafaces to be setup by cloud init." - - "This option is used, when user needs to setup more network interfaces via cloud init." - - "If one network interface is enough, user should use C(cloud_init) I(nic_*) parameters. C(cloud_init) I(nic_*) parameters - are merged with C(cloud_init_nics) parameters." - - "Dictionary can contain following values:" - - "C(nic_boot_protocol) - Set boot protocol of the network interface of Virtual Machine. Can be one of none, dhcp or static." - - "C(nic_ip_address) - If boot protocol is static, set this IP address to network interface of Virtual Machine." - - "C(nic_netmask) - If boot protocol is static, set this netmask to network interface of Virtual Machine." - - "C(nic_gateway) - If boot protocol is static, set this gateway to network interface of Virtual Machine." - - "C(nic_name) - Set name to network interface of Virtual Machine." - - "C(nic_on_boot) - If I(True) network interface will be set to start on boot." + - List of dictionaries representing network interafaces to be setup by cloud init. + - This option is used, when user needs to setup more network interfaces via cloud init. + - If one network interface is enough, user should use C(cloud_init) I(nic_*) parameters. C(cloud_init) I(nic_*) parameters + are merged with C(cloud_init_nics) parameters. + - Dictionary can contain following values. + - C(nic_boot_protocol) - Set boot protocol of the network interface of Virtual Machine. Can be one of C(none), C(dhcp) or C(static). + - C(nic_ip_address) - If boot protocol is static, set this IP address to network interface of Virtual Machine. + - C(nic_netmask) - If boot protocol is static, set this netmask to network interface of Virtual Machine. + - C(nic_gateway) - If boot protocol is static, set this gateway to network interface of Virtual Machine. + - C(nic_name) - Set name to network interface of Virtual Machine. + - C(nic_on_boot) - If I(True) network interface will be set to start on boot. version_added: "2.3" kernel_path: description: - - "Path to a kernel image used to boot the virtual machine." - - "Kernel image must be stored on either the ISO domain or on the host's storage." + - Path to a kernel image used to boot the virtual machine. + - Kernel image must be stored on either the ISO domain or on the host's storage. version_added: "2.3" initrd_path: description: - - "Path to an initial ramdisk to be used with the kernel specified by C(kernel_path) option." - - "Ramdisk image must be stored on either the ISO domain or on the host's storage." + - Path to an initial ramdisk to be used with the kernel specified by C(kernel_path) option. + - Ramdisk image must be stored on either the ISO domain or on the host's storage. version_added: "2.3" kernel_params: description: - - "Kernel command line parameters (formatted as string) to be used with the kernel specified by C(kernel_path) option." + - Kernel command line parameters (formatted as string) to be used with the kernel specified by C(kernel_path) option. version_added: "2.3" instance_type: description: - - "Name of virtual machine's hardware configuration." - - "By default no instance type is used." + - Name of virtual machine's hardware configuration. + - By default no instance type is used. version_added: "2.3" description: description: - - "Description of the Virtual Machine." + - Description of the Virtual Machine. version_added: "2.3" comment: description: - - "Comment of the Virtual Machine." + - Comment of the Virtual Machine. version_added: "2.3" timezone: description: - - "Sets time zone offset of the guest hardware clock." - - "For example: Etc/GMT" + - Sets time zone offset of the guest hardware clock. + - For example C(Etc/GMT) version_added: "2.3" serial_policy: description: - - "Specify a serial number policy for the Virtual Machine." - - "Following options are supported:" - - "C(vm) - Sets the Virtual Machine's UUID as its serial number." - - "C(host) - Sets the host's UUID as the Virtual Machine's serial number." - - "C(custom) - Allows you to specify a custom serial number in C(serial_policy_value)." + - Specify a serial number policy for the Virtual Machine. + - Following options are supported. + - C(vm) - Sets the Virtual Machine's UUID as its serial number. + - C(host) - Sets the host's UUID as the Virtual Machine's serial number. + - C(custom) - Allows you to specify a custom serial number in C(serial_policy_value). version_added: "2.3" serial_policy_value: description: - - "Allows you to specify a custom serial number." - - "This parameter is used only when C(serial_policy) is I(custom)." + - Allows you to specify a custom serial number. + - This parameter is used only when C(serial_policy) is I(custom). version_added: "2.3" vmware: description: - - "Dictionary of values to be used to connect to VMware and import - a virtual machine to oVirt." - - "Dictionary can contain following values:" - - "C(username) - The username to authenticate against the VMware." - - "C(password) - The password to authenticate against the VMware." - - "C(url) - The URL to be passed to the I(virt-v2v) tool for conversion. - For example: I(vpx://wmware_user@vcenter-host/DataCenter/Cluster/esxi-host?no_verify=1)" - - "C(drivers_iso) - The name of the ISO containing drivers that can - be used during the I(virt-v2v) conversion process." - - "C(sparse) - Specifies the disk allocation policy of the resulting - virtual machine: I(true) for sparse, I(false) for preallocated. - Default value is I(true)." - - "C(storage_domain) - Specifies the target storage domain for - converted disks. This is required parameter." + - Dictionary of values to be used to connect to VMware and import + a virtual machine to oVirt. + - Dictionary can contain following values. + - C(username) - The username to authenticate against the VMware. + - C(password) - The password to authenticate against the VMware. + - C(url) - The URL to be passed to the I(virt-v2v) tool for conversion. + For example I(vpx://wmware_user@vcenter-host/DataCenter/Cluster/esxi-host?no_verify=1) + - C(drivers_iso) - The name of the ISO containing drivers that can + be used during the I(virt-v2v) conversion process. + - C(sparse) - Specifies the disk allocation policy of the resulting + virtual machine. I(true) for sparse, I(false) for preallocated. + Default value is I(true). + - C(storage_domain) - Specifies the target storage domain for + converted disks. This is required parameter. version_added: "2.3" xen: description: - - "Dictionary of values to be used to connect to XEN and import - a virtual machine to oVirt." - - "Dictionary can contain following values:" - - "C(url) - The URL to be passed to the I(virt-v2v) tool for conversion. - For example: I(xen+ssh://root@zen.server). This is required paramater." - - "C(drivers_iso) - The name of the ISO containing drivers that can - be used during the I(virt-v2v) conversion process." - - "C(sparse) - Specifies the disk allocation policy of the resulting - virtual machine: I(true) for sparse, I(false) for preallocated. - Default value is I(true)." - - "C(storage_domain) - Specifies the target storage domain for - converted disks. This is required parameter." + - Dictionary of values to be used to connect to XEN and import + a virtual machine to oVirt. + - Dictionary can contain following values. + - C(url) - The URL to be passed to the I(virt-v2v) tool for conversion. + For example I(xen+ssh://root@zen.server). This is required parameter. + - C(drivers_iso) - The name of the ISO containing drivers that can + be used during the I(virt-v2v) conversion process. + - C(sparse) - Specifies the disk allocation policy of the resulting + virtual machine. I(true) for sparse, I(false) for preallocated. + Default value is I(true). + - C(storage_domain) - Specifies the target storage domain for + converted disks. This is required parameter. version_added: "2.3" kvm: description: - - "Dictionary of values to be used to connect to kvm and import - a virtual machine to oVirt." - - "Dictionary can contain following values:" - - "C(name) - The name of the KVM virtual machine." - - "C(username) - The username to authenticate against the KVM." - - "C(password) - The password to authenticate against the KVM." - - "C(url) - The URL to be passed to the I(virt-v2v) tool for conversion. - For example: I(qemu:///system). This is required paramater." - - "C(drivers_iso) - The name of the ISO containing drivers that can - be used during the I(virt-v2v) conversion process." - - "C(sparse) - Specifies the disk allocation policy of the resulting - virtual machine: I(true) for sparse, I(false) for preallocated. - Default value is I(true)." - - "C(storage_domain) - Specifies the target storage domain for - converted disks. This is required parameter." + - Dictionary of values to be used to connect to kvm and import + a virtual machine to oVirt. + - Dictionary can contain following values. + - C(name) - The name of the KVM virtual machine. + - C(username) - The username to authenticate against the KVM. + - C(password) - The password to authenticate against the KVM. + - C(url) - The URL to be passed to the I(virt-v2v) tool for conversion. + For example I(qemu:///system). This is required parameter. + - C(drivers_iso) - The name of the ISO containing drivers that can + be used during the I(virt-v2v) conversion process. + - C(sparse) - Specifies the disk allocation policy of the resulting + virtual machine. I(true) for sparse, I(false) for preallocated. + Default value is I(true). + - C(storage_domain) - Specifies the target storage domain for + converted disks. This is required parameter. version_added: "2.3" notes: - - "If VM is in I(UNASSIGNED) or I(UNKNOWN) state before any operation, the module will fail. - If VM is in I(IMAGE_LOCKED) state before any operation, we try to wait for VM to be I(DOWN). - If VM is in I(SAVING_STATE) state before any operation, we try to wait for VM to be I(SUSPENDED). - If VM is in I(POWERING_DOWN) state before any operation, we try to wait for VM to be I(UP) or I(DOWN). VM can - get into I(UP) state from I(POWERING_DOWN) state, when there is no ACPI or guest agent running inside VM, or - if the shutdown operation fails. - When user specify I(UP) C(state), we always wait to VM to be in I(UP) state in case VM is I(MIGRATING), - I(REBOOTING), I(POWERING_UP), I(RESTORING_STATE), I(WAIT_FOR_LAUNCH). In other states we run start operation on VM. - When user specify I(stopped) C(state), and If user pass C(force) parameter set to I(true) we forcibly stop the VM in - any state. If user don't pass C(force) parameter, we always wait to VM to be in UP state in case VM is - I(MIGRATING), I(REBOOTING), I(POWERING_UP), I(RESTORING_STATE), I(WAIT_FOR_LAUNCH). If VM is in I(PAUSED) or - I(SUSPENDED) state, we start the VM. Then we gracefully shutdown the VM. - When user specify I(suspended) C(state), we always wait to VM to be in UP state in case VM is I(MIGRATING), - I(REBOOTING), I(POWERING_UP), I(RESTORING_STATE), I(WAIT_FOR_LAUNCH). If VM is in I(PAUSED) or I(DOWN) state, - we start the VM. Then we suspend the VM. - When user specify I(absent) C(state), we forcibly stop the VM in any state and remove it." + - If VM is in I(UNASSIGNED) or I(UNKNOWN) state before any operation, the module will fail. + If VM is in I(IMAGE_LOCKED) state before any operation, we try to wait for VM to be I(DOWN). + If VM is in I(SAVING_STATE) state before any operation, we try to wait for VM to be I(SUSPENDED). + If VM is in I(POWERING_DOWN) state before any operation, we try to wait for VM to be I(UP) or I(DOWN). VM can + get into I(UP) state from I(POWERING_DOWN) state, when there is no ACPI or guest agent running inside VM, or + if the shutdown operation fails. + When user specify I(UP) C(state), we always wait to VM to be in I(UP) state in case VM is I(MIGRATING), + I(REBOOTING), I(POWERING_UP), I(RESTORING_STATE), I(WAIT_FOR_LAUNCH). In other states we run start operation on VM. + When user specify I(stopped) C(state), and If user pass C(force) parameter set to I(true) we forcibly stop the VM in + any state. If user don't pass C(force) parameter, we always wait to VM to be in UP state in case VM is + I(MIGRATING), I(REBOOTING), I(POWERING_UP), I(RESTORING_STATE), I(WAIT_FOR_LAUNCH). If VM is in I(PAUSED) or + I(SUSPENDED) state, we start the VM. Then we gracefully shutdown the VM. + When user specify I(suspended) C(state), we always wait to VM to be in UP state in case VM is I(MIGRATING), + I(REBOOTING), I(POWERING_UP), I(RESTORING_STATE), I(WAIT_FOR_LAUNCH). If VM is in I(PAUSED) or I(DOWN) state, + we start the VM. Then we suspend the VM. + When user specify I(absent) C(state), we forcibly stop the VM in any state and remove it. extends_documentation_fragment: ovirt ''' @@ -362,36 +391,36 @@ EXAMPLES = ''' # Examples don't contain auth parameter for simplicity, # look at ovirt_auth module to see how to reuse authentication: -# Creates a new Virtual Machine from template named 'rhel7_template' -ovirt_vms: +- name: Creates a new Virtual Machine from template named 'rhel7_template' + ovirt_vms: state: present name: myvm template: rhel7_template -# Register VM -ovirt_vms: +- name: Register VM + ovirt_vms: state: registered storage_domain: mystorage cluster: mycluster name: myvm -# Register VM using id -ovirt_vms: +- name: Register VM using id + ovirt_vms: state: registered storage_domain: mystorage cluster: mycluster id: 1111-1111-1111-1111 -# Register VM, allowing partial import -ovirt_vms: +- name: Register VM, allowing partial import + ovirt_vms: state: registered storage_domain: mystorage allow_partial_import: "True" cluster: mycluster id: 1111-1111-1111-1111 -# Creates a stateless VM which will always use latest template version: -ovirt_vms: +- name: Creates a stateless VM which will always use latest template version + ovirt_vms: name: myvm template: rhel7 cluster: mycluster @@ -400,7 +429,7 @@ ovirt_vms: # Creates a new server rhel7 Virtual Machine from Blank template # on brq01 cluster with 2GiB memory and 2 vcpu cores/sockets # and attach bootable disk with name rhel7_disk and attach virtio NIC -ovirt_vms: +- ovirt_vms: state: present cluster: brq01 name: myvm @@ -416,8 +445,8 @@ ovirt_vms: nics: - name: nic1 -# Run VM with cloud init: -ovirt_vms: +- name: Run VM with cloud init + ovirt_vms: name: rhel7 template: rhel7 cluster: Default @@ -440,12 +469,12 @@ ovirt_vms: user_name: root root_password: super_password -# Run VM with cloud init, with multiple network interfaces: -ovirt_vms: - name: rhel7_4 - template: rhel7 - cluster: mycluster - cloud_init_nics: +- name: Run VM with cloud init, with multiple network interfaces + ovirt_vms: + name: rhel7_4 + template: rhel7 + cluster: mycluster + cloud_init_nics: - nic_name: eth0 nic_boot_protocol: dhcp nic_on_boot: true @@ -456,8 +485,8 @@ ovirt_vms: nic_gateway: 10.34.63.254 nic_on_boot: true -# Run VM with sysprep: -ovirt_vms: +- name: Run VM with sysprep + ovirt_vms: name: windows2012R2_AD template: windows2012R2 cluster: Default @@ -468,56 +497,55 @@ ovirt_vms: user_name: Administrator root_password: SuperPassword123 -# Migrate/Run VM to/on host named 'host1' -ovirt_vms: +- name: Migrate/Run VM to/on host named 'host1' + ovirt_vms: state: running name: myvm host: host1 -# Change Vm's CD: -ovirt_vms: +- name: Change VMs CD + ovirt_vms: name: myvm cd_iso: drivers.iso -# Eject Vm's CD: -ovirt_vms: +- name: Eject VMs CD + ovirt_vms: name: myvm cd_iso: '' -# Boot VM from CD: -ovirt_vms: +- name: Boot VM from CD + ovirt_vms: name: myvm cd_iso: centos7_x64.iso boot_devices: - cdrom -# Stop vm: -ovirt_vms: +- name: Stop vm + ovirt_vms: state: stopped name: myvm -# Upgrade memory to already created VM: -ovirt_vms: +- name: Upgrade memory to already created VM + ovirt_vms: name: myvm memory: 4GiB -# Hot plug memory to already created and running VM: -# (VM won't be restarted) -ovirt_vms: +- name: Hot plug memory to already created and running VM (VM won't be restarted) + ovirt_vms: name: myvm memory: 4GiB # When change on the VM needs restart of the VM, use next_run state, # The VM will be updated and rebooted if there are any changes. # If present state would be used, VM won't be restarted. -ovirt_vms: +- ovirt_vms: state: next_run name: myvm boot_devices: - network -# Import virtual machine from VMware: -ovirt_vms: +- name: Import virtual machine from VMware + ovirt_vms: state: stopped cluster: mycluster name: vmware_win10 @@ -530,17 +558,17 @@ ovirt_vms: username: user password: password -# create vm from template and create all disks on specific storage domain -ovirt_vms: - name: vm_test - cluster: mycluster - template: mytemplate - storage_domain: mynfs - nics: +- name: Create vm from template and create all disks on specific storage domain + ovirt_vms: + name: vm_test + cluster: mycluster + template: mytemplate + storage_domain: mynfs + nics: - name: nic1 -# Remove VM, if VM is running it will be stopped: -ovirt_vms: +- name: Remove VM, if VM is running it will be stopped + ovirt_vms: state: absent name: myvm ''' @@ -720,26 +748,25 @@ class VmsModule(BaseModule): def update_check(self, entity): return ( - equal(self.param('cluster'), get_link_name(self._connection, entity.cluster)) - and equal(convert_to_bytes(self.param('memory')), entity.memory) - and equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) - and equal(self.param('cpu_cores'), entity.cpu.topology.cores) - and equal(self.param('cpu_sockets'), entity.cpu.topology.sockets) - and equal(self.param('type'), str(entity.type)) - and equal(self.param('operating_system'), str(entity.os.type)) - and equal(self.param('high_availability'), entity.high_availability.enabled) - and equal(self.param('lease'), get_link_name(self._connection, getattr(entity.lease, 'storage_domain', None))) - and equal(self.param('stateless'), entity.stateless) - and equal(self.param('cpu_shares'), entity.cpu_shares) - and equal(self.param('delete_protected'), entity.delete_protected) - and equal(self.param('use_latest_template_version'), entity.use_latest_template_version) - and equal(self.param('boot_devices'), [str(dev) for dev in getattr(entity.os, 'devices', [])]) - and equal(self.param('instance_type'), get_link_name(self._connection, entity.instance_type), ignore_case=True) - and equal(self.param('description'), entity.description) - and equal(self.param('comment'), entity.comment) - and equal(self.param('timezone'), getattr(entity.time_zone, 'name', None)) - and equal(self.param('serial_policy'), str(getattr(entity.serial_number, 'policy', None))) - and equal(self.param('serial_policy_value'), getattr(entity.serial_number, 'value', None)) + equal(self.param('cluster'), get_link_name(self._connection, entity.cluster)) and equal(convert_to_bytes(self.param('memory')), entity.memory) and + equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) and + equal(self.param('cpu_cores'), entity.cpu.topology.cores) and + equal(self.param('cpu_sockets'), entity.cpu.topology.sockets) and + equal(self.param('type'), str(entity.type)) and + equal(self.param('operating_system'), str(entity.os.type)) and + equal(self.param('high_availability'), entity.high_availability.enabled) and + equal(self.param('lease'), get_link_name(self._connection, getattr(entity.lease, 'storage_domain', None))) and + equal(self.param('stateless'), entity.stateless) and + equal(self.param('cpu_shares'), entity.cpu_shares) and + equal(self.param('delete_protected'), entity.delete_protected) and + equal(self.param('use_latest_template_version'), entity.use_latest_template_version) and + equal(self.param('boot_devices'), [str(dev) for dev in getattr(entity.os, 'devices', [])]) and + equal(self.param('instance_type'), get_link_name(self._connection, entity.instance_type), ignore_case=True) and + equal(self.param('description'), entity.description) and + equal(self.param('comment'), entity.comment) and + equal(self.param('timezone'), getattr(entity.time_zone, 'name', None)) and + equal(self.param('serial_policy'), str(getattr(entity.serial_number, 'policy', None))) and + equal(self.param('serial_policy_value'), getattr(entity.serial_number, 'value', None)) ) def pre_create(self, entity): @@ -1122,69 +1149,65 @@ def control_state(vm, vms_service, module): condition=lambda vm: vm.status in [otypes.VmStatus.DOWN, otypes.VmStatus.UP], ) + def main(): argument_spec = ovirt_full_argument_spec( - state=dict( - choices=['running', 'stopped', 'present', 'absent', 'suspended', 'next_run', 'registered'], - default='present', - ), - name=dict(default=None), - id=dict(default=None), - cluster=dict(default=None), - allow_partial_import=dict(default=None, type='bool'), - template=dict(default=None), - template_version=dict(default=None, type='int'), - use_latest_template_version=dict(default=None, type='bool'), - storage_domain=dict(default=None), - disk_format=dict(choices=['cow','raw'], default='cow'), - disks=dict(default=[], type='list'), - memory=dict(default=None), - memory_guaranteed=dict(default=None), - cpu_sockets=dict(default=None, type='int'), - cpu_cores=dict(default=None, type='int'), - cpu_shares=dict(default=None, type='int'), - type=dict(choices=['server', 'desktop']), - operating_system=dict( - default=None, - choices=[ - 'rhel_6_ppc64', 'other', 'freebsd', 'windows_2003x64', 'windows_10', - 'rhel_6x64', 'rhel_4x64', 'windows_2008x64', 'windows_2008R2x64', - 'debian_7', 'windows_2012x64', 'ubuntu_14_04', 'ubuntu_12_04', - 'ubuntu_13_10', 'windows_8x64', 'other_linux_ppc64', 'windows_2003', - 'other_linux', 'windows_10x64', 'windows_2008', 'rhel_3', 'rhel_5', - 'rhel_4', 'other_ppc64', 'sles_11', 'rhel_6', 'windows_xp', 'rhel_7x64', - 'freebsdx64', 'rhel_7_ppc64', 'windows_7', 'rhel_5x64', - 'ubuntu_14_04_ppc64', 'sles_11_ppc64', 'windows_8', - 'windows_2012R2x64', 'windows_2008r2x64', 'ubuntu_13_04', - 'ubuntu_12_10', 'windows_7x64', - ], - ), - cd_iso=dict(default=None), - boot_devices=dict(default=None, type='list'), + state=dict(type='str', default='present', choices=['absent', 'next_run', 'present', 'registered', 'running', 'stopped', 'suspended']), + name=dict(type='str'), + id=dict(type='str'), + cluster=dict(type='str'), + allow_partial_import=dict(type='bool'), + template=dict(type='str'), + template_version=dict(type='int'), + use_latest_template_version=dict(type='bool'), + storage_domain=dict(type='str'), + disk_format=dict(type='str', default='cow', choices=['cow', 'raw']), + disks=dict(type='list', default=[]), + memory=dict(type='str'), + memory_guaranteed=dict(type='str'), + cpu_sockets=dict(type='int'), + cpu_cores=dict(type='int'), + cpu_shares=dict(type='int'), + type=dict(type='str', choices=['server', 'desktop']), + operating_system=dict(type='str', + choices=[ + 'rhel_6_ppc64', 'other', 'freebsd', 'windows_2003x64', 'windows_10', + 'rhel_6x64', 'rhel_4x64', 'windows_2008x64', 'windows_2008R2x64', + 'debian_7', 'windows_2012x64', 'ubuntu_14_04', 'ubuntu_12_04', + 'ubuntu_13_10', 'windows_8x64', 'other_linux_ppc64', 'windows_2003', + 'other_linux', 'windows_10x64', 'windows_2008', 'rhel_3', 'rhel_5', + 'rhel_4', 'other_ppc64', 'sles_11', 'rhel_6', 'windows_xp', 'rhel_7x64', + 'freebsdx64', 'rhel_7_ppc64', 'windows_7', 'rhel_5x64', + 'ubuntu_14_04_ppc64', 'sles_11_ppc64', 'windows_8', + 'windows_2012R2x64', 'windows_2008r2x64', 'ubuntu_13_04', + 'ubuntu_12_10', 'windows_7x64', + ]), + cd_iso=dict(type='str'), + boot_devices=dict(type='list'), high_availability=dict(type='bool'), - lease=dict(default=None), + lease=dict(type='str'), stateless=dict(type='bool'), delete_protected=dict(type='bool'), force=dict(type='bool', default=False), - nics=dict(default=[], type='list'), + nics=dict(type='list', default=[]), cloud_init=dict(type='dict'), - cloud_init_nics=dict(defaul=[], type='list'), + cloud_init_nics=dict(type='list', default=[]), sysprep=dict(type='dict'), - host=dict(default=None), + host=dict(type='str'), clone=dict(type='bool', default=False), clone_permissions=dict(type='bool', default=False), - kernel_path=dict(default=None), - initrd_path=dict(default=None), - kernel_params=dict(default=None), - instance_type=dict(default=None), - description=dict(default=None), - comment=dict(default=None), - timezone=dict(default=None), - serial_policy=dict(default=None, choices=['vm', 'host', 'custom']), - serial_policy_value=dict(default=None), - vmware=dict(default=None, type='dict'), - xen=dict(default=None, type='dict'), - kvm=dict(default=None, type='dict'), + kernel_path=dict(type='str'), + initrd_path=dict(type='str'), + kernel_params=dict(type='str'), + instance_type=dict(type='str'), + description=dict(type='str'), + comment=dict(type='str'), + timezone=dict(type='str'), + serial_policy=dict(type='str', choices=['vm', 'host', 'custom']), + serial_policy_value=dict(type='str'), + vmware=dict(type='dict'), + xen=dict(type='dict'), + kvm=dict(type='dict'), ) module = AnsibleModule( argument_spec=argument_spec, @@ -1256,16 +1279,16 @@ def main(): initrd=module.params.get('initrd_path'), kernel=module.params.get('kernel_path'), ) if ( - module.params.get('kernel_params') - or module.params.get('initrd_path') - or module.params.get('kernel_path') + module.params.get('kernel_params') or + module.params.get('initrd_path') or + module.params.get('kernel_path') ) else None, ) if ( - module.params.get('kernel_params') - or module.params.get('initrd_path') - or module.params.get('kernel_path') - or module.params.get('host') - or initialization + module.params.get('kernel_params') or + module.params.get('initrd_path') or + module.params.get('kernel_path') or + module.params.get('host') or + initialization ) else None, ) diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 7ef6feed449..eaf55abbb9a 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -70,7 +70,6 @@ lib/ansible/modules/cloud/google/gcpubsub.py lib/ansible/modules/cloud/google/gcspanner.py lib/ansible/modules/cloud/lxc/lxc_container.py lib/ansible/modules/cloud/lxd/lxd_container.py -lib/ansible/modules/cloud/misc/ovirt.py lib/ansible/modules/cloud/misc/rhevm.py lib/ansible/modules/cloud/misc/serverless.py lib/ansible/modules/cloud/misc/virt_net.py @@ -85,11 +84,6 @@ lib/ansible/modules/cloud/openstack/os_security_group_rule.py lib/ansible/modules/cloud/openstack/os_server.py lib/ansible/modules/cloud/openstack/os_stack.py lib/ansible/modules/cloud/ovh/ovh_ip_loadbalancing_backend.py -lib/ansible/modules/cloud/ovirt/_ovirt_affinity_groups.py -lib/ansible/modules/cloud/ovirt/ovirt_affinity_group.py -lib/ansible/modules/cloud/ovirt/ovirt_nics.py -lib/ansible/modules/cloud/ovirt/ovirt_permissions.py -lib/ansible/modules/cloud/ovirt/ovirt_vms.py lib/ansible/modules/cloud/packet/packet_sshkey.py lib/ansible/modules/cloud/profitbricks/profitbricks.py lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py