Example #1
0
File: flavor.py Project: sapcc/nova
def migrate_flavors(ctxt, count, hard_delete=False):
    main_db_ids = _get_main_db_flavor_ids(ctxt, count)
    if not main_db_ids:
        return 0, 0

    count_all = len(main_db_ids)
    count_hit = 0

    for flavor_id in main_db_ids:
        try:
            flavor = Flavor.get_by_id(ctxt, flavor_id)
            flavor_values = {field: getattr(flavor, field)
                             for field in flavor.fields}
            flavor._flavor_create(ctxt, flavor_values)
            count_hit += 1
            if hard_delete:
                _destroy_flavor_hard(ctxt, flavor.name)
            else:
                db.flavor_destroy(ctxt, flavor.flavorid)
        except exception.FlavorNotFound:
            LOG.warning('Flavor id %(id)i disappeared during migration',
                        {'id': flavor_id})
        except (exception.FlavorExists, exception.FlavorIdExists) as e:
            LOG.error(six.text_type(e))

    return count_all, count_hit
Example #2
0
def migrate_flavors(ctxt, count, hard_delete=False):
    main_db_ids = _get_main_db_flavor_ids(ctxt, count)
    if not main_db_ids:
        return 0, 0

    count_all = len(main_db_ids)
    count_hit = 0

    for flavor_id in main_db_ids:
        try:
            flavor = Flavor.get_by_id(ctxt, flavor_id)
            flavor_values = {
                field: getattr(flavor, field)
                for field in flavor.fields
            }
            flavor._flavor_create(ctxt, flavor_values)
            count_hit += 1
            if hard_delete:
                _destroy_flavor_hard(ctxt, flavor.name)
            else:
                db.flavor_destroy(ctxt, flavor.flavorid)
        except exception.FlavorNotFound:
            LOG.warning(_LW('Flavor id %(id)i disappeared during migration'),
                        {'id': flavor_id})
        except (exception.FlavorExists, exception.FlavorIdExists) as e:
            LOG.error(six.text_type(e))

    return count_all, count_hit
Example #3
0
def destroy(name):
    """Marks flavor as deleted."""
    try:
        assert name is not None
        db.flavor_destroy(context.get_admin_context(), name)
    except (AssertionError, exception.NotFound):
        LOG.exception(_('Instance type %s not found for deletion') % name)
        raise exception.InstanceTypeNotFoundByName(instance_type_name=name)
def destroy(name):
    """Marks flavor as deleted."""
    try:
        assert name is not None
        db.flavor_destroy(context.get_admin_context(), name)
    except (AssertionError, exception.NotFound):
        LOG.exception(_('Instance type %s not found for deletion') % name)
        raise exception.InstanceTypeNotFoundByName(instance_type_name=name)
Example #5
0
def destroy(name):
    """Marks flavor as deleted."""
    try:
        if not name:
            raise ValueError()
        db.flavor_destroy(context.get_admin_context(), name)
    except (ValueError, exception.NotFound):
        LOG.exception(_('Instance type %s not found for deletion') % name)
        raise exception.FlavorNotFoundByName(flavor_name=name)
Example #6
0
def destroy(name):
    """Marks flavor as deleted."""
    try:
        if not name:
            raise ValueError()
        db.flavor_destroy(context.get_admin_context(), name)
    except (ValueError, exception.NotFound):
        LOG.exception(_LE('Instance type %s not found for deletion'), name)
        raise exception.FlavorNotFoundByName(flavor_name=name)
 def destroy(self):
     # NOTE(danms): Historically the only way to delete a flavor
     # is via name, which is not very precise. We need to be able to
     # support the light construction of a flavor object and subsequent
     # delete request with only our name filled out. However, if we have
     # our id property, we should instead delete with that since it's
     # far more specific.
     try:
         if 'id' in self:
             self._flavor_destroy(self._context, flavor_id=self.id)
         else:
             self._flavor_destroy(self._context, flavorid=self.flavorid)
     except exception.FlavorNotFound:
         db.flavor_destroy(self._context, self.flavorid)
 def destroy(self):
     # NOTE(danms): Historically the only way to delete a flavor
     # is via name, which is not very precise. We need to be able to
     # support the light construction of a flavor object and subsequent
     # delete request with only our name filled out. However, if we have
     # our id property, we should instead delete with that since it's
     # far more specific.
     try:
         if 'id' in self:
             self._flavor_destroy(self._context, flavor_id=self.id)
         else:
             self._flavor_destroy(self._context, name=self.name)
     except exception.FlavorNotFound:
         db.flavor_destroy(self._context, self.name)
Example #9
0
    def destroy(self):
        if self.is_in_use():
            msg = ('Flavor is in use')
            raise exc.HTTPBadRequest(explanation=msg)

        # NOTE(danms): Historically the only way to delete a flavor
        # is via name, which is not very precise. We need to be able to
        # support the light construction of a flavor object and subsequent
        # delete request with only our name filled out. However, if we have
        # our id property, we should instead delete with that since it's
        # far more specific.
        try:
            if 'id' in self:
                db_flavor = self._flavor_destroy(self._context,
                                                 flavor_id=self.id)
            else:
                db_flavor = self._flavor_destroy(self._context,
                                                 flavorid=self.flavorid)
            self._from_db_object(self._context, self, db_flavor)
            self._send_notification(fields.NotificationAction.DELETE)
        except exception.FlavorNotFound:
            db.flavor_destroy(self._context, self.flavorid)
Example #10
0
def migrate_flavors(ctxt, count, hard_delete=False):
    main_db_ids = _get_main_db_flavor_ids(ctxt, count)
    if not main_db_ids:
        return 0, 0

    count_all = len(main_db_ids)
    count_hit = 0

    for flavor_id in main_db_ids:
        try:
            flavor = Flavor.get_by_id(ctxt, flavor_id)
            flavor_values = {field: getattr(flavor, field)
                             for field in flavor.fields}


            # These created_at and updated_at was added because the original values
            # contained time zones and tried to push does values into the database.
            # it might be that the output to the database will be incorrect after this.
            created_at = flavor_values['created_at']
            flavor_values['created_at'] = created_at.replace(tzinfo=None)
            if not flavor_values['deleted_at'] == None:
              deleted_at = flavor_values['deleted_at']
              flavor_values['deleted_at'] = created_at.replace(tzinfo=None)


            flavor._flavor_create(ctxt, flavor_values)
            count_hit += 1
            if hard_delete:
                _destroy_flavor_hard(ctxt, flavor.name)
            else:
                db.flavor_destroy(ctxt, flavor.flavorid)
        except exception.FlavorNotFound:
            LOG.warning(_LW('Flavor id %(id)i disappeared during migration'),
                        {'id': flavor_id})
        except (exception.FlavorExists, exception.FlavorIdExists) as e:
            LOG.error(str(e))

    return count_all, count_hit
Example #11
0
 def destroy(self, context):
     db.flavor_destroy(context, self.name)
Example #12
0
    def tearDown(self):
        db.flavor_destroy(
                self.admin_context, self.disabled_type['name'])

        super(DisabledFlavorsWithRealDBTestV21, self).tearDown()
    def tearDown(self):
        db.flavor_destroy(self.admin_context, self.disabled_type['name'])

        super(DisabledFlavorsWithRealDBTest, self).tearDown()
Example #14
0
 def destroy(self):
     db.flavor_destroy(self._context, self.name)
 def tearDown(self):
     # Remove the instance type from the database
     db.flavor_destroy(self.context, "cg1.4xlarge")
     super(InstanceTypeExtraSpecsTestCase, self).tearDown()
Example #16
0
 def tearDown(self):
     db.flavor_destroy(context.get_admin_context(),
                              "test.small")
     super(InstanceTypeCommandsTestCase, self).tearDown()
 def tearDown(self):
     # Remove the instance type from the database
     db.flavor_destroy(self.context, "cg1.4xlarge")
     super(InstanceTypeExtraSpecsTestCase, self).tearDown()
Example #18
0
 def destroy(self, context):
     db.flavor_destroy(context, self.name)
Example #19
0
 def tearDown(self):
     db.flavor_destroy(context.get_admin_context(), "test.small")
     super(FlavorCommandsTestCase, self).tearDown()
Example #20
0
 def destroy(self):
     db.flavor_destroy(self._context, self.name)