Skip to content

Commit

Permalink
Fixed Misc issues related to VMware customization.
Browse files Browse the repository at this point in the history
- staticIPV4 property can be either None or a valid Array. Need to
  check for None before accessing the ip address.
- Modified few misc. log messages.
- Added a new log message while waiting for the customization config file.
- Added support to configure the maximum amount of time to wait for the
  customization config file.
- VMware Customization Support is provided only for DataSourceOVF class and
  not for any other child classes. Implemented a new variable
  vmware_customization_supported to check whether the 'VMware Customization'
  support is available for a specific datasource or not.
- Changed the function get_vmware_cust_settings to get_max_wait_from_cfg.
- Removed the code that does 'ifdown and iup' in NIC configurator.
  • Loading branch information
stanguturi authored and smoser committed Jan 17, 2017
1 parent e227439 commit 8ddb571
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
37 changes: 33 additions & 4 deletions cloudinit/sources/DataSourceOVF.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, sys_cfg, distro, paths):
self.environment = None
self.cfg = {}
self.supported_seed_starts = ("/", "file://")
self.vmware_customization_supported = True

def __str__(self):
root = sources.DataSource.__str__(self)
Expand Down Expand Up @@ -78,7 +79,10 @@ def get_data(self):
found.append(seed)
elif system_type and 'vmware' in system_type.lower():
LOG.debug("VMware Virtualization Platform found")
if not util.get_cfg_option_bool(
if not self.vmware_customization_supported:
LOG.debug("Skipping the check for "
"VMware Customization support")
elif not util.get_cfg_option_bool(
self.sys_cfg, "disable_vmware_customization", True):
deployPkgPluginPath = search_file("/usr/lib/vmware-tools",
"libdeployPkgPlugin.so")
Expand All @@ -90,17 +94,18 @@ def get_data(self):
# copies the customization specification file to
# /var/run/vmware-imc directory. cloud-init code needs
# to search for the file in that directory.
max_wait = get_max_wait_from_cfg(self.ds_cfg)
vmwareImcConfigFilePath = util.log_time(
logfunc=LOG.debug,
msg="waiting for configuration file",
func=wait_for_imc_cfg_file,
args=("/var/run/vmware-imc", "cust.cfg"))
args=("/var/run/vmware-imc", "cust.cfg", max_wait))

if vmwareImcConfigFilePath:
LOG.debug("Found VMware DeployPkg Config File at %s" %
LOG.debug("Found VMware Customization Config File at %s",
vmwareImcConfigFilePath)
else:
LOG.debug("Did not find VMware DeployPkg Config File Path")
LOG.debug("Did not find VMware Customization Config File")
else:
LOG.debug("Customization for VMware platform is disabled.")

Expand Down Expand Up @@ -206,6 +211,29 @@ def __init__(self, sys_cfg, distro, paths):
DataSourceOVF.__init__(self, sys_cfg, distro, paths)
self.seed_dir = os.path.join(paths.seed_dir, 'ovf-net')
self.supported_seed_starts = ("http://", "https://", "ftp://")
self.vmware_customization_supported = False


def get_max_wait_from_cfg(cfg):
default_max_wait = 90
max_wait_cfg_option = 'vmware_cust_file_max_wait'
max_wait = default_max_wait

if not cfg:
return max_wait

try:
max_wait = int(cfg.get(max_wait_cfg_option, default_max_wait))
except ValueError:
LOG.warn("Failed to get '%s', using %s",
max_wait_cfg_option, default_max_wait)

if max_wait <= 0:
LOG.warn("Invalid value '%s' for '%s', using '%s' instead",
max_wait, max_wait_cfg_option, default_max_wait)
max_wait = default_max_wait

return max_wait


def wait_for_imc_cfg_file(dirpath, filename, maxwait=180, naplen=5):
Expand All @@ -215,6 +243,7 @@ def wait_for_imc_cfg_file(dirpath, filename, maxwait=180, naplen=5):
fileFullPath = search_file(dirpath, filename)
if fileFullPath:
return fileFullPath
LOG.debug("Waiting for VMware Customization Config File")
time.sleep(naplen)
waited += naplen
return None
Expand Down
24 changes: 6 additions & 18 deletions cloudinit/sources/helpers/vmware/imc/config_nic.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def gen_ipv4(self, name, nic):
return lines

# Static Ipv4
v4 = nic.staticIpv4
addrs = nic.staticIpv4
if not addrs:
return lines

v4 = addrs[0]
if v4.ip:
lines.append(' address %s' % v4.ip)
if v4.netmask:
Expand Down Expand Up @@ -197,22 +201,6 @@ def clear_dhcp(self):
util.subp(["pkill", "dhclient"], rcs=[0, 1])
util.subp(["rm", "-f", "/var/lib/dhcp/*"])

def if_down_up(self):
names = []
for nic in self.nics:
name = self.mac2Name.get(nic.mac.lower())
names.append(name)

for name in names:
logger.info('Bring down interface %s' % name)
util.subp(["ifdown", "%s" % name])

self.clear_dhcp()

for name in names:
logger.info('Bring up interface %s' % name)
util.subp(["ifup", "%s" % name])

def configure(self):
"""
Configure the /etc/network/intefaces
Expand All @@ -232,6 +220,6 @@ def configure(self):
for line in lines:
fp.write('%s\n' % line)

self.if_down_up()
self.clear_dhcp()

# vi: ts=4 expandtab

0 comments on commit 8ddb571

Please sign in to comment.