Accept self_link property value in the "name" parameter
It would be convenient to pass (and parse) the self_link property to get to the name without having to construct the latter.
It just requires stripping the endpoint URL (and version) to obtain the path. In other words, name (in objects or requests) could accept a fully-qualified url.
E.g. for a cluster
property self_link: "https://container.googleapis.com/v1/projects/myproject/locations/mylocation/clusters/mycluster"
-> translate to path/name to use as parameter: "projects/myproject/locations/mylocation/clusters/mycluster"
This is useful to refresh the status of a cluster or nodepool. There is currently no property on an existing object that can be used as-is to get a new updated instance of it.
See below my code to ensure (and wait) a cluster is ready to perform an operation. It unfortunately requires to hardcode that endpoint URL as I could not find it anywhere + do string stripping
ENDPOINT_HOST = 'https://container.googleapis.com/v1/'
def get_path(object):
return object.self_link.split(ENDPOINT_HOST)[1]
@backoff.on_predicate(backoff.constant, interval=30, max_time=600)
def await_cluster_ready(cluster: container.Cluster):
cluster = client.get_cluster(name=get_path(cluster))
return cluster.status == cluster.Status.RUNNING
Ideally, this should work client.get_cluster(name=cluster.self_link)
If agreeable, the name parameter could be renamed name_or_link. This would apply across the library and possibly for parent parameter too.
cooling down from our oslo
I'm going to transfer this issue to the google-cloud-python repository as we are preparing to move the code for google-cloud-container to that repository in the next 1-2 weeks.