Beispiel #1
0
 def _list_envs(self):
     """Display all envs"""
     meta = self.parsed_config.get_env_meta()
     rows = []
     for env_name in sorted(meta.keys()):
         marker = ' '
         if meta[env_name]['is_current']:
             marker = '*'
         rows.append((marker, env_name))
     self.stdout.write(render_table_rows(rows) + "\n")
Beispiel #2
0
    def register(self, subparsers, parsed_config):
        self.parsed_config = parsed_config
        config_parser = subparsers.add_parser(
            self.name(),
            description=(
                'Display or update brkt-cli options stored in'
                ' ~/.brkt/config'),
            help='Display or update brkt-cli options'
        )

        config_subparsers = config_parser.add_subparsers(
            dest='config_subcommand'
        )

        # List all options
        config_subparsers.add_parser(
            'list',
            help='Display the values of all options set in the config file',
            description='Display the values of all options set in the config file')

        # All the options available for retrieval/mutation
        rows = []
        descs = self.parsed_config.registered_options()
        opts = sorted(descs.keys())
        for opt in opts:
            rows.append([opt, descs[opt]])
        opts_table = render_table_rows(rows, row_prefix='  ')
        epilog = "\n".join([
            'supported options:',
            '',
            opts_table
        ])

        # Set an option
        set_parser = config_subparsers.add_parser(
            'set',
            help='Set the value for an option',
            description='Set the value for an option',
            epilog=epilog,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        set_parser.add_argument(
            'option',
            help='The option name (e.g. encrypt-gce-image.project)')
        set_parser.add_argument(
            'value',
            help='The option value')

        # Get the value for an option
        get_parser = config_subparsers.add_parser(
            'get',
            help='Get the value for an option',
            description='Get the value for an option',
            epilog=epilog,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        get_parser.add_argument(
            'option',
            help='The option name (e.g. encrypt-gce-image.project)')

        # Unset the value for an option
        unset_parser = config_subparsers.add_parser(
            'unset',
            help='Unset the value for an option',
            description='Unset the value for an option',
            epilog=epilog,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        unset_parser.add_argument(
            'option',
            help='The option name (e.g. encrypt-gce-image.project)')

        # Define or update an environment
        set_env_parser = config_subparsers.add_parser(
            'set-env',
            help='Update the attributes of an environment',
            description="""
Update the attributes of an environment

Environments are persisted in your configuration and can be activated via the
`use-env` config subcommand. This command is particularly helpful if you need
to work with multiple on-prem control-plane deployments. For example, we could
define stage and prod control planes hosted at stage.foo.com and prod.foo.com,
respectively, by executing:

    > brkt config set-env stage --service-domain stage.foo.com
    > brkt config set-env prod --service-domain prod.foo.com

We can switch between the environments using the `use-env` config subcommand
like so:

    > brkt config use-env stage

We can determine the current environment using the `list-envs` config
subcommand:

    > brkt config list-envs
      brkt-hosted
      prod
    * stage
    >

The leading `*' indicates that the `stage' environment is currently active.
""",
            formatter_class=argparse.RawDescriptionHelpFormatter)
        set_env_parser.add_argument(
            'env_name',
            help='The environment name (e.g. stage)')
        set_env_parser.add_argument(
            '--api-server',
            help='The api server (host[:port]) the metavisor will connect to')
        set_env_parser.add_argument(
            '--key-server',
            help='The key server (host[:port]) the metavisor will connect to')
        set_env_parser.add_argument(
            '--network-server',
            help='The network server (host[:port]) the metavisor will connect to')
        set_env_parser.add_argument(
            '--public-api-server',
            help='The public api (host[:port])')
        set_env_parser.add_argument(
            '--service-domain',
            help=('Set server values from the service domain. This option '
                  ' assumes that each server is resolvable via a hostname'
                  ' rooted at service-domain. Specifically, api is expected to'
                  ' live at yetiapi.<service-domain>, key-server at '
                  ' hsmproxy.<service-domain>, network at '
                  ' network.<service-domain>, and public-api-server at'
                  ' api.<service-domain>.')
            )

        # Set the active environment
        use_env_parser = config_subparsers.add_parser(
            'use-env',
            help='Set the active environment',
            description='Set the active environment',
            formatter_class=argparse.ArgumentDefaultsHelpFormatter)
        use_env_parser.add_argument(
            'env_name',
            help='The environment name (e.g. stage)')

        # Display all defined environments
        config_subparsers.add_parser(
            'list-envs',
            help='Display all environments',
            description=(
                "Display all environments. The leading `*' indicates"
                " the currently active environment."))

        # Get the details of a specific environment
        get_env_parser = config_subparsers.add_parser(
            'get-env',
            help='Display the details of a specific environment',
            description='Display the details of an environment',
            formatter_class=argparse.ArgumentDefaultsHelpFormatter)
        get_env_parser.add_argument(
            'env_name',
            help='The environment name')

        # Unset a specific environment
        unset_env_parser = config_subparsers.add_parser(
            'unset-env',
            help='Delete an environment',
            description='Delete an environment')
        unset_env_parser.add_argument(
            'env_name',
            help='The environment name')
Beispiel #3
0
    def register(self, subparsers, parsed_config):
        self.parsed_config = parsed_config
        config_parser = subparsers.add_parser(
            self.name(),
            description=(
                'Display or update brkt-cli options stored in'
                ' ~/.brkt/config')
        )

        config_subparsers = config_parser.add_subparsers(
            dest='config_subcommand'
        )

        # List all options
        config_subparsers.add_parser(
            'list',
            help='display the values of all options set in the config file',
            description='Display the values of all options set in the config file')

        # All the options available for retrieval/mutation
        rows = []
        descs = self.parsed_config.registered_options()
        opts = sorted(descs.keys())
        for opt in opts:
            rows.append([opt, descs[opt]])
        opts_table = render_table_rows(rows, row_prefix='  ')
        epilog = "\n".join([
            'supported options:',
            '',
            opts_table
        ])

        # Set an option
        set_parser = config_subparsers.add_parser(
            'set',
            help='set the value for an option',
            description='Set the value for an option',
            epilog=epilog,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        set_parser.add_argument(
            'option',
            help='the option name (e.g. encrypt-gce-image.project)')
        set_parser.add_argument(
            'value',
            help='the option value')

        # Get the value for an option
        get_parser = config_subparsers.add_parser(
            'get',
            help='get the value for an option',
            description='Get the value for an option',
            epilog=epilog,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        get_parser.add_argument(
            'option',
            help='the option name (e.g. encrypt-gce-image.project)')

        # Unset the value for an option
        unset_parser = config_subparsers.add_parser(
            'unset',
            help='unset the value for an option',
            description='Unset the value for an option',
            epilog=epilog,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        unset_parser.add_argument(
            'option',
            help='the option name (e.g. encrypt-gce-image.project)')