[2.8] VMware: Fix python 3 incompatibility

Add Python2 and Python3 compatible `string.translate` for hostname customization.

Fixes: #54118
(cherry picked from commit 8f89d1d3da)
This commit is contained in:
Klaus Frank 2019-05-27 07:40:49 +02:00 committed by Toshio Kuratomi
parent 116262e5e8
commit 64890cc456
2 changed files with 4 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- vmware_guest now accepts Python 2 and Python 3 compatible string translate method (https://github.com/ansible/ansible/issues/54118).

View file

@ -1580,7 +1580,8 @@ class PyVmomiHelper(PyVmomi):
# Setting hostName, orgName and fullName is mandatory, so we set some default when missing # Setting hostName, orgName and fullName is mandatory, so we set some default when missing
ident.userData.computerName = vim.vm.customization.FixedName() ident.userData.computerName = vim.vm.customization.FixedName()
# computer name will be truncated to 15 characters if using VM name # computer name will be truncated to 15 characters if using VM name
default_name = self.params['name'].translate(None, string.punctuation) default_name = self.params['name'].replace(' ', '')
default_name = ''.join([c for c in default_name if c not in string.punctuation])
ident.userData.computerName.name = str(self.params['customization'].get('hostname', default_name[0:15])) ident.userData.computerName.name = str(self.params['customization'].get('hostname', default_name[0:15]))
ident.userData.fullName = str(self.params['customization'].get('fullname', 'Administrator')) ident.userData.fullName = str(self.params['customization'].get('fullname', 'Administrator'))
ident.userData.orgName = str(self.params['customization'].get('orgname', 'ACME')) ident.userData.orgName = str(self.params['customization'].get('orgname', 'ACME'))