diff --git a/dbod/api/entity.py b/dbod/api/entity.py index 50a0da8..37f2cd9 100644 --- a/dbod/api/entity.py +++ b/dbod/api/entity.py @@ -24,7 +24,7 @@ class Entity(tornado.web.RequestHandler): def get(self, name): """Returns an instance by db_name""" - response = requests.get("http://localhost:3000/instance?db_name=eq." + name) + response = requests.get(config.get('postgrest', 'instance_url') + "?db_name=eq." + name) if response.ok: data = response.json() if data: @@ -51,7 +51,7 @@ def post(self, instance): del entity["volumes"] # Insert the entity in database using PostREST - response = requests.post("http://localhost:3000/instance", json=entity, headers={'Prefer': 'return=representation'}) + response = requests.post(config.get('postgrest', 'instance_url'), json=entity, headers={'Prefer': 'return=representation'}) if response.ok: entid = json.loads(response.text)["id"] logging.debug("Created entity with id: " + str(entid)) @@ -61,9 +61,9 @@ def post(self, instance): volume["instance_id"] = entid # Insert the volumes in database using PostREST - response = requests.post("http://localhost:3000/volume", json=volumes) + response = requests.post(config.get('postgrest', 'volume_url'), json=volumes) if response.ok: - response = requests.post("http://localhost:3000/attribute", json={'instance_id': entid, 'name': 'port', 'value': port}) + response = requests.post(config.get('postgrest', 'attribute_url'), json={'instance_id': entid, 'name': 'port', 'value': port}) if response.ok: self.set_status(CREATED) else: @@ -87,7 +87,7 @@ def put(self, instance): if "port" in entity: port = {"value":entity["port"]} del entity["port"] - response = requests.patch("http://localhost:3000/attribute?instance_id=eq." + str(entid) + "&name=eq.port", json=port) + response = requests.patch(config.get('postgrest', 'attribute_url') + "?instance_id=eq." + str(entid) + "&name=eq.port", json=port) if response.ok: self.set_status(response.status_code) else: @@ -102,9 +102,9 @@ def put(self, instance): del entity["volumes"] # Delete current volumes - response = requests.delete("http://localhost:3000/volume?instance_id=eq." + str(entid)) + response = requests.delete(config.get('postgrest', 'volume_url') + "?instance_id=eq." + str(entid)) if response.ok: - response = requests.post("http://localhost:3000/volume", json=volumes) + response = requests.post(config.get('postgrest', 'volume_url'), json=volumes) if response.ok: self.set_status(response.status_code) else: @@ -115,7 +115,7 @@ def put(self, instance): raise tornado.web.HTTPError(response.status_code) if entity: - response = requests.patch("http://localhost:3000/instance?db_name=eq." + instance, json=entity) + response = requests.patch(config.get('postgrest', 'instance_url') + "?db_name=eq." + instance, json=entity) if response.ok: self.set_status(response.status_code) else: @@ -136,7 +136,7 @@ def delete(self, instance): raise tornado.web.HTTPError(response.status_code) def __get_instance_id__(self, instance): - response = requests.get("http://localhost:3000/instance?db_name=eq." + instance) + response = requests.get(config.get('postgrest', 'instance_url') + "?db_name=eq." + instance) if response.ok: data = response.json() if data: @@ -147,8 +147,8 @@ def __get_instance_id__(self, instance): return None def __delete_instance__(self, inst_id): - requests.delete("http://localhost:3000/attribute?instance_id=eq." + str(inst_id)) - requests.delete("http://localhost:3000/volume?instance_id=eq." + str(inst_id)) - requests.delete("http://localhost:3000/instance?id=eq." + str(inst_id)) + requests.delete(config.get('postgrest', 'attribute_url') + "?instance_id=eq." + str(inst_id)) + requests.delete(config.get('postgrest', 'volume_url') + "?instance_id=eq." + str(inst_id)) + requests.delete(config.get('postgrest', 'instance_url') + "?id=eq." + str(inst_id)) diff --git a/static/api.cfg b/static/api.cfg index 2c6b0d1..785d0e3 100644 --- a/static/api.cfg +++ b/static/api.cfg @@ -21,6 +21,8 @@ rundeck_resources_url=http://localhost:3000/rundeck_instances host_aliases_url=http://localhost:3000/host_aliases entity_metadata_url=http://localhost:3000/metadata instance_url=http://localhost:3000/instance +volume_url=http://localhost:3000/volume +attribute_url=http://localhost:3000/attribute functional_alias_url=http://localhost:3000/functional_aliases [rundeck]