From 0b7feab00b3f85cfa10a2cb78825ffdc65a73e46 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Fri, 8 Jun 2012 12:06:50 +1000 Subject: [PATCH] Add EstimateTemplateCost API see #1 Change-Id: Ib362b5320b5fa050dfb70202838042e222287534 Signed-off-by: Angus Salkeld --- bin/heat | 34 ++++++++++++++++++++++++++++++++++ heat/api/v1/__init__.py | 1 + heat/api/v1/stacks.py | 4 ++++ heat/client.py | 3 +++ 4 files changed, 42 insertions(+) diff --git a/bin/heat b/bin/heat index bb04840981..ffb2d92a06 100755 --- 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 diff --git a/heat/api/v1/__init__.py b/heat/api/v1/__init__.py index a8c8727afd..ceeec986ea 100644 --- a/heat/api/v1/__init__.py +++ b/heat/api/v1/__init__.py @@ -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): diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index 15b39bb1ee..172ac61530 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -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 diff --git a/heat/client.py b/heat/client.py index 9530f3d5f6..52063356dd 100644 --- a/heat/client.py +++ b/heat/client.py @@ -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