<jupyter_start><jupyter_text>This notebook shows how to use Orchestrator APIs for user experiments<jupyter_code>import os
from fabrictestbed.slice_manager import SliceManager, Status, SliceState
import json
ssh_key_file_priv=os.environ['HOME']+"/.ssh/id_rsa"
ssh_key_file_pub=os.environ['HOME']+"/.ssh/id_rsa.pub"

ssh_key_pub = None
with open (ssh_key_file_pub, "r") as myfile:
    ssh_key_pub=myfile.read()
    ssh_key_pub=ssh_key_pub.strip()
slice_name='Slice-l2p2p-ded'<jupyter_output><empty_output><jupyter_text>Create Slice Manager ObjectUsers can request tokens with different Project and Scopes by altering `project_name` and `scope` parameters in the refresh call below.<jupyter_code>slice_manager = SliceManager()<jupyter_output><empty_output><jupyter_text>Orchestrator API example to query for available resources<jupyter_code>status, advertised_topology = slice_manager.resources()

print(f"Status: {status}")
if status == Status.OK:
    print(f"Toplogy: {advertised_topology}")
else:
    print(f"Error: {advertised_topology}")
if status == Status.OK:
    advertised_topology.draw()<jupyter_output><empty_output><jupyter_text>Create SliceIn Release 1.0, user is expected to create tagged interface and assign the IP addresses manually. Please use the example comands indicated below: Run on Node N1```ip link add link eth1 name eth1.200 type vlan id 200ip link set dev eth1.200 upip addr add 192.168.10.51/24 dev eth1.200``` Run on Node N2```ip link add link eth1 name eth1.200 type vlan id 200ip link set dev eth1.200 upip addr add 192.168.10.52/24 dev eth1.200```<jupyter_code>from fabrictestbed.slice_editor import ExperimentTopology, Capacities, ComponentType, ComponentModelType, ServiceType
# Create topology
t = ExperimentTopology()

# Add node
n1 = t.add_node(name='n1', site='UKY')

# Set capacities
cap = Capacities()
cap.set_fields(core=2, ram=6, disk=10)

# Set Properties
n1.set_properties(capacities=cap, image_type='qcow2', image_ref='default_centos_8')

# Add PCI devices
n1.add_component(ctype=ComponentType.NVME, model='P4510', name='c1')

# Add node
n2 = t.add_node(name='n2', site='LBNL')

# Set properties
n2.set_properties(capacities=cap, image_type='qcow2', image_ref='default_centos_8')

# Shared Cards
n1.add_component(model_type=ComponentModelType.SmartNIC_ConnectX_6, name='n1-nic1')
n2.add_component(model_type=ComponentModelType.SmartNIC_ConnectX_6, name='n2-nic1')

# L2PTP Service
t.add_network_service(name='ptp1', nstype=ServiceType.L2PTP,
                      interfaces=[n1.interface_list[0], n2.interface_list[0]])

# Specify VLAN
for i in t.interface_list:
    if_labels = i.get_property(pname="labels")
    if_labels.vlan = "200"
    i.set_properties(labels=if_labels)

# Generate Slice Graph
slice_graph = t.serialize()

# Request slice from Orchestrator
status, reservations = slice_manager.create(slice_name=slice_name, slice_graph=slice_graph, ssh_key=ssh_key_pub)

print("Response Status {}".format(status))
if status == Status.OK:
    print("Reservations created {}".format(reservations))
else:
    print(f"Failure: {reservations}")<jupyter_output><empty_output><jupyter_text>Query Slices<jupyter_code>status, slices = slice_manager.slices(excludes=[SliceState.Closing, SliceState.Dead])

print("Response Status {}".format(status))
if status == Status.OK:
    print("Slices {}".format(slices))
    
    slice_object=list(filter(lambda s: s.slice_name == slice_name, slices))[0]
else:
    print(f"Failure: {slices}")<jupyter_output><empty_output><jupyter_text>Query Slivers<jupyter_code>status, slivers = slice_manager.slivers(slice_object=slice_object)

print("Response Status {}".format(status))
if status == Status.OK:
    print("Slivers {}".format(slivers))
else:
    print(f"Failure: {slivers}")<jupyter_output><empty_output><jupyter_text>Sliver Status<jupyter_code>for s in slivers:
    status, sliver_status = slice_manager.sliver_status(sliver=s)

    print("Response Status {}".format(status))
    if status == Status.OK:
        print()
        print("Sliver Status {}".format(sliver_status))
        print()<jupyter_output><empty_output><jupyter_text>Delete Slice<jupyter_code>status, result = slice_manager.delete(slice_object=slice_object)

print("Response Status {}".format(status))
print("Response received {}".format(result))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12179339033972729, 'fraction_numerical': 0.02334180725675988, 'mean_word_length': 6.742397137745975, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '119518', 'license': 'MIT', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1503, 'n_words': 304, 'path': 'fabric_examples/beta_functionality/l2ptp-dedicated.ipynb', 'repo_name': 'fabric-testbed/jupyter-examples', 'size': '4327'}