Skip to content

Commit

Permalink
HANDLERS: Added get handler to entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joscorbe committed Aug 2, 2016
1 parent 1fd2ab7 commit 6bd4498
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions dbod/api/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
from dbod.config import config

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)
if response.ok:
data = response.json()
if data:
self.write({'response' : data})
self.set_status(OK)
else:
logging.error("Entity metadata not found: " + name)
raise tornado.web.HTTPError(NOT_FOUND)

def post(self, instance):
"""Inserts a new instance in the database"""
entity = json.loads(self.request.body)
Expand Down Expand Up @@ -91,9 +103,9 @@ def put(self, instance):

# Delete current volumes
response = requests.delete("http://localhost:3000/volume?instance_id=eq." + str(entid))
if response.status_code == 204:
if response.ok:
response = requests.post("http://localhost:3000/volume", json=volumes)
if response.status_code == 201:
if response.ok:
self.set_status(response.status_code)
else:
logging.error("Error adding volumes for instance: " + str(entid))
Expand Down Expand Up @@ -126,7 +138,11 @@ def delete(self, instance):
def __get_instance_id__(self, instance):
response = requests.get("http://localhost:3000/instance?db_name=eq." + instance)
if response.ok:
return json.loads(response.text)[0]["id"]
data = response.json()
if data:
return data[0]["id"]
else:
return None
else:
return None

Expand Down

0 comments on commit 6bd4498

Please sign in to comment.