Skip to content

Commit

Permalink
support subnetworks #154
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEdmondson1234 committed Feb 1, 2020
1 parent 2556720 commit c1ebae6
Show file tree
Hide file tree
Showing 65 changed files with 594 additions and 258 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ Suggests:
License: MIT + file LICENSE
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export(gce_make_firewall_rule)
export(gce_make_firewall_webports)
export(gce_make_image_source_url)
export(gce_make_machinetype_url)
export(gce_make_network)
export(gce_metadata_env)
export(gce_pull_registry)
export(gce_push_registry)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Fix being able to restart cluster VMs (#149)
* Remove `gce_list_registry` as its not working
* Add `gce_vm_deletion_protection` to help add or remove deletion protection for VMs
* Support subnetworks (#154) and expose making your own networks via `gce_make_network`

# 0.3.0

Expand Down
26 changes: 18 additions & 8 deletions R/networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ gce_get_external_ip <- function(instance,
#' @param network Name of network resource
#' @param externalIP An external IP you have created previously, leave NULL to have one assigned or "none" for none
#' @param project Project ID for this request
#' @param subnetwork A subnetwork name if its exists
#'
#' You need to provide accessConfig explicitly if you want an ephemeral IP assigned, see \code{https://cloud.google.com/compute/docs/vm-ip-addresses}
#'
#' @return A Network object
#' @keywords internal
gce_make_network <- function(name,
network = "default",
#' @export
gce_make_network <- function(network = "default",
name = NULL,
subnetwork = NULL,
externalIP = NULL,
reservedIp = NULL,
project = gce_get_global_project()){

make_ac <- function(externalIP, name){
Expand All @@ -44,8 +47,7 @@ gce_make_network <- function(name,
list(
list(
natIP = jsonlite::unbox(externalIP),
type = jsonlite::unbox("ONE_TO_ONE_NAT"),
name = jsonlite::unbox(name)
type = jsonlite::unbox("ONE_TO_ONE_NAT")
)
)
}
Expand All @@ -54,16 +56,22 @@ gce_make_network <- function(name,

structure(
list(
list(
rmNullObs(list(
network = jsonlite::unbox(net$selfLink),
subnetwork = jsonlite::unbox(subnetwork),
name = name,
accessConfigs = make_ac(externalIP, name)
)
))
),
class = c("gce_networkInterface", "list")
)

}

is.gce_networkInterface <- function(x){
inherits(x, "gce_networkInterface")
}

#' Returns the specified network.
#'
#'
Expand Down Expand Up @@ -122,7 +130,9 @@ gce_list_networks <- function(filter = NULL,
pageToken = pageToken)
pars <- rmNullObs(pars)

f <- gar_api_generator(url, "GET", pars_args = pars, data_parse_function = function(x) x)
f <- gar_api_generator(url, "GET",
pars_args = pars,
data_parse_function = function(x) x$items)
f()

}
17 changes: 8 additions & 9 deletions R/vms.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ gce_vm_delete_one <- function(instance,
#' @param image Name of the image resource to return
#' @param image_family Name of the image family to search for
#' @param disk_source Specifies a valid URL to an existing Persistent Disk resource.
#' @param network The name of the network interface
#' @param network A network object created by \link{gce_make_network}
#' @param externalIP An external IP you have previously reserved, leave NULL to have one assigned or \code{"none"} for no external access.
#' @param minCpuPlatform Specify a minimum CPU platform as per \href{these Google docs}{https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform}
#' @param project Project ID for this request
Expand All @@ -243,12 +243,12 @@ gce_vm_delete_one <- function(instance,
gce_vm_create <- function(name,
predefined_type = "f1-micro",
image_project = "debian-cloud",
image_family = "debian-8",
image_family = "debian-9",
cpus = NULL,
memory = NULL,
image = "",
disk_source = NULL,
network = "default",
network = gce_make_network("default"),
externalIP = NULL,
canIpForward = NULL,
description = NULL,
Expand All @@ -266,7 +266,8 @@ gce_vm_create <- function(name,
acceleratorType = "nvidia-tesla-p4") {

assert_that(
is.string(name)
is.string(name),
is.gce_networkInterface(network)
)

## missing only works within function its called from
Expand Down Expand Up @@ -323,7 +324,8 @@ gce_vm_create <- function(name,
if(nchar(image_family) > 0){

## creation from image_family
source_image_url <- gce_make_image_source_url(image_project, family = image_family)
source_image_url <- gce_make_image_source_url(image_project,
family = image_family)
} else {
## creation from image
stopifnot(nchar(image) > 0)
Expand Down Expand Up @@ -367,10 +369,7 @@ gce_vm_create <- function(name,
zone = zone)

## make network interface
networkInterfaces <- gce_make_network(name = paste0(name, "-ip"),
network = network,
externalIP = externalIP,
project = project)
networkInterfaces <- network

## make serviceAccounts
if(is.null(serviceAccounts)){
Expand Down
20 changes: 15 additions & 5 deletions man/AttachedDisk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions man/Disk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions man/Instance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/Metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions man/as.cluster.gce_instance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/docker_build.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/docker_cmd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions man/docker_cmd.gce_instance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions man/docker_run.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions man/gce_attach_disk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/gce_check_gpu.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/gce_delete_disk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c1ebae6

Please sign in to comment.