Example #1
0
        def sda_manager_group():
            logging.info("[" + request.method + "] sda manager group - IN")

            l = list()
            ret = dict()

            data = json.loads(request.data)
            SDAManager.set_group_id(data["id"])
            SDAManager.set_current_group_name(data["name"])

            response = requests.get(
                url="http://" + SDAManager().get_sda_manager_endpoint() +
                "/api/v1/management/groups/" + SDAManager.get_group_id(),
                timeout=1500)

            response2 = requests.get(url="http://" +
                                     SDAManager().get_sda_manager_endpoint() +
                                     "/api/v1/management/nodes",
                                     timeout=1500)

            if response.status_code is not 200 or response2.status_code is not 200:
                logging.error("SDAM Server Return Error, Error Code(" +
                              str(response.status_code) + ") - OUT")
                abort(500)

            for obj in response2.json()["nodes"]:
                for member in response.json()["members"]:
                    d = dict()
                    if obj["id"] == member:
                        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)

            ret.update({"devices": l})

            return json.dumps(json.dumps(ret)), 200
        def sda_manager_group():
            logging.info("[" + request.method + "] sda manager group - IN")

            l = list()
            ret = dict()

            data = json.loads(request.data)
            SDAManager.set_group_id(data["id"])
            SDAManager.set_current_group_name(data["groupname"])

            response = requests.get(
                url="http://" + SDAManager().get_sda_manager_ip() + ":" +
                str(Port.sda_manager_port()) + "/api/v1/groups/" +
                SDAManager.get_group_id(),
                timeout=1500)

            response2 = requests.get(
                url="http://" + SDAManager().get_sda_manager_ip() + ":" +
                str(Port.sda_manager_port()) + "/api/v1/agents",
                timeout=1500)

            if response.status_code is not 200 or response2.status_code is not 200:
                logging.error("SDAM Server Return Error, Error Code(" +
                              str(response.status_code) + ") - OUT")
                abort(500)

            for obj in response2.json()["agents"]:
                for member in response.json()["members"]:
                    d = dict()
                    if obj["id"] == member:
                        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)

            ret.update({"devices": l})

            return json.dumps(json.dumps(ret)), 200