From ac1ab674c8ee2481fea447cbfbc02d4e1d2d7967 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Fri, 30 Mar 2012 13:02:28 +1100 Subject: [PATCH] Get simple rpc.call working Signed-off-by: Angus Salkeld --- heat/api/v1/stacks.py | 6 +++++- heat/common/utils.py | 28 ++++++++++++++++++++++++++++ heat/engine/manager.py | 4 ++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index 1b1a3b4a45..bfff3a78c0 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -31,6 +31,8 @@ from webob.exc import (HTTPNotFound, from heat.common import wsgi from heat.engine import client as engine +from heat import rpc +from heat import context logger = logging.getLogger('heat.api.v1.stacks') @@ -103,8 +105,10 @@ class StackController(object): """ Returns the following information for all stacks: """ - c = engine.get_engine_client(req.context) + con = context.get_admin_context() + return rpc.call(con, 'engine', {'method': 'create_stack', + 'args': {'stack_name': req.params['StackName']}}) try: templ = self._get_template(req) except socket.gaierror: diff --git a/heat/common/utils.py b/heat/common/utils.py index 998a90f1cf..901ad703b8 100644 --- a/heat/common/utils.py +++ b/heat/common/utils.py @@ -93,6 +93,34 @@ def strtime(at=None, fmt=PERFECT_TIME_FORMAT): at = utcnow() return at.strftime(fmt) +def parse_strtime(timestr, fmt=PERFECT_TIME_FORMAT): + """Turn a formatted time back into a datetime.""" + return datetime.datetime.strptime(timestr, fmt) + + +def isotime(at=None): + """Stringify time in ISO 8601 format""" + if not at: + at = datetime.datetime.utcnow() + str = at.strftime(ISO_TIME_FORMAT) + tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC' + str += ('Z' if tz == 'UTC' else tz) + return str + + +def parse_isotime(timestr): + """Turn an iso formatted time back into a datetime.""" + try: + return iso8601.parse_date(timestr) + except (iso8601.ParseError, TypeError) as e: + raise ValueError(e.message) + + +def normalize_time(timestamp): + """Normalize time in arbitrary timezone to UTC""" + offset = timestamp.utcoffset() + return timestamp.replace(tzinfo=None) - offset if offset else timestamp + def utcnow(): """Overridable version of utils.utcnow.""" if utcnow.override_time: diff --git a/heat/engine/manager.py b/heat/engine/manager.py index a45453459d..92fd3224e0 100644 --- a/heat/engine/manager.py +++ b/heat/engine/manager.py @@ -60,6 +60,6 @@ class EngineManager(manager.Manager): def __init__(self, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" - def create(self, template, stack_id): - pass + def create_stack(self, context, stack_name): + return {'state': 'woot -> %s' % stack_name}