def testGetAPI(self):
        a = registry.GetAPI('compute', 'v1')
        self.assertEqual('compute', a.name)
        self.assertEqual('v1', a.version)

        a = registry.GetAPI('compute')
        self.assertTrue(a.is_default)

        with self.assertRaises(registry.UnknownAPIError):
            registry.GetAPI('junk')
        with self.assertRaises(registry.UnknownAPIVersionError):
            registry.GetAPI('compute', 'junk')
示例#2
0
 def Run(self, args):
   api = registry.GetAPI(args.api, api_version=args.api_version)
   messages_module = api.GetMessagesModule()
   messages = [
       m for m in messages_module.__dict__.values()
       if issubclass(type(m), type) and issubclass(m, _messages.Message)]
   return [{'name': m.__name__} for m in messages]
 def Run(self, args):
     api = registry.GetAPI(args.api, api_version=args.api_version)
     try:
         message = getattr(api.GetMessagesModule(), args.message)
         return arg_utils.GetRecursiveMessageSpec(message)
     except AttributeError:
         raise exceptions.InvalidArgumentException(
             'message', 'Message [{}] does not exist for API [{}]'.format(
                 args.message, args.api))
 def Run(self, args):
   api = registry.GetAPI(args.api, api_version=args.api_version)
   try:
     message = getattr(api.GetMessagesModule(), args.message)
   except AttributeError:
     raise exceptions.InvalidArgumentException(
         'message', 'Message [{}] does not exist for API [{} {}]'.format(
             args.message, args.api, api.version))
   message_spec = arg_utils.GetRecursiveMessageSpec(message)
   export.GenerateExportSchemas(
       api, args.message, message_spec, args.directory)
示例#5
0
def GenerateMappingFileTemplate(api_name, message_type, skip_fields=None,
                                file_path=None, api_version=None,
                                known_mappings=None):
  """Create a stub Apitools To KRM mapping file for specified Apitools message.

  Args:
      api_name: string, The api containing the message.
      message_type: string, The message to generate mapping for.
      skip_fields: [string], A list of field paths to exclude from mapping file.
      file_path: string, path of destination file. If None, will write result to
        stdout.
      api_version: Version of the api to retrieve the message type from. If None
        will use default API version.
      known_mappings: {string: object}, Fields to pre-initialize in the mapping.

  Returns:
    The path to the created file or file contents if no path specified.
  Raises:
    InvalidDataError, if api or message are invalid.
  """
  try:
    api_obj = registry.GetAPI(api_name, api_version)
    all_messages = api_obj.GetMessagesModule()
    message = getattr(all_messages, message_type)
    mapping_object = _BuildYamlMappingTemplateFromMessage(message)

    if skip_fields:  # Remove Skipped/Unmapped message fields
      for path in skip_fields:
        file_parsers.DeleteItemInDict(mapping_object, path)

    if known_mappings:
      for path, value in six.iteritems(known_mappings):
        file_parsers.FindOrSetItemInDict(mapping_object, path, set_value=value)

    yaml.convert_to_block_text(mapping_object)
    output = yaml.dump(mapping_object, round_trip=True)

    if file_path:
      files.WriteFileAtomically(file_path, output)
      output = file_path

    return output
  except (AttributeError, registry.Error) as ae:
    raise InvalidDataError('Error retrieving message [{message}] from '
                           'API [{api}/{ver}] :: {error}'.format(
                               message=message_type,
                               api=api_name,
                               ver=api_version or 'default',
                               error=ae))
示例#6
0
 def Run(self, args):
     return registry.GetAPI(args.api_name, api_version=args.api_version)