Skip to content

Commit f62a0cb

Browse files
author
Gabriel Monroy
committed
add apps:calculate functionality
1 parent 7f8debc commit f62a0cb

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

api/tests/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ def test_app_actions(self):
135135
response = self.client.post(url, json.dumps(body), content_type='application/json')
136136
self.assertEqual(response.status_code, 200)
137137
self.assertEqual(response.data[1], 0)
138+
# test calculate
139+
url = '/api/apps/{app_id}/calculate'.format(**locals())
140+
response = self.client.post(url)
141+
self.assertEqual(response.status_code, 200)
142+
databag = response.data
143+
self.assertIn('release', databag)
144+
self.assertIn('version', databag['release'])
145+
self.assertIn('containers', databag)
138146

139147
def test_app_errors(self):
140148
formation_id, app_id = 'autotest', 'autotest-errors'

api/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@
313313
views.AppViewSet.as_view({'post': 'logs'})),
314314
url(r'^apps/(?P<id>[a-z0-9-]+)/run/?',
315315
views.AppViewSet.as_view({'post': 'run'})),
316+
url(r'^apps/(?P<id>[a-z0-9-]+)/calculate/?',
317+
views.AppViewSet.as_view({'post': 'calculate'})),
316318
# apps base endpoint
317319
url(r'^apps/(?P<id>[a-z0-9-]+)/?',
318320
views.AppViewSet.as_view({'get': 'retrieve', 'delete': 'destroy'})),

api/views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ def scale(self, request, **kwargs):
280280
return Response(databag, status=status.HTTP_200_OK,
281281
content_type='application/json')
282282

283+
def calculate(self, request, **kwargs):
284+
app = self.get_object()
285+
databag = app.calculate()
286+
return Response(databag, status=status.HTTP_200_OK,
287+
content_type='application/json')
288+
283289
def logs(self, request, **kwargs):
284290
app = self.get_object()
285291
try:

client/deis.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,25 @@ def apps(self, args):
354354
"""
355355
return self.apps_list(args)
356356

357+
def apps_calculate(self, args, quiet=False):
358+
"""
359+
Calculate the application's JSON representation
360+
361+
Usage: deis apps:calculate [--app=<app>]
362+
"""
363+
app = args.get('--app')
364+
if not app:
365+
app = self._session.app
366+
response = self._dispatch('post',
367+
"/api/apps/{}/calculate".format(app))
368+
if response.status_code == requests.codes.ok: # @UndefinedVariable
369+
databag = json.loads(response.content)
370+
if quiet is False:
371+
print(json.dumps(databag, indent=2))
372+
return databag
373+
else:
374+
raise ResponseError(response)
375+
357376
def apps_create(self, args):
358377
"""
359378
Create a new application
@@ -1604,6 +1623,7 @@ def parse_args(cmd):
16041623
'ps': 'containers:list',
16051624
'scale': 'containers:scale',
16061625
'converge': 'formations:converge',
1626+
'calculate': 'apps:calculate',
16071627
}
16081628
if cmd == 'help':
16091629
cmd = sys.argv[-1]

0 commit comments

Comments
 (0)