Add EstimateTemplateCost API

see #1

Change-Id: Ib362b5320b5fa050dfb70202838042e222287534
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2012-06-08 12:06:50 +10:00
parent 3601fb263c
commit 0b7feab00b
4 changed files with 42 additions and 0 deletions

View File

@ -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

View 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):

View 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

View 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