def UpdateContextEndpointEntries(context, http, api_client_default='v1'): """Updates context to set API enpoints; requires context['http'] be set.""" context['project'] = properties.VALUES.core.project.Get(required=True) context['http'] = http api_client = core_apis.ResolveVersion('compute', api_client_default) compute = core_apis.GetClientInstance('compute', api_client, http) context['api-version'] = api_client context['compute'] = compute context['resources'] = resources.REGISTRY.CloneAndSwitchAPIs(compute) # Turn the endpoint into just the host. # eg. https://www.googleapis.com/compute/v1 -> https://www.googleapis.com compute_url = properties.VALUES.api_endpoint_overrides.compute.Get() u_endpoint = urlparse.urlparse(compute_url or 'https://www.googleapis.com') api_host = '%s://%s' % (u_endpoint.scheme, u_endpoint.netloc) context['batch-url'] = urlparse.urljoin(api_host, 'batch') # Construct cloud user accounts client. try: # TODO(user): User a separate API override from compute. clouduseraccounts = core_apis.GetClientInstance( 'clouduseraccounts', api_client, http) except core_apis.UnknownVersionError: # Throw an error here once clouseuseraccounts has a v1 API version. clouduseraccounts = core_apis.GetClientInstance( 'clouduseraccounts', 'beta', http) context['clouduseraccounts'] = clouduseraccounts context['clouduseraccounts-resources'] = ( resources.REGISTRY.CloneAndSwitchAPIs(clouduseraccounts))
def __init__(self, api_default_version='v1', no_http=False): self._api_version = core_apis.ResolveVersion( self._API_NAME, api_default_version) self._client = core_apis.GetClientInstance( self._API_NAME, self._api_version, no_http=no_http) # Turn the endpoint into just the host. # eg. https://www.googleapis.com/compute/v1 -> https://www.googleapis.com endpoint_url = core_apis.GetEffectiveApiEndpoint( self._API_NAME, self._api_version) self._batch_url = GetBatchUrl(endpoint_url)