Skip to content

Commit

Permalink
updates and fixes in pyhton api and agent (#147)
Browse files Browse the repository at this point in the history
Signed-off-by: gabrik <gabriele.baldoni@gmail.com>
  • Loading branch information
gabrik committed Sep 3, 2019
1 parent 220819e commit c30dc4c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 31 deletions.
9 changes: 7 additions & 2 deletions fos-plugins/LXD/LXD_plugin
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,14 @@ class LXD(RuntimePluginFDU):
lxd_img = self.conn.images.create_from_simplestreams(server=self.UBUNTU_IMAGE_SERVER, alias=img_alias)
lxd_img.add_alias(fdu_uuid, description='')
except LXDAPIException as e:
self.logger.info('define_fdu()', '[ ERRO ] LXD Plugin - LXDAPIException when fetching image: {}'.format(e))
if '{}'.format(e) == 'Image with same fingerprint already exists':
self.logger.info('define_fdu()', '[ INFO ] LXD Plugin - Image with same fingerprint already exists')
pass
self.logger.info('define_fdu()', '[ INFO ] LXD Plugin - Image with same fingerprint already exists')
if '{}'.format(e) == 'The requested image couldn\'t be found':
self.logger.info('define_fdu()', '[ ERRO ] LXD Plugin - Unable to find LXD image')
self.write_fdu_error(fdu_uuid, instance_id, 0, 'Cannot find image!')
return

image_name = ''
img_info.update({'uuid': fdu_uuid})
img_info.update({'name': '{}_img'.format(fdu.name)})
Expand Down
12 changes: 2 additions & 10 deletions src/agent/fos-agent/fos_agent.ml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ let agent verbose_flag debug_flag configuration custom_uuid =
let _ = Logs.debug (fun m -> m "[FOS-AGENT] - EV-REMOVE-NET - Properties: %s" (Apero.Properties.to_string props) ) in
let net_id =Apero.Option.get @@ Apero.Properties.get "net_id" props in
let%lwt record = Yaks_connector.Local.Actual.get_node_network (Apero.Option.get state.configuration.agent.uuid) net_p net_id state.yaks >>= fun x -> Lwt.return @@ Apero.Option.get x in
let record = {record with status = `DESTROY} in
let%lwt _ = Yaks_connector.Local.Desired.add_node_network (Apero.Option.get state.configuration.agent.uuid) net_p net_id record state.yaks in
Yaks_connector.Global.Actual.remove_network sys_id Yaks_connector.default_tenant_id record.uuid state.yaks >>= Lwt.return
>>= fun _ ->
let js = JSON.of_string @@ FTypesRecord.string_of_virtual_network record in
Expand Down Expand Up @@ -2114,14 +2116,4 @@ let info =
Cmdliner.Term.info "agent" ~version:"%%VERSION%%" ~doc ~exits:Cmdliner.Term.default_exits ~man


let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)

let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
let () = Cmdliner.Term.exit @@ Cmdliner.Term.eval (agent_t, info)
28 changes: 19 additions & 9 deletions src/api/python/api/fog05/fimapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@
#
# Contributors: Gabriele Baldoni, ADLINK Technology Inc. - API v2


# import re
# import uuid
# import json
# import fnmatch
# import time
import uuid
import random
from fog05.yaks_connector import Yaks_Connector
from fog05.interfaces import Constants
# from jsonschema import validate, ValidationError
# from enum import Enum
# from fog05 import Schemas

from fog05.interfaces.FDU import FDU
from fog05.interfaces.InfraFDU import InfraFDU
from mvar import MVar
Expand Down Expand Up @@ -327,10 +319,28 @@ def remove_network(self, net_uuid):
'''
manifest = self.connector.glob.actual.get_network(
self.sysid, self.tenantid, net_uuid)
if manifest is None:
return
manifest.update({'status': 'remove'})
self.connector.glob.desired.remove_network(
self.sysid, self.tenantid, net_uuid)

def add_network_to_node(self, manifest, nodeid):
net_id = manifest.get('uuid')
net = self.connector.glob.actual.get_node_network(self.sysid, self.tenantid, nodeid, net_id)
if net is not None:
return net
res = self.connector.glob.actual.create_network_in_node(self.sysid, self.tenantid, nodeid, manifest)
if res.get('error') is not None:
raise ValueError('Got Error {}'.format(res['error']))
return res['result']

def remove_network_from_node(self, netid, nodeid):
res = self.connector.glob.actual.remove_network_from_node(self.sysid, self.tenantid, nodeid, netid)
if res.get('error') is not None:
raise ValueError('Got Error {}'.format(res['error']))
return res['result']


def add_connection_point(self, cp_descriptor):
cp_descriptor.update({'status': 'add'})
Expand Down
65 changes: 55 additions & 10 deletions src/api/python/api/fog05/yaks_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from yaks import Yaks, Value, Encoding, Change




class GAD(object):
def __init__(self, workspace, prefix):
self.ws = workspace
Expand Down Expand Up @@ -311,6 +313,11 @@ def get_node_network_router_info_path(self, sysid, tenantid, nodeid, routerid):
[self.prefix, sysid, 'tenants', tenantid,
'nodes', nodeid, 'networks', 'routers', routerid, 'info'])

def get_node_network_info_path(self, sysid, tenantid, nodeid, networkid):
return Constants.create_path([
self.prefix,sysid ,'tenants', tenantid,
'nodes', nodeid, 'networks', networkid, 'info'])


# Evals

Expand Down Expand Up @@ -1031,6 +1038,24 @@ def get_all_node_flavors(self, sysid, tenantid, nodeid):
return d

# Node Network

def add_node_network(self, sysid, tenantid, nodeid, netid, netinfo):
p = self.get_node_network_info_path(sysid, tenantid, nodeid, netid)
v = Value(json.dumps(netinfo), encoding=Encoding.STRING)
return self.ws.put(p, v)

def get_node_network(self, sysid, tenantid, nodeid, netid):
s = self.get_node_network_info_path(sysid, tenantid, nodeid, netid)
kvs = self.ws.get(s)
if len(kvs) == 0:
return None
return json.loads(kvs[0][1].get_value())

def remove_node_network(self, sysid, tenantid, nodeid, netid):
s = self.get_node_network_info_path(sysid, tenantid, nodeid, netid)
return self.ws.remove(s)


def add_node_floating_ip(self, sysid, tenantid, nodeid,floatingid, ip_info):

p = self.get_node_network_floating_ip_info_path(sysid, tenantid, nodeid, floatingid)
Expand Down Expand Up @@ -1203,7 +1228,7 @@ def remove_port_from_router(self, sysid, tenantid, nodeid, router_id, vnet_id):

def onboard_fdu_from_node(self, sysid, tenantid, nodeid, fdu_id, fdu_info):
fname = 'onboard_fdu'
params = {'descriptor':fdu_info}
params = {'descriptor': fdu_info}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1213,7 +1238,7 @@ def onboard_fdu_from_node(self, sysid, tenantid, nodeid, fdu_id, fdu_info):

def define_fdu_in_node(self, sysid, tenantid, nodeid, fdu_id):
fname = 'define_fdu'
params = {'fdu_id':fdu_id}
params = {'fdu_id': fdu_id}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1223,7 +1248,7 @@ def define_fdu_in_node(self, sysid, tenantid, nodeid, fdu_id):

def onboard_ae_from_node(self, sysid, tenantid, nodeid, ae_info):
fname = 'onboard_ae'
params = {'descriptor':ae_info}
params = {'descriptor': ae_info}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1233,7 +1258,7 @@ def onboard_ae_from_node(self, sysid, tenantid, nodeid, ae_info):

def instantiate_ae_from_node(self, sysid, tenantid, nodeid, ae_id):
fname = 'instantiate_ae'
params = {'ae_id':ae_id}
params = {'ae_id': ae_id}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1243,7 +1268,7 @@ def instantiate_ae_from_node(self, sysid, tenantid, nodeid, ae_id):

def offload_ae_from_node(self, sysid, tenantid, nodeid, ae_id):
fname = 'offload_ae'
params = {'ae_id':ae_id}
params = {'ae_id': ae_id}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1253,7 +1278,7 @@ def offload_ae_from_node(self, sysid, tenantid, nodeid, ae_id):

def terminate_ae_from_node(self, sysid, tenantid, nodeid, ae_inst_id):
fname = 'terminate_ae'
params = {'instance_id':ae_inst_id}
params = {'instance_id': ae_inst_id}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1263,7 +1288,7 @@ def terminate_ae_from_node(self, sysid, tenantid, nodeid, ae_inst_id):

def onboard_entity_from_node(self, sysid, tenantid, nodeid, e_info):
fname = 'onboard_entity'
params = {'descriptor':e_info}
params = {'descriptor': e_info}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1273,7 +1298,7 @@ def onboard_entity_from_node(self, sysid, tenantid, nodeid, e_info):

def instantiate_entity_from_node(self, sysid, tenantid, nodeid, e_id):
fname = 'instantiate_entity'
params = {'entity_id':e_id}
params = {'entity_id': e_id}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1283,7 +1308,7 @@ def instantiate_entity_from_node(self, sysid, tenantid, nodeid, e_id):

def offload_entity_from_node(self, sysid, tenantid, nodeid, e_id):
fname = 'offload_entity'
params = {'entity_id':e_id}
params = {'entity_id': e_id}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1293,7 +1318,7 @@ def offload_entity_from_node(self, sysid, tenantid, nodeid, e_id):

def terminate_entity_from_node(self, sysid, tenantid, nodeid, e_inst_id):
fname = 'terminate_entity'
params = {'instance_id':e_inst_id}
params = {'instance_id': e_inst_id}
s = self.get_agent_exec_path_with_params(sysid, tenantid, nodeid, fname, params)
res = self.ws.eval(s)
if len(res) == 0:
Expand All @@ -1302,6 +1327,25 @@ def terminate_entity_from_node(self, sysid, tenantid, nodeid, e_inst_id):
return json.loads(res[0][1].get_value())


def create_network_in_node(self, sysid, tenantid, nodeid, net_info):
fname = 'create_node_network'
params = {'descriptor': json.dumps(net_info)}
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 remove_network_from_node(self, sysid, tenantid, nodeid, net_id):
fname = 'remove_node_netwotk'
params = {'net_id': net_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_agent_eval')
else:
return json.loads(res[0][1].get_value())


class LAD(object):
Expand Down Expand Up @@ -2259,6 +2303,7 @@ def close(self):
self.desired.close()



class Yaks_Connector(object):
def __init__(self, locator):
self.yaks_client = Yaks.login(locator)
Expand Down

0 comments on commit c30dc4c

Please sign in to comment.