Skip to content

Commit

Permalink
Fixing monitoring for FDUs (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrik committed Jul 15, 2019
1 parent 652a2ca commit 9951544
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 26 deletions.
9 changes: 6 additions & 3 deletions fos-plugins/LXD/LXD_plugin
Original file line number Diff line number Diff line change
Expand Up @@ -831,13 +831,13 @@ class LXD(RuntimePluginFDU):
pass

def __monitor_instance(self, fdu_uuid, instance_id, instance_name):
self.logger.info('__monitor_fdu()','[ INFO ] LXD Plugin - Staring monitoring of Container uuid {}'.format(instance_id))
self.logger.info('__monitor_instance()','[ INFO ] LXD Plugin - Staring monitoring of Container uuid {}'.format(instance_id))
while True:
time.sleep(self.update_interval)
try:
record = self.connector.loc.actual.get_node_fdu(self.node, self.uuid, fdu_uuid, instance_id)
if record.get('status') not in ['LAND', 'TAKE_OFF','MIGRATE']:
self.logger.info('__monitor_fdu()','[ INFO ] LXD Plugin - Updating status of {}'.format(fdu_uuid))
self.logger.info('__monitor_instance()','[ INFO ] LXD Plugin - Updating status of {}'.format(fdu_uuid))
c = self.conn.containers.get(instance_name)
cs = c.state()
detailed_state = {}
Expand All @@ -858,7 +858,10 @@ class LXD(RuntimePluginFDU):
# c_net = []
c_net = {}
for i in record.get('interfaces'):
ip = self.call_nw_plugin_function('get_address', {'mac_address':i.get('mac_address','')})
try:
ip = self.call_nw_plugin_function('get_address', {'mac_address':i.get('mac_address','')})
except ValueError:
ip = ''
# Getting address from LXD if unable from network manager, eg. if connected to physical device/lxd bridge
if ip == '':
lxd_net_info_addrs = cs.network[i['vintf_name']]['addresses']
Expand Down
18 changes: 14 additions & 4 deletions fos-plugins/linuxbridge/linuxbridge_plugin
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class LinuxBridge(NetworkPlugin):


def get_address(self, mac_address):
self.logger.info('get_address()', 'Linux Bridge Plugin - Getting IP address for {}'.format(mac_address))

# LEASE FILE FORMAT
# 1560518377 00:16:3e:5e:a8:fa 192.168.123.13 holy-gar 01:00:16:3e:5e:a8:fa
Expand All @@ -197,8 +198,10 @@ class LinuxBridge(NetworkPlugin):
for l in res:
tok = l.split(' ')
if tok[1] == mac_address:
self.logger.info('get_address()', 'Linux Bridge Plugin - IP address for {} is '.format(mac_address, tok[2]))
return {'result': tok[2]}
continue

self.logger.info('get_address()', 'Linux Bridge Plugin - Unable to get IP address for {} '.format(mac_address))
return {'result': ''}


Expand Down Expand Up @@ -648,6 +651,10 @@ class LinuxBridge(NetworkPlugin):
return {'result': rec}

def assign_floating_ip(self, ip_id, cp_id):
# fagent: [ERROR] [FOS-AGENT] - EV-ASSOC-FLOATING-IP - EXCEPTION: (Failure
# "[YAS]:
# EVAL on /alfos/a2d358aa-af2b-42cb-8d23-a89e88b97e5c/network_managers/d42b4163-af35-423a-acb4-a228290cf0be/exec/assign_floating_ip?(ip_id=c02eea4f-6f35-4a87-b8bb-b9ba617e8214;cp_id=a47a8819-72e5-4b4e-86fd-fc30c9fda68b):
# ErrNo 400")
self.logger.info('assign_floating_ip()', 'Assigning floating IP {} to {}'.format(ip_id, cp_id))
rec = self.connector.loc.actual.get_node_floating_ip(self.node, self.uuid, ip_id)
if rec is None:
Expand Down Expand Up @@ -675,7 +682,7 @@ class LinuxBridge(NetworkPlugin):
return {'error': 11}
cp_ip = self.__get_cp_ip(cp_id)
if cp_ip == '':
self.logger.error('remove_floating_ip()', 'Connection point {} as not IP'.format(ip_id))
self.logger.error('remove_floating_ip()', 'Connection point {} has no IP'.format(ip_id))
return {'error': 11}
cmd = 'sudo iptables -t nat -D PREROUTING -d {} -j DNAT --to {}'.format(rec['vface'], cp_ip)
self.call_os_plugin_function('execute_command',{'command':cmd,'blocking':True, 'external':True})
Expand All @@ -689,17 +696,20 @@ class LinuxBridge(NetworkPlugin):

def __get_cp_ip(self, cp_id):
cp_rec = self.connector.loc.actual.get_node_port(self.node, self.uuid, cp_id)
self.logger.info('__get_cp_ip()', 'Get connection point IP for {} Record: {}'.format(cp_id, cp_rec))
fdus = self.connector.loc.actual.get_node_all_fdus_instances(self.node)
cp_ip = ''
for i in fdus:
self.logger.info('__get_cp_ip()', 'Scanning FDUs Record: {}'.format(i))
intfs = i['interfaces']
for intf in intfs:
if intf.get('cp_id') is not None and intf.get('cp_id') != '':
if intf.get('cp_id') == cp_id:
if intf.get('cp_id') == cp_rec['uuid']:
i_name = intf['vintf_name']
hv_info = i['hypervisor_info']
if len(hv_info) > 0:
cp_id = hv_info['network']['i_name']['addresses'][0]['address']
cp_ip = hv_info['network'][i_name]['addresses'][0]['address']
self.logger.info('__get_cp_ip()', 'IP for {} -> {}'.format(cp_id, cp_ip))
return cp_ip

def __cird2block(self, cird):
Expand Down
12 changes: 8 additions & 4 deletions src/agent/fos-agent/fos_agent.ml
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,12 @@ let agent verbose_flag debug_flag configuration custom_uuid =
>>= fun _ ->
let eval_res = FAgentTypes.{result = Some (JSON.of_string (FTypes.string_of_floating_ip floating)) ; error=None} in
Lwt.return @@ FAgentTypes.string_of_eval_result eval_res
| None -> let eval_res = FAgentTypes.{result = None ; error=Some 11} in
| None -> let eval_res = FAgentTypes.{result = None ; error=Some 33} in
let%lwt _ = Logs_lwt.err (fun m -> m "[FOS-AGENT] - EV-ASSOC-FLOATING-IP - EVAL RETURNED NONE") in
Lwt.return @@ FAgentTypes.string_of_eval_result eval_res
with
| _ -> let eval_res = FAgentTypes.{result = None ; error=Some 11} in
| exn -> let eval_res = FAgentTypes.{result = None ; error=Some 22} in
let%lwt _ = Logs_lwt.err (fun m -> m "[FOS-AGENT] - EV-ASSOC-FLOATING-IP - EXCEPTION: %s" (Printexc.to_string exn)) in
Lwt.return @@ FAgentTypes.string_of_eval_result eval_res
in
let eval_remove_floating_ip self (props:Apero.properties) =
Expand All @@ -430,10 +432,12 @@ let agent verbose_flag debug_flag configuration custom_uuid =
>>= fun _ ->
let eval_res = FAgentTypes.{result = Some (JSON.of_string (FTypes.string_of_floating_ip floating)) ; error=None} in
Lwt.return @@ FAgentTypes.string_of_eval_result eval_res
| None -> let eval_res = FAgentTypes.{result = None ; error=Some 11} in
| None -> let eval_res = FAgentTypes.{result = None ; error=Some 33} in
let%lwt _ = Logs_lwt.err (fun m -> m "[FOS-AGENT] - EV-REMOVE-FLOATING-IP - EVAL RETURNED NONE") in
Lwt.return @@ FAgentTypes.string_of_eval_result eval_res
with
| _ -> let eval_res = FAgentTypes.{result = None ; error=Some 11} in
| exn -> let eval_res = FAgentTypes.{result = None ; error=Some 22} in
let%lwt _ = Logs_lwt.err (fun m -> m "[FOS-AGENT] - EV-REMOVE-FLOATING-IP - EXCEPTION: %s" (Printexc.to_string exn)) in
Lwt.return @@ FAgentTypes.string_of_eval_result eval_res
in
(* Listeners *)
Expand Down
7 changes: 7 additions & 0 deletions src/api/python/api/fog05/fimapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ def create_floating_ip(self, nodeid):
def delete_floating_ip(self, nodeid, ip_id):
return self.connector.glob.actual.remove_node_floatingip(self.sysid, self.tenantid, nodeid, ip_id)


def assign_floating_ip(self, nodeid, ip_id, cp_id):
return self.connector.glob.actual.assign_node_floating_ip(self.sysid, self.tenantid, nodeid, ip_id, cp_id)

def retain_floating_ip(self, nodeid, ip_id, cp_id):
return self.connector.glob.actual.retain_node_floating_ip(self.sysid, self.tenantid, nodeid, ip_id, cp_id)

def list(self):
'''
Expand Down
50 changes: 35 additions & 15 deletions src/api/python/api/fog05/yaks_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ def dict2args(self, d):
return '('+b+')'

def get_agent_exec_path(self, sysid, tenantid, nodeid, func_name):
return Constants.create_path([self.prefix, sysid, "tenants",
tenantid, "nodes", nodeid, 'agent', 'exec', func_name])
return Constants.create_path([self.prefix, sysid, 'tenants',
tenantid, 'nodes', nodeid, 'agent', 'exec', func_name])

def get_agent_exec_path_with_params(self, sysid, tenantid, nodeid, func_name, params):
if len(params) > 0:
p = self.dict2args(params)
f = func_name + '?' + p
else:
f = func_name
return Constants.create_path([self.prefix, sysid, "tenants",
tenantid, "nodes", nodeid, 'agent', 'exec',f])
return Constants.create_path([self.prefix, sysid, 'tenants',
tenantid, 'nodes', nodeid, 'agent', 'exec',f])


def extract_userid_from_path(self, path):
Expand Down Expand Up @@ -744,41 +744,61 @@ def get_node_network_port(self, sysid, tenantid, nodeid, portid):
# Agent Evals

def add_node_port_to_network(self, sysid, tenantid, nodeid, portid, network_id):
fname = "add_port_to_network"
fname = 'add_port_to_network'
params = {'cp_uuid': portid, 'network_uuid':network_id}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
raise ValueError('Empty data on exec_os_eval')
raise ValueError('Empty data on exec_agent_eval')
else:
return json.loads(res[0][1].get_value())

def remove_node_port_from_network(self, sysid, tenantid, nodeid, portid):
fname = "remove_port_from_network"
fname = 'remove_port_from_network'
params = {'cp_uuid': portid}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
raise ValueError('Empty data on exec_os_eval')
raise ValueError('Empty data on exec_agent_eval')
else:
return json.loads(res[0][1].get_value())

def add_node_floatingip(self, sysid, tenantid, nodeid):
fname = "create_floating_ip"
fname = 'create_floating_ip'
s = self.get_agent_exec_path(sysid, tenantid, nodeid, fname)
res = self.ws.eval(s)
if len(res) == 0:
raise ValueError('Empty data on exec_os_eval')
raise ValueError('Empty data on exec_agent_eval')
else:
return json.loads(res[0][1].get_value())

def remove_node_floatingip(self, sysid, tenantid, nodeid, ipid):
fname = "delete_floating_ip"
fname = 'delete_floating_ip'
params = {'floating_uuid': ipid}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
raise ValueError('Empty data on exec_os_eval')
raise ValueError('Empty data on exec_agent_eval')
else:
return json.loads(res[0][1].get_value())

def assign_node_floating_ip(self, sysid, tenantid, nodeid, ipid, cpid):
fname = 'assign_floating_ip'
params = {'floating_uuid': ipid, 'cp_uuid': cpid}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
raise ValueError('Empty data on exec_agent_eval')
else:
return json.loads(res[0][1].get_value())

def retain_node_floating_ip(self, sysid, tenantid, nodeid, ipid, cpid):
fname = 'remove_floating_ip'
params = {'floating_uuid': ipid, 'cp_uuid': cpid}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
raise ValueError('Empty data on exec_agent_eval')
else:
return json.loads(res[0][1].get_value())

Expand Down Expand Up @@ -878,7 +898,7 @@ def get_node_fdu_instance_selector(self, nodeid, instanceid):

def get_node_all_fdus_instances_selector(self, nodeid):
return Constants.create_path(
[self.prefix, nodeid, 'runtimes', "*", 'fdu', '*',
[self.prefix, nodeid, 'runtimes', '*', 'fdu', '*',
'instances','*','info'])

def get_node_image_info_path(self, nodeid, pluginid, imgid):
Expand Down Expand Up @@ -1046,7 +1066,7 @@ def exec_nw_eval(self, nodeid, nm_uuid, func_name, parameters):
nodeid, nm_uuid, func_name, parameters)
res = self.ws.eval(s)
if len(res) == 0:
raise ValueError('Empty data on exec_os_eval')
raise ValueError('Empty data on exec_nw_eval')
else:
return json.loads(res[0][1].get_value())

Expand Down Expand Up @@ -1203,7 +1223,7 @@ def get_node_all_fdus_instances(self, nodeid):
res = self.ws.get(p)
if len(res) == 0:
return []
return list(map (lambda x: json.loads(x[1]), res))
return list(map (lambda x: json.loads(x[1].get_value()), res))

def add_node_image(self, nodeid, pluginid, imgid, imginfo):
p = self.get_node_image_info_path(nodeid, pluginid, imgid)
Expand Down

0 comments on commit 9951544

Please sign in to comment.