コード例 #1
0
def run():
    # Parse arguments
    parser = build_parser()
    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    if not vars(args).get('func'):
        parser.print_help()
    else:
        # Add custom plugin dir to import path
        custom_plugins_dir = vars(args).get('custom_plugins_dir')
        if custom_plugins_dir:
            sys.path.append(custom_plugins_dir)

        # Resolve default ip if the --ip argument hasn't been specified
        if not vars(args).get('ip'):
            # Returns None if an error has occurred
            args.ip = host.resolve_default_ip()
            if not args.ip:
                return
        else:
            args.local_connection = False

        args.cli_parameters = get_cli_parameters(args)
        args.custom_settings = get_custom_settings(args)
        logging_setup.configure_logging(args)

        is_completed_without_error = args.func(args)
        if not is_completed_without_error:
            exit(1)
コード例 #2
0
def run():
    # Parse arguments
    parser = build_parser()
    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    if not vars(args).get('func'):
        parser.print_help()
    else:
        # Add custom plugin dir to import path
        custom_plugins_dir = vars(args).get('custom_plugins_dir')
        if custom_plugins_dir:
            sys.path.append(custom_plugins_dir)

        # Resolve default ip if the --ip argument hasn't been specified
        if not vars(args).get('ip'):
            # Returns None if an error has occurred
            args.ip = host.resolve_default_ip()
            if not args.ip:
                return
        else:
            args.local_connection = False

        args.cli_parameters = get_cli_parameters(args)
        args.custom_settings = get_custom_settings(args)
        logging_setup.configure_logging(args)

        is_completed_without_error = args.func(args)
        if not is_completed_without_error:
            exit(1)
コード例 #3
0
    def test_resolve_from_addr_range(self):
        is_listening_mock = MagicMock(return_value=True)
        with patch('conductr_cli.host.is_listening', is_listening_mock):
            result = host.resolve_default_ip()
            self.assertEqual(result, '192.168.10.1')

        is_listening_mock.assert_called_with(
            ipaddress.ip_address('192.168.10.1'), 9005)
コード例 #4
0
    def test_resolve_from_docker(self):
        is_listening_mock = MagicMock(return_value=False)
        vm_type_mock = MagicMock(return_value='vm_type')
        with patch('conductr_cli.host.is_listening', is_listening_mock), \
                patch('conductr_cli.docker.vm_type', vm_type_mock):
            result = host.resolve_default_ip()
            self.assertEqual(result, '127.0.0.1')

        is_listening_mock.assert_called_with(
            ipaddress.ip_address('192.168.10.1'), 9005)
コード例 #5
0
ファイル: test_host.py プロジェクト: fsat/conductr-cli
    def test_resolve(self):
        getenv_mock = MagicMock(return_value="test")
        vm_type_mock = MagicMock(return_value="vm_type")
        resolve_ip_by_vm_type_mock = MagicMock(return_value="resolve_result")
        with patch("os.getenv", getenv_mock), patch("conductr_cli.docker.vm_type", vm_type_mock), patch(
            "conductr_cli.host.resolve_ip_by_vm_type", resolve_ip_by_vm_type_mock
        ):
            result = host.resolve_default_ip()
            self.assertEqual(result, "test")

        getenv_mock.assert_called_with("CONDUCTR_IP", "resolve_result")
        vm_type_mock.assert_called_with()
        resolve_ip_by_vm_type_mock.assert_called_with("vm_type")
コード例 #6
0
def get_cli_parameters(args):
    parameters = ['']
    arg = vars(args).get('scheme')
    if not args.dcos_mode and arg and arg != DEFAULT_SCHEME:
        parameters.append('--scheme {}'.format(args.scheme))
    arg = vars(args).get('host')
    if not args.dcos_mode and arg and arg != host.resolve_default_host():
        parameters.append('--host {}'.format(args.host))
    arg = vars(args).get('ip')
    if not args.dcos_mode and arg and arg != host.resolve_default_ip():
        parameters.append('--ip {}'.format(args.ip))
    arg = vars(args).get('port', int(DEFAULT_PORT))
    if not args.dcos_mode and arg and arg != int(DEFAULT_PORT):
        parameters.append('--port {}'.format(args.port))
    arg = vars(args).get('base_path', DEFAULT_BASE_PATH)
    if not args.dcos_mode and arg and arg != DEFAULT_BASE_PATH:
        parameters.append('--base-path {}'.format(args.base_path))
    arg = vars(args).get('api_version', DEFAULT_API_VERSION)
    if arg and arg != DEFAULT_API_VERSION:
        parameters.append('--api-version {}'.format(args.api_version))
    return ' '.join(parameters)
コード例 #7
0
ファイル: conduct_main.py プロジェクト: fsat/conductr-cli
def get_cli_parameters(args):
    parameters = ['']
    arg = vars(args).get('scheme')
    if not args.dcos_mode and arg and arg != DEFAULT_SCHEME:
        parameters.append('--scheme {}'.format(args.scheme))
    arg = vars(args).get('host')
    if not args.dcos_mode and arg and arg != host.resolve_default_host():
        parameters.append('--host {}'.format(args.host))
    arg = vars(args).get('ip')
    if not args.dcos_mode and arg and arg != host.resolve_default_ip():
        parameters.append('--ip {}'.format(args.ip))
    arg = vars(args).get('port', int(DEFAULT_PORT))
    if not args.dcos_mode and arg and arg != int(DEFAULT_PORT):
        parameters.append('--port {}'.format(args.port))
    arg = vars(args).get('base_path', DEFAULT_BASE_PATH)
    if not args.dcos_mode and arg and arg != DEFAULT_BASE_PATH:
        parameters.append('--base-path {}'.format(args.base_path))
    arg = vars(args).get('api_version', DEFAULT_API_VERSION)
    if arg and arg != DEFAULT_API_VERSION:
        parameters.append('--api-version {}'.format(args.api_version))
    return ' '.join(parameters)
コード例 #8
0
def resolve_host_ip():
    global host_ip
    if not host_ip:
        host_ip = host.resolve_default_ip()
    return host_ip
コード例 #9
0
def resolve_host_ip():
    global host_ip
    if not host_ip:
        host_ip = host.resolve_default_ip()
    return host_ip