Example #1
0
def check_relay_groups(ctx, param, value):
    """Previously (in Elixir) we treated --relay-groups as a single,
    optionally comma-delimited string to specify mulitple relay
    groups. We can now have repeating values instead. To stay as
    backward compatible as we can, we'll split any comma-delimited
    strings and create one flattened list.

    Thus, the following are all equivalent:

    * `-r foo -r bar -r baz`
    * `-r foo,bar,baz`
    * `-r foo -r bar,baz

    Additionally, if any relay groups are given, we'll verify they
    actually exist; if all are real, we return their API
    representations for use later. If any don't exist, we'll just stop
    all processing right here.
    """
    names = [g for gs in value for g in gs.split(",")]

    if names:
        groups = ctx.obj.api.relay_groups(*names)
        raise_if_not_all_present(names, groups,
                                 "The following relay groups do not exist: {}")
        return groups
    else:
        return []
Example #2
0
def check_groups_exist(ctx, param, value):
    "Ensure that all given names refer to existing relay groups."

    groups = ctx.obj.api.relay_groups(*value)
    raise_if_not_all_present(value, groups,
                             "The following relay groups do not exist: {}")
    return groups
Example #3
0
File: relay.py Project: pcn/cogctl
def validate_relay_groups(context, param, value):
    """
    Validates presence of relay groups by name.
    """
    if value == ():
        return value

    names = [name for names in value for name in names.split(",")]
    groups = context.obj.api.relay_groups(*names)
    raise_if_not_all_present(names, groups, "Relay Groups {} do not exist")
    return groups
Example #4
0
def check_bundles(ctx, param, value):
    """Use this to convert a number of bundle names into bundle objects.

    Raises an exception if all names do not refer to existing bundles.

    """
    bundles = ctx.obj.api.bundles(*value)
    raise_if_not_all_present(value,
                             bundles,
                             "The following bundles do not exist: {}")
    return bundles
Example #5
0
def check_relays(ctx, param, value):
    """Ensure that all given names refer to existing relays.

    Assumes that this can be an optional value.

    """
    if value:
        relays = ctx.obj.api.relays(*value)
        raise_if_not_all_present(value,
                                 relays,
                                 "The following relays do not exist: {}")
        return relays
Example #6
0
def check_bundles_in_group(ctx, param, value):
    """Ensure that all the given names refer to bundles that are already
    assigned to the relay group given in the argument "group" (which
    must have been validated before this runs).

    """
    if value:
        group = ctx.params["group"]
        bundles = [b for b in group["bundles"]
                   if b["name"] in value]
        raise_if_not_all_present(value, bundles,
                                 "The following bundles are not "
                                 "assigned to the group '" +
                                 group["name"] + "': {}")
        return bundles
Example #7
0
def check_relays_in_group(ctx, param, value):
    """Ensure that all the given names refer to relays that are already in
    the relay group given in the argument "group" (which must have
    been validated before this runs).

    """
    if value:
        group = ctx.params["group"]
        relays = [r for r in group["relays"]
                  if r["name"] in value]

        raise_if_not_all_present(value, relays,
                                 "The following relays are not members "
                                 "of the group '" + group["name"] + "': {}")
        return relays