from .obj import PpBaseObject
-__version__ = '0.5.3'
+__version__ = '0.5.4'
LOG = logging.getLogger(__name__)
min_max_wait_for_finish_install = 3 * 60
max_max_wait_for_finish_install = 24 * 60 * 60
+ mac_address_template = "00:16:3e:53:{:02x}:{:02x}"
+
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None,
res['default_max_nr_templates_stay'] = self.default_max_nr_templates_stay
res['min_max_wait_for_finish_install'] = self.min_max_wait_for_finish_install
res['max_max_wait_for_finish_install'] = self.max_max_wait_for_finish_install
+ res['mac_address_template'] = self.mac_address_template
res['data_size_mb'] = self.data_size_mb
res['data_size_kb'] = self.data_size_kb
res['data_size'] = self.data_size
from .config import CrTplConfiguration
-__version__ = '0.7.4'
+__version__ = '0.7.5'
LOG = logging.getLogger(__name__)
TZ = pytz.timezone('Europe/Berlin')
self.wait_for_finish_install()
self.post_install_tasks_ssh()
self.poweroff_vm()
+ self.change_mac_address()
self.rotate_templates()
if not self.rotate_only:
self.rename_and_change_vm()
guestId='oracleLinux64Guest',
version='vmx-11',
bootOptions=boot_opts,
- #guestFullName='Oracle Enterprise Linux 7 (64 Bit)',
- #alternateGuestName='OEL 7/64',
)
- #files=vm_file_info, guestId='OracleLinux7_Guest')
- #files=vm_file_info, guestId='OracleLinux7_Guest', version='oel7-4')
if self.verbose > 2:
LOG.debug("Generated VM config:\n{}".format(pp(config)))
"VM {h!r} was not shut down after {t:0.1f} seconds, current state is {s!r}.".format(
h=self.config.template_vm, t=cur_diff, s=guest_state))
+ # -------------------------------------------------------------------------
+ def change_mac_address(self):
+
+ LOG.info("Setting a new, randomized MAC address for template VM ...")
+
+ current_macs = []
+
+ last_tuple1 = random.randint(1, 254)
+ last_tuple2 = random.randint(1, 254)
+ new_mac = self.config.mac_address_template.format(last_tuple1, last_tuple2)
+ 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.")
+
# -------------------------------------------------------------------------
def rotate_templates(self):