summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/sources/DataSourceOVF.py20
-rw-r--r--cloudinit/sources/helpers/vmware/imc/config_nic.py40
2 files changed, 24 insertions, 36 deletions
diff --git a/cloudinit/sources/DataSourceOVF.py b/cloudinit/sources/DataSourceOVF.py
index 6d3bf7bb..72ba5aba 100644
--- a/cloudinit/sources/DataSourceOVF.py
+++ b/cloudinit/sources/DataSourceOVF.py
@@ -63,15 +63,11 @@ class DataSourceOVF(sources.DataSource):
}
(seedfile, contents) = get_ovf_env(self.paths.seed_dir)
- dmi_info = dmi_data()
- system_type = ""
- if dmi_info is None:
- LOG.debug("No dmidata utility found")
- else:
- (_, system_type) = dmi_info
-
- if 'vmware' in system_type.lower():
+ system_type = util.read_dmi_data("system-product-name")
+ if system_type is None:
+ LOG.debug("No system-product-name found")
+ elif 'vmware' in system_type.lower():
LOG.debug("VMware Virtual Platform found")
deployPkgPluginPath = search_file("/usr/lib/vmware-tools", "libdeployPkgPlugin.so")
if deployPkgPluginPath:
@@ -347,14 +343,6 @@ def get_properties(contents):
return props
-def dmi_data():
- sys_uuid = util.read_dmi_data("system-uuid")
- sys_type = util.read_dmi_data("system-product-name")
-
- if not sys_uuid or not sys_type:
- return None
-
- return (sys_uuid.lower(), sys_type)
def search_file(dirpath, filename):
if not dirpath or not filename:
diff --git a/cloudinit/sources/helpers/vmware/imc/config_nic.py b/cloudinit/sources/helpers/vmware/imc/config_nic.py
index d79e6936..172a1649 100644
--- a/cloudinit/sources/helpers/vmware/imc/config_nic.py
+++ b/cloudinit/sources/helpers/vmware/imc/config_nic.py
@@ -22,6 +22,8 @@ import os
import subprocess
import re
+from cloudinit import util
+
logger = logging.getLogger(__name__)
@@ -43,32 +45,30 @@ class NicConfigurator:
Retrieve the primary nic if it exists
@return (NicBase): the primary nic if exists, None otherwise
"""
- primaryNic = None
-
- for nic in self.nics:
- if nic.primary:
- if primaryNic:
- raise Exception('There can only be one primary nic',
- primaryNic.mac, nic.mac)
- primaryNic = nic
-
- return primaryNic
+ primary_nics = [nic for nic in self.nics if nic.primary]
+ if not primary_nics:
+ return None
+ elif len(primary_nics) > 1:
+ raise Exception('There can only be one primary nic',
+ [nic.mac for nic in primary_nics])
+ else:
+ return primary_nics[0]
def find_devices(self):
"""
Create the mac2Name dictionary
The mac address(es) are in the lower case
"""
- cmd = 'ip addr show'
- outText = subprocess.check_output(cmd, shell=True).decode()
- sections = re.split(r'\n\d+: ', '\n' + outText)[1:]
+ cmd = ['ip', 'addr', 'show']
+ (output, err) = util.subp(cmd)
+ sections = re.split(r'\n\d+: ', '\n' + output)[1:]
macPat = r'link/ether (([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2}))'
for section in sections:
- matcher = re.search(macPat, section)
- if not matcher: # Only keep info about nics
+ match = re.search(macPat, section)
+ if not match: # Only keep info about nics
continue
- mac = matcher.group(1).lower()
+ mac = match.group(1).lower()
name = section.split(':', 1)[0]
self.mac2Name[mac] = name
@@ -206,8 +206,8 @@ class NicConfigurator:
def clear_dhcp(self):
logger.info('Clearing DHCP leases')
- subprocess.call('pkill dhclient', shell=True)
- subprocess.check_call('rm -f /var/lib/dhcp/*', shell=True)
+ util.subp(["pkill", "dhclient"])
+ util.subp(["rm", "-f", "/var/lib/dhcp/*"])
def if_down_up(self):
names = []
@@ -217,13 +217,13 @@ class NicConfigurator:
for name in names:
logger.info('Bring down interface %s' % name)
- subprocess.check_call('ifdown %s' % name, shell=True)
+ util.subp(["ifdown", "%s" % name])
self.clear_dhcp()
for name in names:
logger.info('Bring up interface %s' % name)
- subprocess.check_call('ifup %s' % name, shell=True)
+ util.subp(["ifup", "%s" % name])
def configure(self):
"""