Adding gets for individual dbapi resources
This commit is contained in:
parent
2cf52e25b5
commit
e8131625d0
@ -3,8 +3,9 @@ import json
|
||||
|
||||
from django.forms.models import model_to_dict
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
import datetime_to_decimal
|
||||
import datetime_to_decimal as dt
|
||||
import models
|
||||
|
||||
|
||||
@ -12,6 +13,12 @@ def rsp(data):
|
||||
return HttpResponse(json.dumps(data), content_type="application/json")
|
||||
|
||||
|
||||
def _get_model_by_id(klass, model_id):
|
||||
model = get_object_or_404(klass, id=model_id)
|
||||
model_dict = _convert_model(model)
|
||||
return model_dict
|
||||
|
||||
|
||||
def list_usage_launches(request):
|
||||
filter_args = {}
|
||||
if 'instance' in request.GET:
|
||||
@ -26,6 +33,10 @@ def list_usage_launches(request):
|
||||
return rsp({'launches': dicts})
|
||||
|
||||
|
||||
def get_usage_launch(request, launch_id):
|
||||
return rsp({'launch': _get_model_by_id(models.InstanceUsage, launch_id)})
|
||||
|
||||
|
||||
def list_usage_deletes(request):
|
||||
filter_args = {}
|
||||
if 'instance' in request.GET:
|
||||
@ -40,6 +51,10 @@ def list_usage_deletes(request):
|
||||
return rsp({'deletes': dicts})
|
||||
|
||||
|
||||
def get_usage_delete(request, delete_id):
|
||||
return rsp({'delete': _get_model_by_id(models.InstanceDeletes, delete_id)})
|
||||
|
||||
|
||||
def list_usage_exists(request):
|
||||
filter_args = {}
|
||||
if 'instance' in request.GET:
|
||||
@ -54,12 +69,21 @@ def list_usage_exists(request):
|
||||
return rsp({'exists': dicts})
|
||||
|
||||
|
||||
def _convert_model_list(list):
|
||||
def get_usage_exist(request, exist_id):
|
||||
return rsp({'exist': _get_model_by_id(models.InstanceExists, exist_id)})
|
||||
|
||||
|
||||
def _convert_model(model):
|
||||
model_dict = model_to_dict(model)
|
||||
for key in model_dict:
|
||||
if isinstance(model_dict[key], decimal.Decimal):
|
||||
model_dict[key] = str(dt.dt_from_decimal(model_dict[key]))
|
||||
return model_dict
|
||||
|
||||
|
||||
def _convert_model_list(model_list):
|
||||
converted = []
|
||||
for item in list:
|
||||
dict = model_to_dict(item)
|
||||
for key in dict:
|
||||
if isinstance(dict[key], decimal.Decimal):
|
||||
dict[key] = str(datetime_to_decimal.dt_from_decimal(dict[key]))
|
||||
converted.append(dict)
|
||||
for item in model_list:
|
||||
converted.append(_convert_model(item))
|
||||
|
||||
return converted
|
||||
|
@ -27,9 +27,15 @@ urlpatterns = patterns('',
|
||||
|
||||
url(r'db/usage/launches/$',
|
||||
'stacktach.dbapi.list_usage_launches'),
|
||||
url(r'db/usage/launches/(?P<launch_id>\d+)/$',
|
||||
'stacktach.dbapi.get_usage_launch'),
|
||||
url(r'db/usage/deletes/$',
|
||||
'stacktach.dbapi.list_usage_deletes'),
|
||||
url(r'db/usage/deletes/(?P<delete_id>\d+)/$',
|
||||
'stacktach.dbapi.get_usage_delete'),
|
||||
url(r'db/usage/exists/$', 'stacktach.dbapi.list_usage_exists'),
|
||||
url(r'db/usage/exists/(?P<exist_id>\d+)/$',
|
||||
'stacktach.dbapi.get_usage_exist'),
|
||||
|
||||
url(r'^(?P<deployment_id>\d+)/$', 'stacktach.views.home', name='home'),
|
||||
url(r'^(?P<deployment_id>\d+)/details/(?P<column>\w+)/(?P<row_id>\d+)/$',
|
||||
|
@ -147,7 +147,8 @@ def run(deployment_config):
|
||||
transport="librabbitmq",
|
||||
virtual_host=virtual_host)
|
||||
|
||||
while True:
|
||||
# continue_running() is used for testing
|
||||
while continue_running():
|
||||
try:
|
||||
LOG.debug("Processing on '%s'" % name)
|
||||
with kombu.connection.BrokerConnection(**params) as conn:
|
||||
|
Loading…
x
Reference in New Issue
Block a user