def __allocate_services( self, *, rid: ID, inv: NetworkServiceInventory, sliver: NetworkServiceSliver, node_id_to_reservations: dict) -> Tuple[str, BaseSliver, Any]: """ Allocate Network Service Slivers @param rid Reservation Id @param inv Inventory @param sliver Requested sliver @param node_id_to_reservations @return tuple containing delegation id, sliver, error message if any """ self.logger.debug(f"Processing Network Service sliver: {sliver}") delegation_id = None error_msg = None owner_switch = None owner_mpls_ns = None # For each Interface Sliver; for ifs in sliver.interface_info.interfaces.values(): # Fetch Network Node Id and BQM Component Id node_id, bqm_component_id = ifs.get_node_map() bqm_component = self.get_component_sliver(node_id=bqm_component_id) # Get BQM Connection Point in Site Delegation (c) site_cp = FimHelper.get_site_interface_sliver( component=bqm_component, local_name=ifs.get_labels().local_name) self.logger.debug( f"Interface Sliver [Site Delegation] (C): {site_cp}") # Get BQM Peer Connection Point in Site Delegation (a) net_cp = self.get_net_interface_sliver( site_ifs_id=site_cp.node_id, itype=InterfaceType.TrunkPort) if net_cp is None: error_msg = "Peer Connection Point not found from Network AM" raise BrokerException(msg=error_msg) self.logger.debug( f"Peer Interface Sliver [Network Delegation] (A): {site_cp}") # need to find the owner switch of the network service in CBM and take it's name or labels.local_name owner_switch, owner_mpls_ns = self.get_owners( node_id=net_cp.node_id) if bqm_component.get_type() == ComponentType.SharedNIC: # VLAN is already set by the Orchestrator using the information from the Node Sliver Parent Reservation if ifs.get_labels().vlan is None: message = "Shared NIC VLAN cannot be None" self.logger.error(message) raise BrokerException( error_code=ExceptionErrorCode.FAILURE, msg=f"{message}") else: existing_reservations = self.get_existing_reservations( node_id=owner_mpls_ns.node_id, node_id_to_reservations=node_id_to_reservations) # Set vlan - source: (c) - only for dedicated NICs ifs = inv.allocate_ifs( requested_ns=sliver, requested_ifs=ifs, owner_switch=owner_switch, mpls_ns=owner_mpls_ns, bqm_ifs_id=net_cp.node_id, existing_reservations=existing_reservations) # local_name source: (a) ifs_labels = ifs.get_labels() ifs_labels = Labels.update(ifs_labels, local_name=net_cp.get_name()) # NSO device name source: (a) - need to find the owner switch of the network service in CBM # and take its name or labels.local_name # Set the NSO device-name ifs_labels = Labels.update(ifs_labels, device_name=owner_switch.get_name()) adm_ids = owner_switch.get_structural_info().adm_graph_ids site_adm_ids = bqm_component.get_structural_info().adm_graph_ids self.logger.debug(f"Owner MPLS Network Service: {owner_mpls_ns}") self.logger.debug(f"Owner Switch: {owner_switch}") self.logger.debug( f"Owner Switch: {owner_switch.network_service_info}") net_adm_ids = [ x for x in adm_ids if not x in site_adm_ids or site_adm_ids.remove(x) ] if len(net_adm_ids) != 1: error_msg = f"More than 1 or 0 Network Delegations found! net_adm_ids: {net_adm_ids}" self.logger.error(error_msg) raise BrokerException(msg=error_msg) # Update the Interface Sliver Node Map to map to (a) ifs.set_node_map(node_map=(self.combined_broker_model_graph_id, net_cp.node_id)) delegation_id = net_adm_ids[0] ifs.labels = ifs_labels self.logger.debug( f"Allocated Interface Sliver: {ifs} delegation: {delegation_id}" ) # Update the Network Service Sliver Node Map to map to parent of (a) sliver.set_node_map(node_map=(self.combined_broker_model_graph_id, owner_mpls_ns.node_id)) # Set the Subnet and gateway from the Owner Switch (a) if sliver.get_type() == ServiceType.FABNetv6 or sliver.get_type( ) == ServiceType.FABNetv4: existing_reservations = self.get_existing_reservations( node_id=owner_mpls_ns.node_id, node_id_to_reservations=node_id_to_reservations) sliver = inv.allocate(rid=rid, requested_ns=sliver, owner_switch=owner_switch, existing_reservations=existing_reservations) return delegation_id, sliver, error_msg
def allocate( self, *, rid: ID, requested_sliver: BaseSliver, graph_id: str, graph_node: BaseSliver, existing_reservations: List[ABCReservationMixin] ) -> Tuple[str, BaseSliver]: """ Allocate an extending or ticketing reservation :param rid: reservation id of the reservation to be allocated :param requested_sliver: requested sliver :param graph_id: BQM graph id :param graph_node: BQM graph node identified to serve the reservation :param existing_reservations: Existing Reservations served by the same BQM node :return: Tuple of Delegation Id and the Requested Sliver annotated with BQM Node Id and other properties :raises: BrokerException in case the request cannot be satisfied """ if graph_node.get_capacity_delegations() is None or rid is None: raise BrokerException( error_code=Constants.INVALID_ARGUMENT, msg=f"capacity_delegations is missing or reservation is None") if not isinstance(requested_sliver, NodeSliver): raise BrokerException( error_code=Constants.INVALID_ARGUMENT, msg=f"resource type: {requested_sliver.get_type()}") if not isinstance(graph_node, NodeSliver): raise BrokerException( error_code=Constants.INVALID_ARGUMENT, msg=f"resource type: {graph_node.get_type()}") # Always use requested capacities to be mapped from flavor i.e. capacity hints requested_capacity_hints = requested_sliver.get_capacity_hints() catalog = InstanceCatalog() requested_capacities = catalog.get_instance_capacities( instance_type=requested_capacity_hints.instance_type) # Check if Capacities can be satisfied delegation_id = self.__check_capacities( rid=rid, requested_capacities=requested_capacities, delegated_capacities=graph_node.get_capacity_delegations(), existing_reservations=existing_reservations) # Check if Components can be allocated if requested_sliver.attached_components_info is not None: requested_sliver.attached_components_info = self.__check_components( rid=rid, requested_components=requested_sliver.attached_components_info, graph_id=graph_id, graph_node=graph_node, existing_reservations=existing_reservations) requested_sliver.capacity_allocations = Capacities() requested_sliver.capacity_allocations = Labels.update( lab=requested_capacities) requested_sliver.label_allocations = Labels( instance_parent=graph_node.get_name()) requested_sliver.set_node_map(node_map=(graph_id, graph_node.node_id)) self.logger.info( f"Reservation# {rid} is being served by delegation# {delegation_id} " f"node# [{graph_id}/{graph_node.node_id}]") return delegation_id, requested_sliver