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
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):
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):