Skip to content
Snippets Groups Projects
Commit bb094bf1 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common - Context Queries:

- Added method to get Context
- Added method to get Link
parent 0c1d58ef
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!62Add relese/2.0.1 fixes
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from common.proto.context_pb2 import Context, Empty import grpc
from typing import Optional
from common.proto.context_pb2 import Context, ContextId, Empty
from common.tools.object_factory.Context import json_context from common.tools.object_factory.Context import json_context
from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient
...@@ -23,3 +25,17 @@ def create_context( ...@@ -23,3 +25,17 @@ def create_context(
existing_context_uuids = {context_id.context_uuid.uuid for context_id in existing_context_ids.context_ids} existing_context_uuids = {context_id.context_uuid.uuid for context_id in existing_context_ids.context_ids}
if context_uuid in existing_context_uuids: return if context_uuid in existing_context_uuids: return
context_client.SetContext(Context(**json_context(context_uuid))) context_client.SetContext(Context(**json_context(context_uuid)))
def get_context(context_client : ContextClient, context_uuid : str, rw_copy : bool = False) -> Optional[Context]:
try:
# pylint: disable=no-member
context_id = ContextId()
context_id.context_uuid.uuid = context_uuid
ro_context = context_client.GetContext(context_id)
if not rw_copy: return ro_context
rw_context = Context()
rw_context.CopyFrom(ro_context)
return rw_context
except grpc.RpcError:
#LOGGER.exception('Unable to get Context({:s})'.format(str(context_uuid)))
return None
...@@ -12,11 +12,26 @@ ...@@ -12,11 +12,26 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from typing import List, Set import grpc
from common.proto.context_pb2 import ContextId, Empty, Link, Topology, TopologyId from typing import List, Optional, Set
from common.proto.context_pb2 import ContextId, Empty, Link, LinkId, Topology, TopologyId
from common.tools.object_factory.Topology import json_topology_id from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient
def get_link(context_client : ContextClient, link_uuid : str, rw_copy : bool = False) -> Optional[Link]:
try:
# pylint: disable=no-member
link_id = LinkId()
link_id.link_uuid.uuid = link_uuid
ro_link = context_client.GetLink(link_id)
if not rw_copy: return ro_link
rw_link = Link()
rw_link.CopyFrom(ro_link)
return rw_link
except grpc.RpcError:
#LOGGER.exception('Unable to get Link({:s})'.format(str(link_uuid)))
return None
def get_existing_link_uuids(context_client : ContextClient) -> Set[str]: def get_existing_link_uuids(context_client : ContextClient) -> Set[str]:
existing_link_ids = context_client.ListLinkIds(Empty()) existing_link_ids = context_client.ListLinkIds(Empty())
existing_link_uuids = {link_id.link_uuid.uuid for link_id in existing_link_ids.link_ids} existing_link_uuids = {link_id.link_uuid.uuid for link_id in existing_link_ids.link_ids}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment