From 1dfd88d69969b1621103efe090cd9d99a499e535 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 30 Oct 2018 15:25:15 +0100 Subject: [PATCH] Changing MAC address of first interface --- bin/postinst | 7 ++++- lib/cr_vmware_tpl/handler.py | 56 +++++++++--------------------------- python_fb_tools | 2 +- 3 files changed, 21 insertions(+), 44 deletions(-) diff --git a/bin/postinst b/bin/postinst index 3742e94..dda903f 100644 --- a/bin/postinst +++ b/bin/postinst @@ -347,7 +347,12 @@ install_epel() { cp -pv "${repo_file}" /etc/yum.repos.d/.old done - for bname in public-yum-ol7.repo epel.repo epel-testing.repo puppet.repo rpm-repo.pixelpark.com.repo ; do + local repo_files="epel.repo epel-testing.repo puppet.repo rpm-repo.pixelpark.com.repo" + if [[ -f "/etc/oracle-release" ]] ; then + repo_files="public-yum-ol7.repo ${repo_files}" + fi + + for bname in ${repo_files} ; do url="${COBBLER_URL}/custom/create-vmware-tpl/yum.repos/${bname}" tgt="/etc/yum.repos.d/${bname}" echo diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 12ff07e..3496879 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -200,11 +200,11 @@ class CrTplHandler(BaseHandler): else: self.post_install_tasks_ssh() if self.postinstall_errors: - #self.purge_template_vm() + self.vsphere.purge_vm(self.tpl_vm) return 10 else: self.poweroff_vm() - #self.change_mac_address() + self.change_mac_address() return 0 @@ -670,17 +670,17 @@ class CrTplHandler(BaseHandler): if self.postinstall_errors: LOG.warn("Template VM {!r} has to be removed.".format(self.config.template_vm)) - # ------------------------------------------------------------------------- - def purge_template_vm(self): - - self.poweroff_vm() - - LOG.info("Purging VM {!r} because of errors.".format(self.config.template_vm)) - vm = self.get_temp_tpl_vm() - task = vm.Destroy_Task() - self.wait_for_tasks([task]) - - LOG.warn("Successful removed VM {!r}.".format(self.config.template_vm)) +# # ------------------------------------------------------------------------- +# def purge_template_vm(self): +# +# self.vsphere.poweroff_vm(self.tpl_vm) +# +# LOG.info("Purging VM {!r} because of errors.".format(self.config.template_vm)) +# vm = self.get_temp_tpl_vm() +# task = vm.Destroy_Task() +# self.wait_for_tasks([task]) +# +# LOG.warn("Successful removed VM {!r}.".format(self.config.template_vm)) # ------------------------------------------------------------------------- def post_install_tasks_ssh(self): @@ -913,35 +913,7 @@ class CrTplHandler(BaseHandler): LOG.debug("New MAC address: {!r}.".format(new_mac)) vm = self.get_temp_tpl_vm() - - virtual_nic_device = None - for dev in vm.config.hardware.device: - if isinstance(dev, vim.vm.device.VirtualEthernetCard): - virtual_nic_device = dev - break - - if not virtual_nic_device: - raise HandlerError('Could not found virtual EthernetCard.') - - virtual_nic_spec = vim.vm.device.VirtualDeviceSpec() - virtual_nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit - virtual_nic_spec.device = virtual_nic_device - virtual_nic_spec.device.macAddress = new_mac - virtual_nic_spec.device.backing = virtual_nic_device.backing - virtual_nic_spec.device.wakeOnLanEnabled = virtual_nic_device.wakeOnLanEnabled - virtual_nic_spec.device.connectable = virtual_nic_device.connectable - - dev_changes = [] - dev_changes.append(virtual_nic_spec) - spec = vim.vm.ConfigSpec() - spec.deviceChange = dev_changes - - if self.verbose > 2: - LOG.debug("Changes of MAC address:\n{}".format(pp(spec))) - - task = vm.ReconfigVM_Task(spec=spec) - self.wait_for_tasks([task]) - LOG.debug("Successful changed MAC address of VM.") + self.vsphere.set_mac_of_nic(vm, new_mac, nic_nr=0) # ------------------------------------------------------------------------- def rotate_templates(self): diff --git a/python_fb_tools b/python_fb_tools index 04957bb..e46d386 160000 --- a/python_fb_tools +++ b/python_fb_tools @@ -1 +1 @@ -Subproject commit 04957bbf0e37188bcc008dd8d12ed6643cb03da7 +Subproject commit e46d386775b93f051cd5cc81880e94b3ebd4f19b -- 2.39.5