cloudyr / googleComputeEngineR

An R interface to the Google Cloud Compute API, for launching virtual machines

Home Page:https://cloudyr.github.io/googleComputeEngineR/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Modification in default network url

herambgadgil opened this issue · comments

The current gce_vm() function fetches and appends the project and network parameters as follows

gce_get_network <- function(network,
                            project = gce_get_global_project()) {
  url <- sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s",
                 project, network)
  # compute.networks.get
  f <- gar_api_generator(url, "GET", data_parse_function = function(x) x)
  f()
 
}

But having global/networks/ is not necessarily true in all GCP setups. My organization has it setup as this - https://www.googleapis.com/compute/v1/projects/**project-name**/regions/us-central1/subnetworks/local-us-central1-net01

Because of this, I am never able to setup a VM instance through the function. Below is the error snippet that I get

2020-12-14 23:47:06> Creating template VM
i 2020-12-14 23:47:07 > Request Status Code:  404
Error: API returned: The resource 'projects/**project-name**/global/networks/regions/us-central1/subnetworks/local-us-central1-net01' was not found

Solution
Modification in the source code to remove /global/networks/ as default keywords. Users can put them as and when required.

gce_get_network <- function(network,
                            project = gce_get_global_project()) {
  url <- sprintf("https://www.googleapis.com/compute/v1/projects/%s/%s", project, network)
  # compute.networks.get
  f <- gar_api_generator(url, "GET", data_parse_function = function(x) x)
  f()
 
}

https://github.com/cloudyr/googleComputeEngineR/blob/master/R/networks.R