diff options
author | Steve Baker <sbaker@redhat.com> | 2014-01-08 13:45:09 +1300 |
---|---|---|
committer | Steve Baker <sbaker@redhat.com> | 2014-01-13 10:28:37 +1300 |
commit | 43caa308d91080abcf3bdafe8836005e76863f44 (patch) | |
tree | 0a0a77d3e5ef904fe37e3e1437e20451ed6a4296 /heatclient | |
parent | 5c5112553928a3166479172e7a2f0f02730df1cb (diff) | |
download | python-heatclient-43caa308d91080abcf3bdafe8836005e76863f44.tar.gz |
Use template_format.parse for local stack parsing
Previously, API requests contained parsed templates for
json templates, but string content for YAML templates.
This change means that all requests will now contain parsed
templates. A parsed templates is required for get_file
client-side processing.
According to profiling that Clint performed, YAML parsing
could become a significant source of heat server load, so this
change will also mitigate this by pushing out YAML parsing
load to the clients.
This is part of a refactoring in preperation for
supporting the get_file intrinsic function.
Change-Id: Icca0f5e8ad197433872a995419648f841c9f82e0
Diffstat (limited to 'heatclient')
-rw-r--r-- | heatclient/v1/shell.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 1896141..8f4d364 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -17,6 +17,7 @@ import os import urllib import yaml +from heatclient.common import template_format from heatclient.common import utils from heatclient.openstack.common import jsonutils from heatclient.openstack.common.py3kcompat import urlutils @@ -27,31 +28,33 @@ import heatclient.exc as exc def _set_template_fields(hc, args, fields): if args.template_file: tpl = open(args.template_file).read() - if tpl.startswith('{'): - try: - fields['template'] = jsonutils.loads(tpl) - except ValueError as e: - raise exc.CommandError( - "Cannot parse template file: %s" % e) - else: - fields['template'] = tpl - elif args.template_url: + try: + fields['template'] = template_format.parse(tpl) + except ValueError as e: + raise exc.CommandError( + "Cannot parse template file: %s" % e) + return args.template_file + + if args.template_url: fields['template_url'] = args.template_url - elif args.template_object: + return args.template_url + + if args.template_object: template_body = hc.http_client.raw_request('GET', args.template_object) if template_body: try: - fields['template'] = jsonutils.loads(template_body) + fields['template'] = template_format.parse(template_body) except ValueError as e: raise exc.CommandError( "Cannot parse template file: %s" % e) else: raise exc.CommandError('Could not fetch template from %s' % args.template_object) - else: - raise exc.CommandError('Need to specify exactly one of ' - '--template-file, --template-url ' - 'or --template-object') + return args.template_object + + raise exc.CommandError('Need to specify exactly one of ' + '--template-file, --template-url ' + 'or --template-object') def _get_file_contents(resource_registry, fields, base_url='', |