Format parameters for create call

This commit is contained in:
Steve Baker 2012-10-11 13:09:56 +13:00
parent 622719c144
commit 4ba8e46631
6 changed files with 71 additions and 8 deletions

18
.gitignore vendored
View File

@ -1,4 +1,20 @@
.coverage
.venv
*,cover
cover
*.pyc
.idea
*.swp
*~
AUTHORS
build
dist
python_glanceclient.egg-info
ChangeLog
run_tests.err.log
.tox
doc/source/api
*.egg
glanceclient/versioninfo
python_heatclient.egg-info
*.log
*.log

View File

@ -21,6 +21,18 @@ import sys
from heatclient.common import utils
def format_parameters(params):
'''
Reformat parameters into dict of format expected by the API
'''
parameters = {}
if params:
for count, p in enumerate(params.split(';'), 1):
(n, v) = p.split('=')
parameters[n] = v
return parameters
@utils.arg('-u', '--template-url', metavar='<URL>',
help='URL of template.')
@utils.arg('-f', '--template-file', metavar='<FILE>',
@ -35,8 +47,15 @@ from heatclient.common import utils
def do_create(hc, args):
'''Create the stack'''
# Filter out None values
fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))
fields = {'stackname': args.name,
'timeoutmins': args.create_timeout,
'parameters': format_parameters(args.parameters)}
print fields
if args.template_file:
fields['template'] = open(args.template_file).read()
elif args.template_url:
fields['template_url'] = args.template_url
stack = hc.stacks.create(**fields)
utils.print_dict(stack)

View File

@ -88,11 +88,8 @@ class StackManager(base.Manager):
def create(self, **kwargs):
"""Create a stack"""
template_data = None
hdrs = {}
resp, body_iter = self.api.raw_request(
'POST', '/stacks', headers=hdrs, body=template_data)
resp, body_iter = self.api.json_request(
'POST', '/stacks', body=kwargs)
body = json.loads(''.join([c for c in body_iter]))
return Stack(self, body)

View File

@ -1 +1 @@
0.0.6.7cbfd72
0.0.8.622719c

0
tests/v1/__init__.py Normal file
View File

31
tests/v1/test_shell.py Normal file
View File

@ -0,0 +1,31 @@
# Copyright 2012 OpenStack LLC.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
import heatclient.v1.shell as shell
class shellTest(unittest.TestCase):
def test_format_parameters(self):
p = shell.format_parameters('InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
'LinuxDistribution=F17')
self.assertEqual({'InstanceType': 'm1.large',
'DBUsername': 'wp',
'DBPassword': 'verybadpassword',
'KeyName': 'heat_key',
'LinuxDistribution': 'F17'
}, p)
self.assertEqual({}, shell.format_parameters(None))