OpenStack Orchestration (Heat)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.0 KiB

# vim: tabstop=4 shiftwidth=4 softtabstop=4
# 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
# 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 urllib2
import json
import logging
from heat.common import exception
from heat.engine.resources import Resource
from heat.db import api as db_api
from heat.engine import parser
logger = logging.getLogger(__file__)
PROP_PARAMETERS) = ('TemplateURL', 'TimeoutInMinutes', 'Parameters')
class Stack(Resource):
properties_schema = {PROP_TEMPLATE_URL: {'Type': 'String',
'Required': True},
PROP_TIMEOUT_MINS: {'Type': 'Number'},
PROP_PARAMETERS: {'Type': 'Map'}}
def __init__(self, name, json_snippet, stack):
Resource.__init__(self, name, json_snippet, stack)
self._nested = None
def _params(self):
p = self.stack.resolve_runtime_data([PROP_PARAMETERS])
return p
def nested(self):
if self._nested is None:
if self.instance_id is None:
return None
st = db_api.stack_get(self.stack.context, self.instance_id)
if not st:
raise exception.NotFound('Nested stack not found in DB')
n = parser.Stack(self.stack.context,,
self.instance_id, self._params())
self._nested = n
return self._nested
def handle_create(self):
response = urllib2.urlopen([PROP_TEMPLATE_URL])
child_template = json.loads(
self._nested = parser.Stack(self.stack.context,,
rt = {'template': child_template, 'stack_name':}
new_rt = db_api.raw_template_create(None, rt)
parent_stack = db_api.stack_get(self.stack.context,
s = {'name':,
'user_creds_id': parent_stack.user_creds_id,
'username': self.stack.context.username}
new_s = db_api.stack_create(None, s) =
pt = {'template': self._nested.t, 'raw_template_id':}
new_pt = db_api.parsed_template_create(None, pt)
self._nested.parsed_template_id =
def handle_delete(self):
stack = self.nested()
except exception.NotFound:"Stack not found to delete")
if stack is not None:
def FnGetAtt(self, key):
if not key.startswith('Outputs.'):
raise exception.InvalidTemplateAttribute(,
prefix, dot, op = key.partition('.')
stack = self.nested()
if stack is None:
# This seems like a hack, to get past validation
return ''
if op not in self.nested().outputs:
raise exception.InvalidTemplateAttribute(,
return stack.output(op)