Skip to content
This repository was archived by the owner on Apr 1, 2023. It is now read-only.
2 changes: 1 addition & 1 deletion src/mgmt/manager/project/api/default_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def connect_to_hazelcast(hazelcast_ip_port):
vpc_map = hazelcast_client.get_map('com.futurewei.common.model.VPC')

global routing_rule_map
routing_rule_map = hazelcast_client.get_map('com.futurewei.common.model.RoutingRule')
routing_rule_map = hazelcast_client.get_map('com.futurewei.common.model.NeighborRule')

def added(event):
number_of_entries_in_map = len(routing_rule_map.entry_set().result())
Expand Down
29 changes: 27 additions & 2 deletions src/mgmt/manager/project/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ def read_data(self, object_data_input):
self.overlay_type = object_data_input.read_string()

class RoutingRule(IdentifiedDataSerializable):
def __init__(self, id=None, mac=None, hostmac=None, hostip=None, ip=None, vni=None, version=None):
def __init__(self, id=None, mac=None, ariongroup=None, hostmac=None, hostip=None, ip=None, vni=None, version=None):
self.id = id
self.mac = mac
self.ariongroup = ariongroup
self.hostmac = hostmac
self.hostip = hostip
self.ip = ip
Expand All @@ -138,6 +139,7 @@ def get_factory_id(self):
def write_data(self, object_data_output):
object_data_output.write_string(self.id)
object_data_output.write_string(self.mac)
object_data_output.write_string(self.ariongroup)
object_data_output.write_string(self.hostmac)
object_data_output.write_string(self.hostip)
object_data_output.write_string(self.ip)
Expand All @@ -147,6 +149,7 @@ def write_data(self, object_data_output):
def read_data(self, object_data_input):
self.id = object_data_input.read_string()
self.mac = object_data_input.read_string()
self.ariongroup = object_data_input.read_string()
self.hostmac = object_data_input.read_string()
self.hostip = object_data_input.read_string()
self.ip = object_data_input.read_string()
Expand Down Expand Up @@ -207,6 +210,25 @@ def to_json(self):
}


class Gw(db.Model):

__tablename__ = 'gws'

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
node_id = db.Column(db.String(64), db.ForeignKey('nodes.node_id'),
nullable=False)
ip = db.Column(db.String, nullable=False)
mac = db.Column(db.String, nullable=False)

def to_json(self):
return {
'id': self.id,
'ip': self.ip,
'mac': self.mac,
'node_id': self.node_id
}


class Node(db.Model):

__tablename__ = 'nodes'
Expand All @@ -224,6 +246,7 @@ class Node(db.Model):
mac_tenant = db.Column(db.String(18), nullable=False)
inf_zgc = db.Column(db.String(16), nullable=False)
mac_zgc = db.Column(db.String(18), nullable=False)
gws = db.relationship("Gw", backref="node")

def to_json(self):
return {
Expand All @@ -234,10 +257,12 @@ def to_json(self):
'description': self.description,
'ip_control': self.ip_control,
'inf_tenant': self.inf_tenant,
'inf_zgc': self.inf_zgc
'inf_zgc': self.inf_zgc,
'gws': [gw.to_json() for gw in self.gws]
}



class Vpc(db.Model):

__tablename__ = 'vpcs'
Expand Down
71 changes: 62 additions & 9 deletions src/mgmt/manager/project/api/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from kubernetes.client.rest import ApiException
from kubernetes import client, config
from project.api.models import ArionNode, Node, Zgc
from project.api.models import ArionNode, Node, Zgc, Gw
from project import db
from project.api.utils import getGWsFromIpRange, get_mac_from_ip
from project.api.settings import activeZgc, zgc_cidr_range, node_ips
Expand Down Expand Up @@ -122,17 +122,41 @@ def node_load_transit_xdp(ip, inf_tenant, inf_zgc):
rpc.load_transit_xdp(inf_tenant, inf_zgc, int(activeZgc["port_ibo"]))
del rpc


def node_unload_transit_xdp(ip, itf_tenant, itf_zgc):
node_ips.pop(ip, None)
rpc = TrnRpc(ip)
rpc.unload_transit_xdp(ip, itf_tenant, itf_zgc)
del rpc


def update_existing_nodes_gw_ips_macs(node_ip : str, ips : list, macs : list ):
node_to_update = Node.query.filter_by(ip_control=node_ip).first()
print(f'Found this node: {node_to_update.to_json()}')
if node_to_update is None:
print(f'Failed to find Node with ip_control {node_ip}!!!!!!!')
return
else:
for gw in node_to_update.gws:
print(f'Deleting this GW: {gw.to_json()}')
db.session.delete(gw)
db.session.commit()
for i in range(len(ips)):
gw_to_add = Gw(node_id=node_to_update.node_id, ip=ips[i], mac=macs[i])
print(f'Adding this GW: {gw_to_add.to_json()}')
node_to_update.gws.append(gw_to_add)
print(f'Update this node with following info: {node_to_update.to_json()}')
db.session.commit()
print(f'Updated Node with ip_control {node_ip} with updated gw ips and macs.')
return


def set_up_node_from_hazelcast(arion_node: ArionNode):
start_time = time.time()
logger.debug('From Hazelcast: Start to make one node and one droplet for this node.')
new_node = Node()
new_node.node_id = str(uuid.uuid4())
node_id = str(uuid.uuid4())
new_node.node_id = node_id
# Set the node's zgc_id to active_zgc
new_node.zgc_id = activeZgc["zgc_id"]#arion_node.zgc_id
new_node.name = arion_node.name
Expand Down Expand Up @@ -208,7 +232,13 @@ def set_up_node_from_hazelcast(arion_node: ArionNode):
current_length_of_ip_list = len(ip_for_new_droplet)
macs_for_new_droplet = [get_mac_from_ip(ip) for ip in ip_for_new_droplet]

# Each wing node has one droplet, so I need to update the Node with the updated IPs && MACs
for droplet_name in modified_droplets:
modified_node_physical_ip = modified_droplets[droplet_name]['metadata']['labels']['node_ip']
modified_node_gws_ip = modified_droplets[droplet_name]['spec']['ip']
modified_node_gws_mac = modified_droplets[droplet_name]['spec']['mac']
update_existing_nodes_gw_ips_macs(modified_node_physical_ip, modified_node_gws_ip,
modified_node_gws_mac)
update_droplet(modified_droplets[droplet_name])

create_droplet(name='droplet-tenant-' + new_node.name.replace('_', "-").lower(),
Expand All @@ -220,19 +250,25 @@ def set_up_node_from_hazelcast(arion_node: ArionNode):
zgc_id=new_node.zgc_id)

logger.info('Finished updating and adding droplets.')
if len(new_node.gws) == 0:
for i in range(len(ip_for_new_droplet)):
new_node.gws.append(Gw(node_id=node_id, ip=ip_for_new_droplet[i], mac=macs_for_new_droplet[i]))
else:
logger.error('Not enough ip to assign for the new droplet.')
else:
logger.info("First nodes in the ZGC cluster, it gets all the IPs")
zgc = Zgc.query.filter_by(zgc_id=new_node.zgc_id).first()
if zgc is not None:
gws = getGWsFromIpRange(zgc.ip_start, zgc.ip_end)
if len(new_node.gws) == 0:
for gw in gws:
new_node.gws.append(Gw(node_id=node_id, ip=gw['ip'], mac=gw['mac']))
create_droplet(name='droplet-tenant-' + new_node.name.replace('_', "-").lower(),
ip=[gw['ip'] for gw in gws],
ip=[gw['ip'] for gw in gws],
mac=[gw['mac'] for gw in gws],
itf=new_node.inf_tenant,
node_ip= new_node.ip_control,
network='tenant',
network='tenant',
zgc_id=new_node.zgc_id)
else:
logger.error("There's no zgc with zgc_id: {} in the database!".format(new_node.zgc_id))
Expand All @@ -251,7 +287,8 @@ def all_nodes():
logger.debug('Start to make one node and one droplet for this node.')
start_time = time.time()
post_data = request.get_json()
post_data['node_id'] = str(uuid.uuid4())
node_id = str(uuid.uuid4())
post_data['node_id'] = node_id

node_load_transit_xdp(post_data['ip_control'], post_data['inf_tenant'], post_data['inf_zgc'])

Expand Down Expand Up @@ -318,16 +355,26 @@ def all_nodes():
current_length_of_ip_list = len(ip_for_new_droplet)
macs_for_new_droplet = [get_mac_from_ip(ip) for ip in ip_for_new_droplet]

# Each wing node has one droplet, so I need to update the Node with the updated IPs && MACs
for droplet_name in modified_droplets:
modified_node_physical_ip = modified_droplets[droplet_name]['metadata']['labels']['node_ip']
modified_node_gws_ip = modified_droplets[droplet_name]['spec']['ip']
modified_node_gws_mac = modified_droplets[droplet_name]['spec']['mac']
update_existing_nodes_gw_ips_macs(modified_node_physical_ip, modified_node_gws_ip, modified_node_gws_mac)
update_droplet(modified_droplets[droplet_name])

create_droplet(name='droplet-tenant-' + post_data['name'].replace('_', "-").lower(),
ip=ip_for_new_droplet,
mac=macs_for_new_droplet,
itf=post_data['inf_tenant'],
node_ip= post_data['ip_control'],
node_ip=post_data['ip_control'],
network='tenant',
zgc_id=post_data['zgc_id'])
if 'gws' not in post_data:
post_data['gws'] = list()
for i in range(len(ip_for_new_droplet)):
post_data['gws'].append(Gw(node_id=node_id, ip=ip_for_new_droplet[i], mac=macs_for_new_droplet[i]))

logger.info('Finished updating and adding droplets.')
else:
logger.error('Not enough ip to assign for the new droplet.')
Expand All @@ -336,11 +383,15 @@ def all_nodes():
zgc = Zgc.query.filter_by(zgc_id=post_data['zgc_id']).first()
if zgc is not None:
gws = getGWsFromIpRange(zgc.ip_start, zgc.ip_end)
create_droplet(name='droplet-tenant-' + post_data['name'].replace('_', "-").lower(),
ip=[gw['ip'] for gw in gws],
if 'gws' not in post_data:
post_data['gws'] = list()
for gw in gws:
post_data['gws'].append(Gw(node_id=node_id, ip=gw['ip'], mac=gw['mac']))
create_droplet(name='droplet-tenant-' + post_data['name'].replace('_', "-").lower(),
ip=[gw['ip'] for gw in gws],
mac=[gw['mac'] for gw in gws],
itf=post_data['inf_tenant'],
node_ip= post_data['ip_control'],
node_ip=post_data['ip_control'],
network='tenant',
zgc_id=post_data['zgc_id'])
else:
Expand All @@ -351,6 +402,8 @@ def all_nodes():
db.session.commit()

response_object = post_data
if 'gws' in response_object:
response_object['gws'] = [gw.to_json() for gw in response_object['gws']]
end_time = time.time()
logger.debug(f'Arion took {end_time - start_time} seconds to make a node and its droplets.')
status_code = 201
Expand Down
24 changes: 15 additions & 9 deletions test/data/arion_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@
},
"aca_nodes_2": [
{
"ip": "172.16.17.73",
"mac": "48:7b:6b:b9:e2:9a",
"username": "********",
"password": "********"
"ip": "192.168.20.92",
"mac": "e8:bd:d1:01:77:ec",
"username": "***",
"password": "***"
},
{
"ip": "192.168.20.93",
"mac": "e8:bd:d1:01:77:e4",
"username": "***",
"password": "***"
},
{
"ip": "172.16.17.74",
"mac": "48:7b:6b:b9:e2:b2",
"username": "********",
"password": "********"
"ip": "192.168.20.94",
"mac": "e8:bd:d1:01:77:e5",
"username": "***",
"password": "***"
}
],
"server_aca_repo_path": "/home/ubuntu/arion-dp/src/extern/alcor-control-agent",
"server_aca_repo_path": "/home/user/src/Github.com/zzxgzgz/alcor-control-agent",
"ZGC_data": {
"name": "ZGC_test106",
"description": "ZGC_test106",
Expand Down