def test_instance_type_extra_specs_create(self): net_attrs = {"net_arch": "ethernet", "net_mbps": "10000"} self.specs.update(net_attrs) db.flavor_extra_specs_update_or_create(self.context, self.flavorid, net_attrs) actual_specs = db.flavor_extra_specs_get(self.context, self.flavorid) self.assertEqual(self.specs, actual_specs)
def save(self, context): updates = self.obj_get_changes() projects = updates.pop('projects', None) extra_specs = updates.pop('extra_specs', None) if updates: raise exception.ObjectActionError( action='save', reason='read-only fields were changed') if extra_specs: db.flavor_extra_specs_update_or_create(context, self.flavorid, extra_specs) # NOTE(danms): This could be much simpler and more efficient # with a smarter flavor_access_update() method in db_api. if projects is not None: current_projects = [x['project_id'] for x in db.flavor_access_get_by_flavor_id( context, self.flavorid)] for project_id in projects: if project_id not in current_projects: db.flavor_access_add(context, self.flavorid, project_id) else: current_projects.remove(project_id) for condemned_project_id in current_projects: db.flavor_access_remove(context, self.flavorid, condemned_project_id) self.obj_reset_changes()
def test_instance_type_extra_specs_update(self): self.specs["cpu_model"] = "Sandy Bridge" db.flavor_extra_specs_update_or_create( self.context, self.flavorid, dict(cpu_model="Sandy Bridge")) actual_specs = db.flavor_extra_specs_get( self.context, self.flavorid) self.assertEqual(self.specs, actual_specs)
def create(self, req, flavor_id, body): context = req.environ["nova.context"] authorize(context, action="create") self._check_body(body) specs = body.get("extra_specs") try: db.flavor_extra_specs_update_or_create(context, flavor_id, specs) except exception.MetadataLimitExceeded as error: raise exc.HTTPBadRequest(explanation=error.format_message()) return body
def create(self, req, flavor_id, body): context = req.environ['nova.context'] authorize(context, action='create') self._check_body(body) specs = body.get('extra_specs') try: db.flavor_extra_specs_update_or_create(context, flavor_id, specs) except exception.MetadataLimitExceeded as error: raise exc.HTTPBadRequest(explanation=error.format_message()) return body
def test_instance_type_extra_specs_update(self): expected_specs = dict(cpu_arch="x86_64", cpu_model="Sandy Bridge", xpu_arch="fermi", xpus="2", xpu_model="Tesla 2050") db.flavor_extra_specs_update_or_create(self.context, self.flavorid, dict(cpu_model="Sandy Bridge")) actual_specs = db.flavor_extra_specs_get(self.context, self.flavorid) self.assertEquals(expected_specs, actual_specs)
def _add_extra_specs(self, context, flavor_dict, inst_type): extra_specs_dict = flavor_dict.get('extra_specs') inst_type_dict = dict(inst_type) if extra_specs_dict: try: db.flavor_extra_specs_update_or_create( context, inst_type_dict['flavorid'], extra_specs_dict) except exception.MetadataLimitExceeded as error: raise exc.HTTPBadRequest(explanation=unicode(error))
def create(self, req, flavor_id, body): context = req.environ['nova.context'] self.authorize(context, action='create') self._check_body(body) specs = body.get('extra_specs', {}) if not specs or type(specs) is not dict: raise webob.exc.HTTPBadRequest(_('No or bad extra_specs provided')) try: db.flavor_extra_specs_update_or_create(context, flavor_id, specs) except db_exc.DBDuplicateEntry as error: raise webob.exc.HTTPBadRequest(explanation=error.format_message()) return body
def test_instance_type_extra_specs_create(self): expected_specs = dict(cpu_arch="x86_64", cpu_model="Nehalem", xpu_arch="fermi", xpus="2", xpu_model="Tesla 2050", net_arch="ethernet", net_mbps="10000") db.flavor_extra_specs_update_or_create( self.context, self.flavorid, dict(net_arch="ethernet", net_mbps=10000)) actual_specs = db.flavor_extra_specs_get(self.context, self.flavorid) self.assertEquals(expected_specs, actual_specs)
def test_instance_type_extra_specs_update(self): expected_specs = dict(cpu_arch="x86_64", cpu_model="Sandy Bridge", xpu_arch="fermi", xpus="2", xpu_model="Tesla 2050") db.flavor_extra_specs_update_or_create( self.context, self.flavorid, dict(cpu_model="Sandy Bridge")) actual_specs = db.flavor_extra_specs_get( self.context, self.flavorid) self.assertEquals(expected_specs, actual_specs)
def save_extra_specs(self, context, to_add=None, to_delete=None): """Add or delete extra_specs. :param:to_add: A dict of new keys to add/update :param:to_delete: A list of keys to remove """ to_add = to_add if to_add is not None else [] to_delete = to_delete if to_delete is not None else [] db.flavor_extra_specs_update_or_create(context, self.flavorid, to_add) for key in to_delete: db.flavor_extra_specs_delete(context, self.flavorid, key) self.obj_reset_changes(["extra_specs"])
def save_extra_specs(self, context, to_add=None, to_delete=None): """Add or delete extra_specs. :param:to_add: A dict of new keys to add/update :param:to_delete: A list of keys to remove """ to_add = to_add if to_add is not None else [] to_delete = to_delete if to_delete is not None else [] db.flavor_extra_specs_update_or_create(context, self.flavorid, to_add) for key in to_delete: db.flavor_extra_specs_delete(context, self.flavorid, key) self.obj_reset_changes(['extra_specs'])
def test_instance_type_extra_specs_create(self): net_attrs = { "net_arch": "ethernet", "net_mbps": "10000" } self.specs.update(net_attrs) db.flavor_extra_specs_update_or_create( self.context, self.flavorid, net_attrs) actual_specs = db.flavor_extra_specs_get( self.context, self.flavorid) self.assertEqual(self.specs, actual_specs)
def update(self, req, flavor_id, id, body): context = req.environ['nova.context'] authorize(context, action='update') self._check_body(body) if id not in body: expl = _('Request body and URI mismatch') raise exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _('Request body contains too many items') raise exc.HTTPBadRequest(explanation=expl) try: db.flavor_extra_specs_update_or_create(context, flavor_id, body) except exception.MetadataLimitExceeded as error: raise exc.HTTPBadRequest(explanation=error.format_message()) return body
def create(self, req, flavor_id, body): context = req.environ['nova.context'] self.authorize(context, action='create') self._check_body(body) specs = body.get('extra_specs', {}) if not specs or type(specs) is not dict: raise webob.exc.HTTPBadRequest(_('No or bad extra_specs provided')) try: db.flavor_extra_specs_update_or_create(context, flavor_id, specs) except db_exc.DBDuplicateEntry: msg = _("Concurrent transaction has been committed, try again") raise webob.exc.HTTPConflict(explanation=msg) except exception.FlavorNotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) return body
def update(self, req, flavor_id, id, body): context = req.environ["nova.context"] authorize(context, action="update") self._check_body(body) if id not in body: expl = _("Request body and URI mismatch") raise exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _("Request body contains too many items") raise exc.HTTPBadRequest(explanation=expl) try: db.flavor_extra_specs_update_or_create(context, flavor_id, body) except exception.MetadataLimitExceeded as error: raise exc.HTTPBadRequest(explanation=error.format_message()) return body
def update(self, req, flavor_id, id, body): context = req.environ['nova.context'] self.authorize(context, action='update') self._check_body(body) if id not in body: expl = _('Request body and URI mismatch') raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _('Request body contains too many items') raise webob.exc.HTTPBadRequest(explanation=expl) try: db.flavor_extra_specs_update_or_create(context, flavor_id, body) except db_exc.DBDuplicateEntry as error: raise webob.exc.HTTPBadRequest(explanation=error.format_message()) return body
def test_instance_type_extra_specs_create(self): expected_specs = dict(cpu_arch="x86_64", cpu_model="Nehalem", xpu_arch="fermi", xpus="2", xpu_model="Tesla 2050", net_arch="ethernet", net_mbps="10000") db.flavor_extra_specs_update_or_create( self.context, self.flavorid, dict(net_arch="ethernet", net_mbps=10000)) actual_specs = db.flavor_extra_specs_get( self.context, self.flavorid) self.assertEquals(expected_specs, actual_specs)
def update(self, req, flavor_id, id, body): context = req.environ['nova.context'] self.authorize(context, action='update') self._check_body(body) if id not in body: expl = _('Request body and URI mismatch') raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _('Request body contains too many items') raise webob.exc.HTTPBadRequest(explanation=expl) try: db.flavor_extra_specs_update_or_create(context, flavor_id, body) except db_exc.DBDuplicateEntry: msg = _("Concurrent transaction has been committed, try again") raise webob.exc.HTTPConflict(explanation=msg) except exception.FlavorNotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) return body
def _update_flavor_extraspecs(self, context, flavorid, flavor_extraspecs): """ Insert the flavor extra specs """ db.flavor_extra_specs_update_or_create(context, flavorid, flavor_extraspecs)