1
0
mirror of https://github.com/oVirt/ovirt-ansible-vm-infra.git synced 2026-02-05 12:45:39 +01:00

Add wait for ip range (#80)

* add wait for ip range

* update ip filtration

* Update README.md

* fix pep formating
This commit is contained in:
Martin Nečas
2019-06-12 12:00:23 +02:00
committed by Ondra Machacek
parent f195db2892
commit a6f12ec945
5 changed files with 21 additions and 8 deletions

View File

@@ -65,6 +65,7 @@ Role Variables
| affinity_groups | UNDEF | List of dictionaries with affinity groups specifications. |
| wait_for_ip | false | If true, the playbook should wait for the virtual machine IP reported by the guest agent. |
| wait_for_ip_version | v4 | Specify which IP version should be wait for. Either v4 or v6. |
| wait_for_ip_range | 0.0.0.0/0 | Specify CIDR of virutal machine IP which should be reported. Works only for IPv4. |
| debug_vm_create | false | If true, logs the tasks of the virtual machine being created. The log can contain passwords. |
| vm_infra_create_single_timeout | 180 | Time in seconds to wait for VM to be created and started (if state is running). |
| vm_infra_create_poll_interval | 15 | Polling interval. Time in seconds to wait between check of state of VM. |

View File

@@ -2,6 +2,7 @@
debug_vm_create: false
wait_for_ip: false
wait_for_ip_version: v4
wait_for_ip_range: "0.0.0.0/0"
# Create VMs timeouts:
vm_infra_create_single_timeout: 180

View File

@@ -30,19 +30,21 @@ class FilterModule(object):
'Return list of IPs'
return self._parse_ips(ovirt_vms, attr=attr)
def ovirtvmipv4(self, ovirt_vms, attr=None):
def ovirtvmipv4(self, ovirt_vms, attr=None, network_ip=None):
'Return first IPv4 IP'
return self.__get_first_ip(self.ovirtvmipsv4(ovirt_vms, attr))
return self.__get_first_ip(self.ovirtvmipsv4(ovirt_vms, attr, network_ip))
def ovirtvmipsv4(self, ovirt_vms, attr=None):
def ovirtvmipsv4(self, ovirt_vms, attr=None, network_ip=None):
'Return list of IPv4 IPs'
return self._parse_ips(ovirt_vms, lambda version: version == 'v4', attr)
ips = self._parse_ips(ovirt_vms, lambda version: version == 'v4', attr)
resp = [ip for ip in ips if self.__address_in_network(ip, network_ip)]
return resp
def ovirtvmipv6(self, ovirt_vms, attr=None):
def ovirtvmipv6(self, ovirt_vms, attr=None, network_ip=None):
'Return first IPv6 IP'
return self.__get_first_ip(self.ovirtvmipsv6(ovirt_vms, attr))
def ovirtvmipsv6(self, ovirt_vms, attr=None):
def ovirtvmipsv6(self, ovirt_vms, attr=None, network_ip=None):
'Return list of IPv6 IPs'
return self._parse_ips(ovirt_vms, lambda version: version == 'v6', attr)
@@ -80,3 +82,12 @@ class FilterModule(object):
@staticmethod
def __get_first_ip(res):
return res[0] if isinstance(res, list) and res else res
def __address_in_network(self, ip, net):
"Return boolean if IP is in network."
import socket, struct
ipaddr = int(''.join(['%02x' % int(x) for x in ip.split('.')]), 16)
netstr, bits = net.split('/')
netaddr = int(''.join(['%02x' % int(x) for x in netstr.split('.')]), 16)
mask = (0xffffffff << (32 - int(bits))) & 0xffffffff
return (ipaddr & mask) == (netaddr & mask)

View File

@@ -12,7 +12,7 @@
no_log: false
add_host:
name: "{{ item.name }}"
ansible_host: "{{ item | ovirtvmipv4 }}"
ansible_host: "{{ item | ovirtvmipv4(network_ip=wait_for_ip_range) }}"
groups: "{{ (['ovirt_tag_'] * item.tags | length) | zip(item.tags | map(attribute='name') | list) | map('join') | list + ['ovirt_vm'] }}"
ansible_user: root
ansible_password: "{{ vms_passwords | filtervalue('name', item.name) | map(attribute='root_password') | first | default(omit) }}"

View File

@@ -103,7 +103,7 @@
- block:
- set_fact:
ip_cond: "ovirt_vms | ovirtvmip{{ wait_for_ip_version }} | length > 0"
ip_cond: "ovirt_vms | ovirtvmip{{ wait_for_ip_version }}(network_ip='{{ wait_for_ip_range }}') | length > 0"
- name: Wait for VMs IP
ovirt_vm_facts: