def _load_generic(self, attrname): vnf_deployment_flavour = self.__class__.get_by_id( self._context, id=self.id, expected_attrs=None) if attrname not in vnf_deployment_flavour: raise exceptions.ObjectActionError( action='obj_load_attr', reason=_('loading %s requires recursion') % attrname) for field in self.fields: if field in vnf_deployment_flavour and field not in self: setattr(self, field, getattr(vnf_deployment_flavour, field))
def _load_generic(self, attrname): software_image = self.__class__.get_by_id(self._context, id=self.id, expected_attrs=attrname) if attrname not in software_image: raise exceptions.ObjectActionError( action='obj_load_attr', reason=_('loading %s requires recursion') % attrname) for field in self.fields: if field in software_image and field not in self: setattr(self, field, getattr(software_image, field))
def create(self): if self.obj_attr_is_set('id'): raise exceptions.ObjectActionError(action='create', reason=_('already created')) updates = self.obj_get_changes() if 'id' not in updates: updates['id'] = uuidutils.generate_uuid() self.id = updates['id'] db_vnf_resource = _vnf_resource_create(self._context, updates) self._from_db_object(self._context, self, db_vnf_resource)
def _obj_load_attr(self, attrname): """Internal method for loading attributes from vnf flavour.""" if attrname in self.fields and attrname != 'id': self._load_generic(attrname) else: # NOTE(nirajsingh): Raise error if non existing field is # requested. raise exceptions.ObjectActionError( action='obj_load_attr', reason=_('attribute %s not lazy-loadable') % attrname) self.obj_reset_changes([attrname])
def create(self): if self.obj_attr_is_set('id'): raise exceptions.ObjectActionError(action='create', reason=_('already created')) updates = self.obj_get_changes() if 'id' not in updates: updates['id'] = uuidutils.generate_uuid() self.id = updates['id'] metadata = updates.pop('metadata', None) db_sw_image = _vnf_sw_image_create(self._context, updates, metadata=metadata) self._from_db_object(self._context, self, db_sw_image)
def obj_load_attr(self, attrname): if not self._context: raise exceptions.OrphanedObjectError( method='obj_load_attr', objtype=self.obj_name()) if 'id' not in self: raise exceptions.ObjectActionError( action='obj_load_attr', reason=_('attribute %s not lazy-loadable') % attrname) LOG.debug("Lazy-loading '%(attr)s' on %(name)s id %(id)s", {'attr': attrname, 'name': self.obj_name(), 'id': self.id, }) self._obj_load_attr(attrname)
def create(self): if self.obj_attr_is_set('id'): raise exceptions.ObjectActionError(action='create', reason=_('already created')) updates = self.obj_get_changes() if 'id' not in updates: updates['id'] = uuidutils.generate_uuid() self.id = updates['id'] for key in ['vnf_deployment_flavours']: if key in updates.keys(): updates.pop(key) user_data = updates.pop('user_data', None) db_vnf_package = _vnf_package_create(self._context, updates, user_data=user_data) self._from_db_object(self._context, self, db_vnf_package)
def create(self): if self.obj_attr_is_set('id'): raise exceptions.ObjectActionError(action='create', reason='already created') updates = self.obj_get_changes() if 'id' not in updates: updates['id'] = uuidutils.generate_uuid() self.id = updates['id'] if 'software_images' in updates: updates.pop('software_images') special_key = 'instantiation_levels' if special_key in updates: updates[special_key] = jsonutils.dumps(updates.get(special_key)) db_flavour = _vnf_deployment_flavour_create(self._context, updates) self._from_db_object(self._context, self, db_flavour)
def create(self): if self.obj_attr_is_set('id'): raise exceptions.ObjectActionError(action='create', reason=_('already created')) updates = self.obj_get_changes() if 'id' not in updates: updates['id'] = uuidutils.generate_uuid() self.id = updates['id'] # add default vnf_instance_name if not specified # format: 'vnf' + <vnf instance id> if 'vnf_instance_name' not in updates or \ not updates.get("vnf_instance_name"): updates['vnf_instance_name'] = 'vnf-' + self.id self.vnf_instance_name = updates['vnf_instance_name'] db_vnf_instance = _vnf_instance_create(self._context, updates) expected_attrs = ["instantiated_vnf_info"] self._from_db_object(self._context, self, db_vnf_instance, expected_attrs=expected_attrs)
def destroy(self, context): if not self.obj_attr_is_set('id'): raise exceptions.ObjectActionError( action='destroy', reason='no uuid') _destroy_vnf_deployment_flavour(context, self.id)
def destroy(self, context): if not self.obj_attr_is_set('vnf_instance_id'): raise exceptions.ObjectActionError(action='destroy', reason='no uuid') _destroy_instantiated_vnf_info(context, self.vnf_instance_id)