def count_stacks(self, cnxt, filters=None): """ Return the number of stacks that match the given filters :param ctxt: RPC context. :param filters: a dict of ATTR:VALUE to match agains stacks :returns: a integer representing the number of matched stacks """ return db_api.stack_count_all_by_tenant(cnxt, filters=filters)
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) 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.StackResourceLimitExceeded() # 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() # Creates a trust and sets the trust_id and trustor_user_id in # the current context, before we store it in stack.store() # Does nothing if deferred_auth_method is 'password' stack.clients.keystone().create_trust_context() 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, 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_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) 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 :param args: Request parameters/args passed from API """ logger.info(_('template is %s') % template) def _stack_create(stack): # Create/Adopt a stack, and create the periodic task if successful if stack.adopt_stack_data: stack.adopt() else: stack.create() if (stack.action in (stack.CREATE, stack.ADOPT) 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.store() self.thread_group_mgr.start_with_lock(cnxt, stack, self.engine_id, _stack_create, stack) return dict(stack.identifier())