in tools/genconfig/genconfig.py [0:0]
def get_describe_cmd(url, project):
r"""Builds a gcloud describe command given a resource URL.
gcloud command will look like:
gcloud compute instances describe instance-name \
--zone us-central1-f --format yaml
NOTE: only supports compute resources right now.
Args:
url: the URL for this resource.
project: the project of this resource.
Returns:
The gcloud command to be used to describe the resource in YAML, or empty
if no command.
Raises:
Exception: if URL is bad.
"""
m = SELF_LINK_PATTERN.match(url)
if m:
service = m.group(1)
unused_project = m.group(2)
location = m.group(3)
collection = m.group(4)
name = m.group(5)
else:
# May be a truncated selfLink, allowed for compute.
m = COMPUTE_SELF_LINK_PATTERN.match(url)
if not m:
raise Exception('Resource URL must be selfLink: ' + url)
# Assumed truncated selfLink is compute only.
service = 'compute/v1'
location = m.group(2)
collection = m.group(3)
name = m.group(4)
if service != 'compute/v1':
raise Exception(''.join(['!!! Found resource that is unsupported: ', url]))
# Autoscalers have no associated gcloud command for describing.
if collection == 'autoscalers':
print(''.join(['!!! Found autoscaler resource ',
name,
', will attempt to generate config from its associated ',
'instanceGroupManager (NOTE: you must include the '
'associated instanceGroupManager in the resource list).']),
file=sys.stderr)
return ''
return ' '.join(['gcloud compute',
get_gcloud_command_group(collection),
'describe',
name,
get_location_flag(location, url, collection),
'--format yaml',
'--project', project])