示例#1
0
    def test_endpoint_profile_append(self, profiles, m_append_profiles_called):
        """
        Test appending profiles on an endpoint calls correct functions
        """
        with patch("calico_ctl.endpoint.client", autospec=True) as m_client:
            hostname = "m_hostname"
            orchestrator_id = "m_orchestrator_id"
            workload_id = "m_workload_id"
            endpoint_id = "m_endpoint_id"
            endpoint.endpoint_profile_append(hostname, orchestrator_id,
                                             workload_id, endpoint_id,
                                             profiles)

            self.assertEqual(m_client.append_profiles_to_endpoint.called,
                             m_append_profiles_called)
            if m_append_profiles_called:
                m_client.append_profiles_to_endpoint.assert_called_once_with(
                    profiles,
                    hostname=hostname,
                    orchestrator_id=orchestrator_id,
                    workload_id=workload_id,
                    endpoint_id=endpoint_id)
    def test_endpoint_profile_append(self, profiles, m_append_profiles_called):
        """
        Test appending profiles on an endpoint calls correct functions
        """
        with patch("calico_ctl.endpoint.client", autospec=True) as m_client:
            hostname = "m_hostname"
            orchestrator_id = "m_orchestrator_id"
            workload_id = "m_workload_id"
            endpoint_id = "m_endpoint_id"
            endpoint.endpoint_profile_append(hostname,
                                             orchestrator_id,
                                             workload_id,
                                             endpoint_id,
                                             profiles)

            self.assertEqual(m_client.append_profiles_to_endpoint.called,
                             m_append_profiles_called)
            if m_append_profiles_called:
                m_client.append_profiles_to_endpoint.assert_called_once_with(
                                               profiles,
                                               hostname=hostname,
                                               orchestrator_id=orchestrator_id,
                                               workload_id=workload_id,
                                               endpoint_id=endpoint_id)
示例#3
0
def container(arguments):
    """
    Main dispatcher for container commands. Calls the corresponding helper
    function.

    :param arguments: A dictionary of arguments already processed through
    this file's docstring with docopt
    :return: None
    """
    validate_arguments(arguments)

    try:
        if arguments.get("ip"):
            if arguments.get("add"):
                container_ip_add(arguments.get("<CONTAINER>"),
                                 arguments.get("<IP>"),
                                 arguments.get("--interface"))
            elif arguments.get("remove"):
                container_ip_remove(arguments.get("<CONTAINER>"),
                                    arguments.get("<IP>"),
                                    arguments.get("--interface"))
            else:
                if arguments.get("add"):
                    container_add(arguments.get("<CONTAINER>"),
                                  arguments.get("<IP>"),
                                  arguments.get("--interface"))
                if arguments.get("remove"):
                    container_remove(arguments.get("<CONTAINER>"))
        elif arguments.get("endpoint"):
            orchestrator_id, workload_id = \
                                  lookup_workload(arguments.get("<CONTAINER>"))
            endpoint.endpoint_show(hostname, orchestrator_id, workload_id,
                                   None, True)
        elif arguments.get("profile"):
            orchestrator_id, workload_id = \
                                  lookup_workload(arguments.get("<CONTAINER>"))
            if arguments.get("append"):
                endpoint.endpoint_profile_append(hostname, orchestrator_id,
                                                 workload_id, None,
                                                 arguments['<PROFILES>'])
            elif arguments.get("remove"):
                endpoint.endpoint_profile_remove(hostname, orchestrator_id,
                                                 workload_id, None,
                                                 arguments['<PROFILES>'])
            elif arguments.get("set"):
                endpoint.endpoint_profile_set(hostname, orchestrator_id,
                                              workload_id, None,
                                              arguments['<PROFILES>'])
        else:
            if arguments.get("add"):
                container_add(arguments.get("<CONTAINER>"),
                              arguments.get("<IP>"),
                              arguments.get("--interface"))
            if arguments.get("remove"):
                container_remove(arguments.get("<CONTAINER>"))
    except ConnectionError as e:
        # We hit a "Permission denied error (13) if the docker daemon
        # does not have sudo permissions
        if permission_denied_error(e):
            print_paragraph("Unable to run command.  Re-run the "
                            "command as root, or configure the docker "
                            "group to run with sudo privileges (see docker "
                            "installation guide for details).")
        else:
            print_paragraph("Unable to run docker commands. Is the docker "
                            "daemon running?")
        sys.exit(1)
示例#4
0
def container(arguments):
    """
    Main dispatcher for container commands. Calls the corresponding helper
    function.

    :param arguments: A dictionary of arguments already processed through
    this file's docstring with docopt
    :return: None
    """
    validate_arguments(arguments)

    try:
        workload_id = None
        if "<CONTAINER>" in arguments:
            container_id = arguments.get("<CONTAINER>")
            if container_id.startswith("/") and os.path.exists(container_id):
                # The ID is a path. Don't do any docker lookups
                workload_id = escape_etcd(container_id)
                orchestrator_id = NAMESPACE_ORCHESTRATOR_ID
            else:
                info = get_container_info_or_exit(container_id)
                workload_id = info["Id"]
                orchestrator_id = DOCKER_ORCHESTRATOR_ID

        if arguments.get("ip"):
            if arguments.get("add"):
                container_ip_add(arguments.get("<CONTAINER>"),
                                 arguments.get("<IP>"),
                                 arguments.get("--interface"))
            elif arguments.get("remove"):
                container_ip_remove(arguments.get("<CONTAINER>"),
                                    arguments.get("<IP>"),
                                    arguments.get("--interface"))
            else:
                if arguments.get("add"):
                    container_add(arguments.get("<CONTAINER>"),
                                  arguments.get("<IP>"),
                                  arguments.get("--interface"))
                if arguments.get("remove"):
                    container_remove(arguments.get("<CONTAINER>"))
        elif arguments.get("endpoint"):
            endpoint.endpoint_show(hostname,
                                   orchestrator_id,
                                   workload_id,
                                   None,
                                   True)
        elif arguments.get("profile"):
            if arguments.get("append"):
                endpoint.endpoint_profile_append(hostname,
                                                 orchestrator_id,
                                                 workload_id,
                                                 None,
                                                 arguments['<PROFILES>'])
            elif arguments.get("remove"):
                endpoint.endpoint_profile_remove(hostname,
                                                 orchestrator_id,
                                                 workload_id,
                                                 None,
                                                 arguments['<PROFILES>'])
            elif arguments.get("set"):
                endpoint.endpoint_profile_set(hostname,
                                              orchestrator_id,
                                              workload_id,
                                              None,
                                              arguments['<PROFILES>'])
        else:
            if arguments.get("add"):
                container_add(arguments.get("<CONTAINER>"),
                              arguments.get("<IP>"),
                              arguments.get("--interface"))
            if arguments.get("remove"):
                container_remove(arguments.get("<CONTAINER>"))
    except ConnectionError as e:
        # We hit a "Permission denied error (13) if the docker daemon
        # does not have sudo permissions
        if permission_denied_error(e):
            print_paragraph("Unable to run command.  Re-run the "
                            "command as root, or configure the docker "
                            "group to run with sudo privileges (see docker "
                            "installation guide for details).")
        else:
            print_paragraph("Unable to run docker commands. Is the docker "
                            "daemon running?")
        sys.exit(1)
def container(arguments):
    """
    Main dispatcher for container commands. Calls the corresponding helper
    function.

    :param arguments: A dictionary of arguments already processed through
    this file's docstring with docopt
    :return: None
    """
    validate_arguments(arguments)

    try:
        if arguments.get("ip"):
            if arguments.get("add"):
                container_ip_add(arguments.get("<CONTAINER>"),
                                 arguments.get("<IP>"),
                                 arguments.get("--interface"))
            elif arguments.get("remove"):
                container_ip_remove(arguments.get("<CONTAINER>"),
                                    arguments.get("<IP>"),
                                    arguments.get("--interface"))
            else:
                if arguments.get("add"):
                    container_add(arguments.get("<CONTAINER>"),
                                  arguments.get("<IP>"),
                                  arguments.get("--interface"))
                if arguments.get("remove"):
                    container_remove(arguments.get("<CONTAINER>"))
        elif arguments.get("endpoint"):
            orchestrator_id, workload_id = \
                                  lookup_workload(arguments.get("<CONTAINER>"))
            endpoint.endpoint_show(hostname,
                                   orchestrator_id,
                                   workload_id,
                                   None,
                                   True)
        elif arguments.get("profile"):
            orchestrator_id, workload_id = \
                                  lookup_workload(arguments.get("<CONTAINER>"))
            if arguments.get("append"):
                endpoint.endpoint_profile_append(hostname,
                                                 orchestrator_id,
                                                 workload_id,
                                                 None,
                                                 arguments['<PROFILES>'])
            elif arguments.get("remove"):
                endpoint.endpoint_profile_remove(hostname,
                                                 orchestrator_id,
                                                 workload_id,
                                                 None,
                                                 arguments['<PROFILES>'])
            elif arguments.get("set"):
                endpoint.endpoint_profile_set(hostname,
                                              orchestrator_id,
                                              workload_id,
                                              None,
                                              arguments['<PROFILES>'])
        else:
            if arguments.get("add"):
                container_add(arguments.get("<CONTAINER>"),
                              arguments.get("<IP>"),
                              arguments.get("--interface"))
            if arguments.get("remove"):
                container_remove(arguments.get("<CONTAINER>"))
    except ConnectionError as e:
        # We hit a "Permission denied error (13) if the docker daemon
        # does not have sudo permissions
        if permission_denied_error(e):
            print_paragraph("Unable to run command.  Re-run the "
                            "command as root, or configure the docker "
                            "group to run with sudo privileges (see docker "
                            "installation guide for details).")
        else:
            print_paragraph("Unable to run docker commands. Is the docker "
                            "daemon running?")
        sys.exit(1)
示例#6
0
def container(arguments):
    """
    Main dispatcher for container commands. Calls the corresponding helper
    function.

    :param arguments: A dictionary of arguments already processed through
    this file's docstring with docopt
    :return: None
    """
    validate_arguments(arguments)

    try:
        workload_id = None
        if "<CONTAINER>" in arguments:
            container_id = arguments.get("<CONTAINER>")
            if container_id.startswith("/") and os.path.exists(container_id):
                # The ID is a path. Don't do any docker lookups
                workload_id = escape_etcd(container_id)
                orchestrator_id = NAMESPACE_ORCHESTRATOR_ID
            else:
                info = get_container_info_or_exit(container_id)
                workload_id = info["Id"]
                orchestrator_id = DOCKER_ORCHESTRATOR_ID

        if arguments.get("ip"):
            if arguments.get("add"):
                container_ip_add(arguments.get("<CONTAINER>"),
                                 arguments.get("<IP>"),
                                 arguments.get("--interface"))
            elif arguments.get("remove"):
                container_ip_remove(arguments.get("<CONTAINER>"),
                                    arguments.get("<IP>"),
                                    arguments.get("--interface"))
            else:
                if arguments.get("add"):
                    container_add(arguments.get("<CONTAINER>"),
                                  arguments.get("<IP>"),
                                  arguments.get("--interface"))
                if arguments.get("remove"):
                    container_remove(arguments.get("<CONTAINER>"))
        elif arguments.get("endpoint"):
            endpoint.endpoint_show(hostname, orchestrator_id, workload_id,
                                   None, True)
        elif arguments.get("profile"):
            if arguments.get("append"):
                endpoint.endpoint_profile_append(hostname, orchestrator_id,
                                                 workload_id, None,
                                                 arguments['<PROFILES>'])
            elif arguments.get("remove"):
                endpoint.endpoint_profile_remove(hostname, orchestrator_id,
                                                 workload_id, None,
                                                 arguments['<PROFILES>'])
            elif arguments.get("set"):
                endpoint.endpoint_profile_set(hostname, orchestrator_id,
                                              workload_id, None,
                                              arguments['<PROFILES>'])
        else:
            if arguments.get("add"):
                container_add(arguments.get("<CONTAINER>"),
                              arguments.get("<IP>"),
                              arguments.get("--interface"))
            if arguments.get("remove"):
                container_remove(arguments.get("<CONTAINER>"))
    except ConnectionError as e:
        # We hit a "Permission denied error (13) if the docker daemon
        # does not have sudo permissions
        if permission_denied_error(e):
            print_paragraph("Unable to run command.  Re-run the "
                            "command as root, or configure the docker "
                            "group to run with sudo privileges (see docker "
                            "installation guide for details).")
        else:
            print_paragraph("Unable to run docker commands. Is the docker "
                            "daemon running?")
        sys.exit(1)