Beispiel #1
0
def endpoint_profile_remove(hostname, orchestrator_id, workload_id,
                            endpoint_id, profile_names):
    """
    Remove a list of profiles from the endpoint profile list.

    The hostname, orchestrator_id, workload_id, and endpoint_id are all optional
    parameters used to determine which endpoint is being targeted.
    The more parameters used, the faster the endpoint query will be. The
    query must be specific enough to match a single endpoint or it will fail.

    The profile list may not contain duplicate entries, invalid profile names,
    or profiles that are not already in the containers list.

    If no profile is specified, nothing happens.

    :param hostname: The host that the targeted endpoint resides on.
    :param orchestrator_id: The orchestrator that created the targeted endpoint.
    :param workload_id: The ID of workload which created the targeted endpoint.
    :param endpoint_id: The endpoint ID of the targeted endpoint.
    :param profile_names: The list of profile names to remove from the targeted
                          endpoint.
    :return: None
    """
    # Validate the profile list.
    validate_profile_list(profile_names)

    if not profile_names:
        print_paragraph("No profile specified.")
    else:
        try:
            client.remove_profiles_from_endpoint(profile_names,
                                                 hostname=hostname,
                                                 orchestrator_id=orchestrator_id,
                                                 workload_id=workload_id,
                                                 endpoint_id=endpoint_id)
            print_paragraph("Profile(s) %s removed." %
                            (",".join(profile_names)))
        except KeyError:
            print "Failed to remove profiles from endpoint.\n"
            print_paragraph("Endpoint could not be found.\n")
            sys.exit(1)
        except ProfileNotInEndpoint, e:
            print_paragraph("Profile %s is not in endpoint profile "
                            "list." % e.profile_name)
        except MultipleEndpointsMatch:
            print "More than 1 endpoint matches the provided criteria. " \
                  "Please provide additional parameters to refine the search."
            sys.exit(1)
Beispiel #2
0
def endpoint_profile_remove(hostname, orchestrator_id, workload_id,
                            endpoint_id, profile_names):
    """
    Remove a list of profiles from the endpoint profile list.

    The hostname, orchestrator_id, workload_id, and endpoint_id are all optional
    parameters used to determine which endpoint is being targeted.
    The more parameters used, the faster the endpoint query will be. The
    query must be specific enough to match a single endpoint or it will fail.

    The profile list may not contain duplicate entries, invalid profile names,
    or profiles that are not already in the containers list.

    :param hostname: The host that the targeted endpoint resides on.
    :param orchestrator_id: The orchestrator that created the targeted endpoint.
    :param workload_id: The ID of workload which created the targeted endpoint.
    :param endpoint_id: The endpoint ID of the targeted endpoint.
    :param profile_names: The list of profile names to remove from the targeted
                          endpoint.
    :return: None
    """
    # Validate the profile list.
    validate_profile_list(profile_names)

    try:
        client.remove_profiles_from_endpoint(profile_names,
                                             hostname=hostname,
                                             orchestrator_id=orchestrator_id,
                                             workload_id=workload_id,
                                             endpoint_id=endpoint_id)
        print_paragraph("Profiles %s removed from %s." %
                        (",".join(profile_names), endpoint_id))
    except KeyError:
        print "Failed to remove profiles from endpoint.\n"
        print_paragraph("Endpoint %s is unknown to Calico.\n" % endpoint_id)
        sys.exit(1)
    except ProfileNotInEndpoint, e:
        print_paragraph("Profile %s is not in endpoint profile "
                        "list." % e.profile_name)