コード例 #1
0
ファイル: manager.py プロジェクト: curx/guts
 def _convert_disks(self, context, migration_id, disks):
     self._migration_status_update(context, migration_id,
                                   MIGRATION_EVENT['convert'])
     for disk in disks:
         path = disk['path']
         disk['dest_path'] = path.replace('.vmdk', '.qcow2')
         utils.convert_image(path, disk['dest_path'],
                             'qcow2', run_as_root=False)
         disk['size'] = utils.qemu_img_info(disk['dest_path'],
                                            run_as_root=True).virtual_size
コード例 #2
0
 def _convert_disks(self, context, migration_id, disks):
     self._migration_status_update(context, migration_id,
                                   MIGRATION_EVENT['convert'])
     for disk in disks:
         path = disk['path']
         disk['dest_path'] = path.replace('.vmdk', '.qcow2')
         utils.convert_image(path,
                             disk['dest_path'],
                             'qcow2',
                             run_as_root=False)
         disk['size'] = utils.qemu_img_info(disk['dest_path'],
                                            run_as_root=True).virtual_size
コード例 #3
0
ファイル: vsphere.py プロジェクト: aptira/guts
    def get_instance(self, instance_id, con_dir):
        if not self._initialized:
            self._initialize_connection()
        instance = self._find_instance_by_uuid(instance_id)
        # get flavor details.
        vm_disks = []
        for vm_hardware in instance.config.hardware.device:
            if (vm_hardware.key >= 2000) and (vm_hardware.key < 3000):
                vm_disks.append('{}'.format(vm_hardware.capacityInKB/1024/1024))
        disks = ','.join(vm_disks)
        root_disk = vm_disks[0]
        flavor_info = {'name': '%s_flavor' % instance.config.name,
                       'ram': instance.config.hardware.memoryMB,
                       'vcpus': instance.config.hardware.numCPU,
                       'disk': root_disk}
        guest_os_name = instance.config.guestFullName
        powerState = instance.runtime.powerState
        poweredOn = vim.VirtualMachinePowerState.poweredOn

        if powerState == poweredOn:
            task = instance.PowerOff()
            while task.info.state not in [vim.TaskInfo.State.success,
                                          vim.TaskInfo.State.error]:
                time.sleep(1)
        lease = self._get_instance_lease(instance)

        def keep_lease_alive(lease):
            """Keeps the lease alive while GETing the VMDK."""
            while(True):
                time.sleep(5)
                try:
                    # Choosing arbitrary percentage to keep the lease alive.
                    lease.HttpNfcLeaseProgress(50)
                    if (lease.state == vim.HttpNfcLease.State.done):
                        return
                    # If the lease is released, we get an exception.
                    # Returning to kill the thread.
                except Exception as error:
                    raise exception.VSphereException(error.message)
        disks = []
        image_info = {}
        volume_info = []
        try:
            if lease.state == vim.HttpNfcLease.State.ready:
                keepalive_thread = Thread(target=keep_lease_alive,
                                          args=(lease,))

                keepalive_thread.daemon = True
                keepalive_thread.start()
                device_urls = self._get_device_urls(lease)

                for device_url in device_urls:
                    data = {}
                    path = os.path.join(con_dir,
                                        device_url.targetId)
                    self._get_instance_disk(device_url, path)
                    index = device_url.key.split(':')[1]
                    path = utils.convert_vmdk_to_qcow2(path)
                    if index == '0':
                        image_info = {"name": "%s_image_%s" % (instance.name, index),
                                      "local_image_path": path}
                    else:
                        vol_image_info = {"name": "%s_vol_%s" % (instance.name, index),
                                          "local_image_path": path}
                        disk = utils.qemu_img_info(path)
                        vol = {'image_info': vol_image_info,
                               'size': disk.virtual_size/(1024*1024*1024),
                               'name': "%s_vol_%s" % (instance.name, index),
                               'display_name': "%s_vol_%s" % (instance.name, index)}
                        volume_info.append(vol)

                lease.HttpNfcLeaseComplete()
                keepalive_thread.join()
            elif lease.state == vim.HttpNfcLease.State.error:
                raise exception.VSphereException("Failed to download disk.")
            else:
                raise exception.VSphereException("Failed to download disk.")
        except Exception:
            raise exception.VSphereException('Failed to download disk.')

        return {'name': instance.name,
                'image_info': image_info,
                'flavor_info': flavor_info,
                'volume_info': volume_info}