Skip to content

Commit 17e0666

Browse files
committed
patch for choosing vlans for shared nics
1 parent 4a2a469 commit 17e0666

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

fabric_cf/actor/core/policy/network_node_inventory.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ def __update_shared_nic_labels_and_capacities(self, *, available_component: Comp
120120
raise BrokerException(error_code=ExceptionErrorCode.INSUFFICIENT_RESOURCES,
121121
msg=f"{message}")
122122

123-
# Assign the first PCI Id from the list of available PCI slots
124-
requested_component.label_allocations = Labels(bdf=delegated_label.bdf[0], numa=delegated_label.numa[0])
125-
126123
# Find the VLAN from the BQM Component
127124
if available_component.network_service_info is None or \
128125
len(available_component.network_service_info.network_services) != 1:
@@ -145,14 +142,25 @@ def __update_shared_nic_labels_and_capacities(self, *, available_component: Comp
145142

146143
delegation_id, ifs_delegated_labels = self.get_delegations(lab_cap_delegations=ifs.get_label_delegations())
147144

148-
# Determine the index which points to the same PCI id as assigned above
149-
# This index points to the other relevant information such as MAC Address,
150-
# VLAN tag for that PCI device
151-
i = 0
152-
for pci_id in ifs_delegated_labels.bdf:
153-
if pci_id == delegated_label.bdf[0]:
154-
break
155-
i += 1
145+
assigned_bdf = delegated_label.bdf[0]
146+
assigned_numa = delegated_label.numa[0]
147+
148+
# Check if the requested component's VLAN exists in the delegated labels
149+
if requested_component.labels and requested_component.labels.vlan and \
150+
requested_component.labels.vlan in ifs_delegated_labels.vlan:
151+
vlan_index = ifs_delegated_labels.vlan.index(requested_component.labels.vlan)
152+
bdf_for_requested_vlan = ifs_delegated_labels.bdf[vlan_index]
153+
154+
if bdf_for_requested_vlan in delegated_label.bdf:
155+
bdf_index = delegated_label.bdf.index(bdf_for_requested_vlan)
156+
assigned_bdf = bdf_for_requested_vlan
157+
assigned_numa = delegated_label.numa[bdf_index]
158+
159+
# Assign the first PCI Id from the list of available PCI slots
160+
requested_component.label_allocations = Labels(bdf=assigned_bdf, numa=assigned_numa)
161+
162+
# Find index of assigned BDF in the interface delegated labels
163+
assigned_index = ifs_delegated_labels.bdf.index(assigned_bdf)
156164

157165
# Updated the Requested component with VLAN, BDF, MAC
158166
req_ns_name = next(iter(requested_component.network_service_info.network_services))
@@ -162,11 +170,12 @@ def __update_shared_nic_labels_and_capacities(self, *, available_component: Comp
162170

163171
# Do not copy VLAN for OpenStack-vNIC
164172
if requested_component.get_model() == Constants.OPENSTACK_VNIC_MODEL:
165-
lab = Labels(bdf=ifs_delegated_labels.bdf[i], mac=ifs_delegated_labels.mac[i],
166-
local_name=ifs_delegated_labels.local_name[i])
173+
lab = Labels(bdf=ifs_delegated_labels.bdf[assigned_index], mac=ifs_delegated_labels.mac[assigned_index],
174+
local_name=ifs_delegated_labels.local_name[assigned_index])
167175
else:
168-
lab = Labels(bdf=ifs_delegated_labels.bdf[i], mac=ifs_delegated_labels.mac[i],
169-
vlan=ifs_delegated_labels.vlan[i], local_name=ifs_delegated_labels.local_name[i])
176+
lab = Labels(bdf=ifs_delegated_labels.bdf[assigned_index], mac=ifs_delegated_labels.mac[assigned_index],
177+
vlan=ifs_delegated_labels.vlan[assigned_index],
178+
local_name=ifs_delegated_labels.local_name[assigned_index])
170179

171180
# For the Layer 2 copying the IP address to the label allocations
172181
# This is to be used by AM Handler to configure Network Interface

tools/db_cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class MainClass:
4646
GlobalsSingleton.get().load_config()
4747
GlobalsSingleton.get().initialized = True
4848

49-
def __init__(self, user: str, password: str, db: str, host: str = '127.0.0.1:5432'):
49+
def __init__(self, user: str, password: str, db: str, host: str = 'orchestrator-db:5432'):
5050
self.logger = logging.getLogger("db-cli")
5151
file_handler = RotatingFileHandler('./db_cli.log', backupCount=5, maxBytes=50000)
5252
logging.basicConfig(level=logging.DEBUG,
5353
format="%(asctime)s [%(filename)s:%(lineno)d] [%(levelname)s] %(message)s",
5454
handlers=[logging.StreamHandler(), file_handler])
5555

5656
self.db = ActorDatabase(user=user, password=password, database=db, db_host=host, logger=self.logger)
57-
self.neo4j_config = {"url": "neo4j://0.0.0.0:9687",
57+
self.neo4j_config = {"url": "neo4j://orchestrator-neo4j:9687",
5858
"user": "neo4j",
5959
"pass": "password",
6060
"import_host_dir": "/Users/kthare10/renci/code/fabric/ControlFramework/neo4j1/imports/",
@@ -63,10 +63,10 @@ def __init__(self, user: str, password: str, db: str, host: str = '127.0.0.1:543
6363
def get_slices(self, email: str = None, slice_id: str = None, slice_name: str = None):
6464
try:
6565
if slice_id is not None:
66-
slice_obj = self.db.get_slice(slice_id=ID(uid=slice_id))
66+
slice_obj = self.db.get_slices(slice_id=ID(uid=slice_id))
6767
slice_list = [slice_obj]
6868
elif email is not None:
69-
slice_list = self.db.get_slice_by_email(email=email)
69+
slice_list = self.db.get_slices(email=email)
7070
else:
7171
slice_list = self.db.get_slices()
7272

0 commit comments

Comments
 (0)