Skip to content

Commit

Permalink
CONFIG: Removed hardcoded urls and added to config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joscorbe committed Aug 3, 2016
1 parent 6bd4498 commit 2f70536
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 12 additions & 12 deletions dbod/api/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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))


2 changes: 2 additions & 0 deletions static/api.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 2f70536

Please sign in to comment.