]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add EstimateTemplateCost API
authorAngus Salkeld <asalkeld@redhat.com>
Fri, 8 Jun 2012 02:06:50 +0000 (12:06 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Fri, 8 Jun 2012 02:06:50 +0000 (12:06 +1000)
see #1

Change-Id: Ib362b5320b5fa050dfb70202838042e222287534
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
bin/heat
heat/api/v1/__init__.py
heat/api/v1/stacks.py
heat/client.py

index bb0484098134f549ce661acb5afd37942e6b2df4..ffb2d92a06e6a4ea56be7974e79d22623e2cea23 100755 (executable)
--- a/bin/heat
+++ b/bin/heat
@@ -94,6 +94,37 @@ def template_validate(options, arguments):
     print json.dumps(result, indent=2)
 
 
+@utils.catch_error('estimatetemplatecost')
+def estimate_template_cost(options, arguments):
+    parameters = {}
+    try:
+        parameters['StackName'] = arguments.pop(0)
+    except IndexError:
+        logging.error("Please specify the stack name you wish to estimate")
+        logging.error("as the first argument")
+        return utils.FAILURE
+
+    if options.parameters:
+        count = 1
+        for p in options.parameters.split(';'):
+            (n, v) = p.split('=')
+            parameters['Parameters.member.%d.ParameterKey' % count] = n
+            parameters['Parameters.member.%d.ParameterValue' % count] = v
+            count = count + 1
+
+    if options.template_file:
+        parameters['TemplateBody'] = open(options.template_file).read()
+    elif options.template_url:
+        parameters['TemplateUrl'] = options.template_url
+    else:
+        logging.error('Please specify a template file or url')
+        return utils.FAILURE
+
+    c = get_client(options)
+    result = c.estimate_template_cost(**parameters)
+    print json.dumps(result, indent=2)
+
+
 @utils.catch_error('gettemplate')
 def get_template(options, arguments):
     '''
@@ -455,6 +486,7 @@ def lookup_command(parser, command_name):
                 'event-list': stack_events_list,
                 'validate': template_validate,
                 'gettemplate': get_template,
+                'estimate-template-cost': estimate_template_cost,
                 'describe': stack_describe}
 
     commands = {}
@@ -492,6 +524,8 @@ Commands:
 
     gettemplate     Get the template
 
+    estimate-template-cost     Returns the estimated monthly cost of a template
+
     validate        Validate a template
 
     event-list      List events for a stack
index a8c8727afd5c3b69edccdfc05a4f331b2db7fd0c..ceeec986eaaaa83276a4100c7ad6373dc981c823 100644 (file)
@@ -124,6 +124,7 @@ class API(wsgi.Router):
         'events_list': 'DescribeStackEvents',
         'validate_template': 'ValidateTemplate',
         'get_template': 'GetTemplate',
+        'estimate_template_cost': 'EstimateTemplateCost',
     }
 
     def __init__(self, conf, **local_conf):
index 15b39bb1ee2f6b0f88f274bc2722434b27a3ed13..172ac615300e936546834293ccb51cd4d5e5e003 100644 (file)
@@ -169,6 +169,10 @@ class StackController(object):
 
         return {'GetTemplateResult': {'TemplateBody': templ}}
 
+    def estimate_template_cost(self, req):
+        return {'EstimateTemplateCostResult': {
+                'Url': 'http://en.wikipedia.org/wiki/Gratis'}}
+
     def validate_template(self, req):
 
         con = req.context
index 9530f3d5f6f147fb2481d890dc8f804c516ea59f..52063356dd9373c4bcfc3c9a00b64668feacf367 100644 (file)
@@ -70,6 +70,9 @@ class V1Client(base_client.BaseClient):
     def get_template(self, **kwargs):
         return self.stack_request("GetTemplate", "GET", **kwargs)
 
+    def estimate_template_cost(self, **kwargs):
+        return self.stack_request("EstimateTemplateCost", "GET", **kwargs)
+
 HeatClient = V1Client