Skip to content

Commit

Permalink
Merge pull request #134 from fabric-testbed/exclusive_fabfed_net_or_p…
Browse files Browse the repository at this point in the history
…ublic_fabnet

node will only be added to public fabnet if not added to a fabfed (stitch) net…
  • Loading branch information
disprosium8 authored May 10, 2024
2 parents d00a6b0 + 653d653 commit 9723ee7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
4 changes: 2 additions & 2 deletions fabfed/provider/api/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def modified(self):

return False

def retrieve_attribute_from_saved_state(self, resource, resource_name, attribute):
def retrieve_attribute_from_saved_state(self, resource, resource_name, attribute, defaultValue=None):
if self.saved_state:
for state in resource[Constants.SAVED_STATES]:
if state.attributes['name'] == resource_name:
Expand All @@ -206,7 +206,7 @@ def retrieve_attribute_from_saved_state(self, resource, resource_name, attribute
return ret[0]

return ret
return None
return defaultValue

def validate_resource(self, *, resource: dict):
label = resource.get(Constants.LABEL)
Expand Down
2 changes: 1 addition & 1 deletion fabfed/provider/fabric/fabric_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
FABNET_IPV4_PREFIX = "FABNET_IPv4"
FABNET_IPV6_PREFIX = "FABNET_IPv6"
INCLUDE_FABNET_V4 = True
INCLUDE_FABNET_V6 = True
INCLUDE_FABNET_V6 = False

FABRIC_SLEEP_AFTER_SUBMIT_OK = 120 # In seconds

Expand Down
28 changes: 18 additions & 10 deletions fabfed/provider/fabric/fabric_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class FabricNode(Node):
def __init__(self, *, label, delegate: Delegate, nic_model=None, network_label):
def __init__(self, *, label, delegate: Delegate, nic_model: str, network_label: str):
flavor = {'cores': delegate.get_cores(), 'ram': delegate.get_ram(), 'disk': delegate.get_disk()}
super().__init__(label=label, name=delegate.get_name(), image=delegate.get_image(), site=delegate.get_site(),
flavor=str(flavor))
Expand Down Expand Up @@ -46,6 +46,7 @@ def handle_networking(self):
return

v6_dev = v4_dev = stitch_dev = None

try:
# XXX Finding interfaces on stitched networks is currently not working on fablib==1.4.0
# Search for interface directly...
Expand All @@ -56,21 +57,27 @@ def handle_networking(self):
logger.warning(f" Node {self.name} checking for stitch network/device: {e}")

try:
if INCLUDE_FABNET_V4:
if stitch_dev is None and INCLUDE_FABNET_V4:
for itf in slice_object.get_interfaces():
if self.v4net_name in itf.get_name():
v4_dev = itf.get_device_name()
logger.info(f" Node {self.name} has v4 device={v4_dev}")
break
except Exception as e:
logger.warning(f"Node {self.name} checking for ipv4/ipv6: {e}")

if INCLUDE_FABNET_V6:
try:
if stitch_dev is None and INCLUDE_FABNET_V6:
for itf in slice_object.get_interfaces():
if self.v6net_name in itf.get_name():
v6_dev = itf.get_device_name()
logger.info(f" Node {self.name} has v6 device={v6_dev}")
break
except Exception as e:
logger.warning(f"Node {self.name} checking for ipv4/ipv6: {e}")

if INCLUDE_FABNETS:
try:
if stitch_dev and INCLUDE_FABNETS:
v4_net = slice_object.get_network(name=self.v4net_name)
v4_dev = v4_net.get_interfaces()[0].get_device_name() if v4_net and v4_net.get_interfaces() else None
logger.info(f" Node {self.name} has v4 device={v4_dev}")
Expand Down Expand Up @@ -193,14 +200,15 @@ def __init__(self, label, slice_object: Slice, name: str, resource: dict):
self.node: Delegate = slice_object.add_node(name=name, image=image, site=site, cores=cores, ram=ram, disk=disk)

# Use fully automated ip v4
if INCLUDE_FABNET_V4:
self.node.add_fabnet()
if INCLUDE_FABNET_V4 and resource.get(Constants.RES_TYPE_NETWORK) is None:
self.node.add_fabnet(net_type="IPv4", nic_type=self.nic_model)

if INCLUDE_FABNET_V6:
self.node.add_fabnet(net_type="IPv6")
# Use fully automated ip v6
if INCLUDE_FABNET_V6 and resource.get(Constants.RES_TYPE_NETWORK) is None:
self.node.add_fabnet(net_type="IPv6", nic_type=self.nic_model)

# Include two basic NICs for FabNetv4/v6
if INCLUDE_FABNETS:
# This has been deprecated Include two basic NICs for FabNetv4/v6
if INCLUDE_FABNETS and resource.get(Constants.RES_TYPE_NETWORK) is None:
net_iface_v4 = self.node.add_component(model='NIC_Basic',
name=FABRIC_IPV4_NET_IFACE_NAME).get_interfaces()[0]
# TODO: KOMAL:
Expand Down
38 changes: 27 additions & 11 deletions fabfed/provider/fabric/fabric_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def _add_node(self, resource: dict):
assert delegate is not None, "expected to find node {name} in slice {self.name}"
network_label = self.provider.retrieve_attribute_from_saved_state(resource, name, 'network_label')
dataplane_ipv4 = self.provider.retrieve_attribute_from_saved_state(resource, name, 'dataplane_ipv4')
node = FabricNode(label=label, delegate=delegate, network_label=network_label)
nic_model = self.provider.retrieve_attribute_from_saved_state(resource, name, 'nic_model', "NIC_Basic")
node = FabricNode(label=label, delegate=delegate, nic_model=nic_model, network_label=network_label)

if not network_label:
if util.has_resolved_internal_dependencies(resource=resource, attribute='network'):
Expand All @@ -138,12 +139,25 @@ def _add_node(self, resource: dict):

from fabrictestbed_extensions.fablib.network_service import NetworkService

itf = node.delegate.add_component(model="NIC_Basic",
name=FABRIC_STITCH_NET_IFACE_NAME).get_interfaces()[0]
self.logger.info(f"Added interface {itf.get_name()} to node {node.get_name()}")
delegate: NetworkService = network.delegate
self.logger.info(f"adding interface {itf.get_name()} to {delegate.get_name()}")
delegate.add_interface(itf)
itf = None

try:
comp = node.delegate.get_component(name=FABRIC_STITCH_NET_IFACE_NAME)
itf = comp.get_interfaces()[0]
self.logger.info(f"Found interface {itf.get_name()} to node {node.get_name()}")
except Exception as e:
self.logger.warning(
f"Exception while looking for {itf.get_name()} in node {node.get_name()}: {e}")

if itf is None:
itf = node.delegate.add_component(model=nic_model,
name=FABRIC_STITCH_NET_IFACE_NAME).get_interfaces()[0]
self.logger.info(f"Added interface {itf.get_name()} to node {node.get_name()}")

delegate: NetworkService = network.delegate
delegate.add_interface(itf)
self.logger.info(f"Added interface {itf.get_name()} to network {delegate.get_name()}")

node.set_network_label(network.label)

if dataplane_ipv4:
Expand All @@ -162,12 +176,13 @@ def _add_node(self, resource: dict):
if network:
from fabrictestbed_extensions.fablib.network_service import NetworkService

itf = node.delegate.add_component(model="NIC_Basic",
itf = node.delegate.add_component(model=node.nic_model,
name=FABRIC_STITCH_NET_IFACE_NAME).get_interfaces()[0]
self.logger.info(f"Added interface {itf.get_name()} to node {node.get_name()}")
self.logger.info(
f"Added interface {itf.get_name()} to node {node.get_name()} with nic_model={node.nic_model}")
delegate: NetworkService = network.delegate
self.logger.info(f"adding interface {itf.get_name()} to {delegate.get_name()}")
delegate.add_interface(itf)
self.logger.info(f"Added interface {itf.get_name()} to network {delegate.get_name()}")
node.set_network_label(network.label)

self.nodes.append(node)
Expand Down Expand Up @@ -235,7 +250,8 @@ def _reload_nodes(self):

for node in self.nodes:
delegate = self.slice_object.get_node(node.name)
n = FabricNode(label=node.label, delegate=delegate, network_label=node.network_label)
n = FabricNode(label=node.label, delegate=delegate,
nic_model=node.nic_model, network_label=node.network_label)
n.set_network_label(node.network_label)
n.set_used_dataplane_ipv4(node.used_dataplane_ipv4())
temp.append(n)
Expand Down
2 changes: 1 addition & 1 deletion fabfed/provider/fabric/fabric_slice_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def add_ip_address_to_network(slice_delegate, node, net_name, node_addr, subnet,
delegate = slice_delegate.get_node(node.name)

if has_ip_address(slice_delegate, node, node_addr):
logger.info(f'already exists when adding ip addr: {node_addr}')
logger.info(f'node {node.name} already has: {node_addr}')
return

for attempt in range(retry):
Expand Down

0 comments on commit 9723ee7

Please sign in to comment.