Skip to content

Commit

Permalink
Adding two new FDU APIs (#63)
Browse files Browse the repository at this point in the history
Solves #62
  • Loading branch information
gabrik authored Apr 10, 2019
1 parent a316284 commit 04396b1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/ocaml/api/fos-fim-api/fos_fim_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ module FDU = struct
Yaks_connector.Global.Actual.get_node_fdus api.sysid api.tenantid nodeid api.yconnector >>=
Lwt_list.map_p (fun (_,_,f) -> Lwt.return f)

let get_nodes fduid api =
Yaks_connector.Global.Actual.get_fdu_nodes api.sysid api.tenantid fduid api.yconnector

let info fduid api =
Yaks_connector.Global.Actual.get_fdu_info api.sysid api.tenantid fduid api.yconnector

Expand Down
1 change: 1 addition & 0 deletions src/api/ocaml/api/fos-fim-api/fos_fim_api.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module FDU : sig
val migrate : string -> string -> string -> ?wait:bool -> api -> bool Lwt.t
val info_node : string -> string -> api -> FTypesRecord.fdu Lwt.t
val list_node : string -> api -> (FTypesRecord.fdu list) Lwt.t
val get_nodes : string -> api -> (string list) Lwt.t
val info : string -> api -> FTypes.fdu Lwt.t
val instance_info : string -> string -> api -> FTypesRecord.fdu Lwt.t
val list : api -> (FTypes.fdu list) Lwt.t
Expand Down
20 changes: 20 additions & 0 deletions src/api/python/api/fog05/fimapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,26 @@ def info(self, fdu_uuid):
def instance_info(self, fdu_uuid, node_uuid):
return self.connector.glob.actual.get_node_fdu(self.sysid, self.tenantid, node_uuid, fdu_uuid)

def get_nodes(self, fdu_uuid):
'''
List of nodes where the fdu is running
:param fdu_uuid fdu you want to find the nodes
:return: node_uuid list
'''
return self.connector.glob.actual.get_fdu_nodes(self.sysid, self.tenantid, fdu_uuid)

def list_node(self, node_uuid):
'''
List of fdu in the node
:param node_uuid node you want to list the fdus
:return: fdu_uuid list
'''
return self.connector.glob.actual.get_node_fdus(self.sysid, self.tenantid, node_uuid)

def list(self, node_uuid='*'):
'''
Expand Down
9 changes: 9 additions & 0 deletions src/api/python/api/fog05/yaks_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ def remove_node_fdu(self, sysid, tenantid, nodeid, fduid):
p = self.get_node_fdu_info_path(sysid, tenantid, nodeid, fduid)
return self.ws.remove(p)

def get_fdu_nodes(self, sysid, tenantid, fduid):
s = self.get_node_fdu_info_path(sysid, tenantid, "*", fduid)
res = self.ws.get(s)
if len(res) == 0:
return []
else:
xs = map(lambda x: self.extract_nodeid_from_path(x[0]), res)
return list(xs)

def get_network_port(self, sysid, tenantid, portid):
s = self.get_network_port_info_path(sysid, tenantid, portid)
kvs = self.ws.get(s)
Expand Down
9 changes: 9 additions & 0 deletions src/api/python/rest_api/fog05rest/fimapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ def resume(self, fduid, node_uuid):
def migrate(self, fduid, node_uuid, destination_node_uuid):
pass

def get_nodes(self, fdu_uuid, node_uuid):
url = '{}/fdu/get_nodes/{}'.format(self.base_url, fdu_uuid)
return json.loads(str(requests.get(url).content))

def list_node(self, node_uuid):
url = '{}/fdu/list_node/{}'.format(self.base_url, node_uuid)
return json.loads(str(requests.get(url).content))


def info(self, fdu_uuid):
url = '{}/fdu/info/{}'.format(self.base_url, fdu_uuid)
return json.loads(str(requests.get(url).content))
Expand Down
10 changes: 10 additions & 0 deletions src/core/ocaml/fos-core/yaks_connector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,16 @@ module MakeGAD(P: sig val prefix: string end) = struct
let _,v = List.hd kvs in
Lwt.return @@ Fos_im.FTypesRecord.fdu_of_string (Yaks.Value.to_string v)

let get_fdu_nodes sysid tenantid fduid connector =
MVar.read connector >>= fun connector ->
let s = Yaks.Selector.of_path @@ get_node_fdu_info_path sysid tenantid "*" fduid in
Yaks.Workspace.get s connector.ws
>>= fun kvs ->
match kvs with
| [] -> Lwt.fail @@ FException (`InternalError (`Msg ("get_node_fdu_info received empty data!!") ))
| _ ->
Lwt_list.map_p (fun (k,_) -> Lwt.return (extract_nodeid_from_path k)) kvs

(* Global Network descriptors *)
let add_network sysid tenantid netid net_info connector =
let p = get_network_info_path sysid tenantid netid in
Expand Down
11 changes: 11 additions & 0 deletions src/utils/python/rest_proxy/src/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def fdu_pause(fdu_id, node_id):
def fdu_resume(fdu_id, node_id):
return json.dumps({'result':fos_api.fdu.resume(fdu_id, node_id, wait=True)})


@app.route('/fdu/get_nodes/<fdu_id>', methods=['GET'])
def fdu_get_nodes(fdu_id):
return json.dumps(fos_api.fdu.get_nodes(fdu_id))


@app.route('/fdu/list_node/<node_id>', methods=['GET'])
def fdu_node_list(node_id):
return json.dumps(fos_api.fdu.node_id(node_id))


@app.route('/fdu/info/<fdu_id>', methods=['GET'])
def fdu_info(fdu_id):
return json.dumps(fos_api.fdu.info(fdu_id))
Expand Down

0 comments on commit 04396b1

Please sign in to comment.