VMware: Add check for timezone variable (windows customization) (#47135)

* vmware_guest.py: check if value for windows customization with timezone is integer, before proceeding.
pull/43997/head
Vipul Kanade 6 years ago committed by Abhijeet Kasurde
parent acda7bae5f
commit 06d23019e7

@ -717,6 +717,22 @@ class PyVmomiDeviceHelper(object):
mac_addr_regex = re.compile('[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$') mac_addr_regex = re.compile('[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$')
return bool(mac_addr_regex.match(mac_addr)) return bool(mac_addr_regex.match(mac_addr))
def integer_value(self, input_value, name):
"""
Function to return int value for given input, else return error
Args:
input_value: Input value to retrive int value from
name: Name of the Input value (used to build error message)
Returns: (int) if integer value can be obtained, otherwise will send a error message.
"""
if isinstance(input_value, int):
return input_value
elif isinstance(input_value, str) and input_value.isdigit():
return int(input_value)
else:
self.module.fail_json(msg='"%s" attribute should be an'
' integer value.' % name)
class PyVmomiCache(object): class PyVmomiCache(object):
""" This class caches references to objects which are requested multiples times but not modified """ """ This class caches references to objects which are requested multiples times but not modified """
@ -1514,7 +1530,10 @@ class PyVmomiHelper(PyVmomi):
ident.guiUnattended.autoLogonCount = self.params['customization'].get('autologoncount', 1) ident.guiUnattended.autoLogonCount = self.params['customization'].get('autologoncount', 1)
if 'timezone' in self.params['customization']: if 'timezone' in self.params['customization']:
ident.guiUnattended.timeZone = self.params['customization']['timezone'] # Check if timezone value is a int before proceeding.
ident.guiUnattended.timeZone = self.device_helper.integer_value(
self.params['customization']['timezone'],
'customization.timezone')
ident.identification = vim.vm.customization.Identification() ident.identification = vim.vm.customization.Identification()

Loading…
Cancel
Save