def create_vim(self, context, vim): self._validate_default_vim(context, vim) vim_cred = vim['auth_cred'] try: with context.session.begin(subtransactions=True): vim_db = meo_db.Vim(id=vim.get('id'), type=vim.get('type'), tenant_id=vim.get('tenant_id'), name=vim.get('name'), description=vim.get('description'), placement_attr=vim.get('placement_attr'), is_default=vim.get('is_default'), status=vim.get('status'), deleted_at=datetime.min) context.session.add(vim_db) vim_auth_db = meo_db.VimAuth( id=uuidutils.generate_uuid(), vim_id=vim.get('id'), password=vim_cred.pop('password'), vim_project=vim.get('vim_project'), auth_url=vim.get('auth_url'), auth_cred=vim_cred) context.session.add(vim_auth_db) except DBDuplicateEntry as e: raise exceptions.DuplicateEntity(_type="vim", entry=e.columns) vim_dict = self._make_vim_dict(vim_db) self._cos_db_plg.create_event(context, res_id=vim_dict['id'], res_type=constants.RES_TYPE_VIM, res_state=vim_dict['status'], evt_type=constants.RES_EVT_CREATE, tstamp=vim_dict['created_at']) return vim_dict
def create_mes(self, context, mes): LOG.debug('mes %s', mes) mes = mes['mes'] tenant_id = self._get_tenant_id_for_create(context, mes) mesd_id = mes['mesd_id'] vim_id = mes['vim_id'] name = mes.get('name') mes_id = uuidutils.generate_uuid() try: with context.session.begin(subtransactions=True): mesd_db = self._get_resource(context, MESD, mesd_id) mes_db = MES(id=mes_id, tenant_id=tenant_id, name=name, description=mesd_db.description, mea_ids=None, status=constants.PENDING_CREATE, mgmt_urls=None, mesd_id=mesd_id, vim_id=vim_id, error_reason=None, deleted_at=datetime.min) context.session.add(mes_db) except DBDuplicateEntry as e: raise exceptions.DuplicateEntity(_type="mes", entry=e.columns) evt_details = "MES UUID assigned." self._cos_db_plg.create_event( context, res_id=mes_id, res_type=constants.RES_TYPE_mes, res_state=constants.PENDING_CREATE, evt_type=constants.RES_EVT_CREATE, tstamp=mes_db[constants.RES_EVT_CREATED_FLD], details=evt_details) return self._make_mes_dict(mes_db)
def create_mes(self, context, mes): LOG.debug('mes %s', mes) mes = mes['mes'] tenant_id = self._get_tenant_id_for_create(context, mes) mesd_id = mes['mesd_id'] vim_id = mes['vim_id'] name = mes.get('name') mes_mapping = mes['mes_mapping'] mes_id = uuidutils.generate_uuid() try: with context.session.begin(subtransactions=True): mesd_db = self._get_resource(context, MESD, mesd_id) mes_db = MES(id=mes_id, tenant_id=tenant_id, name=name, description=mesd_db.description, mea_ids=None, status=constants.PENDING_CREATE, mes_mapping=mes_mapping, reused=None, mgmt_urls=None, mesd_id=mesd_id, vim_id=vim_id, error_reason=None, deleted_at=datetime.min) context.session.add(mes_db) except DBDuplicateEntry as e: raise exceptions.DuplicateEntity(_type="mes", entry=e.columns) return self._make_mes_dict(mes_db)
def create_mead(self, context, mead): mead = mead['mead'] LOG.debug('mead %s', mead) tenant_id = self._get_tenant_id_for_create(context, mead) service_types = mead.get('service_types') mgmt_driver = mead.get('mgmt_driver') template_source = mead.get("template_source") if (not attributes.is_attr_set(service_types)): LOG.debug('service types unspecified') raise mem.ServiceTypesNotSpecified() try: with context.session.begin(subtransactions=True): mead_id = uuidutils.generate_uuid() mead_db = MEAD(id=mead_id, tenant_id=tenant_id, name=mead.get('name'), description=mead.get('description'), mgmt_driver=mgmt_driver, template_source=template_source, deleted_at=datetime.min) context.session.add(mead_db) for (key, value) in mead.get('attributes', {}).items(): attribute_db = MEADAttribute(id=uuidutils.generate_uuid(), mead_id=mead_id, key=key, value=value) context.session.add(attribute_db) for service_type in (item['service_type'] for item in mead['service_types']): service_type_db = ServiceType(id=uuidutils.generate_uuid(), tenant_id=tenant_id, mead_id=mead_id, service_type=service_type) context.session.add(service_type_db) except DBDuplicateEntry as e: raise exceptions.DuplicateEntity(_type="mead", entry=e.columns) LOG.debug('mead_db %(mead_db)s %(attributes)s ', { 'mead_db': mead_db, 'attributes': mead_db.attributes }) mead_dict = self._make_mead_dict(mead_db) LOG.debug('mead_dict %s', mead_dict) self._cos_db_plg.create_event( context, res_id=mead_dict['id'], res_type=constants.RES_TYPE_MEAD, res_state=constants.RES_EVT_ONBOARDED, evt_type=constants.RES_EVT_CREATE, tstamp=mead_dict[constants.RES_EVT_CREATED_FLD]) return mead_dict
def _create_mea_pre(self, context, mea): LOG.debug('mea %s', mea) tenant_id = self._get_tenant_id_for_create(context, mea) mead_id = mea['mead_id'] name = mea.get('name') mea_id = uuidutils.generate_uuid() attributes = mea.get('attributes', {}) vim_id = mea.get('vim_id') placement_attr = mea.get('placement_attr', {}) try: with context.session.begin(subtransactions=True): mead_db = self._get_resource(context, MEAD, mead_id) mea_db = MEA(id=mea_id, tenant_id=tenant_id, name=name, description=mead_db.description, instance_id=None, mead_id=mead_id, vim_id=vim_id, placement_attr=placement_attr, status=constants.PENDING_CREATE, error_reason=None, deleted_at=datetime.min) context.session.add(mea_db) for key, value in attributes.items(): arg = MEAAttribute(id=uuidutils.generate_uuid(), mea_id=mea_id, key=key, value=value) context.session.add(arg) except DBDuplicateEntry as e: raise exceptions.DuplicateEntity(_type="mea", entry=e.columns) evt_details = "MEA UUID assigned." self._cos_db_plg.create_event( context, res_id=mea_id, res_type=constants.RES_TYPE_MEA, res_state=constants.PENDING_CREATE, evt_type=constants.RES_EVT_CREATE, tstamp=mea_db[constants.RES_EVT_CREATED_FLD], details=evt_details) return self._make_mea_dict(mea_db)
def create_mesd(self, context, mesd): mesd = mesd['mesd'] LOG.debug('mesd %s', mesd) tenant_id = self._get_tenant_id_for_create(context, mesd) template_source = mesd.get('template_source') try: with context.session.begin(subtransactions=True): mesd_id = uuidutils.generate_uuid() mesd_db = MESD( id=mesd_id, tenant_id=tenant_id, name=mesd.get('name'), description=mesd.get('description'), mesd_mapping=mesd.get('mesd_mapping'), deleted_at=datetime.min, template_source=template_source) context.session.add(mesd_db) for (key, value) in mesd.get('attributes', {}).items(): attribute_db = MESDAttribute( id=uuidutils.generate_uuid(), mesd_id=mesd_id, key=key, value=value) context.session.add(attribute_db) except DBDuplicateEntry as e: raise exceptions.DuplicateEntity( _type="mesd", entry=e.columns) LOG.debug('mesd_db %(mesd_db)s %(attributes)s ', {'mesd_db': mesd_db, 'attributes': mesd_db.attributes}) mesd_dict = self._make_mesd_dict(mesd_db) LOG.debug('mesd_dict %s', mesd_dict) self._cos_db_plg.create_event( context, res_id=mesd_dict['id'], res_type=constants.RES_TYPE_MESD, res_state=constants.RES_EVT_ONBOARDED, evt_type=constants.RES_EVT_CREATE, tstamp=mesd_dict[constants.RES_EVT_CREATED_FLD]) return mesd_dict