예제 #1
0
    def test_disable_rollback_extract_false(self):
        args = api.extract_args({"disable_rollback": False})
        self.assertIn("disable_rollback", args)
        self.assertFalse(args.get("disable_rollback"))

        args = api.extract_args({"disable_rollback": "False"})
        self.assertIn("disable_rollback", args)
        self.assertFalse(args.get("disable_rollback"))

        args = api.extract_args({"disable_rollback": "false"})
        self.assertIn("disable_rollback", args)
        self.assertFalse(args.get("disable_rollback"))
    def test_disable_rollback_extract_true(self):
        args = api.extract_args({'disable_rollback': True})
        self.assertIn('disable_rollback', args)
        self.assertTrue(args.get('disable_rollback'))

        args = api.extract_args({'disable_rollback': 'True'})
        self.assertIn('disable_rollback', args)
        self.assertTrue(args.get('disable_rollback'))

        args = api.extract_args({'disable_rollback': 'true'})
        self.assertIn('disable_rollback', args)
        self.assertTrue(args.get('disable_rollback'))
예제 #3
0
    def test_disable_rollback_extract_true(self):
        args = api.extract_args({"disable_rollback": True})
        self.assertIn("disable_rollback", args)
        self.assertTrue(args.get("disable_rollback"))

        args = api.extract_args({"disable_rollback": "True"})
        self.assertIn("disable_rollback", args)
        self.assertTrue(args.get("disable_rollback"))

        args = api.extract_args({"disable_rollback": "true"})
        self.assertIn("disable_rollback", args)
        self.assertTrue(args.get("disable_rollback"))
    def test_disable_rollback_extract_false(self):
        args = api.extract_args({'disable_rollback': False})
        self.assertIn('disable_rollback', args)
        self.assertFalse(args.get('disable_rollback'))

        args = api.extract_args({'disable_rollback': 'False'})
        self.assertIn('disable_rollback', args)
        self.assertFalse(args.get('disable_rollback'))

        args = api.extract_args({'disable_rollback': 'false'})
        self.assertIn('disable_rollback', args)
        self.assertFalse(args.get('disable_rollback'))
예제 #5
0
    def test_disable_rollback_extract_true(self):
        args = api.extract_args({'disable_rollback': True})
        self.assertIn('disable_rollback', args)
        self.assertTrue(args.get('disable_rollback'))

        args = api.extract_args({'disable_rollback': 'True'})
        self.assertIn('disable_rollback', args)
        self.assertTrue(args.get('disable_rollback'))

        args = api.extract_args({'disable_rollback': 'true'})
        self.assertIn('disable_rollback', args)
        self.assertTrue(args.get('disable_rollback'))
예제 #6
0
    def test_disable_rollback_extract_false(self):
        args = api.extract_args({'disable_rollback': False})
        self.assertIn('disable_rollback', args)
        self.assertFalse(args.get('disable_rollback'))

        args = api.extract_args({'disable_rollback': 'False'})
        self.assertIn('disable_rollback', args)
        self.assertFalse(args.get('disable_rollback'))

        args = api.extract_args({'disable_rollback': 'false'})
        self.assertIn('disable_rollback', args)
        self.assertFalse(args.get('disable_rollback'))
예제 #7
0
    def update_stack(self, cnxt, stack_identity, template, params, args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(cnxt, stack_identity)

        current_stack = parser.Stack.load(cnxt, stack=db_stack)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template)
        stack_name = current_stack.name
        template_params = parser.Parameters(stack_name, tmpl, params)
        common_params = api.extract_args(args)

        updated_stack = parser.Stack(cnxt, stack_name, tmpl, template_params,
                                     **common_params)

        updated_stack.validate()

        self._start_in_thread(db_stack.id, current_stack.update, updated_stack)

        return dict(current_stack.identifier())
예제 #8
0
파일: manager.py 프로젝트: kiranmurari/heat
    def create_stack(self, context, 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)

        if db_api.stack_get_by_name(None, stack_name):
            raise AttributeError('Stack already exists with that 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(context, stack_name, tmpl, template_params,
                             **common_params)

        response = stack.validate()
        if response['Description'] != 'Successfully validated':
            return response

        stack_id = stack.store()
        greenpool.spawn_n(stack.create)

        return dict(stack.identifier())
예제 #9
0
파일: service.py 프로젝트: HuaiJiang/heat
    def preview_stack(self, cnxt, stack_name, template, params, files, args):
        """
        Simulates a new stack using the provided template.

        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
        """

        LOG.info(_('previewing stack %s') % stack_name)
        tmpl = parser.Template(template, files=files)
        self._validate_new_stack(cnxt, stack_name, tmpl)

        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()

        return api.format_stack_preview(stack)
예제 #10
0
파일: service.py 프로젝트: B-Rich/heat
    def preview_stack(self, cnxt, stack_name, template, params, files, args):
        """
        Simulates a new stack using the provided template.

        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
        """

        LOG.info(_('previewing stack %s') % stack_name)
        tmpl = parser.Template(template, files=files)
        self._validate_new_stack(cnxt, stack_name, tmpl)

        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()

        return api.format_stack_preview(stack)
예제 #11
0
파일: service.py 프로젝트: kraman/heat
    def update_stack(self, cnxt, stack_identity, template, params, args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(cnxt, stack_identity)

        current_stack = parser.Stack.load(cnxt, stack=db_stack)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template)
        stack_name = current_stack.name
        template_params = parser.Parameters(stack_name, tmpl, params)
        common_params = api.extract_args(args)

        updated_stack = parser.Stack(cnxt, stack_name, tmpl,
                                     template_params, **common_params)

        updated_stack.validate()

        self._start_in_thread(db_stack.id, current_stack.update, updated_stack)

        return dict(current_stack.identifier())
예제 #12
0
파일: service.py 프로젝트: AsherBond/heat
    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())
예제 #13
0
파일: service.py 프로젝트: HuaiJiang/heat
    def update_stack(self, cnxt, stack_identity, template, params, files,
                     args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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_identity: 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
        """
        LOG.info(_('template is %s') % template)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(cnxt, stack_identity)

        current_stack = parser.Stack.load(cnxt, stack=db_stack)

        if current_stack.action == current_stack.SUSPEND:
            msg = _('Updating a stack when it is suspended')
            raise exception.NotSupported(feature=msg)

        if current_stack.status == current_stack.IN_PROGRESS:
            msg = _('Updating a stack when another action is in progress')
            raise exception.NotSupported(feature=msg)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template, files=files)
        if len(tmpl[tmpl.RESOURCES]) > cfg.CONF.max_resources_per_stack:
            raise exception.RequestLimitExceeded(
                message=exception.StackResourceLimitExceeded.msg_fmt)
        stack_name = current_stack.name
        common_params = api.extract_args(args)
        common_params.setdefault(rpc_api.PARAM_TIMEOUT,
                                 current_stack.timeout_mins)
        env = environment.Environment(params)
        updated_stack = parser.Stack(cnxt, stack_name, tmpl, env,
                                     **common_params)
        updated_stack.parameters.set_stack_id(current_stack.identifier())

        self._validate_deferred_auth_context(cnxt, updated_stack)
        updated_stack.validate()

        self.thread_group_mgr.start_with_lock(cnxt, current_stack,
                                              self.engine_id,
                                              current_stack.update,
                                              updated_stack)

        return dict(current_stack.identifier())
예제 #14
0
    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())
예제 #15
0
    def update_stack(self, cnxt, stack_identity, template, params,
                     files, args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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_identity: 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)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(cnxt, stack_identity)

        current_stack = parser.Stack.load(cnxt, stack=db_stack)

        if current_stack.action == current_stack.SUSPEND:
            msg = _('Updating a stack when it is suspended')
            raise exception.NotSupported(feature=msg)

        if current_stack.status == current_stack.IN_PROGRESS:
            msg = _('Updating a stack when another action is in progress')
            raise exception.NotSupported(feature=msg)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template, files=files)
        if len(tmpl[tmpl.RESOURCES]) > cfg.CONF.max_resources_per_stack:
            raise exception.RequestLimitExceeded(
                message=exception.StackResourceLimitExceeded.msg_fmt)
        stack_name = current_stack.name
        common_params = api.extract_args(args)
        common_params.setdefault(rpc_api.PARAM_TIMEOUT,
                                 current_stack.timeout_mins)
        env = environment.Environment(params)
        updated_stack = parser.Stack(cnxt, stack_name, tmpl,
                                     env, **common_params)
        updated_stack.parameters.set_stack_id(current_stack.identifier())

        self._validate_deferred_auth_context(cnxt, updated_stack)
        updated_stack.validate()

        self.thread_group_mgr.start_with_lock(cnxt, current_stack,
                                              self.engine_id,
                                              current_stack.update,
                                              updated_stack)

        return dict(current_stack.identifier())
예제 #16
0
    def _parse_template_and_validate_stack(self, cnxt, stack_name, template,
                                           params, files, args):
        tmpl = parser.Template(template, files=files)
        self._validate_new_stack(cnxt, stack_name, tmpl)

        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()
        return stack
예제 #17
0
파일: service.py 프로젝트: AnyBucket/heat
    def _parse_template_and_validate_stack(self, cnxt, stack_name, template,
                                           params, files, args):
        tmpl = parser.Template(template, files=files)
        self._validate_new_stack(cnxt, stack_name, tmpl)

        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()
        return stack
예제 #18
0
파일: service.py 프로젝트: falalawang/heat
    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.stack_watch.start_watch_task(stack.id, cnxt)
            else:
                logger.warning(_("Stack create failed, status %s") %
                               stack.status)

        tmpl = parser.Template(template, files=files)
        self._validate_new_stack(cnxt, stack_name, tmpl)

        # 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())
예제 #19
0
    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.stack_watch.start_watch_task(stack.id, cnxt)
            else:
                logger.warning(_("Stack create failed, status %s") %
                               stack.status)

        tmpl = parser.Template(template, files=files)
        self._validate_new_stack(cnxt, stack_name, tmpl)

        # 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())
예제 #20
0
파일: service.py 프로젝트: wyattla/heat
    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._timer_in_thread(stack.id, self._periodic_watcher_task,
                                      sid=stack.id)
            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())
예제 #21
0
    def update_stack(self, cnxt, stack_identity, template, params, files,
                     args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(cnxt, stack_identity)

        current_stack = parser.Stack.load(cnxt, stack=db_stack)

        if current_stack.action == current_stack.SUSPEND:
            msg = _('Updating a stack when it is suspended')
            raise exception.NotSupported(feature=msg)

        if current_stack.status == current_stack.IN_PROGRESS:
            msg = _('Updating a stack when another action is in progress')
            raise exception.NotSupported(feature=msg)

        # Now parse the template and any parameters for the updated
        # stack definition.
        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)
        stack_name = current_stack.name
        common_params = api.extract_args(args)
        env = environment.Environment(params)
        updated_stack = parser.Stack(cnxt, stack_name, tmpl, env,
                                     **common_params)

        self._validate_deferred_auth_context(cnxt, updated_stack)
        updated_stack.validate()

        self._start_in_thread(db_stack.id, current_stack.update, updated_stack)

        return dict(current_stack.identifier())
예제 #22
0
파일: service.py 프로젝트: spil-robert/heat
    def create_stack(self, context, 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(context, 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(context, stack_name, tmpl, template_params,
                             **common_params)

        response = stack.validate()
        if response:
            return {'Description': response}

        stack_id = stack.store()

        self._start_in_thread(stack_id, _stack_create, stack)

        return dict(stack.identifier())
예제 #23
0
    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())
예제 #24
0
    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())
예제 #25
0
파일: service.py 프로젝트: read1984/heat
    def update_stack(self, cnxt, stack_identity, template, params, files, args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(cnxt, stack_identity)

        current_stack = parser.Stack.load(cnxt, stack=db_stack)

        if current_stack.action == current_stack.SUSPEND:
            msg = _("Updating a stack when it is suspended")
            raise exception.NotSupported(feature=msg)

        if current_stack.status == current_stack.IN_PROGRESS:
            msg = _("Updating a stack when another action is in progress")
            raise exception.NotSupported(feature=msg)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template, files=files)
        if len(tmpl[tpl.RESOURCES]) > cfg.CONF.max_resources_per_stack:
            raise exception.RequestLimitExceeded(message=exception.StackResourceLimitExceeded.message)
        stack_name = current_stack.name
        common_params = api.extract_args(args)
        env = environment.Environment(params)
        updated_stack = parser.Stack(cnxt, stack_name, tmpl, env, **common_params)

        self._validate_deferred_auth_context(cnxt, updated_stack)
        updated_stack.validate()

        self._start_in_thread(db_stack.id, current_stack.update, updated_stack)

        return dict(current_stack.identifier())
예제 #26
0
    def create_stack(self, context, 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)

        if db_api.stack_get_by_name(context, stack_name):
            raise AttributeError('Stack already exists with that 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(context, stack_name, tmpl, template_params,
                             **common_params)

        response = stack.validate()
        if response:
            return {'Description': response}

        stack_id = stack.store()

        self._start_in_thread(stack_id, stack_name, stack.create)

        # Schedule a periodic watcher task for this stack
        self._timer_in_thread(stack_id,
                              stack_name,
                              self._periodic_watcher_task,
                              sid=stack_id)

        return dict(stack.identifier())
예제 #27
0
    def update_stack(self, context, stack_identity, template, params, args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(context, stack_identity)

        current_stack = parser.Stack.load(context, db_stack.id)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template)
        stack_name = current_stack.name
        template_params = parser.Parameters(stack_name, tmpl, params)
        common_params = api.extract_args(args)

        updated_stack = parser.Stack(context, stack_name, tmpl,
                                     template_params, **common_params)

        response = updated_stack.validate()
        if response['Description'] != 'Successfully validated':
            return response

        # Spawn a greenthread to do the update, and register a
        # callback to remove the thread from stack_threads when done
        gt = greenpool.spawn(current_stack.update, updated_stack)
        gt.link(self._gt_done_callback, stack_id=db_stack.id)
        self.stack_threads[db_stack.id].add(gt)

        return dict(current_stack.identifier())
예제 #28
0
파일: manager.py 프로젝트: ishantTyagi/heat
    def update_stack(self, context, stack_identity, template, params, args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(context, stack_identity)

        current_stack = parser.Stack.load(context, db_stack.id)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template)
        stack_name = current_stack.name
        template_params = parser.Parameters(stack_name, tmpl, params)
        common_params = api.extract_args(args)

        updated_stack = parser.Stack(context, stack_name, tmpl,
                                     template_params, **common_params)

        response = updated_stack.validate()
        if response['Description'] != 'Successfully validated':
            return response

        # Spawn a greenthread to do the update, and register a
        # callback to remove the thread from stack_threads when done
        gt = greenpool.spawn(current_stack.update, updated_stack)
        gt.link(self._gt_done_callback, stack_id=db_stack.id)
        self.stack_threads[db_stack.id].add(gt)

        return dict(current_stack.identifier())
예제 #29
0
    def create_stack(self, context, 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)

        if db_api.stack_get_by_name(None, stack_name):
            raise AttributeError('Stack already exists with that 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(context, stack_name, tmpl, template_params,
                             **common_params)

        response = stack.validate()
        if response['Description'] != 'Successfully validated':
            return response

        stack_id = stack.store()

        # Spawn a greenthread to do the create, and register a
        # callback to remove the thread from stack_threads when done
        gt = greenpool.spawn(stack.create)
        gt.link(self._gt_done_callback, stack_id=stack_id)
        self.stack_threads[stack_id].add(gt)

        return dict(stack.identifier())
예제 #30
0
    def update_stack(self, context, stack_name, template, params, args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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)

        auth.authenticate(context)

        # Get the database representation of the existing stack
        db_stack = db_api.stack_get_by_name(None, stack_name)
        if not db_stack:
            raise AttributeError('No stack exists with that name')

        current_stack = parser.Stack.load(context, db_stack.id)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template)
        template_params = parser.Parameters(stack_name, tmpl, params)
        common_params = api.extract_args(args)

        updated_stack = parser.Stack(context, stack_name, tmpl,
                                     template_params, **common_params)

        response = updated_stack.validate()
        if response['Description'] != 'Successfully validated':
            return response

        greenpool.spawn_n(current_stack.update, updated_stack)

        return {'StackName': current_stack.name, 'StackId': current_stack.id}
예제 #31
0
파일: service.py 프로젝트: jake-liu/heat
    def update_stack(self, cnxt, stack_identity, template, params, files, args):
        """
        The update_stack method updates an existing stack based on the
        provided template and parameters.
        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)

        self._validate_mandatory_credentials(cnxt)

        # Get the database representation of the existing stack
        db_stack = self._get_stack(cnxt, stack_identity)

        if db_stack.status != parser.Stack.COMPLETE:
            raise exception.ActionInProgress(stack_name=db_stack.name, action=db_stack.action)

        current_stack = parser.Stack.load(cnxt, stack=db_stack)

        # Now parse the template and any parameters for the updated
        # stack definition.
        tmpl = parser.Template(template, files=files)
        stack_name = current_stack.name
        common_params = api.extract_args(args)
        env = environment.Environment(params)
        updated_stack = parser.Stack(cnxt, stack_name, tmpl, env, **common_params)

        updated_stack.validate()

        self._start_in_thread(db_stack.id, current_stack.update, updated_stack)

        return dict(current_stack.identifier())
예제 #32
0
파일: service.py 프로젝트: zaneb/heat
    def create_stack(self, context, 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)

        if db_api.stack_get_by_name(context, stack_name):
            raise AttributeError("Stack already exists with that 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(context, stack_name, tmpl, template_params, **common_params)

        response = stack.validate()
        if response:
            return {"Description": response}

        stack_id = stack.store()

        self._start_in_thread(stack_id, stack_name, stack.create)

        # Schedule a periodic watcher task for this stack
        self._timer_in_thread(stack_id, stack_name, self._periodic_watcher_task, sid=stack_id)

        return dict(stack.identifier())
 def test_tags_extract_not_present(self):
     args = api.extract_args({})
     self.assertNotIn('tags', args)
예제 #34
0
 def test_timeout_extract(self):
     p = {'timeout_mins': '5'}
     args = api.extract_args(p)
     self.assertEqual(5, args['timeout_mins'])
예제 #35
0
 def test_timeout_extract_garbage(self):
     p = {'timeout_mins': 'wibble'}
     args = api.extract_args(p)
     self.assertTrue('timeout_mins' not in args)
 def test_tags_extract(self):
     p = {'tags': ["tag1", "tag2"]}
     args = api.extract_args(p)
     self.assertEqual(['tag1', 'tag2'], args['tags'])
 def test_adopt_stack_data_extract_not_present(self):
     args = api.extract_args({})
     self.assertNotIn('adopt_stack_data', args)
예제 #38
0
 def test_timeout_extract_none(self):
     p = {'timeout_mins': None}
     args = api.extract_args(p)
     self.assertTrue('timeout_mins' not in args)
예제 #39
0
 def test_timeout_extract_not_present(self):
     args = api.extract_args({})
     self.assertTrue('timeout_mins' not in args)
 def test_adopt_stack_data_extract_present(self):
     p = {'adopt_stack_data': json.dumps({'Resources': {}})}
     args = api.extract_args(p)
     self.assertTrue(args.get('adopt_stack_data'))
예제 #41
0
 def test_adopt_stack_data_extract_present(self):
     p = {'adopt_stack_data': json.dumps({'Resources': {}})}
     args = api.extract_args(p)
     self.assertTrue(args.get('adopt_stack_data'))
예제 #42
0
 def test_timeout_extract_zero(self):
     p = {'timeout_mins': '0'}
     args = api.extract_args(p)
     self.assertTrue('timeout_mins' not in args)
예제 #43
0
 def test_timeout_extract_none(self):
     p = {'timeout_mins': None}
     args = api.extract_args(p)
     self.assertNotIn('timeout_mins', args)
예제 #44
0
 def test_timeout_extract_zero(self):
     p = {'timeout_mins': '0'}
     args = api.extract_args(p)
     self.assertNotIn('timeout_mins', args)
예제 #45
0
 def test_timeout_extract_not_present(self):
     args = api.extract_args({})
     self.assertTrue('timeout_mins' not in args)
예제 #46
0
 def test_timeout_extract_none(self):
     p = {'timeout_mins': None}
     args = api.extract_args(p)
     self.assertTrue('timeout_mins' not in args)
예제 #47
0
 def test_timeout_extract_garbage(self):
     p = {'timeout_mins': 'wibble'}
     args = api.extract_args(p)
     self.assertTrue('timeout_mins' not in args)
예제 #48
0
 def test_timeout_extract_garbage(self):
     p = {'timeout_mins': 'wibble'}
     args = api.extract_args(p)
     self.assertNotIn('timeout_mins', args)
 def test_timeout_extract_zero(self):
     p = {'timeout_mins': '0'}
     args = api.extract_args(p)
     self.assertNotIn('timeout_mins', args)
예제 #50
0
 def test_timeout_extract_not_present(self):
     args = api.extract_args({})
     self.assertNotIn('timeout_mins', args)
 def test_timeout_extract_garbage(self):
     p = {'timeout_mins': 'wibble'}
     args = api.extract_args(p)
     self.assertNotIn('timeout_mins', args)
예제 #52
0
 def test_adopt_stack_data_extract_not_present(self):
     args = api.extract_args({})
     self.assertNotIn('adopt_stack_data', args)
 def test_timeout_extract_none(self):
     p = {'timeout_mins': None}
     args = api.extract_args(p)
     self.assertNotIn('timeout_mins', args)
 def test_timeout_extract(self):
     p = {'timeout_mins': '5'}
     args = api.extract_args(p)
     self.assertEqual(5, args['timeout_mins'])
 def test_timeout_extract_not_present(self):
     args = api.extract_args({})
     self.assertNotIn('timeout_mins', args)