From 06d23019e73757b0d3accdf99e580a82d23e634a Mon Sep 17 00:00:00 2001 From: Vipul Kanade Date: Sat, 20 Oct 2018 09:05:48 -0700 Subject: [PATCH] VMware: Add check for timezone variable (windows customization) (#47135) * vmware_guest.py: check if value for windows customization with timezone is integer, before proceeding. --- .../modules/cloud/vmware/vmware_guest.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index 8508a124ba0..5d7c472c78a 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -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}$') 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): """ 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) 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()