mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
ovirt: PEP8 compliancy fixes (#32316)
* ovirt: PEP8 compliancy fixes This PR includes: - PEP8 compliancy fixes Signed-off-by: Satyajit Bulage <sbulage@redhat.com> * Improve documentation * Update documentation * Update documentation * Update documentation * Fix legacy-files.txt * Update documentation * Fix PEP8 issue * Fix PEP8 issue * Fix another PEP8 issue * More typo fixes * Yet another PEP8 typo
This commit is contained in:
parent
a2d34e914e
commit
1857d11034
6 changed files with 669 additions and 772 deletions
|
@ -1,21 +1,20 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
# (c) 2013, Vincent Van der Kussen <vincent at vanderkussen.org>
|
# Copyright: (c) 2013, Vincent Van der Kussen <vincent at vanderkussen.org>
|
||||||
# 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 = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: ovirt
|
module: ovirt
|
||||||
author: "Vincent Van der Kussen (@vincentvdk)"
|
author:
|
||||||
|
- Vincent Van der Kussen (@vincentvdk)
|
||||||
short_description: oVirt/RHEV platform management
|
short_description: oVirt/RHEV platform management
|
||||||
description:
|
description:
|
||||||
- This module only supports oVirt/RHEV version 3. A newer module M(ovirt_vms) supports oVirt/RHV version 4.
|
- 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:
|
options:
|
||||||
user:
|
user:
|
||||||
description:
|
description:
|
||||||
- the user to authenticate with
|
- The user to authenticate with.
|
||||||
default: null
|
|
||||||
required: true
|
required: true
|
||||||
aliases: []
|
|
||||||
url:
|
url:
|
||||||
description:
|
description:
|
||||||
- the url of the oVirt instance
|
- The url of the oVirt instance.
|
||||||
default: null
|
|
||||||
required: true
|
required: true
|
||||||
aliases: []
|
|
||||||
instance_name:
|
instance_name:
|
||||||
description:
|
description:
|
||||||
- the name of the instance to use
|
- The name of the instance to use.
|
||||||
default: null
|
|
||||||
required: true
|
required: true
|
||||||
aliases: [ vmname ]
|
aliases: [ vmname ]
|
||||||
password:
|
password:
|
||||||
description:
|
description:
|
||||||
- password of the user to authenticate with
|
- Password of the user to authenticate with.
|
||||||
default: null
|
|
||||||
required: true
|
required: true
|
||||||
aliases: []
|
|
||||||
image:
|
image:
|
||||||
description:
|
description:
|
||||||
- template to use for the instance
|
- The template to use for the instance.
|
||||||
default: null
|
|
||||||
required: false
|
|
||||||
aliases: []
|
|
||||||
resource_type:
|
resource_type:
|
||||||
description:
|
description:
|
||||||
- whether you want to deploy an image or create an instance from scratch.
|
- Whether you want to deploy an image or create an instance from scratch.
|
||||||
default: null
|
choices: [ new, template ]
|
||||||
required: false
|
|
||||||
aliases: []
|
|
||||||
choices: [ 'new', 'template' ]
|
|
||||||
zone:
|
zone:
|
||||||
description:
|
description:
|
||||||
- deploy the image to this oVirt cluster
|
- Deploy the image to this oVirt cluster.
|
||||||
default: null
|
|
||||||
required: false
|
|
||||||
aliases: []
|
|
||||||
instance_disksize:
|
instance_disksize:
|
||||||
description:
|
description:
|
||||||
- size of the instance's disk in GB
|
- Size of the instance's disk in GB.
|
||||||
default: null
|
|
||||||
required: false
|
|
||||||
aliases: [ vm_disksize]
|
aliases: [ vm_disksize]
|
||||||
instance_cpus:
|
instance_cpus:
|
||||||
description:
|
description:
|
||||||
- the instance's number of cpu's
|
- The instance's number of CPUs.
|
||||||
default: 1
|
default: 1
|
||||||
required: false
|
|
||||||
aliases: [ vmcpus ]
|
aliases: [ vmcpus ]
|
||||||
instance_nic:
|
instance_nic:
|
||||||
description:
|
description:
|
||||||
- name of the network interface in oVirt/RHEV
|
- The name of the network interface in oVirt/RHEV.
|
||||||
default: null
|
|
||||||
required: false
|
|
||||||
aliases: [ vmnic ]
|
aliases: [ vmnic ]
|
||||||
instance_network:
|
instance_network:
|
||||||
description:
|
description:
|
||||||
- the logical network the machine should belong to
|
- The logical network the machine should belong to.
|
||||||
default: rhevm
|
default: rhevm
|
||||||
required: false
|
|
||||||
aliases: [ vmnetwork ]
|
aliases: [ vmnetwork ]
|
||||||
instance_mem:
|
instance_mem:
|
||||||
description:
|
description:
|
||||||
- the instance's amount of memory in MB
|
- The instance's amount of memory in MB.
|
||||||
default: null
|
|
||||||
required: false
|
|
||||||
aliases: [ vmmem ]
|
aliases: [ vmmem ]
|
||||||
instance_type:
|
instance_type:
|
||||||
description:
|
description:
|
||||||
- define if the instance is a server or desktop
|
- Define whether the instance is a server or desktop.
|
||||||
|
choices: [ desktop, server ]
|
||||||
default: server
|
default: server
|
||||||
required: false
|
|
||||||
aliases: [ vmtype ]
|
aliases: [ vmtype ]
|
||||||
choices: [ 'server', 'desktop' ]
|
|
||||||
disk_alloc:
|
disk_alloc:
|
||||||
description:
|
description:
|
||||||
- define if disk is thin or preallocated
|
- Define whether disk is thin or preallocated.
|
||||||
|
choices: [ preallocated, thin ]
|
||||||
default: thin
|
default: thin
|
||||||
required: false
|
|
||||||
aliases: []
|
|
||||||
choices: [ 'thin', 'preallocated' ]
|
|
||||||
disk_int:
|
disk_int:
|
||||||
description:
|
description:
|
||||||
- interface type of the disk
|
- Interface type of the disk.
|
||||||
|
choices: [ ide, virtio ]
|
||||||
default: virtio
|
default: virtio
|
||||||
required: false
|
|
||||||
aliases: []
|
|
||||||
choices: [ 'virtio', 'ide' ]
|
|
||||||
instance_os:
|
instance_os:
|
||||||
description:
|
description:
|
||||||
- type of Operating System
|
- Type of Operating System.
|
||||||
default: null
|
|
||||||
required: false
|
|
||||||
aliases: [ vmos ]
|
aliases: [ vmos ]
|
||||||
instance_cores:
|
instance_cores:
|
||||||
description:
|
description:
|
||||||
- define the instance's number of cores
|
- Define the instance's number of cores.
|
||||||
default: 1
|
default: 1
|
||||||
required: false
|
|
||||||
aliases: [ vmcores ]
|
aliases: [ vmcores ]
|
||||||
sdomain:
|
sdomain:
|
||||||
description:
|
description:
|
||||||
- the Storage Domain where you want to create the instance's disk on.
|
- The Storage Domain where you want to create the instance's disk on.
|
||||||
default: null
|
|
||||||
required: false
|
|
||||||
aliases: []
|
|
||||||
region:
|
region:
|
||||||
description:
|
description:
|
||||||
- the oVirt/RHEV datacenter where you want to deploy to
|
- The oVirt/RHEV datacenter where you want to deploy to.
|
||||||
default: null
|
|
||||||
required: false
|
|
||||||
aliases: []
|
|
||||||
instance_dns:
|
instance_dns:
|
||||||
description:
|
description:
|
||||||
- define the instance's Primary DNS server
|
- Define the instance's Primary DNS server.
|
||||||
required: false
|
|
||||||
aliases: [ dns ]
|
aliases: [ dns ]
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
instance_domain:
|
instance_domain:
|
||||||
description:
|
description:
|
||||||
- define the instance's Domain
|
- Define the instance's Domain.
|
||||||
required: false
|
|
||||||
aliases: [ domain ]
|
aliases: [ domain ]
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
instance_hostname:
|
instance_hostname:
|
||||||
description:
|
description:
|
||||||
- define the instance's Hostname
|
- Define the instance's Hostname.
|
||||||
required: false
|
|
||||||
aliases: [ hostname ]
|
aliases: [ hostname ]
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
instance_ip:
|
instance_ip:
|
||||||
description:
|
description:
|
||||||
- define the instance's IP
|
- Define the instance's IP.
|
||||||
required: false
|
|
||||||
aliases: [ ip ]
|
aliases: [ ip ]
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
instance_netmask:
|
instance_netmask:
|
||||||
description:
|
description:
|
||||||
- define the instance's Netmask
|
- Define the instance's Netmask.
|
||||||
required: false
|
|
||||||
aliases: [ netmask ]
|
aliases: [ netmask ]
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
instance_rootpw:
|
instance_rootpw:
|
||||||
description:
|
description:
|
||||||
- define the instance's Root password
|
- Define the instance's Root password.
|
||||||
required: false
|
|
||||||
aliases: [ rootpw ]
|
aliases: [ rootpw ]
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
instance_key:
|
instance_key:
|
||||||
description:
|
description:
|
||||||
- define the instance's Authorized key
|
- Define the instance's Authorized key.
|
||||||
required: false
|
|
||||||
aliases: [ key ]
|
aliases: [ key ]
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- create, terminate or remove instances
|
- Create, terminate or remove instances.
|
||||||
default: 'present'
|
choices: [ absent, present, restarted, shutdown, started ]
|
||||||
required: false
|
default: present
|
||||||
aliases: []
|
|
||||||
choices: ['present', 'absent', 'shutdown', 'started', 'restarted']
|
|
||||||
|
|
||||||
requirements:
|
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
|
user: admin@internal
|
||||||
url: https://ovirt.example.com
|
url: https://ovirt.example.com
|
||||||
instance_name: ansiblevm04
|
instance_name: ansiblevm04
|
||||||
password: secret
|
password: secret
|
||||||
image: centos_64
|
image: centos_64
|
||||||
zone: cluster01
|
zone: cluster01
|
||||||
resource_type: template"
|
resource_type: template
|
||||||
|
|
||||||
# Full example to create new instance from scratch
|
- name: Full example to create new instance from scratch
|
||||||
ovirt:
|
ovirt:
|
||||||
instance_name: testansible
|
instance_name: testansible
|
||||||
resource_type: new
|
resource_type: new
|
||||||
instance_type: server
|
instance_type: server
|
||||||
|
@ -225,26 +175,26 @@ ovirt:
|
||||||
sdomain: FIBER01
|
sdomain: FIBER01
|
||||||
instance_cores: 1
|
instance_cores: 1
|
||||||
instance_os: rhel_6x64
|
instance_os: rhel_6x64
|
||||||
disk_int: virtio"
|
disk_int: virtio
|
||||||
|
|
||||||
# stopping an instance
|
- name: Stopping an existing instance
|
||||||
ovirt:
|
ovirt:
|
||||||
instance_name: testansible
|
instance_name: testansible
|
||||||
state: stopped
|
state: stopped
|
||||||
user: admin@internal
|
user: admin@internal
|
||||||
password: secret
|
password: secret
|
||||||
url: https://ovirt.example.com
|
url: https://ovirt.example.com
|
||||||
|
|
||||||
# starting an instance
|
- name: Start an existing instance
|
||||||
ovirt:
|
ovirt:
|
||||||
instance_name: testansible
|
instance_name: testansible
|
||||||
state: started
|
state: started
|
||||||
user: admin@internal
|
user: admin@internal
|
||||||
password: secret
|
password: secret
|
||||||
url: https://ovirt.example.com
|
url: https://ovirt.example.com
|
||||||
|
|
||||||
# starting an instance with cloud init information
|
- name: Start an instance with cloud init information
|
||||||
ovirt:
|
ovirt:
|
||||||
instance_name: testansible
|
instance_name: testansible
|
||||||
state: started
|
state: started
|
||||||
user: admin@internal
|
user: admin@internal
|
||||||
|
@ -256,8 +206,8 @@ ovirt:
|
||||||
netmask: 255.255.255.0
|
netmask: 255.255.255.0
|
||||||
gateway: 192.0.2.1
|
gateway: 192.0.2.1
|
||||||
rootpw: bigsecret
|
rootpw: bigsecret
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -281,6 +231,7 @@ def conn(url, user, password):
|
||||||
raise Exception("error connecting to the oVirt API")
|
raise Exception("error connecting to the oVirt API")
|
||||||
return api
|
return api
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------- #
|
# ------------------------------------------------------------------- #
|
||||||
# Create VM from scratch
|
# Create VM from scratch
|
||||||
def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, vmmem, vmdisk_alloc, sdomain, vmcores, vmos, vmdisk_int):
|
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),
|
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
|
# 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',
|
vmdisk = params.Disk(size=1024 * 1024 * 1024 * int(vmdisk_size), wipe_after_delete=True, sparse=True, interface=vmdisk_int, type_="System",
|
||||||
storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)]))
|
format='cow',
|
||||||
|
storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)]))
|
||||||
# define network parameters
|
# define network parameters
|
||||||
network_net = params.Network(name=vmnetwork)
|
network_net = params.Network(name=vmnetwork)
|
||||||
nic_net1 = params.NIC(name='nic1', network=network_net, interface='virtio')
|
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
|
# define VM params
|
||||||
vmparams = params.VM(name=vmname, cluster=conn.clusters.get(name=zone), os=params.OperatingSystem(type_=vmos),
|
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),
|
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
|
# define disk params
|
||||||
vmdisk= params.Disk(size=1024 * 1024 * 1024 * int(vmdisk_size), wipe_after_delete=True, sparse=False, interface=vmdisk_int, type_="System",
|
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)]))
|
format='raw', storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)]))
|
||||||
# define network parameters
|
# define network parameters
|
||||||
network_net = params.Network(name=vmnetwork)
|
network_net = params.Network(name=vmnetwork)
|
||||||
nic_net1 = params.NIC(name=vmnic, network=network_net, interface='virtio')
|
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
|
# create an instance from a template
|
||||||
def create_vm_template(conn, vmname, image, zone):
|
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:
|
try:
|
||||||
conn.vms.add(vmparams)
|
conn.vms.add(vmparams)
|
||||||
except:
|
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)
|
nic = params.GuestNicConfiguration(name='eth0', boot_protocol='STATIC', ip=ipinfo, on_boot=True)
|
||||||
nics = params.Nics()
|
nics = params.Nics()
|
||||||
nics = params.GuestNicsConfiguration(nic_configuration=[nic])
|
nics = params.GuestNicsConfiguration(nic_configuration=[nic])
|
||||||
initialization=params.Initialization(regenerate_ssh_keys=True, host_name=hostname, domain=domain, user_name='root',
|
initialization = params.Initialization(regenerate_ssh_keys=True, host_name=hostname, domain=domain, user_name='root',
|
||||||
root_password=rootpw, nic_configurations=nics, dns_servers=dns,
|
root_password=rootpw, nic_configurations=nics, dns_servers=dns,
|
||||||
authorized_ssh_keys=key)
|
authorized_ssh_keys=key)
|
||||||
action = params.Action(use_cloud_init=use_cloud_init, vm=params.VM(initialization=initialization))
|
action = params.Action(use_cloud_init=use_cloud_init, vm=params.VM(initialization=initialization))
|
||||||
vm.start(action=action)
|
vm.start(action=action)
|
||||||
|
|
||||||
|
|
||||||
# Stop instance
|
# Stop instance
|
||||||
def vm_stop(conn, vmname):
|
def vm_stop(conn, vmname):
|
||||||
vm = conn.vms.get(name=vmname)
|
vm = conn.vms.get(name=vmname)
|
||||||
vm.stop()
|
vm.stop()
|
||||||
|
|
||||||
|
|
||||||
# restart instance
|
# restart instance
|
||||||
def vm_restart(conn, vmname):
|
def vm_restart(conn, vmname):
|
||||||
state = vm_status(conn, vmname)
|
state = vm_status(conn, vmname)
|
||||||
|
@ -365,11 +319,13 @@ def vm_restart(conn, vmname):
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
vm.start()
|
vm.start()
|
||||||
|
|
||||||
|
|
||||||
# remove an instance
|
# remove an instance
|
||||||
def vm_remove(conn, vmname):
|
def vm_remove(conn, vmname):
|
||||||
vm = conn.vms.get(name=vmname)
|
vm = conn.vms.get(name=vmname)
|
||||||
vm.delete()
|
vm.delete()
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------- #
|
# ------------------------------------------------------------------- #
|
||||||
# VM statuses
|
# VM statuses
|
||||||
#
|
#
|
||||||
|
@ -395,76 +351,75 @@ def get_vm(conn, vmname):
|
||||||
# ------------------------------------------------------------------- #
|
# ------------------------------------------------------------------- #
|
||||||
# Main
|
# Main
|
||||||
|
|
||||||
def main():
|
|
||||||
|
|
||||||
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
state = dict(default='present', choices=['present', 'absent', 'shutdown', 'started', 'restart']),
|
state=dict(type='str', default='present', choices=['absent', 'present', 'restart', 'shutdown', 'started']),
|
||||||
#name = dict(required=True),
|
user=dict(type='str', required=True),
|
||||||
user = dict(required=True),
|
url=dict(type='str', required=True),
|
||||||
url = dict(required=True),
|
instance_name=dict(type='str', required=True, aliases=['vmname']),
|
||||||
instance_name = dict(required=True, aliases=['vmname']),
|
password=dict(type='str', required=True, no_log=True),
|
||||||
password = dict(required=True, no_log=True),
|
image=dict(type='str'),
|
||||||
image = dict(),
|
resource_type=dict(type='str', choices=['new', 'template']),
|
||||||
resource_type = dict(choices=['new', 'template']),
|
zone=dict(type='str'),
|
||||||
zone = dict(),
|
instance_disksize=dict(type='str', aliases=['vm_disksize']),
|
||||||
instance_disksize = dict(aliases=['vm_disksize']),
|
instance_cpus=dict(type='str', default=1, aliases=['vmcpus']),
|
||||||
instance_cpus = dict(default=1, aliases=['vmcpus']),
|
instance_nic=dict(type='str', aliases=['vmnic']),
|
||||||
instance_nic = dict(aliases=['vmnic']),
|
instance_network=dict(type='str', default='rhevm', aliases=['vmnetwork']),
|
||||||
instance_network = dict(default='rhevm', aliases=['vmnetwork']),
|
instance_mem=dict(type='str', aliases=['vmmem']),
|
||||||
instance_mem = dict(aliases=['vmmem']),
|
instance_type=dict(type='str', default='server', aliases=['vmtype'], choices=['desktop', 'server']),
|
||||||
instance_type = dict(default='server', aliases=['vmtype'], choices=['server', 'desktop']),
|
disk_alloc=dict(type='str', default='thin', choices=['preallocated', 'thin']),
|
||||||
disk_alloc = dict(default='thin', choices=['thin', 'preallocated']),
|
disk_int=dict(type='str', default='virtio', choices=['ide', 'virtio']),
|
||||||
disk_int = dict(default='virtio', choices=['virtio', 'ide']),
|
instance_os=dict(type='str', aliases=['vmos']),
|
||||||
instance_os = dict(aliases=['vmos']),
|
instance_cores=dict(type='str', default=1, aliases=['vmcores']),
|
||||||
instance_cores = dict(default=1, aliases=['vmcores']),
|
instance_hostname=dict(type='str', aliases=['hostname']),
|
||||||
instance_hostname = dict(aliases=['hostname']),
|
instance_ip=dict(type='str', aliases=['ip']),
|
||||||
instance_ip = dict(aliases=['ip']),
|
instance_netmask=dict(type='str', aliases=['netmask']),
|
||||||
instance_netmask = dict(aliases=['netmask']),
|
instance_gateway=dict(type='str', aliases=['gateway']),
|
||||||
instance_gateway = dict(aliases=['gateway']),
|
instance_domain=dict(type='str', aliases=['domain']),
|
||||||
instance_domain = dict(aliases=['domain']),
|
instance_dns=dict(type='str', aliases=['dns']),
|
||||||
instance_dns = dict(aliases=['dns']),
|
instance_rootpw=dict(type='str', aliases=['rootpw']),
|
||||||
instance_rootpw = dict(aliases=['rootpw']),
|
instance_key=dict(type='str', aliases=['key']),
|
||||||
instance_key = dict(aliases=['key']),
|
sdomain=dict(type='str'),
|
||||||
sdomain = dict(),
|
region=dict(type='str'),
|
||||||
region = dict(),
|
),
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not HAS_OVIRTSDK:
|
if not HAS_OVIRTSDK:
|
||||||
module.fail_json(msg='ovirtsdk required for this module')
|
module.fail_json(msg='ovirtsdk required for this module')
|
||||||
|
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
user = module.params['user']
|
user = module.params['user']
|
||||||
url = module.params['url']
|
url = module.params['url']
|
||||||
vmname = module.params['instance_name']
|
vmname = module.params['instance_name']
|
||||||
password = module.params['password']
|
password = module.params['password']
|
||||||
image = module.params['image'] # name of the image to deploy
|
image = module.params['image'] # name of the image to deploy
|
||||||
resource_type = module.params['resource_type'] # template or from scratch
|
resource_type = module.params['resource_type'] # template or from scratch
|
||||||
zone = module.params['zone'] # oVirt cluster
|
zone = module.params['zone'] # oVirt cluster
|
||||||
vmdisk_size = module.params['instance_disksize'] # disksize
|
vmdisk_size = module.params['instance_disksize'] # disksize
|
||||||
vmcpus = module.params['instance_cpus'] # number of cpu
|
vmcpus = module.params['instance_cpus'] # number of cpu
|
||||||
vmnic = module.params['instance_nic'] # network interface
|
vmnic = module.params['instance_nic'] # network interface
|
||||||
vmnetwork = module.params['instance_network'] # logical network
|
vmnetwork = module.params['instance_network'] # logical network
|
||||||
vmmem = module.params['instance_mem'] # mem size
|
vmmem = module.params['instance_mem'] # mem size
|
||||||
vmdisk_alloc = module.params['disk_alloc'] # thin, preallocated
|
vmdisk_alloc = module.params['disk_alloc'] # thin, preallocated
|
||||||
vmdisk_int = module.params['disk_int'] # disk interface virtio or ide
|
vmdisk_int = module.params['disk_int'] # disk interface virtio or ide
|
||||||
vmos = module.params['instance_os'] # Operating System
|
vmos = module.params['instance_os'] # Operating System
|
||||||
vmtype = module.params['instance_type'] # server or desktop
|
vmtype = module.params['instance_type'] # server or desktop
|
||||||
vmcores = module.params['instance_cores'] # number of cores
|
vmcores = module.params['instance_cores'] # number of cores
|
||||||
sdomain = module.params['sdomain'] # storage domain to store disk on
|
sdomain = module.params['sdomain'] # storage domain to store disk on
|
||||||
region = module.params['region'] # oVirt Datacenter
|
region = module.params['region'] # oVirt Datacenter
|
||||||
hostname = module.params['instance_hostname']
|
hostname = module.params['instance_hostname']
|
||||||
ip = module.params['instance_ip']
|
ip = module.params['instance_ip']
|
||||||
netmask = module.params['instance_netmask']
|
netmask = module.params['instance_netmask']
|
||||||
gateway = module.params['instance_gateway']
|
gateway = module.params['instance_gateway']
|
||||||
domain = module.params['instance_domain']
|
domain = module.params['instance_domain']
|
||||||
dns = module.params['instance_dns']
|
dns = module.params['instance_dns']
|
||||||
rootpw = module.params['instance_rootpw']
|
rootpw = module.params['instance_rootpw']
|
||||||
key = module.params['instance_key']
|
key = module.params['instance_key']
|
||||||
#initialize connection
|
# initialize connection
|
||||||
try:
|
try:
|
||||||
c = conn(url+"/api", user, password)
|
c = conn(url + "/api", user, password)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg='%s' % e)
|
module.fail_json(msg='%s' % e)
|
||||||
|
|
||||||
|
@ -475,14 +430,14 @@ def main():
|
||||||
create_vm_template(c, vmname, image, zone)
|
create_vm_template(c, vmname, image, zone)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg='%s' % 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':
|
elif resource_type == 'new':
|
||||||
# FIXME: refactor, use keyword args.
|
# FIXME: refactor, use keyword args.
|
||||||
try:
|
try:
|
||||||
create_vm(c, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, vmmem, vmdisk_alloc, sdomain, vmcores, vmos, vmdisk_int)
|
create_vm(c, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, vmmem, vmdisk_alloc, sdomain, vmcores, vmos, vmdisk_int)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg='%s' % 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:
|
else:
|
||||||
module.exit_json(changed=False, msg="You did not specify a resource type")
|
module.exit_json(changed=False, msg="You did not specify a resource type")
|
||||||
else:
|
else:
|
||||||
|
@ -492,7 +447,7 @@ def main():
|
||||||
if vm_status(c, vmname) == 'up':
|
if vm_status(c, vmname) == 'up':
|
||||||
module.exit_json(changed=False, msg="VM %s is already running" % vmname)
|
module.exit_json(changed=False, msg="VM %s is already running" % vmname)
|
||||||
else:
|
else:
|
||||||
#vm_start(c, vmname)
|
# vm_start(c, vmname)
|
||||||
vm_start(c, vmname, hostname, ip, netmask, gateway, domain, dns, rootpw, key)
|
vm_start(c, vmname, hostname, ip, netmask, gateway, domain, dns, rootpw, key)
|
||||||
module.exit_json(changed=True, msg="VM %s started" % vmname)
|
module.exit_json(changed=True, msg="VM %s started" % vmname)
|
||||||
|
|
||||||
|
|
|
@ -1,85 +1,67 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
|
||||||
# Copyright (c) 2016 Red Hat, Inc.
|
# Copyright: (c) 2017, Ansible Project
|
||||||
#
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# 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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: ovirt_affinity_group
|
module: ovirt_affinity_group
|
||||||
short_description: Module to manage affinity groups in oVirt/RHV
|
short_description: Module to manage affinity groups in oVirt/RHV
|
||||||
version_added: "2.3"
|
version_added: "2.3"
|
||||||
author: "Ondra Machacek (@machacekondra)"
|
author:
|
||||||
|
- Ondra Machacek (@machacekondra)
|
||||||
description:
|
description:
|
||||||
- "This module manage affinity groups in oVirt/RHV. It can also manage assignments
|
- "This module manage affinity groups in oVirt/RHV. It can also manage assignments
|
||||||
of those groups to VMs."
|
of those groups to VMs."
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- "Name of the affinity group to manage."
|
- Name of the affinity group to manage.
|
||||||
required: true
|
required: true
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- "Should the affinity group be present or absent."
|
- Should the affinity group be present or absent.
|
||||||
choices: ['present', 'absent']
|
choices: [ absent, present ]
|
||||||
default: present
|
default: present
|
||||||
cluster:
|
cluster:
|
||||||
description:
|
description:
|
||||||
- "Name of the cluster of the affinity group."
|
- Name of the cluster of the affinity group.
|
||||||
description:
|
description:
|
||||||
description:
|
description:
|
||||||
- "Description of the affinity group."
|
- Description of the affinity group.
|
||||||
host_enforcing:
|
host_enforcing:
|
||||||
description:
|
description:
|
||||||
- "If I(true) VM cannot start on host if it does not satisfy the C(host_rule)."
|
- If I(yes) 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.)"
|
- This parameter is support since oVirt/RHV 4.1 version.
|
||||||
|
type: bool
|
||||||
host_rule:
|
host_rule:
|
||||||
description:
|
description:
|
||||||
- "If I(positive) I(all) VMs in this group should run on the this host."
|
- 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."
|
- 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.)"
|
- This parameter is support since oVirt/RHV 4.1 version.
|
||||||
choices:
|
choices: [ negative, positive ]
|
||||||
- positive
|
|
||||||
- negative
|
|
||||||
vm_enforcing:
|
vm_enforcing:
|
||||||
description:
|
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:
|
vm_rule:
|
||||||
description:
|
description:
|
||||||
- "If I(positive) I(all) VMs in this group should run on the host defined by C(host_rule)."
|
- 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(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."
|
- If I(disabled) this affinity group doesn't take effect.
|
||||||
choices:
|
choices: [ disabled, negative, positive ]
|
||||||
- positive
|
|
||||||
- negative
|
|
||||||
- disabled
|
|
||||||
vms:
|
vms:
|
||||||
description:
|
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:
|
hosts:
|
||||||
description:
|
description:
|
||||||
- "List of the hosts names, which should have assigned this affinity group."
|
- List of the hosts names, which should have assigned this affinity group.
|
||||||
- "C(This parameter is support since oVirt/RHV 4.1 version.)"
|
- This parameter is support since oVirt/RHV 4.1 version.
|
||||||
extends_documentation_fragment: ovirt
|
extends_documentation_fragment: ovirt
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -87,8 +69,8 @@ EXAMPLES = '''
|
||||||
# Examples don't contain auth parameter for simplicity,
|
# Examples don't contain auth parameter for simplicity,
|
||||||
# look at ovirt_auth module to see how to reuse authentication:
|
# 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
|
- name: Create(if not exists) and assign affinity group to VMs vm1 and vm2 and host host1
|
||||||
- ovirt_affinity_group:
|
ovirt_affinity_group:
|
||||||
name: mygroup
|
name: mygroup
|
||||||
cluster: mycluster
|
cluster: mycluster
|
||||||
vm_enforcing: true
|
vm_enforcing: true
|
||||||
|
@ -101,8 +83,8 @@ EXAMPLES = '''
|
||||||
hosts:
|
hosts:
|
||||||
- host1
|
- host1
|
||||||
|
|
||||||
# Detach VMs from affinity group and disable VM rule:
|
- name: Detach VMs from affinity group and disable VM rule
|
||||||
- ovirt_affinity_group:
|
ovirt_affinity_group:
|
||||||
name: mygroup
|
name: mygroup
|
||||||
cluster: mycluster
|
cluster: mycluster
|
||||||
vm_enforcing: false
|
vm_enforcing: false
|
||||||
|
@ -114,8 +96,8 @@ EXAMPLES = '''
|
||||||
- host1
|
- host1
|
||||||
- host2
|
- host2
|
||||||
|
|
||||||
# Remove affinity group
|
- name: Remove affinity group
|
||||||
- ovirt_affinity_group:
|
ovirt_affinity_group:
|
||||||
state: absent
|
state: absent
|
||||||
cluster: mycluster
|
cluster: mycluster
|
||||||
name: mygroup
|
name: mygroup
|
||||||
|
@ -245,13 +227,10 @@ class AffinityGroupsModule(BaseModule):
|
||||||
def update_check(self, entity):
|
def update_check(self, entity):
|
||||||
assigned_vms = self.assigned_vms(entity)
|
assigned_vms = self.assigned_vms(entity)
|
||||||
do_update = (
|
do_update = (
|
||||||
equal(self.param('description'), entity.description)
|
equal(self.param('description'), entity.description) and equal(self.param('vm_enforcing'), entity.enforcing) and equal(
|
||||||
and equal(self.param('vm_enforcing'), entity.enforcing)
|
|
||||||
and equal(
|
|
||||||
self.param('vm_rule') == 'positive' if self.param('vm_rule') else None,
|
self.param('vm_rule') == 'positive' if self.param('vm_rule') else None,
|
||||||
entity.positive
|
entity.positive
|
||||||
)
|
) and equal(self._vm_ids, assigned_vms)
|
||||||
and equal(self._vm_ids, assigned_vms)
|
|
||||||
)
|
)
|
||||||
# Following attributes is supported since 4.1,
|
# Following attributes is supported since 4.1,
|
||||||
# so return if it doesn't exist:
|
# so return if it doesn't exist:
|
||||||
|
@ -262,32 +241,24 @@ class AffinityGroupsModule(BaseModule):
|
||||||
return do_update and (
|
return do_update and (
|
||||||
equal(
|
equal(
|
||||||
self.param('host_rule') == 'positive' if self.param('host_rule') else None,
|
self.param('host_rule') == 'positive' if self.param('host_rule') else None,
|
||||||
entity.hosts_rule.positive
|
entity.hosts_rule.positive) and equal(self.param('host_enforcing'), entity.hosts_rule.enforcing) and equal(
|
||||||
)
|
|
||||||
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,
|
self.param('vm_rule') in ['negative', 'positive'] if self.param('vm_rule') else None,
|
||||||
entity.vms_rule.enabled
|
entity.vms_rule.enabled) and equal(self._host_ids, sorted([host.id for host in entity.hosts]))
|
||||||
)
|
|
||||||
and equal(self._host_ids, sorted([host.id for host in entity.hosts]))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ovirt_full_argument_spec(
|
argument_spec = ovirt_full_argument_spec(
|
||||||
state=dict(
|
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||||
choices=['present', 'absent'],
|
cluster=dict(type='str', required=True),
|
||||||
default='present',
|
name=dict(type='str', required=True),
|
||||||
),
|
description=dict(type='str'),
|
||||||
cluster=dict(default=None, required=True),
|
vm_enforcing=dict(type='bool'),
|
||||||
name=dict(default=None, required=True),
|
vm_rule=dict(type='str', choices=['disabled', 'negative', 'positive']),
|
||||||
description=dict(default=None),
|
host_enforcing=dict(type='bool'),
|
||||||
vm_enforcing=dict(default=None, type='bool'),
|
host_rule=dict(type='str', choices=['negative', 'positive']),
|
||||||
vm_rule=dict(default=None, choices=['positive', 'negative', 'disabled']),
|
vms=dict(type='list'),
|
||||||
host_enforcing=dict(default=None, type='bool'),
|
hosts=dict(type='list'),
|
||||||
host_rule=dict(default=None, choices=['positive', 'negative']),
|
|
||||||
vms=dict(default=None, type='list'),
|
|
||||||
hosts=dict(default=None, type='list'),
|
|
||||||
)
|
)
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
|
|
|
@ -1,71 +1,56 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
|
||||||
# Copyright (c) 2016 Red Hat, Inc.
|
# Copyright: (c) 2017, Ansible Project
|
||||||
#
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# 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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: ovirt_nics
|
module: ovirt_nics
|
||||||
short_description: Module to manage network interfaces of Virtual Machines in oVirt/RHV
|
short_description: Module to manage network interfaces of Virtual Machines in oVirt/RHV
|
||||||
version_added: "2.3"
|
version_added: "2.3"
|
||||||
author: "Ondra Machacek (@machacekondra)"
|
author:
|
||||||
|
- Ondra Machacek (@machacekondra)
|
||||||
description:
|
description:
|
||||||
- "Module to manage network interfaces of Virtual Machines in oVirt/RHV."
|
- Module to manage network interfaces of Virtual Machines in oVirt/RHV.
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- "Name of the network interface to manage."
|
- Name of the network interface to manage.
|
||||||
required: true
|
required: true
|
||||||
vm:
|
vm:
|
||||||
description:
|
description:
|
||||||
- "Name of the Virtual Machine to manage."
|
- Name of the Virtual Machine to manage.
|
||||||
- "You must provide either C(vm) parameter or C(template) parameter."
|
- You must provide either C(vm) parameter or C(template) parameter.
|
||||||
template:
|
template:
|
||||||
description:
|
description:
|
||||||
- "Name of the template to manage."
|
- Name of the template to manage.
|
||||||
- "You must provide either C(vm) parameter or C(template) parameter."
|
- You must provide either C(vm) parameter or C(template) parameter.
|
||||||
version_added: "2.4"
|
version_added: "2.4"
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- "Should the Virtual Machine NIC be present/absent/plugged/unplugged."
|
- Should the Virtual Machine NIC be present/absent/plugged/unplugged.
|
||||||
choices: ['present', 'absent', 'plugged', 'unplugged']
|
choices: [ absent, plugged, present, unplugged ]
|
||||||
default: present
|
default: present
|
||||||
network:
|
network:
|
||||||
description:
|
description:
|
||||||
- "Logical network to which the VM network interface should use,
|
- Logical network to which the VM network interface should use,
|
||||||
by default Empty network is used if network is not specified."
|
by default Empty network is used if network is not specified.
|
||||||
profile:
|
profile:
|
||||||
description:
|
description:
|
||||||
- "Virtual network interface profile to be attached to VM network interface."
|
- Virtual network interface profile to be attached to VM network interface.
|
||||||
interface:
|
interface:
|
||||||
description:
|
description:
|
||||||
- "Type of the network interface."
|
- Type of the network interface.
|
||||||
choices: ['virtio', 'e1000', 'rtl8139', 'pci_passthrough', 'rtl8139_virtio', 'spapr_vlan']
|
choices: [ e1000, pci_passthrough, rtl8139, rtl8139_virtio, spapr_vlan, virtio ]
|
||||||
default: 'virtio'
|
default: virtio
|
||||||
mac_address:
|
mac_address:
|
||||||
description:
|
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
|
extends_documentation_fragment: ovirt
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -73,8 +58,8 @@ EXAMPLES = '''
|
||||||
# Examples don't contain auth parameter for simplicity,
|
# Examples don't contain auth parameter for simplicity,
|
||||||
# look at ovirt_auth module to see how to reuse authentication:
|
# look at ovirt_auth module to see how to reuse authentication:
|
||||||
|
|
||||||
# Add NIC to VM
|
- name: Add NIC to VM
|
||||||
- ovirt_nics:
|
ovirt_nics:
|
||||||
state: present
|
state: present
|
||||||
vm: myvm
|
vm: myvm
|
||||||
name: mynic
|
name: mynic
|
||||||
|
@ -83,21 +68,20 @@ EXAMPLES = '''
|
||||||
profile: ovirtmgmt
|
profile: ovirtmgmt
|
||||||
network: ovirtmgmt
|
network: ovirtmgmt
|
||||||
|
|
||||||
# Plug NIC to VM
|
- name: Plug NIC to VM
|
||||||
- ovirt_nics:
|
ovirt_nics:
|
||||||
state: plugged
|
state: plugged
|
||||||
vm: myvm
|
vm: myvm
|
||||||
name: mynic
|
name: mynic
|
||||||
|
|
||||||
# Unplug NIC from VM
|
- name: Unplug NIC from VM
|
||||||
- ovirt_nics:
|
ovirt_nics:
|
||||||
state: unplugged
|
state: unplugged
|
||||||
vm: myvm
|
vm: myvm
|
||||||
name: mynic
|
name: mynic
|
||||||
|
|
||||||
|
- name: Add NIC to template
|
||||||
# add NIC to template
|
ovirt_nics:
|
||||||
- ovirt_nics:
|
|
||||||
auth: "{{ ovirt_auth }}"
|
auth: "{{ ovirt_auth }}"
|
||||||
state: present
|
state: present
|
||||||
template: my_template
|
template: my_template
|
||||||
|
@ -106,13 +90,11 @@ EXAMPLES = '''
|
||||||
profile: ovirtmgmt
|
profile: ovirtmgmt
|
||||||
network: ovirtmgmt
|
network: ovirtmgmt
|
||||||
|
|
||||||
|
- name: Remove NIC from VM
|
||||||
# Remove NIC from VM
|
ovirt_nics:
|
||||||
- ovirt_nics:
|
|
||||||
state: absent
|
state: absent
|
||||||
vm: myvm
|
vm: myvm
|
||||||
name: mynic
|
name: mynic
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -191,22 +173,19 @@ class EntityNicsModule(BaseModule):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ovirt_full_argument_spec(
|
argument_spec = ovirt_full_argument_spec(
|
||||||
state=dict(
|
state=dict(type='str', default='present', choices=['absent', 'plugged', 'present', 'unplugged']),
|
||||||
choices=['present', 'absent', 'plugged', 'unplugged'],
|
vm=dict(type='str'),
|
||||||
default='present'
|
template=dict(type='str'),
|
||||||
),
|
name=dict(type='str', required=True),
|
||||||
vm=dict(required=False),
|
interface=dict(type='str'),
|
||||||
template=dict(required=False),
|
profile=dict(type='str'),
|
||||||
name=dict(required=True),
|
network=dict(type='str'),
|
||||||
interface=dict(default=None),
|
mac_address=dict(type='str'),
|
||||||
profile=dict(default=None),
|
|
||||||
network=dict(default=None),
|
|
||||||
mac_address=dict(default=None),
|
|
||||||
)
|
)
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
required_one_of=[['vm', 'template']]
|
required_one_of=[['vm', 'template']],
|
||||||
)
|
)
|
||||||
check_sdk(module)
|
check_sdk(module)
|
||||||
|
|
||||||
|
@ -249,7 +228,7 @@ def main():
|
||||||
networks_service = dcs_service.service(dc.id).networks_service()
|
networks_service = dcs_service.service(dc.id).networks_service()
|
||||||
network = next(
|
network = next(
|
||||||
(n for n in networks_service.list()
|
(n for n in networks_service.list()
|
||||||
if n.name == module.params['network']),
|
if n.name == module.params['network']),
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
if network is None:
|
if network is None:
|
||||||
|
|
|
@ -1,92 +1,75 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
|
||||||
# Copyright (c) 2016 Red Hat, Inc.
|
# Copyright: (c) 2017, Ansible Project
|
||||||
#
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# 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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: ovirt_permissions
|
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"
|
version_added: "2.3"
|
||||||
author: "Ondra Machacek (@machacekondra)"
|
author:
|
||||||
|
- Ondra Machacek (@machacekondra)
|
||||||
description:
|
description:
|
||||||
- "Module to manage permissions of users/groups in oVirt/RHV"
|
- Module to manage permissions of users/groups in oVirt/RHV.
|
||||||
options:
|
options:
|
||||||
role:
|
role:
|
||||||
description:
|
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
|
default: UserRole
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- "Should the permission be present/absent."
|
- Should the permission be present/absent.
|
||||||
choices: ['present', 'absent']
|
choices: [ absent, present ]
|
||||||
default: present
|
default: present
|
||||||
object_id:
|
object_id:
|
||||||
description:
|
description:
|
||||||
- "ID of the object where the permissions should be managed."
|
- ID of the object where the permissions should be managed.
|
||||||
object_name:
|
object_name:
|
||||||
description:
|
description:
|
||||||
- "Name of the object where the permissions should be managed."
|
- Name of the object where the permissions should be managed.
|
||||||
object_type:
|
object_type:
|
||||||
description:
|
description:
|
||||||
- "The object where the permissions should be managed."
|
- The object where the permissions should be managed.
|
||||||
default: 'vm'
|
choices:
|
||||||
choices: [
|
- cluster
|
||||||
'data_center',
|
- cpu_profile
|
||||||
'cluster',
|
- data_center
|
||||||
'host',
|
- disk
|
||||||
'storage_domain',
|
- disk_profile
|
||||||
'network',
|
- host
|
||||||
'disk',
|
- network
|
||||||
'vm',
|
- storage_domain
|
||||||
'vm_pool',
|
- system
|
||||||
'template',
|
- template
|
||||||
'cpu_profile',
|
- vm
|
||||||
'disk_profile',
|
- vm_pool
|
||||||
'vnic_profile',
|
- vnic_profile
|
||||||
'system',
|
default: vm
|
||||||
]
|
|
||||||
user_name:
|
user_name:
|
||||||
description:
|
description:
|
||||||
- "Username of the user to manage. In most LDAPs it's I(uid) of the user,
|
- 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."
|
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,
|
- 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."
|
you should ensure the user exists by using M(ovirt_users) module.
|
||||||
group_name:
|
group_name:
|
||||||
description:
|
description:
|
||||||
- "Name of the group to manage."
|
- Name of the group to manage.
|
||||||
- "Note that if group don't exist in the system this module will fail,
|
- 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."
|
you should ensure the group exists by using M(ovirt_groups) module.
|
||||||
authz_name:
|
authz_name:
|
||||||
description:
|
description:
|
||||||
- "Authorization provider of the user/group. In previous versions of oVirt/RHV known as domain."
|
- Authorization provider of the user/group.
|
||||||
required: true
|
required: true
|
||||||
aliases: ['domain']
|
aliases: [ domain ]
|
||||||
namespace:
|
namespace:
|
||||||
description:
|
description:
|
||||||
- "Namespace of the authorization provider, where user/group resides."
|
- Namespace of the authorization provider, where user/group resides.
|
||||||
required: false
|
|
||||||
extends_documentation_fragment: ovirt
|
extends_documentation_fragment: ovirt
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -94,16 +77,16 @@ EXAMPLES = '''
|
||||||
# Examples don't contain auth parameter for simplicity,
|
# Examples don't contain auth parameter for simplicity,
|
||||||
# look at ovirt_auth module to see how to reuse authentication:
|
# look at ovirt_auth module to see how to reuse authentication:
|
||||||
|
|
||||||
# Add user user1 from authorization provider example.com-authz
|
- name: Add user user1 from authorization provider example.com-authz
|
||||||
- ovirt_permissions:
|
ovirt_permissions:
|
||||||
user_name: user1
|
user_name: user1
|
||||||
authz_name: example.com-authz
|
authz_name: example.com-authz
|
||||||
object_type: vm
|
object_type: vm
|
||||||
object_name: myvm
|
object_name: myvm
|
||||||
role: UserVmManager
|
role: UserVmManager
|
||||||
|
|
||||||
# Remove permission from user
|
- name: Remove permission from user
|
||||||
- ovirt_permissions:
|
ovirt_permissions:
|
||||||
state: absent
|
state: absent
|
||||||
user_name: user1
|
user_name: user1
|
||||||
authz_name: example.com-authz
|
authz_name: example.com-authz
|
||||||
|
@ -241,35 +224,30 @@ class PermissionsModule(BaseModule):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ovirt_full_argument_spec(
|
argument_spec = ovirt_full_argument_spec(
|
||||||
state=dict(
|
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||||
choices=['present', 'absent'],
|
role=dict(type='str', default='UserRole'),
|
||||||
default='present',
|
object_type=dict(type='str', default='vm',
|
||||||
),
|
choices=[
|
||||||
role=dict(default='UserRole'),
|
'cluster',
|
||||||
object_type=dict(
|
'cpu_profile',
|
||||||
default='vm',
|
'data_center',
|
||||||
choices=[
|
'disk',
|
||||||
'data_center',
|
'disk_profile',
|
||||||
'cluster',
|
'host',
|
||||||
'host',
|
'network',
|
||||||
'storage_domain',
|
'storage_domain',
|
||||||
'network',
|
'system',
|
||||||
'disk',
|
'template',
|
||||||
'vm',
|
'vm',
|
||||||
'vm_pool',
|
'vm_pool',
|
||||||
'template',
|
'vnic_profile',
|
||||||
'cpu_profile',
|
]),
|
||||||
'disk_profile',
|
authz_name=dict(type='str', required=True, aliases=['domain']),
|
||||||
'vnic_profile',
|
object_id=dict(type='str'),
|
||||||
'system',
|
object_name=dict(type='str'),
|
||||||
]
|
user_name=dict(type='str'),
|
||||||
),
|
group_name=dict(type='str'),
|
||||||
authz_name=dict(required=True, aliases=['domain']),
|
namespace=dict(type='str'),
|
||||||
object_id=dict(default=None),
|
|
||||||
object_name=dict(default=None),
|
|
||||||
user_name=dict(rdefault=None),
|
|
||||||
group_name=dict(default=None),
|
|
||||||
namespace=dict(default=None),
|
|
||||||
)
|
)
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
|
@ -277,10 +255,7 @@ def main():
|
||||||
)
|
)
|
||||||
check_sdk(module)
|
check_sdk(module)
|
||||||
|
|
||||||
if (
|
if (module.params['object_name'] is None and module.params['object_id'] is None) and module.params['object_type'] != 'system':
|
||||||
(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')
|
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:
|
if module.params['user_name'] is None and module.params['group_name'] is None:
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -70,7 +70,6 @@ lib/ansible/modules/cloud/google/gcpubsub.py
|
||||||
lib/ansible/modules/cloud/google/gcspanner.py
|
lib/ansible/modules/cloud/google/gcspanner.py
|
||||||
lib/ansible/modules/cloud/lxc/lxc_container.py
|
lib/ansible/modules/cloud/lxc/lxc_container.py
|
||||||
lib/ansible/modules/cloud/lxd/lxd_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/rhevm.py
|
||||||
lib/ansible/modules/cloud/misc/serverless.py
|
lib/ansible/modules/cloud/misc/serverless.py
|
||||||
lib/ansible/modules/cloud/misc/virt_net.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_server.py
|
||||||
lib/ansible/modules/cloud/openstack/os_stack.py
|
lib/ansible/modules/cloud/openstack/os_stack.py
|
||||||
lib/ansible/modules/cloud/ovh/ovh_ip_loadbalancing_backend.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/packet/packet_sshkey.py
|
||||||
lib/ansible/modules/cloud/profitbricks/profitbricks.py
|
lib/ansible/modules/cloud/profitbricks/profitbricks.py
|
||||||
lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py
|
lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue