示例#1
0
 def nic_recfg(self):
     """ Reconfigure a VM network adapter """
     devices = []
     edit = True
     host = Query.get_obj(self.virtual_machines.view, self.opts.name)
     nic_cfg_opts = {}
     label = self.opts.nic_prefix + ' ' + str(self.opts.nic_id)
     try:
         key, controller = Query.get_key(host, label)
     except IOError:
         pass
     if self.opts.nic_id:
         for item in host.config.hardware.device:
             if label == item.deviceInfo.label:
                 if self.opts.network:
                     nic_cfg_opts.update({
                         'key': key,
                         'controller': controller,
                         'container': host.runtime.host.network,
                         'network': self.opts.network,
                         'mac_address': item.macAddress,
                         'unit': item.unitNumber,
                     })
                     if self.opts.driver == 'e1000':
                         nic_cfg_opts.update({'driver': 'VirtualE1000'})
                     devices.append(
                         self.nic_config(edit=edit, **nic_cfg_opts))
                     if devices:
                         self.logger.info('%s label: %s %s network: %s',
                                          host.name, self.opts.nic_prefix,
                                          self.opts.nic_id,
                                          self.opts.network)
                         self.reconfig(host, **{'deviceChange': devices})
示例#2
0
    def umount_wrapper(self, *names):
        """
        Wrapper method for un-mounting isos on multiple VMs.

        Args:
            names (tuple): a tuple of VM names in vCenter.
        """
        for name in names:
            print('Umount ISO from %s' % (name))
            host = Query.get_obj(self.virtual_machines.view, name)

            key, controller = Query.get_key(host, 'CD/DVD')

            self.logger.info('ISO on %s', name)
            cdrom_cfg = []
            cdrom_cfg_opts = {}
            cdrom_cfg_opts.update({
                'umount': True,
                'key': key,
                'controller': controller,
            })
            cdrom_cfg.append(self.cdrom_config(**cdrom_cfg_opts))
            #cdrom_cfg.append(self.cdrom_config(umount=True, key=key,
            #    controller=controller))
            config = {'deviceChange': cdrom_cfg}
            self.logger.debug(host, config)
            self.reconfig(host, **config)
示例#3
0
    def mount_wrapper(self, datastore, path, *names):
        """
        Wrapper method for mounting isos on multiple VMs.

        Args:
            datastore (str): Name of datastore where the ISO is located.
            path (str): Path inside datastore where the ISO is located.
            names (str): A tuple of VM names in vCenter.
        """
        for name in names:
            host = Query.get_obj(self.virtual_machines.view, name)

            print('Mounting [%s] %s on %s' % (datastore, path, name))
            cdrom_cfg = []
            key, controller = Query.get_key(host, 'CD/DVD')

            cdrom_cfg_opts = {}
            cdrom_cfg_opts.update({
                'datastore': datastore,
                'iso_path': path,
                'iso_name': name,
                'key': key,
                'controller': controller,
            })
            cdrom_cfg.append(self.cdrom_config(**cdrom_cfg_opts))

            config = {'deviceChange': cdrom_cfg}
            self.logger.debug(cdrom_cfg_opts, config)
            self.reconfig(host, **config)
示例#4
0
    def umount_wrapper(self, *names):
        """
        Wrapper method for un-mounting isos on multiple VMs.

        Args:
            names (tuple): a tuple of VM names in vCenter.
        """
        for name in names:
            print('Umount ISO from %s' % (name))
            host = Query.get_obj(self.virtual_machines.view, name)

            key, controller = Query.get_key(host, 'CD/DVD')

            self.logger.info('ISO on %s', name)
            cdrom_cfg = []
            cdrom_cfg_opts = {}
            cdrom_cfg_opts.update(
                {
                    'umount' : True,
                    'key' : key,
                    'controller' : controller,
                }
            )
            cdrom_cfg.append(self.cdrom_config(**cdrom_cfg_opts))
            #cdrom_cfg.append(self.cdrom_config(umount=True, key=key,
            #    controller=controller))
            config = {'deviceChange' : cdrom_cfg}
            self.logger.debug(host, config)
            self.reconfig(host, **config)
示例#5
0
    def mount_wrapper(self, datastore, path, *names):
        """
        Wrapper method for mounting isos on multiple VMs.

        Args:
            datastore (str): Name of datastore where the ISO is located.
            path (str): Path inside datastore where the ISO is located.
            names (str): A tuple of VM names in vCenter.
        """
        for name in names:
            host = Query.get_obj(
                self.virtual_machines.view, name
            )

            print('Mounting [%s] %s on %s' % (datastore, path, name))
            cdrom_cfg = []
            key, controller = Query.get_key(host, 'CD/DVD')

            cdrom_cfg_opts = {}
            cdrom_cfg_opts.update(
                {
                    'datastore' : datastore,
                    'iso_path' : path,
                    'iso_name' : name,
                    'key': key,
                    'controller' : controller,
                }
            )
            cdrom_cfg.append(self.cdrom_config(**cdrom_cfg_opts))

            config = {'deviceChange' : cdrom_cfg}
            self.logger.debug(cdrom_cfg_opts, config)
            self.reconfig(host, **config)
示例#6
0
    def disk_recfg(self):
        """ Reconfigure a VM disk."""
        devices = []
        edit = True
        host = Query.get_obj(self.virtual_machines.view, self.opts.name)
        disk_cfg_opts = {}
        # KB
        tokbytes = 1024*1024
        label = self.opts.disk_prefix + ' ' + str(self.opts.disk_id)
        try:
            key, controller = Query.get_key(host, label)
        except IOError:
            pass
        if self.opts.disk_id:
            for item in host.config.hardware.device:
                if label == item.deviceInfo.label:
                    disk_new_size = self.opts.sizeGB * tokbytes
                    current_size = item.capacityInKB
                    current_size_gb = int(current_size / (1024*1024))
                    if disk_new_size == current_size:
                        raise ValueError(
                            'New size and existing size are equal'.format()
                        )
                    if disk_new_size < current_size:
                        raise ValueError(
                            'Size {0} does not exceed {1}'.format(
                                disk_new_size, current_size
                            )
                        )
                    disk_delta = disk_new_size - current_size
                    ds_capacity_kb = item.backing.datastore.summary.capacity / 1024
                    ds_free_kb = item.backing.datastore.summary.freeSpace / 1024
                    threshold_pct = 0.10
                    if (ds_free_kb - disk_delta) / ds_capacity_kb < threshold_pct:
                        raise ValueError(
                            '{0} {1} disk space low, aborting.'.format(
                                host.resourcePool.parent.name,
                                item.backing.datastore.name
                            )
                        )

                    disk_cfg_opts.update(
                        {
                            'size' : disk_new_size,
                            'key' : key,
                            'controller' : controller,
                            'unit' : item.unitNumber,
                            'filename' : item.backing.fileName
                        }
                    )
            if disk_cfg_opts:
                devices.append(self.disk_config(edit=edit, **disk_cfg_opts))
                self.logger.info(
                    '%s label: %s %s current_size: %s new_size: %s', host.name,
                    self.opts.disk_prefix, self.opts.disk_id, current_size_gb, self.opts.sizeGB
                )
                self.reconfig(host, **{'deviceChange': devices})
示例#7
0
 def disk_recfg(self):
     """ Reconfigure a VM disk."""
     devices = []
     edit = True
     host = Query.get_obj(self.virtual_machines.view, self.opts.name)
     disk_cfg_opts = {}
     # KB
     tokbytes = 1024 * 1024
     label = self.opts.disk_prefix + ' ' + str(self.opts.disk_id)
     try:
         key, controller = Query.get_key(host, label)
     except IOError:
         pass
     if self.opts.disk_id:
         for item in host.config.hardware.device:
             if label == item.deviceInfo.label:
                 disk_new_size = self.opts.sizeGB * tokbytes
                 current_size = item.capacityInKB
                 current_size_gb = int(current_size / (1024 * 1024))
                 if disk_new_size == current_size:
                     raise ValueError(
                         'New size and existing size are equal'.format())
                 elif disk_new_size < current_size:
                     raise ValueError('Size {0} does not exceed {1}'.format(
                         disk_new_size, current_size))
                 disk_delta = disk_new_size - current_size
                 ds_capacity_kb = item.backing.datastore.summary.capacity / 1024
                 ds_free_kb = item.backing.datastore.summary.freeSpace / 1024
                 threshold_pct = 0.10
                 if (ds_free_kb -
                         disk_delta) / ds_capacity_kb < threshold_pct:
                     raise ValueError(
                         '{0} {1} disk space low, aborting.'.format(
                             host.resourcePool.parent.name,
                             item.backing.datastore.name))
                 else:
                     disk_cfg_opts.update({
                         'size': disk_new_size,
                         'key': key,
                         'controller': controller,
                         'unit': item.unitNumber,
                         'filename': item.backing.fileName
                     })
         if disk_cfg_opts:
             devices.append(self.disk_config(edit=edit, **disk_cfg_opts))
             self.logger.info(
                 '%s label: %s %s current_size: %s new_size: %s', host.name,
                 self.opts.disk_prefix, self.opts.disk_id, current_size_gb,
                 self.opts.sizeGB)
             self.reconfig(host, **{'deviceChange': devices})
示例#8
0
 def nic_recfg(self):
     """ Reconfigure a VM network adapter """
     devices = []
     edit = True
     host = Query.get_obj(self.virtual_machines.view, self.opts.name)
     nic_cfg_opts = {}
     label = self.opts.nic_prefix + ' ' + str(self.opts.nic_id)
     try:
         key, controller = Query.get_key(host, label)
     except IOError:
         pass
     if self.opts.nic_id:
         for item in host.config.hardware.device:
             if label == item.deviceInfo.label:
                 if self.opts.network:
                     nic_cfg_opts.update(
                         {
                             'key' : key,
                             'controller' : controller,
                             'container' : host.runtime.host.network,
                             'network' : self.opts.network,
                             'mac_address': item.macAddress,
                             'unit' : item.unitNumber,
                         }
                     )
                     if self.opts.driver == 'e1000':
                         nic_cfg_opts.update({'driver': 'VirtualE1000'})
                     devices.append(
                         self.nic_config(edit=edit, **nic_cfg_opts)
                     )
                     if devices:
                         self.logger.info(
                             '%s label: %s %s network: %s', host.name,
                             self.opts.nic_prefix, self.opts.nic_id,
                             self.opts.network
                         )
                         self.reconfig(host, **{'deviceChange': devices})