diff --git a/src/context/proto/context_pb2.py b/src/context/proto/context_pb2.py index e852430e3381e0aff2a0651d0107d81271fcefab..58d582f037688e25c06cbfc39cae27df46ae1fc5 100644 --- a/src/context/proto/context_pb2.py +++ b/src/context/proto/context_pb2.py @@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( syntax='proto3', serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\rcontext.proto\x12\x07\x63ontext\"\x07\n\x05\x45mpty\"\x14\n\x04Uuid\x12\x0c\n\x04uuid\x18\x01 \x01(\t\"F\n\x05\x45vent\x12\x11\n\ttimestamp\x18\x01 \x01(\x01\x12*\n\nevent_type\x18\x02 \x01(\x0e\x32\x16.context.EventTypeEnum\"0\n\tContextId\x12#\n\x0c\x63ontext_uuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"\x87\x01\n\x07\x43ontext\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12#\n\x08topology\x18\x02 \x03(\x0b\x32\x11.context.Topology\x12/\n\ncontroller\x18\x03 \x01(\x0b\x32\x1b.context.TeraFlowController\"8\n\rContextIdList\x12\'\n\x0b\x63ontext_ids\x18\x01 \x03(\x0b\x32\x12.context.ContextId\"1\n\x0b\x43ontextList\x12\"\n\x08\x63ontexts\x18\x01 \x03(\x0b\x32\x10.context.Context\"U\n\x0c\x43ontextEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12&\n\ncontext_id\x18\x02 \x01(\x0b\x32\x12.context.ContextId\"Z\n\nTopologyId\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12$\n\rtopology_uuid\x18\x02 \x01(\x0b\x32\r.context.Uuid\"t\n\x08Topology\x12(\n\x0btopology_id\x18\x01 \x01(\x0b\x32\x13.context.TopologyId\x12 \n\x07\x64\x65vices\x18\x02 \x03(\x0b\x32\x0f.context.Device\x12\x1c\n\x05links\x18\x03 \x03(\x0b\x32\r.context.Link\";\n\x0eTopologyIdList\x12)\n\x0ctopology_ids\x18\x01 \x03(\x0b\x32\x13.context.TopologyId\"5\n\x0cTopologyList\x12%\n\ntopologies\x18\x01 \x03(\x0b\x32\x11.context.Topology\"X\n\rTopologyEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12(\n\x0btopology_id\x18\x02 \x01(\x0b\x32\x13.context.TopologyId\".\n\x08\x44\x65viceId\x12\"\n\x0b\x64\x65vice_uuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"\x8f\x02\n\x06\x44\x65vice\x12$\n\tdevice_id\x18\x01 \x01(\x0b\x32\x11.context.DeviceId\x12\x13\n\x0b\x64\x65vice_type\x18\x02 \x01(\t\x12,\n\rdevice_config\x18\x03 \x01(\x0b\x32\x15.context.DeviceConfig\x12\x43\n\x19\x64\x65vive_operational_status\x18\x04 \x01(\x0e\x32 .context.DeviceOperationalStatus\x12\x31\n\x0e\x64\x65vice_drivers\x18\x05 \x03(\x0e\x32\x19.context.DeviceDriverEnum\x12$\n\tendpoints\x18\x06 \x03(\x0b\x32\x11.context.EndPoint\"9\n\x0c\x44\x65viceConfig\x12)\n\x0c\x63onfig_rules\x18\x01 \x03(\x0b\x32\x13.context.ConfigRule\"5\n\x0c\x44\x65viceIdList\x12%\n\ndevice_ids\x18\x01 \x03(\x0b\x32\x11.context.DeviceId\".\n\nDeviceList\x12 \n\x07\x64\x65vices\x18\x01 \x03(\x0b\x32\x0f.context.Device\"R\n\x0b\x44\x65viceEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12$\n\tdevice_id\x18\x02 \x01(\x0b\x32\x11.context.DeviceId\"*\n\x06LinkId\x12 \n\tlink_uuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"P\n\x04Link\x12 \n\x07link_id\x18\x01 \x01(\x0b\x32\x0f.context.LinkId\x12&\n\tendpoints\x18\x02 \x03(\x0b\x32\x13.context.EndPointId\"/\n\nLinkIdList\x12!\n\x08link_ids\x18\x01 \x03(\x0b\x32\x0f.context.LinkId\"(\n\x08LinkList\x12\x1c\n\x05links\x18\x01 \x03(\x0b\x32\r.context.Link\"L\n\tLinkEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12 \n\x07link_id\x18\x02 \x01(\x0b\x32\x0f.context.LinkId\"X\n\tServiceId\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12#\n\x0cservice_uuid\x18\x02 \x01(\x0b\x32\r.context.Uuid\"\x91\x02\n\x07Service\x12&\n\nservice_id\x18\x01 \x01(\x0b\x32\x12.context.ServiceId\x12.\n\x0cservice_type\x18\x02 \x01(\x0e\x32\x18.context.ServiceTypeEnum\x12&\n\tendpoints\x18\x03 \x03(\x0b\x32\x13.context.EndPointId\x12(\n\x0b\x63onstraints\x18\x04 \x03(\x0b\x32\x13.context.Constraint\x12,\n\rservice_state\x18\x05 \x01(\x0b\x32\x15.context.ServiceState\x12.\n\x0eservice_config\x18\x06 \x01(\x0b\x32\x16.context.ServiceConfig\"@\n\x0cServiceState\x12\x30\n\rservice_state\x18\x01 \x01(\x0e\x32\x19.context.ServiceStateEnum\":\n\rServiceConfig\x12)\n\x0c\x63onfig_rules\x18\x01 \x03(\x0b\x32\x13.context.ConfigRule\"8\n\rServiceIdList\x12\'\n\x0bservice_ids\x18\x01 \x03(\x0b\x32\x12.context.ServiceId\"1\n\x0bServiceList\x12\"\n\x08services\x18\x01 \x03(\x0b\x32\x10.context.Service\"U\n\x0cServiceEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12&\n\nservice_id\x18\x02 \x01(\x0b\x32\x12.context.ServiceId\"\x82\x01\n\nEndPointId\x12(\n\x0btopology_id\x18\x01 \x01(\x0b\x32\x13.context.TopologyId\x12$\n\tdevice_id\x18\x02 \x01(\x0b\x32\x11.context.DeviceId\x12$\n\rendpoint_uuid\x18\x03 \x01(\x0b\x32\r.context.Uuid\"G\n\x08\x45ndPoint\x12(\n\x0b\x65ndpoint_id\x18\x01 \x01(\x0b\x32\x13.context.EndPointId\x12\x11\n\tport_type\x18\x02 \x01(\t\"e\n\nConfigRule\x12)\n\x06\x61\x63tion\x18\x01 \x01(\x0e\x32\x19.context.ConfigActionEnum\x12\x14\n\x0cresource_key\x18\x02 \x01(\t\x12\x16\n\x0eresource_value\x18\x03 \x01(\t\"?\n\nConstraint\x12\x17\n\x0f\x63onstraint_type\x18\x01 \x01(\t\x12\x18\n\x10\x63onstraint_value\x18\x02 \x01(\t\"6\n\x0c\x43onnectionId\x12&\n\x0f\x63onnection_uuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"\x8d\x01\n\nConnection\x12,\n\rconnection_id\x18\x01 \x01(\x0b\x32\x15.context.ConnectionId\x12.\n\x12related_service_id\x18\x02 \x01(\x0b\x32\x12.context.ServiceId\x12!\n\x04path\x18\x03 \x03(\x0b\x32\x13.context.EndPointId\"A\n\x10\x43onnectionIdList\x12-\n\x0e\x63onnection_ids\x18\x01 \x03(\x0b\x32\x15.context.ConnectionId\":\n\x0e\x43onnectionList\x12(\n\x0b\x63onnections\x18\x01 \x03(\x0b\x32\x13.context.Connection\"^\n\x12TeraFlowController\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x12\n\nip_address\x18\x02 \x01(\t\x12\x0c\n\x04port\x18\x03 \x01(\r\"U\n\x14\x41uthenticationResult\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x15\n\rauthenticated\x18\x02 \x01(\x08*j\n\rEventTypeEnum\x12\x17\n\x13\x45VENTTYPE_UNDEFINED\x10\x00\x12\x14\n\x10\x45VENTTYPE_CREATE\x10\x01\x12\x14\n\x10\x45VENTTYPE_UPDATE\x10\x02\x12\x14\n\x10\x45VENTTYPE_REMOVE\x10\x03*\xc5\x01\n\x10\x44\x65viceDriverEnum\x12\x1a\n\x16\x44\x45VICEDRIVER_UNDEFINED\x10\x00\x12\x1b\n\x17\x44\x45VICEDRIVER_OPENCONFIG\x10\x01\x12\x1e\n\x1a\x44\x45VICEDRIVER_TRANSPORT_API\x10\x02\x12\x13\n\x0f\x44\x45VICEDRIVER_P4\x10\x03\x12&\n\"DEVICEDRIVER_IETF_NETWORK_TOPOLOGY\x10\x04\x12\x1b\n\x17\x44\x45VICEDRIVER_ONF_TR_352\x10\x05*N\n\x17\x44\x65viceOperationalStatus\x12\x0f\n\x0bKEEP_STATUS\x10\x00\x12\x15\n\x08\x44ISABLED\x10\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01\x12\x0b\n\x07\x45NABLED\x10\x01*\x81\x01\n\x0fServiceTypeEnum\x12\x17\n\x13SERVICETYPE_UNKNOWN\x10\x00\x12\x14\n\x10SERVICETYPE_L3NM\x10\x01\x12\x14\n\x10SERVICETYPE_L2NM\x10\x02\x12)\n%SERVICETYPE_TAPI_CONNECTIVITY_SERVICE\x10\x03*j\n\x10ServiceStateEnum\x12\x19\n\x15SERVICESTATUS_PLANNED\x10\x00\x12\x18\n\x14SERVICESTATUS_ACTIVE\x10\x01\x12!\n\x1dSERVICESTATUS_PENDING_REMOVAL\x10\x02*]\n\x10\x43onfigActionEnum\x12\x1a\n\x16\x43ONFIGACTION_UNDEFINED\x10\x00\x12\x14\n\x10\x43ONFIGACTION_SET\x10\x01\x12\x17\n\x13\x43ONFIGACTION_DELETE\x10\x02\x32\xa5\r\n\x0e\x43ontextService\x12:\n\x0eListContextIds\x12\x0e.context.Empty\x1a\x16.context.ContextIdList\"\x00\x12\x36\n\x0cListContexts\x12\x0e.context.Empty\x1a\x14.context.ContextList\"\x00\x12\x34\n\nGetContext\x12\x12.context.ContextId\x1a\x10.context.Context\"\x00\x12\x34\n\nSetContext\x12\x10.context.Context\x1a\x12.context.ContextId\"\x00\x12\x35\n\rRemoveContext\x12\x12.context.ContextId\x1a\x0e.context.Empty\"\x00\x12=\n\x10GetContextEvents\x12\x0e.context.Empty\x1a\x15.context.ContextEvent\"\x00\x30\x01\x12@\n\x0fListTopologyIds\x12\x12.context.ContextId\x1a\x17.context.TopologyIdList\"\x00\x12=\n\x0eListTopologies\x12\x12.context.ContextId\x1a\x15.context.TopologyList\"\x00\x12\x37\n\x0bGetTopology\x12\x13.context.TopologyId\x1a\x11.context.Topology\"\x00\x12\x37\n\x0bSetTopology\x12\x11.context.Topology\x1a\x13.context.TopologyId\"\x00\x12\x37\n\x0eRemoveTopology\x12\x13.context.TopologyId\x1a\x0e.context.Empty\"\x00\x12?\n\x11GetTopologyEvents\x12\x0e.context.Empty\x1a\x16.context.TopologyEvent\"\x00\x30\x01\x12\x38\n\rListDeviceIds\x12\x0e.context.Empty\x1a\x15.context.DeviceIdList\"\x00\x12\x34\n\x0bListDevices\x12\x0e.context.Empty\x1a\x13.context.DeviceList\"\x00\x12\x31\n\tGetDevice\x12\x11.context.DeviceId\x1a\x0f.context.Device\"\x00\x12\x31\n\tSetDevice\x12\x0f.context.Device\x1a\x11.context.DeviceId\"\x00\x12\x33\n\x0cRemoveDevice\x12\x11.context.DeviceId\x1a\x0e.context.Empty\"\x00\x12;\n\x0fGetDeviceEvents\x12\x0e.context.Empty\x1a\x14.context.DeviceEvent\"\x00\x30\x01\x12\x34\n\x0bListLinkIds\x12\x0e.context.Empty\x1a\x13.context.LinkIdList\"\x00\x12\x30\n\tListLinks\x12\x0e.context.Empty\x1a\x11.context.LinkList\"\x00\x12+\n\x07GetLink\x12\x0f.context.LinkId\x1a\r.context.Link\"\x00\x12+\n\x07SetLink\x12\r.context.Link\x1a\x0f.context.LinkId\"\x00\x12/\n\nRemoveLink\x12\x0f.context.LinkId\x1a\x0e.context.Empty\"\x00\x12\x37\n\rGetLinkEvents\x12\x0e.context.Empty\x1a\x12.context.LinkEvent\"\x00\x30\x01\x12>\n\x0eListServiceIds\x12\x12.context.ContextId\x1a\x16.context.ServiceIdList\"\x00\x12:\n\x0cListServices\x12\x12.context.ContextId\x1a\x14.context.ServiceList\"\x00\x12\x34\n\nGetService\x12\x12.context.ServiceId\x1a\x10.context.Service\"\x00\x12\x34\n\nSetService\x12\x10.context.Service\x1a\x12.context.ServiceId\"\x00\x12\x35\n\rRemoveService\x12\x12.context.ServiceId\x1a\x0e.context.Empty\"\x00\x12=\n\x10GetServiceEvents\x12\x0e.context.Empty\x1a\x15.context.ServiceEvent\"\x00\x30\x01\x62\x06proto3' + serialized_pb=b'\n\rcontext.proto\x12\x07\x63ontext\"\x07\n\x05\x45mpty\"\x14\n\x04Uuid\x12\x0c\n\x04uuid\x18\x01 \x01(\t\"F\n\x05\x45vent\x12\x11\n\ttimestamp\x18\x01 \x01(\x01\x12*\n\nevent_type\x18\x02 \x01(\x0e\x32\x16.context.EventTypeEnum\"0\n\tContextId\x12#\n\x0c\x63ontext_uuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"\x87\x01\n\x07\x43ontext\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12#\n\x08topology\x18\x02 \x03(\x0b\x32\x11.context.Topology\x12/\n\ncontroller\x18\x03 \x01(\x0b\x32\x1b.context.TeraFlowController\"8\n\rContextIdList\x12\'\n\x0b\x63ontext_ids\x18\x01 \x03(\x0b\x32\x12.context.ContextId\"1\n\x0b\x43ontextList\x12\"\n\x08\x63ontexts\x18\x01 \x03(\x0b\x32\x10.context.Context\"U\n\x0c\x43ontextEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12&\n\ncontext_id\x18\x02 \x01(\x0b\x32\x12.context.ContextId\"Z\n\nTopologyId\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12$\n\rtopology_uuid\x18\x02 \x01(\x0b\x32\r.context.Uuid\"~\n\x08Topology\x12(\n\x0btopology_id\x18\x01 \x01(\x0b\x32\x13.context.TopologyId\x12%\n\ndevice_ids\x18\x02 \x03(\x0b\x32\x11.context.DeviceId\x12!\n\x08link_ids\x18\x03 \x03(\x0b\x32\x0f.context.LinkId\";\n\x0eTopologyIdList\x12)\n\x0ctopology_ids\x18\x01 \x03(\x0b\x32\x13.context.TopologyId\"5\n\x0cTopologyList\x12%\n\ntopologies\x18\x01 \x03(\x0b\x32\x11.context.Topology\"X\n\rTopologyEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12(\n\x0btopology_id\x18\x02 \x01(\x0b\x32\x13.context.TopologyId\".\n\x08\x44\x65viceId\x12\"\n\x0b\x64\x65vice_uuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"\x8f\x02\n\x06\x44\x65vice\x12$\n\tdevice_id\x18\x01 \x01(\x0b\x32\x11.context.DeviceId\x12\x13\n\x0b\x64\x65vice_type\x18\x02 \x01(\t\x12,\n\rdevice_config\x18\x03 \x01(\x0b\x32\x15.context.DeviceConfig\x12\x43\n\x19\x64\x65vive_operational_status\x18\x04 \x01(\x0e\x32 .context.DeviceOperationalStatus\x12\x31\n\x0e\x64\x65vice_drivers\x18\x05 \x03(\x0e\x32\x19.context.DeviceDriverEnum\x12$\n\tendpoints\x18\x06 \x03(\x0b\x32\x11.context.EndPoint\"9\n\x0c\x44\x65viceConfig\x12)\n\x0c\x63onfig_rules\x18\x01 \x03(\x0b\x32\x13.context.ConfigRule\"5\n\x0c\x44\x65viceIdList\x12%\n\ndevice_ids\x18\x01 \x03(\x0b\x32\x11.context.DeviceId\".\n\nDeviceList\x12 \n\x07\x64\x65vices\x18\x01 \x03(\x0b\x32\x0f.context.Device\"R\n\x0b\x44\x65viceEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12$\n\tdevice_id\x18\x02 \x01(\x0b\x32\x11.context.DeviceId\"*\n\x06LinkId\x12 \n\tlink_uuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"S\n\x04Link\x12 \n\x07link_id\x18\x01 \x01(\x0b\x32\x0f.context.LinkId\x12)\n\x0c\x65ndpoint_ids\x18\x02 \x03(\x0b\x32\x13.context.EndPointId\"/\n\nLinkIdList\x12!\n\x08link_ids\x18\x01 \x03(\x0b\x32\x0f.context.LinkId\"(\n\x08LinkList\x12\x1c\n\x05links\x18\x01 \x03(\x0b\x32\r.context.Link\"L\n\tLinkEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12 \n\x07link_id\x18\x02 \x01(\x0b\x32\x0f.context.LinkId\"X\n\tServiceId\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12#\n\x0cservice_uuid\x18\x02 \x01(\x0b\x32\r.context.Uuid\"\x94\x02\n\x07Service\x12&\n\nservice_id\x18\x01 \x01(\x0b\x32\x12.context.ServiceId\x12.\n\x0cservice_type\x18\x02 \x01(\x0e\x32\x18.context.ServiceTypeEnum\x12)\n\x0c\x65ndpoint_ids\x18\x03 \x03(\x0b\x32\x13.context.EndPointId\x12(\n\x0b\x63onstraints\x18\x04 \x03(\x0b\x32\x13.context.Constraint\x12,\n\rservice_state\x18\x05 \x01(\x0b\x32\x15.context.ServiceState\x12.\n\x0eservice_config\x18\x06 \x01(\x0b\x32\x16.context.ServiceConfig\"@\n\x0cServiceState\x12\x30\n\rservice_state\x18\x01 \x01(\x0e\x32\x19.context.ServiceStateEnum\":\n\rServiceConfig\x12)\n\x0c\x63onfig_rules\x18\x01 \x03(\x0b\x32\x13.context.ConfigRule\"8\n\rServiceIdList\x12\'\n\x0bservice_ids\x18\x01 \x03(\x0b\x32\x12.context.ServiceId\"1\n\x0bServiceList\x12\"\n\x08services\x18\x01 \x03(\x0b\x32\x10.context.Service\"U\n\x0cServiceEvent\x12\x1d\n\x05\x65vent\x18\x01 \x01(\x0b\x32\x0e.context.Event\x12&\n\nservice_id\x18\x02 \x01(\x0b\x32\x12.context.ServiceId\"\x82\x01\n\nEndPointId\x12(\n\x0btopology_id\x18\x01 \x01(\x0b\x32\x13.context.TopologyId\x12$\n\tdevice_id\x18\x02 \x01(\x0b\x32\x11.context.DeviceId\x12$\n\rendpoint_uuid\x18\x03 \x01(\x0b\x32\r.context.Uuid\"G\n\x08\x45ndPoint\x12(\n\x0b\x65ndpoint_id\x18\x01 \x01(\x0b\x32\x13.context.EndPointId\x12\x11\n\tport_type\x18\x02 \x01(\t\"e\n\nConfigRule\x12)\n\x06\x61\x63tion\x18\x01 \x01(\x0e\x32\x19.context.ConfigActionEnum\x12\x14\n\x0cresource_key\x18\x02 \x01(\t\x12\x16\n\x0eresource_value\x18\x03 \x01(\t\"?\n\nConstraint\x12\x17\n\x0f\x63onstraint_type\x18\x01 \x01(\t\x12\x18\n\x10\x63onstraint_value\x18\x02 \x01(\t\"6\n\x0c\x43onnectionId\x12&\n\x0f\x63onnection_uuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"\x8d\x01\n\nConnection\x12,\n\rconnection_id\x18\x01 \x01(\x0b\x32\x15.context.ConnectionId\x12.\n\x12related_service_id\x18\x02 \x01(\x0b\x32\x12.context.ServiceId\x12!\n\x04path\x18\x03 \x03(\x0b\x32\x13.context.EndPointId\"A\n\x10\x43onnectionIdList\x12-\n\x0e\x63onnection_ids\x18\x01 \x03(\x0b\x32\x15.context.ConnectionId\":\n\x0e\x43onnectionList\x12(\n\x0b\x63onnections\x18\x01 \x03(\x0b\x32\x13.context.Connection\"^\n\x12TeraFlowController\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x12\n\nip_address\x18\x02 \x01(\t\x12\x0c\n\x04port\x18\x03 \x01(\r\"U\n\x14\x41uthenticationResult\x12&\n\ncontext_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x15\n\rauthenticated\x18\x02 \x01(\x08*j\n\rEventTypeEnum\x12\x17\n\x13\x45VENTTYPE_UNDEFINED\x10\x00\x12\x14\n\x10\x45VENTTYPE_CREATE\x10\x01\x12\x14\n\x10\x45VENTTYPE_UPDATE\x10\x02\x12\x14\n\x10\x45VENTTYPE_REMOVE\x10\x03*\xc5\x01\n\x10\x44\x65viceDriverEnum\x12\x1a\n\x16\x44\x45VICEDRIVER_UNDEFINED\x10\x00\x12\x1b\n\x17\x44\x45VICEDRIVER_OPENCONFIG\x10\x01\x12\x1e\n\x1a\x44\x45VICEDRIVER_TRANSPORT_API\x10\x02\x12\x13\n\x0f\x44\x45VICEDRIVER_P4\x10\x03\x12&\n\"DEVICEDRIVER_IETF_NETWORK_TOPOLOGY\x10\x04\x12\x1b\n\x17\x44\x45VICEDRIVER_ONF_TR_352\x10\x05*C\n\x17\x44\x65viceOperationalStatus\x12\r\n\tUNDEFINED\x10\x00\x12\x0c\n\x08\x44ISABLED\x10\x01\x12\x0b\n\x07\x45NABLED\x10\x02*\x81\x01\n\x0fServiceTypeEnum\x12\x17\n\x13SERVICETYPE_UNKNOWN\x10\x00\x12\x14\n\x10SERVICETYPE_L3NM\x10\x01\x12\x14\n\x10SERVICETYPE_L2NM\x10\x02\x12)\n%SERVICETYPE_TAPI_CONNECTIVITY_SERVICE\x10\x03*j\n\x10ServiceStateEnum\x12\x19\n\x15SERVICESTATUS_PLANNED\x10\x00\x12\x18\n\x14SERVICESTATUS_ACTIVE\x10\x01\x12!\n\x1dSERVICESTATUS_PENDING_REMOVAL\x10\x02*]\n\x10\x43onfigActionEnum\x12\x1a\n\x16\x43ONFIGACTION_UNDEFINED\x10\x00\x12\x14\n\x10\x43ONFIGACTION_SET\x10\x01\x12\x17\n\x13\x43ONFIGACTION_DELETE\x10\x02\x32\xa5\r\n\x0e\x43ontextService\x12:\n\x0eListContextIds\x12\x0e.context.Empty\x1a\x16.context.ContextIdList\"\x00\x12\x36\n\x0cListContexts\x12\x0e.context.Empty\x1a\x14.context.ContextList\"\x00\x12\x34\n\nGetContext\x12\x12.context.ContextId\x1a\x10.context.Context\"\x00\x12\x34\n\nSetContext\x12\x10.context.Context\x1a\x12.context.ContextId\"\x00\x12\x35\n\rRemoveContext\x12\x12.context.ContextId\x1a\x0e.context.Empty\"\x00\x12=\n\x10GetContextEvents\x12\x0e.context.Empty\x1a\x15.context.ContextEvent\"\x00\x30\x01\x12@\n\x0fListTopologyIds\x12\x12.context.ContextId\x1a\x17.context.TopologyIdList\"\x00\x12=\n\x0eListTopologies\x12\x12.context.ContextId\x1a\x15.context.TopologyList\"\x00\x12\x37\n\x0bGetTopology\x12\x13.context.TopologyId\x1a\x11.context.Topology\"\x00\x12\x37\n\x0bSetTopology\x12\x11.context.Topology\x1a\x13.context.TopologyId\"\x00\x12\x37\n\x0eRemoveTopology\x12\x13.context.TopologyId\x1a\x0e.context.Empty\"\x00\x12?\n\x11GetTopologyEvents\x12\x0e.context.Empty\x1a\x16.context.TopologyEvent\"\x00\x30\x01\x12\x38\n\rListDeviceIds\x12\x0e.context.Empty\x1a\x15.context.DeviceIdList\"\x00\x12\x34\n\x0bListDevices\x12\x0e.context.Empty\x1a\x13.context.DeviceList\"\x00\x12\x31\n\tGetDevice\x12\x11.context.DeviceId\x1a\x0f.context.Device\"\x00\x12\x31\n\tSetDevice\x12\x0f.context.Device\x1a\x11.context.DeviceId\"\x00\x12\x33\n\x0cRemoveDevice\x12\x11.context.DeviceId\x1a\x0e.context.Empty\"\x00\x12;\n\x0fGetDeviceEvents\x12\x0e.context.Empty\x1a\x14.context.DeviceEvent\"\x00\x30\x01\x12\x34\n\x0bListLinkIds\x12\x0e.context.Empty\x1a\x13.context.LinkIdList\"\x00\x12\x30\n\tListLinks\x12\x0e.context.Empty\x1a\x11.context.LinkList\"\x00\x12+\n\x07GetLink\x12\x0f.context.LinkId\x1a\r.context.Link\"\x00\x12+\n\x07SetLink\x12\r.context.Link\x1a\x0f.context.LinkId\"\x00\x12/\n\nRemoveLink\x12\x0f.context.LinkId\x1a\x0e.context.Empty\"\x00\x12\x37\n\rGetLinkEvents\x12\x0e.context.Empty\x1a\x12.context.LinkEvent\"\x00\x30\x01\x12>\n\x0eListServiceIds\x12\x12.context.ContextId\x1a\x16.context.ServiceIdList\"\x00\x12:\n\x0cListServices\x12\x12.context.ContextId\x1a\x14.context.ServiceList\"\x00\x12\x34\n\nGetService\x12\x12.context.ServiceId\x1a\x10.context.Service\"\x00\x12\x34\n\nSetService\x12\x10.context.Service\x1a\x12.context.ServiceId\"\x00\x12\x35\n\rRemoveService\x12\x12.context.ServiceId\x1a\x0e.context.Empty\"\x00\x12=\n\x10GetServiceEvents\x12\x0e.context.Empty\x1a\x15.context.ServiceEvent\"\x00\x30\x01\x62\x06proto3' ) _EVENTTYPEENUM = _descriptor.EnumDescriptor( @@ -53,8 +53,8 @@ _EVENTTYPEENUM = _descriptor.EnumDescriptor( ], containing_type=None, serialized_options=None, - serialized_start=3364, - serialized_end=3470, + serialized_start=3380, + serialized_end=3486, ) _sym_db.RegisterEnumDescriptor(_EVENTTYPEENUM) @@ -99,8 +99,8 @@ _DEVICEDRIVERENUM = _descriptor.EnumDescriptor( ], containing_type=None, serialized_options=None, - serialized_start=3473, - serialized_end=3670, + serialized_start=3489, + serialized_end=3686, ) _sym_db.RegisterEnumDescriptor(_DEVICEDRIVERENUM) @@ -113,25 +113,25 @@ _DEVICEOPERATIONALSTATUS = _descriptor.EnumDescriptor( create_key=_descriptor._internal_create_key, values=[ _descriptor.EnumValueDescriptor( - name='KEEP_STATUS', index=0, number=0, + name='UNDEFINED', index=0, number=0, serialized_options=None, type=None, create_key=_descriptor._internal_create_key), _descriptor.EnumValueDescriptor( - name='DISABLED', index=1, number=-1, + name='DISABLED', index=1, number=1, serialized_options=None, type=None, create_key=_descriptor._internal_create_key), _descriptor.EnumValueDescriptor( - name='ENABLED', index=2, number=1, + name='ENABLED', index=2, number=2, serialized_options=None, type=None, create_key=_descriptor._internal_create_key), ], containing_type=None, serialized_options=None, - serialized_start=3672, - serialized_end=3750, + serialized_start=3688, + serialized_end=3755, ) _sym_db.RegisterEnumDescriptor(_DEVICEOPERATIONALSTATUS) @@ -166,8 +166,8 @@ _SERVICETYPEENUM = _descriptor.EnumDescriptor( ], containing_type=None, serialized_options=None, - serialized_start=3753, - serialized_end=3882, + serialized_start=3758, + serialized_end=3887, ) _sym_db.RegisterEnumDescriptor(_SERVICETYPEENUM) @@ -197,8 +197,8 @@ _SERVICESTATEENUM = _descriptor.EnumDescriptor( ], containing_type=None, serialized_options=None, - serialized_start=3884, - serialized_end=3990, + serialized_start=3889, + serialized_end=3995, ) _sym_db.RegisterEnumDescriptor(_SERVICESTATEENUM) @@ -228,8 +228,8 @@ _CONFIGACTIONENUM = _descriptor.EnumDescriptor( ], containing_type=None, serialized_options=None, - serialized_start=3992, - serialized_end=4085, + serialized_start=3997, + serialized_end=4090, ) _sym_db.RegisterEnumDescriptor(_CONFIGACTIONENUM) @@ -244,9 +244,9 @@ DEVICEDRIVER_TRANSPORT_API = 2 DEVICEDRIVER_P4 = 3 DEVICEDRIVER_IETF_NETWORK_TOPOLOGY = 4 DEVICEDRIVER_ONF_TR_352 = 5 -KEEP_STATUS = 0 -DISABLED = -1 -ENABLED = 1 +UNDEFINED = 0 +DISABLED = 1 +ENABLED = 2 SERVICETYPE_UNKNOWN = 0 SERVICETYPE_L3NM = 1 SERVICETYPE_L2NM = 2 @@ -592,14 +592,14 @@ _TOPOLOGY = _descriptor.Descriptor( is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='devices', full_name='context.Topology.devices', index=1, + name='device_ids', full_name='context.Topology.device_ids', index=1, number=2, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='links', full_name='context.Topology.links', index=2, + name='link_ids', full_name='context.Topology.link_ids', index=2, number=3, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, @@ -618,7 +618,7 @@ _TOPOLOGY = _descriptor.Descriptor( oneofs=[ ], serialized_start=605, - serialized_end=721, + serialized_end=731, ) @@ -649,8 +649,8 @@ _TOPOLOGYIDLIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=723, - serialized_end=782, + serialized_start=733, + serialized_end=792, ) @@ -681,8 +681,8 @@ _TOPOLOGYLIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=784, - serialized_end=837, + serialized_start=794, + serialized_end=847, ) @@ -720,8 +720,8 @@ _TOPOLOGYEVENT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=839, - serialized_end=927, + serialized_start=849, + serialized_end=937, ) @@ -752,8 +752,8 @@ _DEVICEID = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=929, - serialized_end=975, + serialized_start=939, + serialized_end=985, ) @@ -819,8 +819,8 @@ _DEVICE = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=978, - serialized_end=1249, + serialized_start=988, + serialized_end=1259, ) @@ -851,8 +851,8 @@ _DEVICECONFIG = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1251, - serialized_end=1308, + serialized_start=1261, + serialized_end=1318, ) @@ -883,8 +883,8 @@ _DEVICEIDLIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1310, - serialized_end=1363, + serialized_start=1320, + serialized_end=1373, ) @@ -915,8 +915,8 @@ _DEVICELIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1365, - serialized_end=1411, + serialized_start=1375, + serialized_end=1421, ) @@ -954,8 +954,8 @@ _DEVICEEVENT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1413, - serialized_end=1495, + serialized_start=1423, + serialized_end=1505, ) @@ -986,8 +986,8 @@ _LINKID = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1497, - serialized_end=1539, + serialized_start=1507, + serialized_end=1549, ) @@ -1007,7 +1007,7 @@ _LINK = _descriptor.Descriptor( is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='endpoints', full_name='context.Link.endpoints', index=1, + name='endpoint_ids', full_name='context.Link.endpoint_ids', index=1, number=2, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, @@ -1025,8 +1025,8 @@ _LINK = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1541, - serialized_end=1621, + serialized_start=1551, + serialized_end=1634, ) @@ -1057,8 +1057,8 @@ _LINKIDLIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1623, - serialized_end=1670, + serialized_start=1636, + serialized_end=1683, ) @@ -1089,8 +1089,8 @@ _LINKLIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1672, - serialized_end=1712, + serialized_start=1685, + serialized_end=1725, ) @@ -1128,8 +1128,8 @@ _LINKEVENT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1714, - serialized_end=1790, + serialized_start=1727, + serialized_end=1803, ) @@ -1167,8 +1167,8 @@ _SERVICEID = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1792, - serialized_end=1880, + serialized_start=1805, + serialized_end=1893, ) @@ -1195,7 +1195,7 @@ _SERVICE = _descriptor.Descriptor( is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='endpoints', full_name='context.Service.endpoints', index=2, + name='endpoint_ids', full_name='context.Service.endpoint_ids', index=2, number=3, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, @@ -1234,8 +1234,8 @@ _SERVICE = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1883, - serialized_end=2156, + serialized_start=1896, + serialized_end=2172, ) @@ -1266,8 +1266,8 @@ _SERVICESTATE = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2158, - serialized_end=2222, + serialized_start=2174, + serialized_end=2238, ) @@ -1298,8 +1298,8 @@ _SERVICECONFIG = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2224, - serialized_end=2282, + serialized_start=2240, + serialized_end=2298, ) @@ -1330,8 +1330,8 @@ _SERVICEIDLIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2284, - serialized_end=2340, + serialized_start=2300, + serialized_end=2356, ) @@ -1362,8 +1362,8 @@ _SERVICELIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2342, - serialized_end=2391, + serialized_start=2358, + serialized_end=2407, ) @@ -1401,8 +1401,8 @@ _SERVICEEVENT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2393, - serialized_end=2478, + serialized_start=2409, + serialized_end=2494, ) @@ -1447,8 +1447,8 @@ _ENDPOINTID = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2481, - serialized_end=2611, + serialized_start=2497, + serialized_end=2627, ) @@ -1486,8 +1486,8 @@ _ENDPOINT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2613, - serialized_end=2684, + serialized_start=2629, + serialized_end=2700, ) @@ -1532,8 +1532,8 @@ _CONFIGRULE = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2686, - serialized_end=2787, + serialized_start=2702, + serialized_end=2803, ) @@ -1571,8 +1571,8 @@ _CONSTRAINT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2789, - serialized_end=2852, + serialized_start=2805, + serialized_end=2868, ) @@ -1603,8 +1603,8 @@ _CONNECTIONID = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2854, - serialized_end=2908, + serialized_start=2870, + serialized_end=2924, ) @@ -1649,8 +1649,8 @@ _CONNECTION = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2911, - serialized_end=3052, + serialized_start=2927, + serialized_end=3068, ) @@ -1681,8 +1681,8 @@ _CONNECTIONIDLIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=3054, - serialized_end=3119, + serialized_start=3070, + serialized_end=3135, ) @@ -1713,8 +1713,8 @@ _CONNECTIONLIST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=3121, - serialized_end=3179, + serialized_start=3137, + serialized_end=3195, ) @@ -1759,8 +1759,8 @@ _TERAFLOWCONTROLLER = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=3181, - serialized_end=3275, + serialized_start=3197, + serialized_end=3291, ) @@ -1798,8 +1798,8 @@ _AUTHENTICATIONRESULT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=3277, - serialized_end=3362, + serialized_start=3293, + serialized_end=3378, ) _EVENT.fields_by_name['event_type'].enum_type = _EVENTTYPEENUM @@ -1814,8 +1814,8 @@ _CONTEXTEVENT.fields_by_name['context_id'].message_type = _CONTEXTID _TOPOLOGYID.fields_by_name['context_id'].message_type = _CONTEXTID _TOPOLOGYID.fields_by_name['topology_uuid'].message_type = _UUID _TOPOLOGY.fields_by_name['topology_id'].message_type = _TOPOLOGYID -_TOPOLOGY.fields_by_name['devices'].message_type = _DEVICE -_TOPOLOGY.fields_by_name['links'].message_type = _LINK +_TOPOLOGY.fields_by_name['device_ids'].message_type = _DEVICEID +_TOPOLOGY.fields_by_name['link_ids'].message_type = _LINKID _TOPOLOGYIDLIST.fields_by_name['topology_ids'].message_type = _TOPOLOGYID _TOPOLOGYLIST.fields_by_name['topologies'].message_type = _TOPOLOGY _TOPOLOGYEVENT.fields_by_name['event'].message_type = _EVENT @@ -1833,7 +1833,7 @@ _DEVICEEVENT.fields_by_name['event'].message_type = _EVENT _DEVICEEVENT.fields_by_name['device_id'].message_type = _DEVICEID _LINKID.fields_by_name['link_uuid'].message_type = _UUID _LINK.fields_by_name['link_id'].message_type = _LINKID -_LINK.fields_by_name['endpoints'].message_type = _ENDPOINTID +_LINK.fields_by_name['endpoint_ids'].message_type = _ENDPOINTID _LINKIDLIST.fields_by_name['link_ids'].message_type = _LINKID _LINKLIST.fields_by_name['links'].message_type = _LINK _LINKEVENT.fields_by_name['event'].message_type = _EVENT @@ -1842,7 +1842,7 @@ _SERVICEID.fields_by_name['context_id'].message_type = _CONTEXTID _SERVICEID.fields_by_name['service_uuid'].message_type = _UUID _SERVICE.fields_by_name['service_id'].message_type = _SERVICEID _SERVICE.fields_by_name['service_type'].enum_type = _SERVICETYPEENUM -_SERVICE.fields_by_name['endpoints'].message_type = _ENDPOINTID +_SERVICE.fields_by_name['endpoint_ids'].message_type = _ENDPOINTID _SERVICE.fields_by_name['constraints'].message_type = _CONSTRAINT _SERVICE.fields_by_name['service_state'].message_type = _SERVICESTATE _SERVICE.fields_by_name['service_config'].message_type = _SERVICECONFIG @@ -2210,8 +2210,8 @@ _CONTEXTSERVICE = _descriptor.ServiceDescriptor( index=0, serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_start=4088, - serialized_end=5789, + serialized_start=4093, + serialized_end=5794, methods=[ _descriptor.MethodDescriptor( name='ListContextIds', diff --git a/src/context/service/database/Models.py b/src/context/service/database/Models.py new file mode 100644 index 0000000000000000000000000000000000000000..8b8d974d6c3383ba1e0241c1cb8b87c3a279fa94 --- /dev/null +++ b/src/context/service/database/Models.py @@ -0,0 +1,56 @@ +from common.orm.fields.IntegerField import IntegerField +from common.orm.fields.StringField import StringField +from common.orm.model.Model import Model +from common.orm.fields.ForeignKeyField import ForeignKeyField +from common.orm.fields.PrimaryKeyField import PrimaryKeyField + +class ContextModel(Model): + pk = PrimaryKeyField() + +class TopologyModel(Model): + pk = PrimaryKeyField() + context_fk = ForeignKeyField(ContextModel) + +class DeviceModel(Model): + pk = PrimaryKeyField() + device_type = StringField() + +class TopologyDeviceModel(Model): + pk = PrimaryKeyField() + topology_fk = ForeignKeyField(TopologyModel) + device_fk = ForeignKeyField(DeviceModel) + +class DeviceConfigModel(Model): + pk = PrimaryKeyField() + device_fk = ForeignKeyField(DeviceModel) + +class DeviceConfigRuleModel(Model): + pk = PrimaryKeyField() + device_config_fk = ForeignKeyField(DeviceConfigModel) + position = IntegerField(min_value=0, required=True) + key = StringField(required=True) + value = StringField(required=True) + +#message Device { +# DeviceConfig device_config = 3; +# DeviceOperationalStatus devive_operational_status = 4; +# repeated DeviceDriverEnum device_drivers = 5; +# repeated EndPoint endpoints = 6; +#} + +class LinkModel(Model): + link_uuid = PrimaryKeyField() + +class TopologyLinkModel(Model): + topology_fk = ForeignKeyField(TopologyModel) + link_fk = ForeignKeyField(LinkModel) + +class EndPointModel(Model): + endpoint_uuid = PrimaryKeyField() + +class ServiceModel(Model): + endpoint_uuid = PrimaryKeyField() + + +# TODO: implement query methods to find, for instance, topologies belonging to a context +# from Context instance, retrieve references of a specific Model type diff --git a/src/context/service/database/old_objects/Collection.py b/src/context/service/database/old_objects/Collection.py new file mode 100644 index 0000000000000000000000000000000000000000..30bc1b6942fd37141cc528fca10551e2e37d528f --- /dev/null +++ b/src/context/service/database/old_objects/Collection.py @@ -0,0 +1,38 @@ +from __future__ import annotations +from typing import List +from ..backend._Backend import _Backend +from ._Object import _Object +from .Tools import format_key + +class Collection: + def __init__(self, parent : _Object, key_pattern : str): + if not issubclass(parent, _Object): + str_class_path = '{}.{}'.format(_Object.__module__, _Object.__name__) + raise AttributeError('parent must inherit from {}'.format(str_class_path)) + if (not isinstance(key_pattern, str)) or (len(key_pattern) == 0): + raise AttributeError('key_pattern must be a non-empty instance of str') + + self._parent = parent + self._backend : _Backend = self._parent.backend + self._key_list = format_key(key_pattern, self._parent, container_name='_list') + self._key_set = format_key(key_pattern, self._parent, container_name='_set') + + def add(self, object_uuid : str) -> None: + if self._backend.set_has(self._key_set, object_uuid): return + self._backend.set_add(self._key_set, object_uuid) + self._backend.list_push_last(self._key_list, object_uuid) + + def get(self) -> List[str]: + return self._backend.list_get_all(self._key_list) + + def contains(self, object_uuid : str) -> bool: + return self._backend.set_has(self._key_set, object_uuid) + + def clear(self) -> None: + self._backend.delete(self._key_set) + self._backend.delete(self._key_list) + + def delete(self, object_uuid : str) -> None: + if not self._backend.set_has(self._key_set, object_uuid): return + self._backend.set_remove(self._key_set, object_uuid) + self._backend.list_remove_first_occurrence(self._key_list, object_uuid) diff --git a/src/context/service/database/objects/Constraint.py b/src/context/service/database/old_objects/Constraint.py similarity index 100% rename from src/context/service/database/objects/Constraint.py rename to src/context/service/database/old_objects/Constraint.py diff --git a/src/context/service/database/objects/Context.py b/src/context/service/database/old_objects/Context.py similarity index 100% rename from src/context/service/database/objects/Context.py rename to src/context/service/database/old_objects/Context.py diff --git a/src/context/service/database/objects/Device.py b/src/context/service/database/old_objects/Device.py similarity index 100% rename from src/context/service/database/objects/Device.py rename to src/context/service/database/old_objects/Device.py diff --git a/src/context/service/database/objects/DeviceOperationalStatus.py b/src/context/service/database/old_objects/DeviceOperationalStatus.py similarity index 100% rename from src/context/service/database/objects/DeviceOperationalStatus.py rename to src/context/service/database/old_objects/DeviceOperationalStatus.py diff --git a/src/context/service/database/objects/Endpoint.py b/src/context/service/database/old_objects/Endpoint.py similarity index 100% rename from src/context/service/database/objects/Endpoint.py rename to src/context/service/database/old_objects/Endpoint.py diff --git a/src/context/service/database/objects/Link.py b/src/context/service/database/old_objects/Link.py similarity index 100% rename from src/context/service/database/objects/Link.py rename to src/context/service/database/old_objects/Link.py diff --git a/src/context/service/database/objects/LinkEndpoint.py b/src/context/service/database/old_objects/LinkEndpoint.py similarity index 100% rename from src/context/service/database/objects/LinkEndpoint.py rename to src/context/service/database/old_objects/LinkEndpoint.py diff --git a/src/context/service/database/objects/Service.py b/src/context/service/database/old_objects/Service.py similarity index 100% rename from src/context/service/database/objects/Service.py rename to src/context/service/database/old_objects/Service.py diff --git a/src/context/service/database/objects/ServiceEndpoint.py b/src/context/service/database/old_objects/ServiceEndpoint.py similarity index 100% rename from src/context/service/database/objects/ServiceEndpoint.py rename to src/context/service/database/old_objects/ServiceEndpoint.py diff --git a/src/context/service/database/objects/ServiceState.py b/src/context/service/database/old_objects/ServiceState.py similarity index 100% rename from src/context/service/database/objects/ServiceState.py rename to src/context/service/database/old_objects/ServiceState.py diff --git a/src/context/service/database/objects/ServiceType.py b/src/context/service/database/old_objects/ServiceType.py similarity index 100% rename from src/context/service/database/objects/ServiceType.py rename to src/context/service/database/old_objects/ServiceType.py diff --git a/src/context/service/database/objects/Topology.py b/src/context/service/database/old_objects/Topology.py similarity index 100% rename from src/context/service/database/objects/Topology.py rename to src/context/service/database/old_objects/Topology.py diff --git a/src/context/service/database/objects/_Keys.py b/src/context/service/database/old_objects/_Keys.py similarity index 100% rename from src/context/service/database/objects/_Keys.py rename to src/context/service/database/old_objects/_Keys.py diff --git a/src/context/service/database/objects/__init__.py b/src/context/service/database/old_objects/__init__.py similarity index 100% rename from src/context/service/database/objects/__init__.py rename to src/context/service/database/old_objects/__init__.py diff --git a/src/context/service/database/objects/_structure.txt b/src/context/service/database/old_objects/_structure.txt similarity index 100% rename from src/context/service/database/objects/_structure.txt rename to src/context/service/database/old_objects/_structure.txt diff --git a/src/context/service/database/Database.py b/src/context/service/database/old_objects/old_Database.py similarity index 100% rename from src/context/service/database/Database.py rename to src/context/service/database/old_objects/old_Database.py diff --git a/src/context/service/grpc_server/ContextServiceServicerImpl.py b/src/context/service/grpc_server/ContextServiceServicerImpl.py index b2c87eba2a6a78f9b511bdd5cb52d5495b531697..6bd10730357fed0d3f45aeb22a2d06bcced3225a 100644 --- a/src/context/service/grpc_server/ContextServiceServicerImpl.py +++ b/src/context/service/grpc_server/ContextServiceServicerImpl.py @@ -1,40 +1,30 @@ import grpc, logging -from prometheus_client import Counter, Histogram +from typing import Iterator from common.Constants import DEFAULT_CONTEXT_UUID, DEFAULT_TOPOLOGY_UUID -from common.exceptions.ServiceException import ServiceException -from context.proto.context_pb2 import Empty, Link, LinkId, Topology +#from common.exceptions.ServiceException import ServiceException +from common.metrics.Metrics import create_metrics, safe_and_metered_rpc_method +from common.orm.Database import Database +from context.proto.context_pb2 import \ + Context, ContextEvent, ContextId, ContextIdList, ContextList, \ + Device, DeviceEvent, DeviceId, DeviceIdList, DeviceList, \ + Empty, \ + Link, LinkEvent, LinkId, LinkIdList, LinkList, \ + Service, ServiceEvent, ServiceId, ServiceIdList, ServiceList, \ + Topology, TopologyEvent, TopologyId, TopologyIdList, TopologyList from context.proto.context_pb2_grpc import ContextServiceServicer -from context.service.database.api.Database import Database -from .Tools import check_link_id_request, check_link_request +#from .Tools import check_link_id_request, check_link_request LOGGER = logging.getLogger(__name__) -GETTOPOLOGY_COUNTER_STARTED = Counter ('context_gettopology_counter_started', - 'Context:GetTopology counter of requests started' ) -GETTOPOLOGY_COUNTER_COMPLETED = Counter ('context_gettopology_counter_completed', - 'Context:GetTopology counter of requests completed') -GETTOPOLOGY_COUNTER_FAILED = Counter ('context_gettopology_counter_failed', - 'Context:GetTopology counter of requests failed' ) -GETTOPOLOGY_HISTOGRAM_DURATION = Histogram('context_gettopology_histogram_duration', - 'Context:GetTopology histogram of request duration') - -ADDLINK_COUNTER_STARTED = Counter ('context_addlink_counter_started', - 'Context:AddLink counter of requests started' ) -ADDLINK_COUNTER_COMPLETED = Counter ('context_addlink_counter_completed', - 'Context:AddLink counter of requests completed') -ADDLINK_COUNTER_FAILED = Counter ('context_addlink_counter_failed', - 'Context:AddLink counter of requests failed' ) -ADDLINK_HISTOGRAM_DURATION = Histogram('context_addlink_histogram_duration', - 'Context:AddLink histogram of request duration') - -DELETELINK_COUNTER_STARTED = Counter ('context_deletelink_counter_started', - 'Context:DeleteLink counter of requests started' ) -DELETELINK_COUNTER_COMPLETED = Counter ('context_deletelink_counter_completed', - 'Context:DeleteLink counter of requests completed') -DELETELINK_COUNTER_FAILED = Counter ('context_deletelink_counter_failed', - 'Context:DeleteLink counter of requests failed' ) -DELETELINK_HISTOGRAM_DURATION = Histogram('context_deletelink_histogram_duration', - 'Context:DeleteLink histogram of request duration') +SERVICE_NAME = 'Context' +METHOD_NAMES = [ + 'ListContextIds', 'ListContexts', 'GetContext', 'SetContext', 'RemoveContext', 'GetContextEvents', + 'ListTopologyIds', 'ListTopologies', 'GetTopology', 'SetTopology', 'RemoveTopology', 'GetTopologyEvents', + 'ListDeviceIds', 'ListDevices', 'GetDevice', 'SetDevice', 'RemoveDevice', 'GetDeviceEvents', + 'ListLinkIds', 'ListLinks', 'GetLink', 'SetLink', 'RemoveLink', 'GetLinkEvents', + 'ListServiceIds', 'ListServices', 'GetService', 'SetService', 'RemoveService', 'GetServiceEvents', +] +METRICS = create_metrics(SERVICE_NAME, METHOD_NAMES) class ContextServiceServicerImpl(ContextServiceServicer): def __init__(self, database : Database): @@ -42,89 +32,197 @@ class ContextServiceServicerImpl(ContextServiceServicer): self.database = database LOGGER.debug('Servicer Created') - @GETTOPOLOGY_HISTOGRAM_DURATION.time() - def GetTopology(self, request : Empty, grpc_context : grpc.ServicerContext) -> Topology: - GETTOPOLOGY_COUNTER_STARTED.inc() - try: - LOGGER.debug('GetTopology request: {}'.format(str(request))) - - # ----- Validate request data and pre-conditions ----------------------------------------------------------- - db_context = self.database.context(DEFAULT_CONTEXT_UUID).create() - db_topology = db_context.topology(DEFAULT_TOPOLOGY_UUID).create() - - # ----- Retrieve data from the database -------------------------------------------------------------------- - json_topology = db_topology.dump() - - # ----- Compose reply -------------------------------------------------------------------------------------- - reply = Topology(**json_topology) - LOGGER.debug('GetTopology reply: {}'.format(str(reply))) - GETTOPOLOGY_COUNTER_COMPLETED.inc() - return reply - except ServiceException as e: # pragma: no cover (ServiceException not thrown) - LOGGER.exception('GetTopology exception') - GETTOPOLOGY_COUNTER_FAILED.inc() - grpc_context.abort(e.code, e.details) - except Exception as e: # pragma: no cover - LOGGER.exception('GetTopology exception') - GETTOPOLOGY_COUNTER_FAILED.inc() - grpc_context.abort(grpc.StatusCode.INTERNAL, str(e)) - - @ADDLINK_HISTOGRAM_DURATION.time() - def AddLink(self, request : Link, grpc_context : grpc.ServicerContext) -> LinkId: - ADDLINK_COUNTER_STARTED.inc() - try: - LOGGER.debug('AddLink request: {}'.format(str(request))) - - # ----- Validate request data and pre-conditions ----------------------------------------------------------- - link_id, db_endpoints = check_link_request('AddLink', request, self.database, LOGGER) - - # ----- Implement changes in the database ------------------------------------------------------------------ - db_context = self.database.context(DEFAULT_CONTEXT_UUID).create() - db_topology = db_context.topology(DEFAULT_TOPOLOGY_UUID).create() - db_link = db_topology.link(link_id).create() - for db_endpoint in db_endpoints: - link_endpoint_id = '{}/{}'.format( - db_endpoint.device_uuid, db_endpoint.endpoint_uuid) - db_link.endpoint(link_endpoint_id).create(db_endpoint) - - # ----- Compose reply -------------------------------------------------------------------------------------- - reply = LinkId(**db_link.dump_id()) - LOGGER.debug('AddLink reply: {}'.format(str(reply))) - ADDLINK_COUNTER_COMPLETED.inc() - return reply - except ServiceException as e: - LOGGER.exception('AddLink exception') - ADDLINK_COUNTER_FAILED.inc() - grpc_context.abort(e.code, e.details) - except Exception as e: # pragma: no cover - LOGGER.exception('AddLink exception') - ADDLINK_COUNTER_FAILED.inc() - grpc_context.abort(grpc.StatusCode.INTERNAL, str(e)) - - @DELETELINK_HISTOGRAM_DURATION.time() - def DeleteLink(self, request : LinkId, grpc_context : grpc.ServicerContext) -> Empty: - DELETELINK_COUNTER_STARTED.inc() - try: - LOGGER.debug('DeleteLink request: {}'.format(str(request))) - - # ----- Validate request data and pre-conditions ----------------------------------------------------------- - link_id = check_link_id_request('DeleteLink', request, self.database, LOGGER) - - # ----- Implement changes in the database ------------------------------------------------------------------ - db_context = self.database.context(DEFAULT_CONTEXT_UUID).create() - db_topology = db_context.topology(DEFAULT_TOPOLOGY_UUID).create() - db_topology.link(link_id).delete() - - # ----- Compose reply -------------------------------------------------------------------------------------- - reply = Empty() - LOGGER.debug('DeleteLink reply: {}'.format(str(reply))) - DELETELINK_COUNTER_COMPLETED.inc() - return reply - except ServiceException as e: - LOGGER.exception('DeleteLink exception') - DELETELINK_COUNTER_FAILED.inc() - grpc_context.abort(e.code, e.details) - except Exception as e: # pragma: no cover - LOGGER.exception('DeleteLink exception') - DELETELINK_COUNTER_FAILED.inc() - grpc_context.abort(grpc.StatusCode.INTERNAL, str(e)) + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListContextIds(self, request: Empty, context : grpc.ServicerContext) -> ContextIdList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListContexts(self, request: Empty, context : grpc.ServicerContext) -> ContextList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetContext(self, request: ContextId, context : grpc.ServicerContext) -> Context: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def SetContext(self, request: Context, context : grpc.ServicerContext) -> ContextId: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def RemoveContext(self, request: ContextId, context : grpc.ServicerContext) -> Empty: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetContextEvents(self, request: Empty, context : grpc.ServicerContext) -> Iterator[ContextEvent]: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListTopologyIds(self, request: ContextId, context : grpc.ServicerContext) -> TopologyIdList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListTopologies(self, request: ContextId, context : grpc.ServicerContext) -> TopologyList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetTopology(self, request: TopologyId, context : grpc.ServicerContext) -> Topology: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def SetTopology(self, request: Topology, context : grpc.ServicerContext) -> TopologyId: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def RemoveTopology(self, request: TopologyId, context : grpc.ServicerContext) -> Empty: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetTopologyEvents(self, request: Empty, context : grpc.ServicerContext) -> Iterator[TopologyEvent]: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListDeviceIds(self, request: Empty, context : grpc.ServicerContext) -> DeviceIdList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListDevices(self, request: Empty, context : grpc.ServicerContext) -> DeviceList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetDevice(self, request: DeviceId, context : grpc.ServicerContext) -> Device: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def SetDevice(self, request: Device, context : grpc.ServicerContext) -> DeviceId: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def RemoveDevice(self, request: DeviceId, context : grpc.ServicerContext) -> Empty: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetDeviceEvents(self, request: Empty, context : grpc.ServicerContext) -> Iterator[DeviceEvent]: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListLinkIds(self, request: Empty, context : grpc.ServicerContext) -> LinkIdList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListLinks(self, request: Empty, context : grpc.ServicerContext) -> LinkList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetLink(self, request: LinkId, context : grpc.ServicerContext) -> Link: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def SetLink(self, request: Link, context : grpc.ServicerContext) -> LinkId: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def RemoveLink(self, request: LinkId, context : grpc.ServicerContext) -> Empty: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetLinkEvents(self, request: Empty, context : grpc.ServicerContext) -> Iterator[LinkEvent]: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListServiceIds(self, request: ContextId, context : grpc.ServicerContext) -> ServiceIdList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def ListServices(self, request: ContextId, context : grpc.ServicerContext) -> ServiceList: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetService(self, request: ServiceId, context : grpc.ServicerContext) -> Service: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def SetService(self, request: Service, context : grpc.ServicerContext) -> ServiceId: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def RemoveService(self, request: ServiceId, context : grpc.ServicerContext) -> Empty: + pass + + @safe_and_metered_rpc_method(METRICS, LOGGER) + def GetServiceEvents(self, request: Empty, context : grpc.ServicerContext) -> Iterator[ServiceEvent]: + pass + + + + + +# @safe_and_metered_rpc_method(METRICS, LOGGER) +# def GetTopology(self, request : Empty, grpc_context : grpc.ServicerContext) -> Topology: +# # ----- Validate request data and pre-conditions ----------------------------------------------------------- +# db_context = self.database.context(DEFAULT_CONTEXT_UUID).create() +# db_topology = db_context.topology(DEFAULT_TOPOLOGY_UUID).create() +# +# # ----- Retrieve data from the database -------------------------------------------------------------------- +# json_topology = db_topology.dump() +# +# # ----- Compose reply -------------------------------------------------------------------------------------- +# return Topology(**json_topology) +# +# def CreaAddLink(self, request : Link, grpc_context : grpc.ServicerContext) -> LinkId: +# ADDLINK_COUNTER_STARTED.inc() +# try: +# LOGGER.debug('AddLink request: {}'.format(str(request))) +# +# # ----- Validate request data and pre-conditions ----------------------------------------------------------- +# link_id, db_endpoints = check_link_request('AddLink', request, self.database, LOGGER) +# +# # ----- Implement changes in the database ------------------------------------------------------------------ +# db_context = self.database.context(DEFAULT_CONTEXT_UUID).create() +# db_topology = db_context.topology(DEFAULT_TOPOLOGY_UUID).create() +# db_link = db_topology.link(link_id).create() +# for db_endpoint in db_endpoints: +# link_endpoint_id = '{}/{}'.format( +# db_endpoint.device_uuid, db_endpoint.endpoint_uuid) +# db_link.endpoint(link_endpoint_id).create(db_endpoint) +# +# # ----- Compose reply -------------------------------------------------------------------------------------- +# reply = LinkId(**db_link.dump_id()) +# LOGGER.debug('AddLink reply: {}'.format(str(reply))) +# ADDLINK_COUNTER_COMPLETED.inc() +# return reply +# except ServiceException as e: +# LOGGER.exception('AddLink exception') +# ADDLINK_COUNTER_FAILED.inc() +# grpc_context.abort(e.code, e.details) +# except Exception as e: # pragma: no cover +# LOGGER.exception('AddLink exception') +# ADDLINK_COUNTER_FAILED.inc() +# grpc_context.abort(grpc.StatusCode.INTERNAL, str(e)) +# +# @DELETELINK_HISTOGRAM_DURATION.time() +# def DeleteLink(self, request : LinkId, grpc_context : grpc.ServicerContext) -> Empty: +# DELETELINK_COUNTER_STARTED.inc() +# try: +# LOGGER.debug('DeleteLink request: {}'.format(str(request))) +# +# # ----- Validate request data and pre-conditions ----------------------------------------------------------- +# link_id = check_link_id_request('DeleteLink', request, self.database, LOGGER) +# +# # ----- Implement changes in the database ------------------------------------------------------------------ +# db_context = self.database.context(DEFAULT_CONTEXT_UUID).create() +# db_topology = db_context.topology(DEFAULT_TOPOLOGY_UUID).create() +# db_topology.link(link_id).delete() +# +# # ----- Compose reply -------------------------------------------------------------------------------------- +# reply = Empty() +# LOGGER.debug('DeleteLink reply: {}'.format(str(reply))) +# DELETELINK_COUNTER_COMPLETED.inc() +# return reply +# except ServiceException as e: +# LOGGER.exception('DeleteLink exception') +# DELETELINK_COUNTER_FAILED.inc() +# grpc_context.abort(e.code, e.details) +# except Exception as e: # pragma: no cover +# LOGGER.exception('DeleteLink exception') +# DELETELINK_COUNTER_FAILED.inc() +# grpc_context.abort(grpc.StatusCode.INTERNAL, str(e)) diff --git a/src/context/tests/orm_populate_data.py b/src/context/tests/orm_populate_data.py new file mode 100644 index 0000000000000000000000000000000000000000..ead4e628937ba13973ccf2f87a7210b39f077f53 --- /dev/null +++ b/src/context/tests/orm_populate_data.py @@ -0,0 +1,152 @@ +import json, logging, time +from common.Constants import DEFAULT_CONTEXT_UUID, DEFAULT_TOPOLOGY_UUID +from context.service.database.api.Database import Database +from context.service.database.api.context.service.ServiceState import ServiceState +from context.service.database.api.context.service.ServiceType import ServiceType +from context.service.database.api.context.topology.device.OperationalStatus import OperationalStatus + +LOGGER = logging.getLogger(__name__) + +def populate_example( + database : Database, context_uuid : str = DEFAULT_CONTEXT_UUID, topology_uuid : str = DEFAULT_TOPOLOGY_UUID, + add_devices : bool = True, add_links : bool = True, add_services : bool = True): + + if add_links: + if not add_devices: raise Exception('add_links requires add_devices') + + if add_services: + if not add_devices: raise Exception('add_services requires add_devices') + if not add_links: raise Exception('add_services requires add_links') + + with database: + database.clear_all() + + context = database.context(context_uuid).create() + topology = context.topology(topology_uuid).create() + + if add_devices: + dev_1 = topology.device('DEV1').create( + device_type='ROADM', device_config='<config/>', device_operational_status=OperationalStatus.ENABLED) + dev1_ep2 = dev_1.endpoint('EP2').create(port_type='WDM') + dev1_ep3 = dev_1.endpoint('EP3').create(port_type='WDM') + dev1_ep4 = dev_1.endpoint('EP4').create(port_type='WDM') + dev1_ep5 = dev_1.endpoint('EP5').create(port_type='OCH') + dev1_ep6 = dev_1.endpoint('EP6').create(port_type='OCH') + dev1_ep7 = dev_1.endpoint('EP7').create(port_type='OCH') + + dev_2 = topology.device('DEV2').create( + device_type='ROADM', device_config='<config/>', device_operational_status=OperationalStatus.ENABLED) + dev2_ep1 = dev_2.endpoint('EP1').create(port_type='WDM') + dev2_ep3 = dev_2.endpoint('EP3').create(port_type='WDM') + dev2_ep4 = dev_2.endpoint('EP4').create(port_type='WDM') + dev2_ep5 = dev_2.endpoint('EP5').create(port_type='OCH') + dev2_ep6 = dev_2.endpoint('EP6').create(port_type='OCH') + dev2_ep7 = dev_2.endpoint('EP7').create(port_type='OCH') + + dev_3 = topology.device('DEV3').create( + device_type='ROADM', device_config='<config/>', device_operational_status=OperationalStatus.ENABLED) + dev3_ep1 = dev_3.endpoint('EP1').create(port_type='WDM') + dev3_ep2 = dev_3.endpoint('EP2').create(port_type='WDM') + dev3_ep4 = dev_3.endpoint('EP4').create(port_type='WDM') + dev3_ep5 = dev_3.endpoint('EP5').create(port_type='OCH') + dev3_ep6 = dev_3.endpoint('EP6').create(port_type='OCH') + dev3_ep7 = dev_3.endpoint('EP7').create(port_type='OCH') + + dev_4 = topology.device('DEV4').create( + device_type='ROADM', device_config='<config/>', device_operational_status=OperationalStatus.ENABLED) + dev4_ep1 = dev_4.endpoint('EP1').create(port_type='WDM') + dev4_ep2 = dev_4.endpoint('EP2').create(port_type='WDM') + dev4_ep3 = dev_4.endpoint('EP3').create(port_type='WDM') + dev4_ep5 = dev_4.endpoint('EP5').create(port_type='OCH') + dev4_ep6 = dev_4.endpoint('EP6').create(port_type='OCH') + dev4_ep7 = dev_4.endpoint('EP7').create(port_type='OCH') + + if add_links: + link_dev1_to_dev2 = topology.link('DEV1/EP2 ==> DEV2/EP1').create() + link_dev1_to_dev2.endpoint('DEV1/EP2').create(dev1_ep2) + link_dev1_to_dev2.endpoint('DEV2/EP1').create(dev2_ep1) + + link_dev1_to_dev3 = topology.link('DEV1/EP3 ==> DEV3/EP1').create() + link_dev1_to_dev3.endpoint('DEV1/EP3').create(dev1_ep3) + link_dev1_to_dev3.endpoint('DEV3/EP1').create(dev3_ep1) + + link_dev1_to_dev4 = topology.link('DEV1/EP4 ==> DEV4/EP1').create() + link_dev1_to_dev4.endpoint('DEV1/EP4').create(dev1_ep4) + link_dev1_to_dev4.endpoint('DEV4/EP1').create(dev4_ep1) + + link_dev2_to_dev1 = topology.link('DEV2/EP1 ==> DEV1/EP2').create() + link_dev2_to_dev1.endpoint('DEV2/EP1').create(dev2_ep1) + link_dev2_to_dev1.endpoint('DEV1/EP2').create(dev1_ep2) + + link_dev2_to_dev3 = topology.link('DEV2/EP3 ==> DEV3/EP2').create() + link_dev2_to_dev3.endpoint('DEV2/EP3').create(dev2_ep3) + link_dev2_to_dev3.endpoint('DEV3/EP2').create(dev3_ep2) + + link_dev2_to_dev4 = topology.link('DEV2/EP4 ==> DEV4/EP2').create() + link_dev2_to_dev4.endpoint('DEV2/EP4').create(dev2_ep4) + link_dev2_to_dev4.endpoint('DEV4/EP2').create(dev4_ep2) + + link_dev3_to_dev1 = topology.link('DEV3/EP1 ==> DEV1/EP3').create() + link_dev3_to_dev1.endpoint('DEV3/EP1').create(dev3_ep1) + link_dev3_to_dev1.endpoint('DEV1/EP3').create(dev1_ep3) + + link_dev3_to_dev2 = topology.link('DEV3/EP2 ==> DEV2/EP3').create() + link_dev3_to_dev2.endpoint('DEV3/EP2').create(dev3_ep2) + link_dev3_to_dev2.endpoint('DEV2/EP3').create(dev2_ep3) + + link_dev3_to_dev4 = topology.link('DEV3/EP4 ==> DEV4/EP3').create() + link_dev3_to_dev4.endpoint('DEV3/EP4').create(dev3_ep4) + link_dev3_to_dev4.endpoint('DEV4/EP3').create(dev4_ep3) + + link_dev4_to_dev1 = topology.link('DEV4/EP1 ==> DEV1/EP4').create() + link_dev4_to_dev1.endpoint('DEV4/EP1').create(dev4_ep1) + link_dev4_to_dev1.endpoint('DEV1/EP4').create(dev1_ep4) + + link_dev4_to_dev2 = topology.link('DEV4/EP2 ==> DEV2/EP4').create() + link_dev4_to_dev2.endpoint('DEV4/EP2').create(dev4_ep2) + link_dev4_to_dev2.endpoint('DEV2/EP4').create(dev2_ep4) + + link_dev4_to_dev3 = topology.link('DEV4/EP3 ==> DEV3/EP4').create() + link_dev4_to_dev3.endpoint('DEV4/EP3').create(dev4_ep3) + link_dev4_to_dev3.endpoint('DEV3/EP4').create(dev3_ep4) + + if add_services: + service = context.service('S01').create(ServiceType.L3NM, '<config/>', ServiceState.PLANNED) + service.endpoint('S01/EP01').create(dev1_ep5) + service.endpoint('S01/EP02').create(dev2_ep5) + service.endpoint('S01/EP03').create(dev3_ep5) + service.endpoint('S01/EP04').create(dev4_ep5) + + service = context.service('S02').create(ServiceType.L3NM, '<config/>', ServiceState.PLANNED) + service.endpoint('S02/EP01').create(dev1_ep6) + service.endpoint('S02/EP02').create(dev2_ep6) + service.endpoint('S02/EP03').create(dev3_ep6) + service.endpoint('S02/EP04').create(dev4_ep6) + + service = context.service('S03').create(ServiceType.L3NM, '<config/>', ServiceState.PLANNED) + service.endpoint('S03/EP01').create(dev1_ep7) + service.endpoint('S03/EP02').create(dev2_ep7) + service.endpoint('S03/EP03').create(dev3_ep7) + service.endpoint('S03/EP04').create(dev4_ep7) + +def sequence(database : Database): + populate_example(database) + + with database: + LOGGER.info('Dump:') + for entry in database.dump(): + LOGGER.info(' {}'.format(entry)) + + with database: + t0 = time.time() + context = database.context(DEFAULT_CONTEXT_UUID).create() + json_context = context.dump() + t1 = time.time() + LOGGER.info(json.dumps(json_context)) + LOGGER.info('Dump elapsed: {}'.format(1000.0 * (t1-t0))) + + with database: + database.context(DEFAULT_CONTEXT_UUID).delete() + LOGGER.info('Dump:') + for entry in database.dump(): + LOGGER.info(' {}'.format(entry)) diff --git a/src/context/tests/test_orm_backend_inmemory.py b/src/context/tests/test_orm_backend_inmemory.py new file mode 100644 index 0000000000000000000000000000000000000000..b4bcf876e3c7097523dd94cf6b3cbf98ddd390e9 --- /dev/null +++ b/src/context/tests/test_orm_backend_inmemory.py @@ -0,0 +1,10 @@ +import logging +from context.service.database.Database import Database +from context.service.database._engine.Factory import get_database_backend, BackendEnum +from .populate_database import sequence + +logging.basicConfig(level=logging.INFO) + +def test_inmemory(): + database_backend = get_database_backend(engine=BackendEnum.INMEMORY) + sequence(Database(database_backend)) diff --git a/src/context/tests/test_orm_backend_redis.py b/src/context/tests/test_orm_backend_redis.py new file mode 100644 index 0000000000000000000000000000000000000000..f14afe30b0138581e97c1e09f2bbb2ec2223e399 --- /dev/null +++ b/src/context/tests/test_orm_backend_redis.py @@ -0,0 +1,11 @@ +import logging +from context.service.database.Factory import get_database, DatabaseEngineEnum +from .populate_database import sequence + +logging.basicConfig(level=logging.INFO) + +def test_redis(): + database = get_database( + engine=DatabaseEngineEnum.REDIS, REDISDB_SERVICE_HOST='127.0.0.1', REDISDB_SERVICE_PORT=31926, + REDISDB_DATABASE_ID=0) + sequence(database) diff --git a/src/context/tests/test_unitary_orm_context_inmemory.py b/src/context/tests/test_unitary_orm_context_inmemory.py new file mode 100644 index 0000000000000000000000000000000000000000..9d697c46629b0949a24d48071f5ed44db7bf4bd5 --- /dev/null +++ b/src/context/tests/test_unitary_orm_context_inmemory.py @@ -0,0 +1,104 @@ +import logging, pytest +from common.Constants import DEFAULT_CONTEXT_UUID, DEFAULT_TOPOLOGY_UUID +from common.orm.Database import Database +from common.orm.Factory import get_database_backend, BackendEnum +from context.service.database.Models import ContextModel, DeviceModel, LinkModel, TopologyDeviceModel, TopologyLinkModel, TopologyModel + +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.DEBUG) + +@pytest.fixture(scope='session') +def database(): + database_backend = get_database_backend(engine=BackendEnum.INMEMORY) + _database = Database(database_backend) + return _database + +def test_create_context_topology(database : Database): + context = ContextModel(database, DEFAULT_CONTEXT_UUID) + context.save() + + topology = TopologyModel(database, DEFAULT_TOPOLOGY_UUID) + topology.context_fk = context + topology.save() + +def test_create_devices(database : Database): + topology = TopologyModel(database, DEFAULT_TOPOLOGY_UUID) + + device_01 = DeviceModel(database, 'dev-01') + device_01.save() + + relation_topology_device_01 = TopologyDeviceModel(database, 'admin--dev-01') + relation_topology_device_01.topology_fk = topology + relation_topology_device_01.device_fk = device_01 + relation_topology_device_01.save() + + device_02 = DeviceModel(database, 'dev-02') + device_02.save() + + relation_topology_device_02 = TopologyDeviceModel(database, 'admin--dev-02') + relation_topology_device_02.topology_fk = topology + relation_topology_device_02.device_fk = device_02 + relation_topology_device_02.save() + + device_03 = DeviceModel(database, 'dev-03') + device_03.save() + + relation_topology_device_03 = TopologyDeviceModel(database, 'admin--dev-03') + relation_topology_device_03.topology_fk = topology + relation_topology_device_03.device_fk = device_03 + relation_topology_device_03.save() + +def test_create_links(database : Database): + topology = TopologyModel(database, DEFAULT_TOPOLOGY_UUID) + + link_01 = LinkModel(database, 'dev-01') + link_01.save() + + relation_topology_link_01 = TopologyLinkModel(database, 'admin--dev-01') + relation_topology_link_01.topology_fk = topology + relation_topology_link_01.link_fk = link_01 + relation_topology_link_01.save() + + link_02 = LinkModel(database, 'dev-02') + link_02.save() + + relation_topology_link_02 = TopologyLinkModel(database, 'admin--dev-02') + relation_topology_link_02.topology_fk = topology + relation_topology_link_02.link_fk = link_02 + relation_topology_link_02.save() + + link_03 = LinkModel(database, 'dev-03') + link_03.save() + + relation_topology_link_03 = TopologyLinkModel(database, 'admin--dev-03') + relation_topology_link_03.topology_fk = topology + relation_topology_link_03.link_fk = link_03 + relation_topology_link_03.save() + +def test_dump(database : Database): + db_entries = database.dump() + LOGGER.info('----- Database Dump [{:3d} entries] -------------------------'.format(len(db_entries))) + for db_entry in db_entries: + LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) + LOGGER.info('-----------------------------------------------------------') + raise Exception() + +# assert len(database_dump) == 9 +# assert database_dump[ 0] == ('dict', 'Member[brad]', +# "{'name': 'Brad', 'pk': 'brad', 'team': 'Team[admin]'}") +# assert database_dump[ 1] == ('dict', 'Member[john]', +# "{'name': 'John', 'pk': 'john', 'place': 'Workplace[bcn]', 'team': 'Team[dev-ops]'}") +# assert database_dump[ 2] == ('dict', 'Team[admin]', +# "{'name': 'Admin', 'pk': 'admin'}") +# assert database_dump[ 3] == ('set', 'Team[admin]/references', +# "{'Member[brad]:team'}") +# assert database_dump[ 4] == ('dict', 'Team[dev-ops]', +# "{'name': 'Dev Ops', 'pk': 'dev-ops'}") +# assert database_dump[ 5] == ('set', 'Team[dev-ops]/references', +# "{'Member[john]:team'}") +# assert database_dump[ 6] == ('dict', 'Workplace[bcn]', +# "{'name': 'Barcelona', 'pk': 'bcn'}") +# assert database_dump[ 7] == ('set', 'Workplace[bcn]/references', +# "{'Member[john]:place'}") +# assert database_dump[ 8] == ('dict', 'Workplace[mad]', +# "{'name': 'Madrid', 'pk': 'mad'}")