summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Rozet <trozet@redhat.com>2017-09-22 10:35:53 -0400
committerTim Rozet <trozet@redhat.com>2017-09-22 10:35:53 -0400
commit57c0f8adbb5dabe9ddd66b049b543c596fa0f068 (patch)
tree8551a7835a7535f3ae817d322c38614837362655
parentfbc49a7d84eefbecb2ef9774bae99d30e66a52be (diff)
Adds detection for virsh default network IP
In case a user already has a default virsh network and the default IP is not 192.168.122.1, this patch will allow detecting and using the found value. Change-Id: Id5d46a820d89e86c9b5897f5d29b83ed32f9d6f9 Signed-off-by: Tim Rozet <trozet@redhat.com>
-rw-r--r--apex/virtual/virtual_utils.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/apex/virtual/virtual_utils.py b/apex/virtual/virtual_utils.py
index 255d2c69..1fe2c399 100644
--- a/apex/virtual/virtual_utils.py
+++ b/apex/virtual/virtual_utils.py
@@ -14,6 +14,7 @@ import os
import platform
import pprint
import subprocess
+import xml.etree.ElementTree as ET
from apex.common import utils
from apex.virtual import configure_vm as vm_lib
@@ -26,6 +27,28 @@ DEFAULT_PASS = 'password'
DEFAULT_VIRT_IP = '192.168.122.1'
+def get_virt_ip():
+ try:
+ virsh_net_xml = subprocess.check_output(['virsh', 'net-dumpxml',
+ 'default'],
+ stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError:
+ logging.warning('Unable to detect default virsh network IP. Will '
+ 'use 192.168.122.1')
+ return DEFAULT_VIRT_IP
+
+ tree = ET.fromstring(virsh_net_xml)
+ ip_tag = tree.find('ip')
+ if ip_tag:
+ virsh_ip = ip_tag.get('address')
+ if virsh_ip:
+ logging.debug("Detected virsh default network ip: "
+ "{}".format(virsh_ip))
+ return virsh_ip
+
+ return DEFAULT_VIRT_IP
+
+
def generate_inventory(target_file, ha_enabled=False, num_computes=1,
controller_ram=DEFAULT_RAM, arch=platform.machine(),
compute_ram=DEFAULT_RAM, vcpus=4):
@@ -42,7 +65,7 @@ def generate_inventory(target_file, ha_enabled=False, num_computes=1,
"""
node = {'mac_address': '',
- 'ipmi_ip': DEFAULT_VIRT_IP,
+ 'ipmi_ip': get_virt_ip(),
'ipmi_user': DEFAULT_USER,
'ipmi_pass': DEFAULT_PASS,
'pm_type': 'pxe_ipmitool',
@@ -86,7 +109,7 @@ def host_setup(node):
vbmc_manager = vbmc_lib.VirtualBMCManager()
for name, port in node.items():
vbmc_manager.add(username=DEFAULT_USER, password=DEFAULT_PASS,
- port=port, address=DEFAULT_VIRT_IP, domain_name=name,
+ port=port, address=get_virt_ip(), domain_name=name,
libvirt_uri='qemu:///system',
libvirt_sasl_password=False,
libvirt_sasl_username=False)