def get_source(context, id):
    """Retrieves single source by ID."""
    if id is None:
        msg = _("ID cannot be None")
        raise exception.InvalidSource(reason=msg)

    return db.source_get(context, id)
Example #2
0
def get_source(context, id):
    """Retrieves single source by ID."""
    if id is None:
        msg = _("ID cannot be None")
        raise exception.InvalidSource(reason=msg)

    return db.source_get(context, id)
Example #3
0
    def create_migration(self, context, migration_ref):
        """Creates the migration process of a VM."""
        try:
            vm_id = migration_ref.get('source_instance_id')
            vm = db.vm_get(context, vm_id)
            source = db.source_get(context, vm.get('source_id'))

            migration_id = migration_ref.get('id')
            self._migration_status_update(context, migration_id,
                                          MIGRATION_EVENT['connect'],
                                          MIGRATION_STATUS['init'])

            driver = self._get_driver_from_source(context, source)

            source_vm_id = vm.get('uuid_at_source')

            vm_conversion_dir = os.path.join(CONF.conversion_dir, vm_id)
            utils.execute('mkdir', '-p', vm_conversion_dir, run_as_root=False)

            self._migration_status_update(context, migration_id,
                                          MIGRATION_EVENT['fetch'],
                                          MIGRATION_STATUS['inprogress'])
            disks = driver.download_vm_disks(context, source_vm_id,
                                             vm_conversion_dir)

            self._convert_disks(context, migration_id, disks)

            image_name_prefix = vm.get('name')

            if not image_name_prefix:
                image_name_prefix = vm_id

            self._upload_to_glance(context, migration_id, image_name_prefix,
                                   disks)

            name = vm.get('id')
            memory = int(vm.get('memory'))
            cpus = int(vm.get('vcpus'))
            root_gb = int(disks[0].get('size')) / 1024 / 1024 / 1024

            flavor = self._flavor_create(context, name, memory, cpus, root_gb)

            dest_id = self._boot_vm(context, migration_id, disks,
                                    image_name_prefix, flavor)

            self._migration_status_update(context, migration_id,
                                          MIGRATION_EVENT['done'],
                                          MIGRATION_STATUS['complete'])

            db.vm_update(context, vm_id, {
                'migrated': True,
                'dest_id': dest_id
            })
        except Exception:
            self._migration_status_update(context, migration_id, None,
                                          MIGRATION_STATUS['error'])
            raise
Example #4
0
File: manager.py Project: curx/guts
    def create_migration(self, context, migration_ref):
        """Creates the migration process of a VM."""
        try:
            vm_id = migration_ref.get('source_instance_id')
            vm = db.vm_get(context, vm_id)
            source = db.source_get(context, vm.get('source_id'))

            migration_id = migration_ref.get('id')
            self._migration_status_update(context, migration_id,
                                          MIGRATION_EVENT['connect'],
                                          MIGRATION_STATUS['init'])

            driver = self._get_driver_from_source(context, source)

            source_vm_id = vm.get('uuid_at_source')

            vm_conversion_dir = os.path.join(CONF.conversion_dir, vm_id)
            utils.execute('mkdir', '-p', vm_conversion_dir,
                          run_as_root = False)

            self._migration_status_update(context, migration_id,
                                          MIGRATION_EVENT['fetch'],
                                          MIGRATION_STATUS['inprogress'])
            disks = driver.download_vm_disks(context, source_vm_id,
                                             vm_conversion_dir)

            self._convert_disks(context, migration_id, disks)

            image_name_prefix = vm.get('name')

            if not image_name_prefix:
                image_name_prefix = vm_id

            self._upload_to_glance(context, migration_id,
                                   image_name_prefix, disks)

            dest_id = self._boot_vm(context, migration_id,
                                    disks, image_name_prefix)

            self._migration_status_update(context, migration_id,
                                          MIGRATION_EVENT['done'],
                                          MIGRATION_STATUS['complete'])

            db.vm_update(context, vm_id, {'migrated': True,
                                          'dest_id': dest_id})
        except Exception:
            self._migration_status_update(context, migration_id,
                                          None, MIGRATION_STATUS['error'])
            raise
Example #5
0
File: manager.py Project: curx/guts
    def fetch_vms(self, context, source_hypervisor_id):
        """Fetch VM list from source hypervisor"""
        if not source_hypervisor_id:
            raise

        source = db.source_get(context, source_hypervisor_id)

        driver = self._get_driver_from_source(context, source)
        vms = driver.get_vms_list()

        db.delete_vms_by_source_id(context, source_hypervisor_id)

        for vm in vms:
            vm['source_id'] = source_hypervisor_id
            db.vm_create(context, vm)
Example #6
0
    def validate_for_migration(self, context, migration_ref):
        """Validates if all conditions before actual migration

        Raises:
            InvalidPowerState: Virtual Instance not in correct power state.
        """
        instance_id = migration_ref.get('source_instance_id')
        vm = db.vm_get(context, instance_id)
        source = db.source_get(context, vm.get('source_id'))
        driver = self._get_driver_from_source(context, source)
        continue_migration, error_cls = driver.validate_for_migration(
            vm.get('uuid_at_source'))
        if (not continue_migration and issubclass(
                error_cls, exception.MigrationValidationFailed)):
            raise error_cls(instance_id=instance_id)
Example #7
0
    def fetch_vms(self, context, source_hypervisor_id):
        """Fetch VM list from source hypervisor"""
        if not source_hypervisor_id:
            raise Exception

        source = db.source_get(context, source_hypervisor_id)

        driver = self._get_driver_from_source(context, source)
        vms = driver.get_vms_list()

        db.delete_vms_by_source_id(context, source_hypervisor_id)

        for vm in vms:
            vm['source_id'] = source_hypervisor_id
            db.vm_create(context, vm)
Example #8
0
    def validate_for_migration(self, context, migration_ref):
        """Validates if all conditions before actual migration

        Raises:
            InvalidPowerState: Virtual Instance not in correct power state.
        """
        instance_id = migration_ref.get('source_instance_id')
        vm = db.vm_get(context, instance_id)
        source = db.source_get(context, vm.get('source_id'))
        driver = self._get_driver_from_source(context, source)
        continue_migration, error_cls = driver.validate_for_migration(
            vm.get('uuid_at_source')
        )
        if (not continue_migration and
                issubclass(error_cls, exception.MigrationValidationFailed)):
            raise error_cls(instance_id=instance_id)