Loading src/spine_leaf/service/SpineLeafServicerImpl.py +1 −1 Changes for src/spine_leaf/service/SpineLeafServicerImpl.py: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ from common.proto.spine_leaf_pb2 import ( ) from common.proto.spine_leaf_pb2_grpc import SpineLeafServicer from .configurator.config_payload import build_deploy_payload from .configurator.resource_allocator import ResourceAllocator from .configurator.ResourceAllocator import ResourceAllocator from .database.Database import SpineLeafDatabase as InternalDatabase Loading src/spine_leaf/service/configurator/resource_allocator.py→src/spine_leaf/service/configurator/ResourceAllocator.py +13 −13 Changes for src/spine_leaf/service/configurator/ResourceAllocator.py: 13 added lines, 13 removed lines. Original line number Diff line number Diff line Loading @@ -21,15 +21,15 @@ from common.proto.logical_resources_pb2 import ( ResourceTypeQuery, Tuple as LRTuple, ) from common.proto.spineleaf_pb2 import ConfigSetting from logical_resources.client.Logicalresourceclient import LogicalResourceClient from common.proto.spine_leaf_pb2 import ConfigSetting from logical_resources.client.LogicalResourcesClient import LogicalResourcesClient LOGGER = logging.getLogger(__name__) class ResourceAllocator: def __init__(self) -> None: super().__init__() self.logical_resource_client = LogicalResourceClient() self.logical_resources_client = LogicalResourcesClient() def _pick_first_available( self, Loading @@ -43,26 +43,26 @@ class ResourceAllocator: return None def _reserve(self, resource_type: str, value: str, fabric_id: str) -> TypingTuple[bool, str]: if self.logical_resource_client is None: if self.logical_resources_client is None: return False, 'LogicalResources client not available' request = ResourceReservation( tuple=LRTuple(type=resource_type, value=value), fabric_id=FabricId(fabric_id=fabric_id), ) reply = self.logical_resource_client.ReserveResource(request) reply = self.logical_resources_client.ReserveResource(request) return bool(getattr(reply, 'success', False)), str(getattr(reply, 'message', '')) def _release(self, resource_type: str, value: str, fabric_id: str) -> None: if self.logical_resource_client is None: if self.logical_resources_client is None: return request = ResourceReservation( tuple=LRTuple(type=resource_type, value=value), fabric_id=FabricId(fabric_id=fabric_id), ) self.logical_resource_client.ReleaseResource(request) self.logical_resources_client.ReleaseResource(request) def _rollback_reservations(self, reservations: List[TypingTuple[str, str]], fabric_id: str) -> None: Loading @@ -73,9 +73,9 @@ class ResourceAllocator: LOGGER.exception('Failed rollback for resource %s=%s', resource_type, value) def _is_reserved_by_fabric(self, resource_type: str, value: str, fabric_id: str) -> bool: if self.logical_resource_client is None: if self.logical_resources_client is None: return False reply = self.logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type=resource_type)) reply = self.logical_resources_client.GetResourcesByType(ResourceTypeQuery(resource_type=resource_type)) for entry in reply.resources: if entry.value == value and entry.allocated and entry.fabric_id == fabric_id: return True Loading @@ -87,16 +87,16 @@ class ResourceAllocator: fabric_id: Optional[str] = None, allow_same_fabric: bool = False, ) -> Optional[str]: if self.logical_resource_client is None: if self.logical_resources_client is None: return None reply = self.logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type=resource_type)) reply = self.logical_resources_client.GetResourcesByType(ResourceTypeQuery(resource_type=resource_type)) return self._pick_first_available(reply, fabric_id=fabric_id, allow_same_fabric=allow_same_fabric) def _infer_remote_as(self, local_asn: str, fabric_id: str) -> Optional[str]: if self.logical_resource_client is None: if self.logical_resources_client is None: return None reply = self.logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type='asn')) reply = self.logical_resources_client.GetResourcesByType(ResourceTypeQuery(resource_type='asn')) for entry in reply.resources: Loading Loading
src/spine_leaf/service/SpineLeafServicerImpl.py +1 −1 Changes for src/spine_leaf/service/SpineLeafServicerImpl.py: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ from common.proto.spine_leaf_pb2 import ( ) from common.proto.spine_leaf_pb2_grpc import SpineLeafServicer from .configurator.config_payload import build_deploy_payload from .configurator.resource_allocator import ResourceAllocator from .configurator.ResourceAllocator import ResourceAllocator from .database.Database import SpineLeafDatabase as InternalDatabase Loading
src/spine_leaf/service/configurator/resource_allocator.py→src/spine_leaf/service/configurator/ResourceAllocator.py +13 −13 Changes for src/spine_leaf/service/configurator/ResourceAllocator.py: 13 added lines, 13 removed lines. Original line number Diff line number Diff line Loading @@ -21,15 +21,15 @@ from common.proto.logical_resources_pb2 import ( ResourceTypeQuery, Tuple as LRTuple, ) from common.proto.spineleaf_pb2 import ConfigSetting from logical_resources.client.Logicalresourceclient import LogicalResourceClient from common.proto.spine_leaf_pb2 import ConfigSetting from logical_resources.client.LogicalResourcesClient import LogicalResourcesClient LOGGER = logging.getLogger(__name__) class ResourceAllocator: def __init__(self) -> None: super().__init__() self.logical_resource_client = LogicalResourceClient() self.logical_resources_client = LogicalResourcesClient() def _pick_first_available( self, Loading @@ -43,26 +43,26 @@ class ResourceAllocator: return None def _reserve(self, resource_type: str, value: str, fabric_id: str) -> TypingTuple[bool, str]: if self.logical_resource_client is None: if self.logical_resources_client is None: return False, 'LogicalResources client not available' request = ResourceReservation( tuple=LRTuple(type=resource_type, value=value), fabric_id=FabricId(fabric_id=fabric_id), ) reply = self.logical_resource_client.ReserveResource(request) reply = self.logical_resources_client.ReserveResource(request) return bool(getattr(reply, 'success', False)), str(getattr(reply, 'message', '')) def _release(self, resource_type: str, value: str, fabric_id: str) -> None: if self.logical_resource_client is None: if self.logical_resources_client is None: return request = ResourceReservation( tuple=LRTuple(type=resource_type, value=value), fabric_id=FabricId(fabric_id=fabric_id), ) self.logical_resource_client.ReleaseResource(request) self.logical_resources_client.ReleaseResource(request) def _rollback_reservations(self, reservations: List[TypingTuple[str, str]], fabric_id: str) -> None: Loading @@ -73,9 +73,9 @@ class ResourceAllocator: LOGGER.exception('Failed rollback for resource %s=%s', resource_type, value) def _is_reserved_by_fabric(self, resource_type: str, value: str, fabric_id: str) -> bool: if self.logical_resource_client is None: if self.logical_resources_client is None: return False reply = self.logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type=resource_type)) reply = self.logical_resources_client.GetResourcesByType(ResourceTypeQuery(resource_type=resource_type)) for entry in reply.resources: if entry.value == value and entry.allocated and entry.fabric_id == fabric_id: return True Loading @@ -87,16 +87,16 @@ class ResourceAllocator: fabric_id: Optional[str] = None, allow_same_fabric: bool = False, ) -> Optional[str]: if self.logical_resource_client is None: if self.logical_resources_client is None: return None reply = self.logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type=resource_type)) reply = self.logical_resources_client.GetResourcesByType(ResourceTypeQuery(resource_type=resource_type)) return self._pick_first_available(reply, fabric_id=fabric_id, allow_same_fabric=allow_same_fabric) def _infer_remote_as(self, local_asn: str, fabric_id: str) -> Optional[str]: if self.logical_resource_client is None: if self.logical_resources_client is None: return None reply = self.logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type='asn')) reply = self.logical_resources_client.GetResourcesByType(ResourceTypeQuery(resource_type='asn')) for entry in reply.resources: Loading