Example #1
0
def get_config_schema(command):
    """
    :param command: the subcommand name
    :type command: str
    :returns: the subcommand's configuration schema
    :rtype: dict
    """

    # import here to avoid circular import
    from dcos.subcommand import (command_executables, config_schema,
                                 default_subcommands)

    # core.* config variables are special.  They're valid, but don't
    # correspond to any particular subcommand, so we must handle them
    # separately.
    if command == "core":
        return json.loads(
            pkg_resources.resource_string(
                'dcos', 'data/config-schema/core.json').decode('utf-8'))
    elif command in default_subcommands():
        return json.loads(
            pkg_resources.resource_string(
                'dcos',
                'data/config-schema/{}.json'.format(command)).decode('utf-8'))
    else:
        executable = command_executables(command)
        return config_schema(executable, command)
Example #2
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    if not _is_valid_configuration():
        return 1

    args = docopt.docopt(
        __doc__,
        version='dcos version {}'.format(dcoscli.version),
        options_first=True)

    if args['<command>'] != 'config' and \
       not auth.check_if_user_authenticated():
        auth.force_auth()

    if not _config_log_level_environ(args['--log-level']):
        return 1

    err = util.configure_logger_from_environ()
    if err is not None:
        emitter.publish(err)
        return 1

    command = args['<command>']
    http.silence_requests_warnings()

    if not command:
        command = "help"

    executable = subcommand.command_executables(command, util.dcos_path())

    subproc = Popen([executable,  command] + args['<args>'],
                    stderr=PIPE)

    return analytics.wait_and_track(subproc)
Example #3
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    args = docopt.docopt(
        __doc__,
        version='dcos version {}'.format(dcoscli.version),
        options_first=True)

    log_level = args['--log-level']
    if log_level and not _config_log_level_environ(log_level):
        return 1

    if args['--debug']:
        os.environ[constants.DCOS_DEBUG_ENV] = 'true'

    util.configure_process_from_environ()

    if args['<command>'] != 'config' and \
       not auth.check_if_user_authenticated():
        auth.force_auth()

    command = args['<command>']
    http.silence_requests_warnings()

    if not command:
        command = "help"

    executable = subcommand.command_executables(command)

    subproc = Popen([executable,  command] + args['<args>'],
                    stderr=PIPE)
    if dcoscli.version != 'SNAPSHOT':
        return analytics.wait_and_track(subproc)
    else:
        return analytics.wait_and_capture(subproc)[0]
Example #4
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    http.silence_requests_warnings()
    config = util.get_config()
    set_ssl_info_env_vars(config)

    args = docopt.docopt(default_doc("dcos"), options_first=True)

    log_level = args['--log-level']
    if log_level and not _config_log_level_environ(log_level):
        return 1

    if args['--debug']:
        os.environ[constants.DCOS_DEBUG_ENV] = 'true'

    util.configure_process_from_environ()

    if args['--version']:
        return _get_versions(config.get("core.dcos_url"))

    command = args['<command>']

    if not command:
        command = "help"

    if command in subcommand.default_subcommands():
        sc = SubcommandMain(command, args['<args>'])
    else:
        executable = subcommand.command_executables(command)
        sc = subcommand.SubcommandProcess(
            executable, command, args['<args>'])

    exitcode, _ = sc.run_and_capture()
    return exitcode
Example #5
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    args = docopt.docopt(__doc__,
                         version='dcos version {}'.format(dcoscli.version),
                         options_first=True)

    log_level = args['--log-level']
    if log_level and not _config_log_level_environ(log_level):
        return 1

    if args['--debug']:
        os.environ[constants.DCOS_DEBUG_ENV] = 'true'

    util.configure_process_from_environ()

    if args['<command>'] != 'config' and \
       not auth.check_if_user_authenticated():
        auth.force_auth()

    command = args['<command>']
    http.silence_requests_warnings()

    if not command:
        command = "help"

    executable = subcommand.command_executables(command)

    subproc = Popen([executable, command] + args['<args>'], stderr=PIPE)
    if dcoscli.version != 'SNAPSHOT':
        return analytics.wait_and_track(subproc)
    else:
        return analytics.wait_and_capture(subproc)[0]
Example #6
0
def get_config_schema(command):
    """
    :param command: the subcommand name
    :type command: str
    :returns: the subcommand's configuration schema
    :rtype: dict
    """

    # import here to avoid circular import
    from dcos.subcommand import (command_executables, config_schema,
                                 default_subcommands)

    # handle config schema for core.* properties and built-in subcommands
    if command == "core" or command in default_subcommands():
        try:
            schema = pkg_resources.resource_string(
                'dcos', 'data/config-schema/{}.json'.format(command))
        except FileNotFoundError:
            msg = "Subcommand '{}' is not configurable.".format(command)
            raise DCOSException(msg)

        return json.loads(schema.decode('utf-8'))

    try:
        executable = command_executables(command)
    except DCOSException as e:
        msg = "Config section '{}' is invalid: {}".format(command, e)
        raise DCOSException(msg)

    return config_schema(executable, command)
Example #7
0
def _help_command(command):
    """
    :param command: the command name for which you want to see a help
    :type command: str
    :returns: process return code
    :rtype: int
    """

    executable = subcommand.command_executables(command)
    return subprocess.call([executable, command, '--help'])
Example #8
0
def _help_command(command):
    """
    :param command: the command name for which you want to see a help
    :type command: str
    :returns: process return code
    :rtype: int
    """

    executable = subcommand.command_executables(command)
    return subprocess.call([executable, command, '--help'])
Example #9
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    args = docopt.docopt(
        _doc(),
        version='dcos version {}'.format(dcoscli.version),
        options_first=True)

    log_level = args['--log-level']
    if log_level and not _config_log_level_environ(log_level):
        return 1

    if args['--debug']:
        os.environ[constants.DCOS_DEBUG_ENV] = 'true'

    util.configure_process_from_environ()

    if args['<command>'] != 'config' and \
       not auth.check_if_user_authenticated():
        auth.force_auth()

    config = util.get_config()
    set_ssl_info_env_vars(config)

    command = args['<command>']
    http.silence_requests_warnings()

    if not command:
        command = "help"

    executable = subcommand.command_executables(command)

    cluster_id = None
    if dcoscli.version != 'SNAPSHOT' and command and \
            command not in ["config", "help"]:
        try:
            cluster_id = mesos.DCOSClient().metadata().get('CLUSTER_ID')
        except DCOSAuthenticationException:
                raise
        except:
            msg = 'Unable to get the cluster_id of the cluster.'
            logger.exception(msg)

    # the call to retrieve cluster_id must happen before we run the subcommand
    # so that if you have auth enabled we don't ask for user/pass multiple
    # times (with the text being out of order) before we can cache the auth
    # token
    subproc = Popen([executable,  command] + args['<args>'],
                    stderr=PIPE)

    if dcoscli.version != 'SNAPSHOT':
        return analytics.wait_and_track(subproc, cluster_id)
    else:
        return analytics.wait_and_capture(subproc)[0]
Example #10
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    args = docopt.docopt(_doc(),
                         version='dcos version {}'.format(dcoscli.version),
                         options_first=True)

    log_level = args['--log-level']
    if log_level and not _config_log_level_environ(log_level):
        return 1

    if args['--debug']:
        os.environ[constants.DCOS_DEBUG_ENV] = 'true'

    util.configure_process_from_environ()

    if args['<command>'] != 'config' and \
       not auth.check_if_user_authenticated():
        auth.force_auth()

    config = util.get_config()
    set_ssl_info_env_vars(config)

    command = args['<command>']
    http.silence_requests_warnings()

    if not command:
        command = "help"

    executable = subcommand.command_executables(command)

    cluster_id = None
    if dcoscli.version != 'SNAPSHOT' and command and \
            command not in ["config", "help"]:
        try:
            cluster_id = mesos.DCOSClient().metadata().get('CLUSTER_ID')
        except DCOSAuthenticationException:
            raise
        except:
            msg = 'Unable to get the cluster_id of the cluster.'
            logger.exception(msg)

    # the call to retrieve cluster_id must happen before we run the subcommand
    # so that if you have auth enabled we don't ask for user/pass multiple
    # times (with the text being out of order) before we can cache the auth
    # token
    subproc = Popen([executable, command] + args['<args>'], stderr=PIPE)

    if dcoscli.version != 'SNAPSHOT':
        return analytics.wait_and_track(subproc, cluster_id)
    else:
        return analytics.wait_and_capture(subproc)[0]
Example #11
0
def _help_command(command):
    """
    :param command: the command name for which you want to see a help
    :type command: str
    :returns: process return code
    :rtype: int
    """

    if command in subcommand.default_subcommands():
        emitter.publish(default_command_documentation(command))
        return 0
    else:
        executable = subcommand.command_executables(command)
        return subprocess.call([executable, command, '--help'])
Example #12
0
def _help_command(command):
    """
    :param command: the command name for which you want to see a help
    :type command: str
    :returns: process return code
    :rtype: int
    """

    if command in subcommand.default_subcommands():
        emitter.publish(default_command_documentation(command))
        return 0
    else:
        executable = subcommand.command_executables(command)
        return subprocess.Subproc().call([executable, command, '--help'])
Example #13
0
def get_config_schema(command):
    """
    :param command: the subcommand name
    :type command: str
    :returns: the subcommand's configuration schema
    :rtype: dict
    """

    # core.* config variables are special.  They're valid, but don't
    # correspond to any particular subcommand, so we must handle them
    # separately.
    if command == "core":
        return json.loads(
            pkg_resources.resource_string(
                'dcos', 'data/config-schema/core.json').decode('utf-8'))

    executable = subcommand.command_executables(command)
    return subcommand.config_schema(executable)
Example #14
0
def get_config_schema(command):
    """
    :param command: the subcommand name
    :type command: str
    :returns: the subcommand's configuration schema
    :rtype: dict
    """

    # core.* config variables are special.  They're valid, but don't
    # correspond to any particular subcommand, so we must handle them
    # separately.
    if command == "core":
        return json.loads(
            pkg_resources.resource_string(
                'dcos',
                'data/config-schema/core.json').decode('utf-8'))

    executable = subcommand.command_executables(command)
    return subcommand.config_schema(executable, command)
Example #15
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    http.silence_requests_warnings()

    args = docopt.docopt(default_doc("dcos"), options_first=True)

    log_level = args['--log-level']
    if log_level and not _config_log_level_environ(log_level):
        return 1

    if args['--debug']:
        os.environ[constants.DCOS_DEBUG_ENV] = 'true'

    util.configure_process_from_environ()

    if args['--version']:
        return _get_versions()

    command = args['<command>']

    if not command:
        return dcos_help()

    if config.uses_deprecated_config():
        if constants.DCOS_CONFIG_ENV in os.environ:
            msg = ('{} is deprecated, please consider using '
                   '`dcos cluster setup <dcos_url>`.')
            err = errors.DefaultError(msg.format(constants.DCOS_CONFIG_ENV))
            emitter.publish(err)

        cluster.move_to_cluster_config()

    if command in subcommand.default_subcommands():
        sc = SubcommandMain(command, args['<args>'])
    else:
        executable = subcommand.command_executables(command)
        sc = subcommand.SubcommandProcess(executable, command, args['<args>'])

    exitcode, _ = sc.run_and_capture()
    return exitcode
Example #16
0
def test_uninstall_cli_only_when_no_apps_remain():
    with util.temptext(b'{"name": "/hello1"}') as opts_hello1, \
            util.temptext(b'{"name": "/hello2"}') as opts_hello2:
        stderr = (
            b'This is a Community service. '
            b'Community services are not tested '
            b'for production environments. '
            b'There may be bugs, incomplete features, '
            b'incorrect documentation, or other discrepancies.\n'
            b'By Deploying, you agree to the Terms '
            b'and Conditions https://mesosphere.com/'
            b'catalog-terms-conditions/#community-services\n'
            b'A sample pre-installation message\n'
            b'Installing Marathon app for package [helloworld] version '
            b'[0.1.0]\n'
            b'Installing CLI subcommand for package [helloworld] '
            b'version [0.1.0]\n'
            b'New commands available: http\n'
            b'A sample post-installation message\n'
        )

        uninstall_stderr = (
            b'Uninstalled package [helloworld] version [0.1.0]\n'
        )
        with _package(name='helloworld',
                      args=['--yes', '--options='+opts_hello1[1]],
                      stderr=stderr,
                      uninstall_app_id='/hello1',
                      uninstall_stderr=uninstall_stderr):

            with _package(name='helloworld',
                          args=['--yes', '--options='+opts_hello2[1]],
                          stderr=stderr,
                          uninstall_app_id='/hello2',
                          uninstall_stderr=uninstall_stderr):

                subcommand.command_executables('http')

            # helloworld subcommand should still be there as there is the
            # /hello1 app installed
            subcommand.command_executables('http')

        # helloworld subcommand should have been removed
        with pytest.raises(errors.DCOSException) as exc_info:
            subcommand.command_executables('helloworld')

        assert str(exc_info.value) == "'helloworld' is not a dcos command."
Example #17
0
def test_uninstall_cli_only_when_no_apps_remain():
    with util.temptext(b'{"name": "/hello1"}') as opts_hello1, \
         util.temptext(b'{"name": "/hello2"}') as opts_hello2:

        stdout = (b'By Deploying, you agree to the Terms '
                  b'and Conditions https://mesosphere.com/'
                  b'catalog-terms-conditions/#community-services\n'
                  b'A sample pre-installation message\n'
                  b'Installing Marathon app for package [helloworld] version '
                  b'[0.1.0]\n'
                  b'Installing CLI subcommand for package [helloworld] '
                  b'version [0.1.0]\n'
                  b'New command available: dcos ' +
                  _executable_name(b'helloworld') +
                  b'\nA sample post-installation message\n')

        stderr = b'Uninstalled package [helloworld] version [0.1.0]\n'
        with _package(name='helloworld',
                      args=['--yes', '--options=' + opts_hello1[1]],
                      stdout=stdout,
                      uninstall_app_id='/hello1',
                      uninstall_stderr=stderr):

            with _package(name='helloworld',
                          args=['--yes', '--options=' + opts_hello2[1]],
                          stdout=stdout,
                          uninstall_app_id='/hello2',
                          uninstall_stderr=stderr):

                subcommand.command_executables('helloworld')

            # helloworld subcommand should still be there as there is the
            # /hello1 app installed
            subcommand.command_executables('helloworld')

        # helloworld subcommand should have been removed
        try:
            subcommand.command_executables('helloworld')
        except errors.DCOSException as e:
            assert str(e) == "'helloworld' is not a dcos command."
            return

        assert False, "expected command_executables('helloworld') to fail"
Example #18
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    args = docopt.docopt(
        default_doc("dcos"),
        version='dcos version {}'.format(dcoscli.version),
        options_first=True)

    log_level = args['--log-level']
    if log_level and not _config_log_level_environ(log_level):
        return 1

    if args['--debug']:
        os.environ[constants.DCOS_DEBUG_ENV] = 'true'

    util.configure_process_from_environ()

    if args['<command>'] != 'config' and \
       not auth.check_if_user_authenticated():
        auth.force_auth()

    config = util.get_config()
    set_ssl_info_env_vars(config)

    command = args['<command>']
    http.silence_requests_warnings()

    if not command:
        command = "help"

    cluster_id = None
    if dcoscli.version != 'SNAPSHOT' and command and \
            command not in ["config", "help"]:
        try:
            cluster_id = mesos.DCOSClient().metadata().get('CLUSTER_ID')
        except DCOSAuthenticationException:
                raise
        except:
            msg = 'Unable to get the cluster_id of the cluster.'
            logger.exception(msg)

    # send args call to segment.io
    with ThreadPoolExecutor(max_workers=2) as reporting_executor:
        analytics.segment_track_cli(reporting_executor, config, cluster_id)

        # the call to retrieve cluster_id must happen before we run the
        # subcommand so that if you have auth enabled we don't ask for
        # user/pass multiple times (with the text being out of order)
        # before we can cache the auth token
        if command in subcommand.default_subcommands():
            sc = SubcommandMain(command, args['<args>'])
        else:
            executable = subcommand.command_executables(command)
            sc = subcommand.SubcommandProcess(
                executable, command, args['<args>'])

        exitcode, err = sc.run_and_capture()

        if err:
            analytics.track_err(
                reporting_executor, exitcode, err, config, cluster_id)

        return exitcode
Example #19
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    args = docopt.docopt(default_doc("dcos"),
                         version='dcos version {}'.format(dcoscli.version),
                         options_first=True)

    log_level = args['--log-level']
    if log_level and not _config_log_level_environ(log_level):
        return 1

    if args['--debug']:
        os.environ[constants.DCOS_DEBUG_ENV] = 'true'

    util.configure_process_from_environ()

    if args['<command>'] != 'config' and \
       not auth.check_if_user_authenticated():
        auth.force_auth()

    config = util.get_config()
    set_ssl_info_env_vars(config)

    command = args['<command>']
    http.silence_requests_warnings()

    if not command:
        command = "help"

    cluster_id = None
    if dcoscli.version != 'SNAPSHOT' and command and \
            command not in ["config", "help"]:
        try:
            cluster_id = mesos.DCOSClient().metadata().get('CLUSTER_ID')
        except DCOSAuthenticationException:
            raise
        except:
            msg = 'Unable to get the cluster_id of the cluster.'
            logger.exception(msg)

    # send args call to segment.io
    with ThreadPoolExecutor(max_workers=2) as reporting_executor:
        analytics.segment_track_cli(reporting_executor, config, cluster_id)

        # the call to retrieve cluster_id must happen before we run the
        # subcommand so that if you have auth enabled we don't ask for
        # user/pass multiple times (with the text being out of order)
        # before we can cache the auth token
        if command in subcommand.default_subcommands():
            sc = SubcommandMain(command, args['<args>'])
        else:
            executable = subcommand.command_executables(command)
            sc = subcommand.SubcommandProcess(executable, command,
                                              args['<args>'])

        exitcode, err = sc.run_and_capture()

        if err:
            analytics.track_err(reporting_executor, exitcode, err, config,
                                cluster_id)

        return exitcode