def create_stack(self, cnxt, stack_name, template, params, files, args): """ The create_stack method creates a new stack using the template provided. Note that at this stage the template has already been fetched from the heat-api process if using a template-url. :param cnxt: RPC context. :param stack_name: Name of the stack you want to create. :param template: Template of stack you want to create. :param params: Stack Input Params :param files: Files referenced from the template :param args: Request parameters/args passed from API """ logger.info(_('template is %s') % template) def _stack_create(stack): # Create the stack, and create the periodic task if successful stack.create() if stack.action == stack.CREATE and stack.status == stack.COMPLETE: # Schedule a periodic watcher task for this stack self._start_watch_task(stack.id, cnxt) else: logger.warning( _("Stack create failed, status %s") % stack.status) if db_api.stack_get_by_name(cnxt, stack_name): raise exception.StackExists(stack_name=stack_name) tenant_limit = cfg.CONF.max_stacks_per_tenant if db_api.stack_count_all_by_tenant(cnxt) >= tenant_limit: message = _("You have reached the maximum stacks per tenant, %d." " Please delete some stacks.") % tenant_limit raise exception.RequestLimitExceeded(message=message) tmpl = parser.Template(template, files=files) if len(tmpl[tpl.RESOURCES]) > cfg.CONF.max_resources_per_stack: raise exception.RequestLimitExceeded( message=exception.StackResourceLimitExceeded.msg_fmt) # Extract the common query parameters common_params = api.extract_args(args) env = environment.Environment(params) stack = parser.Stack(cnxt, stack_name, tmpl, env, **common_params) self._validate_deferred_auth_context(cnxt, stack) stack.validate() stack_id = stack.store() self._start_in_thread(stack_id, _stack_create, stack) return dict(stack.identifier())
def _validate_new_stack(self, cnxt, stack_name, parsed_template): if db_api.stack_get_by_name(cnxt, stack_name): raise exception.StackExists(stack_name=stack_name) tenant_limit = cfg.CONF.max_stacks_per_tenant if db_api.stack_count_all(cnxt) >= tenant_limit: message = _("You have reached the maximum stacks per tenant, %d." " Please delete some stacks.") % tenant_limit raise exception.RequestLimitExceeded(message=message) num_resources = len(parsed_template[parsed_template.RESOURCES]) if num_resources > cfg.CONF.max_resources_per_stack: message = exception.StackResourceLimitExceeded.msg_fmt raise exception.RequestLimitExceeded(message=message)
def create_stack(self, cnxt, stack_name, template, params, files, args): """ The create_stack method creates a new stack using the template provided. Note that at this stage the template has already been fetched from the heat-api process if using a template-url. :param cnxt: RPC context. :param stack_name: Name of the stack you want to create. :param template: Template of stack you want to create. :param params: Stack Input Params :param files: Files referenced from the template (currently provider templates). :param args: Request parameters/args passed from API """ logger.info('template is %s' % template) self._validate_mandatory_credentials(cnxt) def _stack_create(stack): # Create the stack, and create the periodic task if successful stack.create() if stack.action == stack.CREATE and stack.status == stack.COMPLETE: # Schedule a periodic watcher task for this stack self._start_watch_task(stack.id, cnxt) else: logger.warning("Stack create failed, status %s" % stack.status) if db_api.stack_get_by_name(cnxt, stack_name): raise exception.StackExists(stack_name=stack_name) tmpl = parser.Template(template, files=files) # Extract the common query parameters common_params = api.extract_args(args) env = environment.Environment(params) stack = parser.Stack(cnxt, stack_name, tmpl, env, **common_params) stack.validate() stack_id = stack.store() self._start_in_thread(stack_id, _stack_create, stack) return dict(stack.identifier())
def create_stack(self, cnxt, stack_name, template, params, args): """ The create_stack method creates a new stack using the template provided. Note that at this stage the template has already been fetched from the heat-api process if using a template-url. arg1 -> RPC context. arg2 -> Name of the stack you want to create. arg3 -> Template of stack you want to create. arg4 -> Stack Input Params arg4 -> Request parameters/args passed from API """ logger.info('template is %s' % template) def _stack_create(stack): # Create the stack, and create the periodic task if successful stack.create() if stack.state == stack.CREATE_COMPLETE: # Schedule a periodic watcher task for this stack self._timer_in_thread(stack.id, self._periodic_watcher_task, sid=stack.id) else: logger.warning("Stack create failed, state %s" % stack.state) if db_api.stack_get_by_name(cnxt, stack_name): raise exception.StackExists(stack_name=stack_name) tmpl = parser.Template(template) # Extract the template parameters, and any common query parameters template_params = parser.Parameters(stack_name, tmpl, params) common_params = api.extract_args(args) stack = parser.Stack(cnxt, stack_name, tmpl, template_params, **common_params) stack.validate() stack_id = stack.store() self._start_in_thread(stack_id, _stack_create, stack) return dict(stack.identifier())
def test_map_remote_error_already_exists_error(self): ex = common_exception.StackExists(stack_name="teststack") expected = aws_exception.AlreadyExistsError self.assertIsInstance(aws_exception.map_remote_error(ex), expected)