def sda_manager_app(): logging.info("[" + request.method + "] sda manager app - IN") if request.method == "POST": l = list() ret = dict() data = json.loads(request.data) SDAManager.set_app_id(data["id"]) response = requests.get( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/agents/" + SDAManager.get_device_id() + "/apps/" + SDAManager.get_app_id(), timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) for obj in response.json()["services"]: d = dict() d.update({"name": str(obj["name"])}) d.update({"state": str(obj["state"]["Status"])}) d.update({"exitcode": str(obj["state"]["ExitCode"])}) l.append(d) ret.update({"services": l}) return json.dumps(json.dumps(ret)), 200 elif request.method == "DELETE": response = requests.delete( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/agents/" + SDAManager.get_device_id() + "/apps/" + SDAManager.get_app_id(), timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) return "", 200 else: return abort(404)
def sda_manager_app_yaml(): logging.info("[" + request.method + "] sda manager app YAML - IN") if request.method == "GET": d = dict() response = requests.get( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/agents/" + SDAManager.get_device_id() + "/apps/" + SDAManager.get_app_id(), timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) if "description" in response.json(): d = response.json()["description"] return json.dumps(json.dumps(d)), 200 elif request.method == "POST": data = json.loads(request.data) response = requests.post( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/agents/" + SDAManager.get_device_id() + "/apps/" + SDAManager.get_app_id(), data=data["data"], timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) return "", 200
def sda_manager_group_app_update(): logging.info("[" + request.method + "] sda manager group app update - IN") response = requests.post( url="http://" + SDAManager().get_sda_manager_endpoint() + "/api/v1/management/groups/" + SDAManager.get_group_id() + "/apps/" + SDAManager.get_app_id() + "/update", timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) return "", 200
def sda_manager_app_update(): logging.info("[" + request.method + "] sda manager app update - IN") response = requests.post( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/agents/" + SDAManager.get_device_id() + "/apps/" + SDAManager.get_app_id() + "/update", timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) return "", 200
def sda_manager_group_app_yaml(): logging.info("[" + request.method + "] sda manager group app YAML - IN") data = json.loads(request.data) response = requests.post( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/groups/" + SDAManager.get_group_id() + "/apps/" + SDAManager.get_app_id(), data=data["data"], timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) return "", 200
def sda_manager_group_app(): if request.method == "POST": logging.info("[" + request.method + "] sda manager group app - IN") l = list() l2 = list() ret = dict() SDAManager.set_app_id(json.loads(request.data)["id"]) response = requests.get( url="http://" + SDAManager().get_sda_manager_endpoint() + "/api/v1/management/nodes", timeout=1500) response2 = requests.get( url="http://" + SDAManager().get_sda_manager_endpoint() + "/api/v1/management/groups/" + SDAManager.get_group_id() + "/apps", timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) for obj in response.json()["nodes"]: d = dict() if "id" in obj: d.update({"id": str(obj["id"])}) res = requests.get( url="http://" + SDAManager().get_sda_manager_endpoint() + "/api/v1/management/nodes/" + str(obj["id"]) + "/configuration", timeout=1500) if res.status_code is 200: for prop in res.json()["properties"]: if "devicename" in prop: d.update({"name": str(prop["devicename"])}) if "ip" in obj: d.update({"ip": str(obj["ip"])}) if "status" in obj: d.update({"status": str(obj["status"])}) l.append(d) for obj2 in response2.json()["apps"]: if obj2["id"] == SDAManager.get_app_id(): for device in l: for member in obj2["members"]: if device["id"] == member: l2.append(device) break ret.update({"devices": l2}) return json.dumps(json.dumps(ret)), 200 elif request.method == "DELETE": response = requests.delete( url="http://" + SDAManager().get_sda_manager_endpoint() + "/api/v1/management/groups/" + SDAManager.get_group_id() + "/apps/" + SDAManager.get_app_id(), timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) return "", 200
def sda_manager_group_app(): if request.method == "POST": logging.info("[" + request.method + "] sda manager group app - IN") l = list() l2 = list() ret = dict() SDAManager.set_app_id(json.loads(request.data)["id"]) response = requests.get( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/agents", timeout=1500) response2 = requests.get( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/groups/" + SDAManager.get_group_id() + "/apps", timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) for obj in response.json()["agents"]: d = dict() if "id" in obj: d.update({"id": str(obj["id"])}) if "host" in obj: d.update({"host": str(obj["host"])}) if "port" in obj: d.update({"port": str(obj["port"])}) l.append(d) for obj2 in response2.json()["apps"]: if obj2["id"] == SDAManager.get_app_id(): for device in l: for member in obj2["members"]: if device["id"] == member: l2.append(device) break ret.update({"devices": l2}) return json.dumps(json.dumps(ret)), 200 elif request.method == "DELETE": response = requests.delete( url="http://" + SDAManager().get_sda_manager_ip() + ":" + str(Port.sda_manager_port()) + "/api/v1/groups/" + SDAManager.get_group_id() + "/apps/" + SDAManager.get_app_id(), timeout=1500) if response.status_code is not 200: logging.error("SDAM Server Return Error, Error Code(" + str(response.status_code) + ") - OUT") abort(500) return "", 200