Ejemplo n.º 1
0
 def set_fields(self, **kwargs):
     """
     Universal integer setter for all fields.
     Values should be non-negative integers. Throws a RuntimeError
     if you try to set a non-existent field.
     :param kwargs:
     :return: self to support call chaining
     """
     for k, v in kwargs.items():
         try:
             # will toss an exception if field is not defined
             self.__getattribute__(k)
             if k == Constants.PROP_CAPACITIES or k == Constants.PROP_ALLOCATED_CAPACITIES:
                 c = Capacities()
                 v = c.from_json(json_string=v)
             elif k == Constants.PROP_LABELS or k == Constants.PROP_ALLOCATED_LABELS:
                 l = Labels()
                 v = l.from_json(json_string=v)
             elif k == Constants.PROP_CAPACITY_HINTS:
                 ch = CapacityHints()
                 v = ch.from_json(json_string=v)
             self.__setattr__(k, v)
         except AttributeError:
             raise RuntimeError(
                 f"Unable to set field {k} of reservation, no such field available"
             )
     return self
Ejemplo n.º 2
0
    def create_unit(include_pci: bool = True,
                    include_image: bool = True,
                    include_name: bool = True,
                    include_instance_name: bool = False) -> Unit:
        """
        Create a unit
        :param include_pci:
        :param include_image:
        :param include_name:
        :param include_instance_name:
        :return:
        """
        u = Unit(rid=ID(uid='rid-1'))
        sliver = NodeSliver()
        cap = Capacities()
        cap.set_fields(core=2, ram=8, disk=10)
        sliver.set_properties(type=NodeType.VM,
                              site="RENC",
                              capacity_allocations=cap)
        sliver.label_allocations = Labels().set_fields(
            instance_parent="renc-w3")
        catalog = InstanceCatalog()
        instance_type = catalog.map_capacities_to_instance(cap=cap)
        cap_hints = CapacityHints().set_fields(instance_type=instance_type)
        sliver.set_properties(
            capacity_hints=cap_hints,
            capacity_allocations=catalog.get_instance_capacities(
                instance_type=instance_type))

        if include_name:
            sliver.set_properties(name="n2")

        if include_image:
            sliver.set_properties(image_type='qcow2',
                                  image_ref='default_fedora')

        if include_pci:
            component = ComponentSliver()
            labels = Labels()
            labels.set_fields(bdf=["0000:41:00.0", "0000:41:00.1"])
            component.set_properties(type=ComponentType.SmartNIC,
                                     model='ConnectX-5',
                                     name='nic1',
                                     label_allocations=labels)
            #labels.set_fields(bdf="0000:81:00.0")
            #component.set_properties(type=ComponentType.GPU, model='Tesla T4', name='nic12', label_allocations=labels)
            sliver.attached_components_info = AttachedComponentsInfo()
            sliver.attached_components_info.add_device(device_info=component)

        if include_instance_name:
            sliver.label_allocations.set_fields(instance="instance-001")

        u.set_sliver(sliver=sliver)
        return u
 def build_sliver(self) -> BaseSliver:
     node_sliver = NodeSliver()
     node_sliver.resource_type = NodeType.VM
     node_sliver.node_id = "test-slice-node-1"
     cap = Capacities(core=4, ram=64, disk=500)
     catalog = InstanceCatalog()
     instance_type = catalog.map_capacities_to_instance(cap=cap)
     cap_hints = CapacityHints(instance_type=instance_type)
     node_sliver.set_properties(name="node-1", type=NodeType.VM, site="RENC",
                                capacities=cap, image_type='qcow2', image_ref='default_centos_8',
                                capacity_hints=cap_hints)
     node_sliver.set_capacity_allocations(cap=catalog.get_instance_capacities(instance_type=instance_type))
     node_map = tuple([self.arm.graph_id, 'HX6VQ53'])
     node_sliver.set_node_map(node_map=node_map)
     return node_sliver
 def build_sliver(self) -> NodeSliver:
     node_sliver = NodeSliver()
     node_sliver.resource_type = NodeType.VM
     node_sliver.node_id = "test-slice-node-1"
     cap = Capacities(core=4, ram=64, disk=500)
     catalog = InstanceCatalog()
     instance_type = catalog.map_capacities_to_instance(cap=cap)
     cap_hints = CapacityHints(instance_type=instance_type)
     node_sliver.set_properties(name="node-1",
                                type=NodeType.VM,
                                site="RENC",
                                capacities=cap,
                                image_type='qcow2',
                                image_ref='default_centos_8',
                                capacity_hints=cap_hints)
     return node_sliver
Ejemplo n.º 5
0
    def testCapacitiesLabels(self):
        ns = NodeSliver()
        cap_hint = CapacityHints(instance_type='blah')
        lab = Labels(vlan_range='1-4096')
        ns.set_properties(capacities=Capacities(unit=1, core=2), labels=lab, capacity_hints=cap_hint)
        assert(ns.get_capacity_hints().instance_type == 'blah')
        assert(ns.get_labels().vlan_range == '1-4096')
        assert(ns.get_capacities().core == 2)

        with self.assertRaises(LabelException):
            Labels(vlan_range='1-8000')

        with self.assertRaises(LabelException):
            Labels(asn='600000')

        with self.assertRaises(LabelException):
            Labels(vlan='4098')

        with self.assertRaises(LabelException):
            Labels(inner_vlan='6000')
    def __build_network_node_reservations(self, slice_graph: ABCASMPropertyGraph) \
            -> Tuple[List[TicketReservationAvro], Dict[str, str]]:
        reservations = []
        sliver_to_res_mapping = {}
        for nn_id in slice_graph.get_all_network_nodes():

            # Build Network Node Sliver
            sliver = slice_graph.build_deep_node_sliver(node_id=nn_id)

            # Validate Node Sliver
            self.__validate_node_sliver(sliver=sliver)

            # Compute Requested Capacities from Capacity Hints
            requested_capacities = sliver.get_capacities()
            requested_capacity_hints = sliver.get_capacity_hints()
            catalog = InstanceCatalog()
            if requested_capacities is None and requested_capacity_hints is not None:
                requested_capacities = catalog.get_instance_capacities(
                    instance_type=requested_capacity_hints.instance_type)
                sliver.set_capacities(cap=requested_capacities)

            # Compute Capacity Hints from Requested Capacities
            if requested_capacity_hints is None and requested_capacities is not None:
                instance_type = catalog.map_capacities_to_instance(cap=requested_capacities)
                requested_capacity_hints = CapacityHints(instance_type=instance_type)
                sliver.set_capacity_hints(caphint=requested_capacity_hints)

            # Generate reservation for the sliver
            reservation = self.reservation_converter.generate_reservation(sliver=sliver,
                                                                          slice_id=self.slice_obj.get_slice_id(),
                                                                          end_time=self.slice_obj.get_lease_end())
            reservations.append(reservation)

            self.logger.trace(f"Mapped sliver: {sliver.node_id} to res: {reservation.get_reservation_id()}")

            # Maintain Sliver Id to Reservation Mapping
            sliver_to_res_mapping[sliver.node_id] = reservation.get_reservation_id()
        return reservations, sliver_to_res_mapping
    def build_sliver_with_components(self) -> NodeSliver:
        node_sliver = NodeSliver()
        node_sliver.resource_type = NodeType.VM
        node_sliver.node_id = "test-slice-node-1"
        cap = Capacities(core=4, ram=64, disk=500)
        catalog = InstanceCatalog()
        instance_type = catalog.map_capacities_to_instance(cap=cap)
        cap_hints = CapacityHints(instance_type=instance_type)
        node_sliver.set_properties(name="node-1",
                                   type=NodeType.VM,
                                   site="RENC",
                                   capacities=cap,
                                   image_type='qcow2',
                                   image_ref='default_centos_8',
                                   capacity_hints=cap_hints)
        component_sliver = ComponentSliver()
        component_sliver.set_properties(type=ComponentType.SmartNIC,
                                        model='ConnectX-6',
                                        name='nic1')
        node_sliver.attached_components_info = AttachedComponentsInfo()
        node_sliver.attached_components_info.add_device(
            device_info=component_sliver)

        return node_sliver
Ejemplo n.º 8
0
    def create_unit(include_pci: bool = True,
                    include_image: bool = True,
                    include_name: bool = True,
                    include_instance_name: bool = False,
                    include_ns: bool = False) -> Unit:
        """
        Create a unit
        :param include_pci:
        :param include_image:
        :param include_name:
        :param include_instance_name:
        :param include_ns:
        :return:
        """
        u = Unit(rid=ID(uid="rid-1"))
        sliver = NodeSliver()
        cap = Capacities()
        cap.set_fields(core=4, ram=64, disk=500)
        catalog = InstanceCatalog()
        instance_type = catalog.map_capacities_to_instance(cap=cap)
        cap_hints = CapacityHints().set_fields(instance_type=instance_type)
        sliver.set_properties(
            type=NodeType.VM,
            site="RENC",
            capacity_hints=cap_hints,
            capacity_allocations=catalog.get_instance_capacities(
                instance_type=instance_type))
        sliver.label_allocations = Labels().set_fields(
            instance_parent="renc-w1.fabric-testbed.net")

        if include_name:
            sliver.set_properties(name="n1")

        if include_image:
            sliver.set_properties(image_type='qcow2',
                                  image_ref='default_centos_8')

        if include_pci:
            component = ComponentSliver()
            labels = Labels()
            labels.set_fields(bdf=["0000:41:00.0", "0000:41:00.1"])
            component.set_properties(type=ComponentType.SmartNIC,
                                     model='ConnectX-6',
                                     name='nic1',
                                     label_allocations=labels)
            sliver.attached_components_info = AttachedComponentsInfo()
            sliver.attached_components_info.add_device(device_info=component)

        if include_instance_name:
            sliver.label_allocations.set_fields(instance="instance-001")

        if include_ns:
            sliver.network_service_info = NetworkServiceInfo()
            ns = NetworkServiceSliver()
            ns.interface_info = InterfaceInfo()
            ifs1 = InterfaceSliver()
            c = Capacities()
            c.bw = 100
            c.unit = 1
            l1 = Labels()
            l1.ipv4 = '192.168.11.3'
            l1.vlan = '200'
            l1.local_name = 'p1'
            la_1 = Labels()
            la_1.mac = '0C:42:A1:EA:C7:51'
            la_1.vlan = '200'
            ifs1.capacities = c
            ifs1.labels = l1
            ifs1.label_allocations = la_1

            ifs2 = InterfaceSliver()
            ifs2.capacities = c
            l2 = Labels()
            l2.ipv4 = '192.168.11.2'
            l2.local_name = 'p2'
            la_2 = Labels()
            la_2.mac = '0C:42:A1:EA:C7:52'

            ifs2.labels = l2
            ifs2.label_allocations = la_1

            ns.interface_info.interfaces = {'ifs1': ifs1, 'ifs2': ifs2}
            sliver.network_service_info.network_services = {'ns1': ns}

        u.set_sliver(sliver=sliver)
        return u
    def _test_h_request_insufficient_cores(self):
        broker = self.get_broker()
        controller = self.get_controller()
        policy = broker.get_policy()
        policy.allocation_horizon = 10

        clock = broker.get_actor_clock()

        proxy = ClientCallbackHelper(name=controller.get_name(),
                                     guid=controller.get_guid())
        broker_callback = ClientCallbackHelper(name=broker.get_name(),
                                               guid=broker.get_guid())
        ActorRegistrySingleton.get().register_callback(callback=proxy)
        ActorRegistrySingleton.get().register_callback(
            callback=broker_callback)

        slice_obj = SliceFactory.create(slice_id=ID(), name="inventory_slice")
        slice_obj.set_inventory(value=True)

        source = self.get_source_delegation(self.broker, slice_obj)
        self.broker.register_slice(slice_object=slice_obj)
        self.broker.register_delegation(delegation=source)
        self.broker.donate_delegation(delegation=source)

        cycle = 1
        broker.external_tick(cycle=cycle)
        cycle += 1

        start = clock.cycle_start_date(cycle=self.DonateStartCycle)
        end = clock.cycle_end_date(cycle=self.DonateEndCycle - 1)
        sliver = self.build_sliver_with_components()
        caphint = CapacityHints(instance_type="fabric.c64.m384.d4000")
        sliver.set_capacity_hints(caphint=caphint)

        request = self.get_reservation_for_network_node(start,
                                                        end,
                                                        sliver=sliver)
        broker.ticket(reservation=request,
                      callback=proxy,
                      caller=proxy.get_identity())

        self.assertEqual(proxy.prepared, 0)
        self.assertEqual(proxy.called, 0)

        for c in range(cycle, self.DonateEndCycle):
            broker.external_tick(cycle=c)
            while broker.get_current_cycle() != c:
                time.sleep(0.001)

            while proxy.prepared != 1:
                time.sleep(0.001)

            self.assert_failed(request)
            self.assertEqual(1, proxy.prepared)

            if proxy.called > 0:
                print("Proxy Called")
            #    self.assert_failed(proxy.get_reservation(), proxy.update_data)

        broker.await_no_pending_reservations()

        self.assertEqual(1, proxy.get_called())
        self.assertTrue(request.is_closed())