def get_resource_config()

in tools/genconfig/genconfig.py [0:0]


def get_resource_config(pstr, project, urls):
  """Returns a list of DM resource configurations.

  The algorithm for this is:

  1) Load resource properties into YAML
  2) Move name into the resource name field
  3) Map kind to DM type
  4) Scrub properties of output-only fields from the API
  5) Fill resource properties with scrubbed properties

  Args:
    pstr: the string blob of resource properties to be converted to resource
      config.
    project: the project of the associated resource, used for parameterization

  Returns:
    A list of valid DM configuration for this resource and any auxiliary
    resources.
  """

  for url in urls:
    if url.startswith('projects'):
      url = "https://www.googleapis.com/compute/v1/" + url
    m = SELF_LINK_PATTERN.match(url)
    name = m.group(5)
    ref = "$(ref." + name + ".selfLink)"
    pstr = pstr.replace(url, ref)
  pstr = pstr.replace(project, "{{env['project']}}")
  props = yaml.load(pstr)

  return get_resource_config_from_dict(props)