Esempio n. 1
0
    def plan(self, force=False, sys_path=None):
        """Run the CFNgin plan action.

        Args:
            force (bool): Explicitly enable the action even if an environment
                file is not found.
            sys_path (Optional[str]): Explicitly define a path to work in.
                If not provided, ``self.sys_path`` is used.

        """
        if self.should_skip(force):
            return
        if not sys_path:
            sys_path = self.sys_path
        config_file_names = self.find_config_files(sys_path=sys_path)
        with SafeHaven(environ=self.__ctx.env_vars):
            for config_name in config_file_names:
                logger = PrefixAdaptor(os.path.basename(config_name), LOGGER)
                logger.notice("plan (in progress)")
                with SafeHaven(argv=["stacker", "diff", config_name]):
                    ctx = self.load(config_name)
                    action = diff.Action(
                        context=ctx,
                        provider_builder=self._get_provider_builder(
                            ctx.config.service_role),
                    )
                    action.execute()
                logger.success("plan (complete)")
Esempio n. 2
0
    def deploy(self, force=False, sys_path=None):
        """Run the CFNgin deploy action.

        Args:
            force (bool): Explicitly enable the action even if an environment
                file is not found.
            sys_path (Optional[str]): Explicitly define a path to work in.
                If not provided, ``self.sys_path`` is used.

        """
        if self.should_skip(force):
            return
        if not sys_path:
            sys_path = self.sys_path
        config_file_names = self.find_config_files(sys_path=sys_path)

        with SafeHaven(environ=self.__ctx.env_vars,
                       sys_modules_exclude=["awacs", "troposphere"]):
            for config_name in config_file_names:
                logger = PrefixAdaptor(os.path.basename(config_name), LOGGER)
                logger.notice("deploy (in progress)")
                with SafeHaven(
                        argv=["stacker", "build", config_name],
                        sys_modules_exclude=["awacs", "troposphere"],
                ):
                    ctx = self.load(config_name)
                    action = build.Action(
                        context=ctx,
                        provider_builder=self._get_provider_builder(
                            ctx.config.service_role),
                    )
                    action.execute(concurrency=self.concurrency,
                                   tail=self.tail)
                logger.success("deploy (complete)")
Esempio n. 3
0
    def destroy(self, force=False, sys_path=None):
        """Run the CFNgin destroy action.

        Args:
            force (bool): Explicitly enable the action even if an environment
                file is not found.
            syspath (Optional[str]): Explicitly define a path to work in.
                If not provided, ``self.sys_path`` is used.

        """
        if self.should_skip(force):
            return
        if not sys_path:
            sys_path = self.sys_path
        config_file_names = self.find_config_files(sys_path=sys_path)
        # destroy should run in reverse to handle dependencies
        config_file_names.reverse()

        with SafeHaven(environ=self.__ctx.env_vars):
            for config_name in config_file_names:
                logger = PrefixAdaptor(os.path.basename(config_name), LOGGER)
                logger.notice('destroy (in progress)')
                with SafeHaven(argv=['stacker', 'destroy', config_name]):
                    ctx = self.load(config_name)
                    action = destroy.Action(
                        context=ctx,
                        provider_builder=self._get_provider_builder(
                            ctx.config.service_role))
                    action.execute(concurrency=self.concurrency,
                                   force=True,
                                   tail=self.tail)
                logger.success('destroy (complete)')
Esempio n. 4
0
    def __init__(
        self,
        environment=None,
        boto3_credentials=None,
        stack_names=None,
        config=None,
        config_path=None,
        region=None,
        force_stacks=None,
    ):
        """Instantiate class.

        Args:
            boto3_credentials (Optional[Dict[str, str]]): Credentials to use
                when creating a boto3 session from context.
            environment (dict): A dictionary used to pass in information about
                the environment. Useful for templating.
            stack_names (list): A list of stack_names to operate on. If not
                passed, usually all stacks defined in the config will be
                operated on.
            config (:class:`runway.cfngin.config.Config`): The CFNgin
                configuration being operated on.
            config_path (str): Path to the config file that was provided.
            region (str): Name of an AWS region if provided as a CLI argument.
            force_stacks (list): A list of stacks to force work on. Used to
                work on locked stacks.

        """
        self.__boto3_credentials = boto3_credentials
        self._bucket_name = None
        self._persistent_graph = None
        self._persistent_graph_lock_code = None
        self._persistent_graph_lock_tag = "cfngin_lock_code"
        self._s3_bucket_verified = None
        self._stacks = None
        self._targets = None
        self._upload_to_s3 = None
        # TODO load the config from context instead of taking it as an arg
        self.config = config or Config()
        # TODO set this value when provisioning a Config object in context
        # set to a fake location for the time being but this should be set
        # by all runtime entry points. the only time the fake value should be
        # used is during tests.
        self.config_path = config_path or "./"
        self.bucket_region = self.config.cfngin_bucket_region or region
        self.environment = environment
        self.force_stacks = force_stacks or []
        self.hook_data = {}  # TODO change to MutableMap in next major release
        self.logger = PrefixAdaptor(config_path, LOGGER)
        self.region = region
        self.s3_conn = self.get_session(region=self.bucket_region).client("s3")
        self.stack_names = stack_names or []
Esempio n. 5
0
    def __init__(self, stack, fn=None, watch_func=None):
        """Instantiate class.

        Args:
            stack (:class:`runway.cfngin.stack.Stack`): The stack associated
                with this step
            fn (Optional[Callable]): Function to run to execute the step.
                This function will be ran multiple times until the step is
                "done".
            watch_func (Optional[Callable]): Function that will be called to
                "tail" the step action.

        """
        self.stack = stack
        self.status = PENDING
        self.last_updated = time.time()
        self.logger = PrefixAdaptor(self.stack.name, LOGGER)
        self.fn = fn
        self.watch_func = watch_func