def scale_ns(nsId, body): """ Starts a process to scale the Network Service associated with the instance identified by "nsId". Parameters ---------- nsId: string Identifier of the Network Service Instance. body: request body Returns ------- string Id of the operation associated to the Network Service instantiation. """ log_queue.put( ["INFO", "scale_ns for nsId %s with body: %s" % (nsId, body)]) # client = MongoClient() # fgtso_db = client.fgtso # ns_coll = fgtso_db.ns if not ns_db.exists_nsId(nsId): return 404 status = ns_db.get_ns_status(nsId) if status != "INSTANTIATED": return 400 ns_db.set_ns_status(nsId, "INSTANTIATING") operationId = create_operation_identifier(nsId, "INSTANTIATION") ps = Process(target=scale_ns_process, args=(nsId, body)) ps.start() # save process processes[operationId] = ps return operationId
def instantiate_ns(nsId, body, requester): """ Starts a process to instantiate the Network Service associated to the instance identified by "nsId". Parameters ---------- nsId: string Identifier of the Network Service Instance. body: request body Returns ------- string Id of the operation associated to the Network Service instantiation. """ log_queue.put(["INFO", "*****Time measure: SOEc SOEc instantiating a nested"]) log_queue.put(["INFO", "instantiate_ns for nsId %s with body: %s" % (nsId, body)]) #client = MongoClient() #fgtso_db = client.fgtso #ns_coll = fgtso_db.ns if not ns_db.exists_nsId(nsId): return 404 status = ns_db.get_ns_status(nsId) if status != "NOT_INSTANTIATED": return 400 ns_db.save_instantiation_info(nsId, body, requester) operationId = create_operation_identifier(nsId, "INSTANTIATION") ps = Process(target=instantiate_ns_process, args=(nsId, body)) ps.start() # save process processes[operationId] = ps # log_queue.put(["INFO", "*****Time measure: SOEc finished instantiation at SOEc"]) return operationId
def query_ns(nsId): """ Returns the information of the Network Service Instance identified by nsId. Parameters ---------- nsId: string Identifier of the NS instance to terminate. Returns ------- dict Information of the Network Service Instance. """ if not ns_db.exists_nsId(nsId): # TODO create errors return 404 # TODO: lines below are a stub status = ns_db.get_ns_status(nsId) vs_status = "FAILED" if status in ["TERMINATED", "INSTANTIATING", "TERMINATING"]: vs_status = "NOT_INSTANTIATED" elif status == "INSTANTIATED": vs_status = "INSTANTIATED" nsd_id = ns_db.get_nsdId(nsId) nsd_json = nsd_db.get_nsd_json(nsd_id) ns_name = ns_db.get_ns_name(nsId) ns_description = ns_db.get_ns_description(nsId) flavour_id = ns_db.get_ns_flavour_id(nsId) info = { "nsInstanceId": nsId, "nsName": ns_name, "description": ns_description, "nsdId": nsd_id, "flavourId": flavour_id, "nsState": vs_status, } #turn void the sap_info and the monitoring if the service is terminated if vs_status == "NOT_INSTANTIATED": info["sapInfo"] = [] log_queue.put(["INFO", "hola"]) return info if "sapd" in nsd_json["nsd"]: total_sap_info = get_ns_sap_info(nsId, nsd_json["nsd"]["sapd"]) if total_sap_info is not None: info["sapInfo"] = total_sap_info dashboard_info = ns_db.get_dashboard_info(nsId) if "dashboardUrl" in dashboard_info.keys(): info["monitoringDashboardUrl"] = dashboard_info["dashboardUrl"] log_queue.put( ["INFO", "query_result: %s" % dumps(info, indent=4, sort_keys=True)]) return info
def terminate_ns(nsId, requester): """ Starts a process to terminate the NS instance identified by "nsId". Parameters ---------- nsId: string Identifier of the NS instance to terminate. requester: string IP address of the entity making the request Returns ------- operationId: string Identifier of the operation in charge of terminating the service. """ log_queue.put( ["INFO", "*****Time measure: SOEc SOEc terminating a nested"]) if not ns_db.exists_nsId(nsId): return 404 registered_requester = ns_db.get_ns_requester(nsId) if (registered_requester != requester): return 404 # check the ns status status = ns_db.get_ns_status(nsId) log_queue.put( ["INFO", "Network service %s is in %s state." % (nsId, status)]) if status in ["TERMINATING", "TERMINATED", "NOT_INSTANTIATED"]: return 400 # if status is INSTANTIATING, kill the instantiation process if status == "INSTANTIATING": # set related operation as CANCELLED operationId = operation_db.get_operationId(nsId, "INSTANTIATION") operation_db.set_operation_status(operationId, "CANCELLED") # cancel instantiation process process = processes[operationId] process.terminate() process.join() operationId = create_operation_identifier(nsId, "TERMINATION") ps = Process(target=terminate_ns_process, args=(nsId, None)) ps.start() # save process processes[operationId] = ps # log_queue.put(["INFO", "*****Time measure: finished termination at SOEc"]) return operationId
def query_ns(nsId): """ Returns the information of the Network Service Instance identified by nsId. Parameters ---------- nsId: string Identifier of the NS instance to terminate. Returns ------- dict Information of the Network Service Instance. """ if not ns_db.exists_nsId(nsId): return 404 status = ns_db.get_ns_status(nsId) nsd_id = ns_db.get_nsdId(nsId) nsd_json = nsd_db.get_nsd_json(nsd_id) ns_name = ns_db.get_ns_name(nsId) ns_description = ns_db.get_ns_description(nsId) flavour_id = ns_db.get_ns_flavour_id(nsId) info = { "nsInstanceId": nsId, "nsName": ns_name, "description": ns_description, "nsdId": nsd_id, "flavourId": flavour_id, "nsState": status, } if "sapd" in nsd_json["nsd"]: info["sapInfo"] = get_ns_sap_info(nsId, nsd_json["nsd"]["sapd"]) query_result = {"queryNsResult": [info]} log_queue.put([ "DEBUG", "query_result: %s" % dumps(query_result, indent=4, sort_keys=True) ]) return query_result