示例#1
0
def ValidateMeasurementsFlag(options_list):
    """Verifies correct usage of the measurements configuration flag.

  The user of the flag must provide at least one option. All provided options
  must be valid. The NONE option cannot be combined with other options.

  Args:
    options_list: A list of strings parsed from the provided value for the
      flag.

  Returns:
    True if the list of options provided as the value for the flag meets all
    the documented requirements.

  Raises:
    flags.ValidationError: If the list of options provided as the value for
      the flag does not meet the documented requirements.
  """
    for option in options_list:
        if option not in MEASUREMENTS_ALL:
            raise flags.ValidationError('%s: Invalid value for --%s' %
                                        (option, MEASUREMENTS_FLAG_NAME))
        if option == MEASUREMENTS_NONE and len(options_list) != 1:
            raise flags.ValidationError(
                '%s: Cannot combine with other --%s options' %
                (option, MEASUREMENTS_FLAG_NAME))
    return True
示例#2
0
def ValidateVmMetadataFlag(options_list):
    """Verifies correct usage of the vm metadata flag.

  All provided options must be in the form of key:value.

  Args:
    options_list: A list of strings parsed from the provided value for the
      flag.

  Returns:
    True if the list of options provided as the value for the flag meets
    requirements.

  Raises:
    flags.ValidationError: If the list of options provided as the value for
      the flag does not meet requirements.
  """
    for option in options_list:
        if ':' not in option[1:-1]:
            raise flags.ValidationError(
                '"%s" not in expected key:value format' % option)
    return True