def __validate_node_sliver(sliver: NodeSliver): """ Validate Network Node Sliver @param sliver Node Sliver @raises exception for invalid slivers """ if sliver.get_capacities() is None and sliver.get_capacity_hints() is None: raise OrchestratorException(message="Either Capacity or Capacity Hints must be specified!", http_error_code=BAD_REQUEST)
def testLocation(self): ns = NodeSliver() loc = Location(postal='100 Europa Dr., Chapel Hill, NC 27517') assert(loc.postal is not None) ns.set_properties(location=loc) loc1 = ns.get_property('location') lat, lon = loc1.to_latlon() self.assertGreater(lat, 35.00) self.assertLess(lon, -79.00)
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
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_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
def create_sliver(self, name: str, pci_address: str, gpu_name: str) -> Unit: u = Unit(rid=ID(uid=name)) sliver = NodeSliver() cap = Capacities(core=2, ram=6, disk=10) sliver.set_properties(type=NodeType.VM, site="UKY", capacity_allocations=cap) sliver.label_allocations = Labels(instance_parent="uky-w2.fabric-testbed.net") catalog = InstanceCatalog() instance_type = catalog.map_capacities_to_instance(cap=cap) cap_hints = CapacityHints(instance_type=instance_type) sliver.set_properties(capacity_hints=cap_hints, capacity_allocations=catalog.get_instance_capacities(instance_type=instance_type)) sliver.set_properties(name=name) sliver.set_properties(image_type='qcow2', image_ref='default_ubuntu_20') component = ComponentSliver() labels = Labels(bdf=pci_address) component.set_properties(type=ComponentType.GPU, model='Tesla T4', name=gpu_name, label_allocations=labels) sliver.attached_components_info = AttachedComponentsInfo() sliver.attached_components_info.add_device(device_info=component) u.set_sliver(sliver=sliver) u.set_resource_type(rtype=ResourceType(resource_type=NodeType.VM.name)) return u
def testNodeSliver(self): ns = NodeSliver() ns.set_properties(name='node1', type=NodeType.Server, management_ip='192.168.1.1') with self.assertRaises(ValueError) as ve: ns.set_property('management_ip', '192.168.1.x')
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 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 __cleanup(self, *, sliver: NodeSliver, unit_id: str, raise_exception: bool = False): """ Cleanup VM and detach PCI devices :param sliver: Sliver :param unit_id: Unit Id :param raise_exception: Raise exception if raise_exception flag is True :return: """ try: playbook_path = self.get_config()[AmConstants.PLAYBOOK_SECTION][ AmConstants.PB_LOCATION] inventory_path = self.get_config()[AmConstants.PLAYBOOK_SECTION][ AmConstants.PB_INVENTORY] worker_node = sliver.label_allocations.instance_parent instance_name = sliver.label_allocations.instance if inventory_path is None or playbook_path is None: raise VmHandlerException( f"Missing config parameters playbook_path: {playbook_path} " f"inventory_path: {inventory_path}") if sliver.attached_components_info is not None and worker_node is not None and instance_name is not None: for device in sliver.attached_components_info.devices.values(): try: resource_type = str(device.get_type()) playbook = self.get_config()[ AmConstants.PLAYBOOK_SECTION][resource_type] if playbook is None or inventory_path is None: raise VmHandlerException( f"Missing config parameters playbook: {playbook} " f"playbook_path: {playbook_path} inventory_path: {inventory_path}" ) full_playbook_path = f"{playbook_path}/{playbook}" if device.label_allocations.bdf is None: raise VmHandlerException( f"Missing required parameters bdf: {device.label_allocations.bdf}" ) self.get_logger().info( f"Attaching/Detaching Devices {full_playbook_path}" ) self.__attach_detach_pci( playbook_path=full_playbook_path, inventory_path=inventory_path, instance_name=instance_name, host=worker_node, device_name=unit_id, component=device, attach=False) except Exception as e: self.get_logger().error( f"Error occurred detaching device: {device}") if raise_exception: raise e resource_type = str(sliver.get_type()) playbook = self.get_config()[ AmConstants.PLAYBOOK_SECTION][resource_type] full_playbook_path = f"{playbook_path}/{playbook}" if sliver.get_name() is None: raise VmHandlerException( f"Missing required parameters vm_name: {sliver.get_name()}" ) # Delete VM self.__delete_vm(playbook_path=full_playbook_path, inventory_path=inventory_path, vm_name=sliver.get_name(), unit_id=unit_id) except Exception as e: self.get_logger().error(f"Exception occurred in cleanup {e}") self.get_logger().error(traceback.format_exc()) if raise_exception: raise e