Skip to content

Commit

Permalink
support minCPUplatform #112
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEdmondson1234 committed Feb 13, 2019
1 parent 320f9b4 commit b6dc442
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 73 deletions.
6 changes: 2 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

S3method(as.cluster,gce_instance)
S3method(as.container,character)
S3method(as.container,container)
S3method(as.container,list)
Expand All @@ -17,6 +16,7 @@ S3method(print,gce_instanceList)
S3method(print,gce_region_operation)
S3method(print,gce_zone_operation)
S3method(print,machineTypeList)
export(as.cluster.gce_instance)
export(as.container)
export(container_logs)
export(container_rm)
Expand All @@ -33,11 +33,9 @@ export(gce_auth)
export(gce_check_container)
export(gce_check_gpu)
export(gce_check_ssh)
export(gce_check_zone_op)
export(gce_delete_disk)
export(gce_delete_firewall_rule)
export(gce_delete_op)
export(gce_delete_zone_op)
export(gce_extract_projectzone)
export(gce_future_install_packages)
export(gce_get_disk)
Expand All @@ -55,7 +53,6 @@ export(gce_get_network)
export(gce_get_op)
export(gce_get_project)
export(gce_get_zone)
export(gce_get_zone_op)
export(gce_global_project)
export(gce_global_zone)
export(gce_list_disks)
Expand Down Expand Up @@ -84,6 +81,7 @@ export(gce_rstudio_password)
export(gce_schedule_docker)
export(gce_set_machinetype)
export(gce_set_metadata)
export(gce_set_mincpuplatform)
export(gce_shiny_addapp)
export(gce_shiny_listapps)
export(gce_shiny_logs)
Expand Down
4 changes: 4 additions & 0 deletions R/instances_admin.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ as.gce_instance <- function(x,
} else {
stop("Unrecognised instance class - ", class(x))
}

ins
}

#' Check if is gce_instance
Expand Down Expand Up @@ -202,6 +204,7 @@ Instance <- function(name = NULL,
scheduling = NULL,
serviceAccounts = NULL,
tags = NULL,
minCpuPlatform = NULL,
guestAccelerators = NULL) {

structure(list(canIpForward = canIpForward,
Expand All @@ -210,6 +213,7 @@ Instance <- function(name = NULL,
metadata = Metadata(metadata),
name = name,
disks = disks,
minCpuPlatform = minCpuPlatform,
networkInterfaces = networkInterfaces,
scheduling = scheduling,
serviceAccounts = serviceAccounts,
Expand Down
22 changes: 22 additions & 0 deletions R/min-cpu-platform.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#' Set a minCPU platform on a stopped instance
#'
#' @param instance The (stopped) instance to set a minimum CPU platform upon
#' @param minCpuPlatform The platform to set
#'
#' @export
#' @importFrom googleAuthR gar_api_generator
gce_set_mincpuplatform <- function(instance, minCpuPlatform){
instance <- as.gce_instance(instance)
instance_pz <- gce_extract_projectzone(instance)

assert_that(is.string(minCpuPlatform))

f <- gar_api_generator(
sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s/setMinCpuPlatform",
instance_pz$project, instance_pz$zone, instance$name),
"POST",
data_parse_function = function(x) x
)

f(the_body = list(minCpuPlatform = minCpuPlatform))
}
7 changes: 7 additions & 0 deletions R/vms.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ gce_vm_delete <- function(instance,
#' @param disk_source Specifies a valid URL to an existing Persistent Disk resource.
#' @param network The name of the network interface
#' @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
#' @param zone The name of the zone for this request
#' @param dry_run whether to just create the request JSON
Expand Down Expand Up @@ -248,6 +249,7 @@ gce_vm_create <- function(name,
scheduling = NULL,
serviceAccounts = NULL,
tags = NULL,
minCpuPlatform = NULL,
project = gce_get_global_project(),
zone = gce_get_global_zone(),
dry_run = FALSE,
Expand Down Expand Up @@ -367,6 +369,10 @@ gce_vm_create <- function(name,
if(is.null(serviceAccounts)){
serviceAccounts = gce_make_serviceaccounts()
}

if(!is.null(minCpuPlatform)){
assert_that(is.string(minCpuPlatform))
}

## make instance object
the_instance <- Instance(canIpForward = canIpForward,
Expand All @@ -375,6 +381,7 @@ gce_vm_create <- function(name,
metadata = metadata,
disks = init_disk,
name = name,
minCpuPlatform = minCpuPlatform,
networkInterfaces = networkInterfaces,
scheduling = scheduling,
serviceAccounts = serviceAccounts,
Expand Down
3 changes: 2 additions & 1 deletion man/Instance.Rd

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

2 changes: 1 addition & 1 deletion man/as.cluster.gce_instance.Rd

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

32 changes: 0 additions & 32 deletions man/gce_delete_zone_op.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/gce_get_op.Rd

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

30 changes: 0 additions & 30 deletions man/gce_get_zone_op.Rd

This file was deleted.

8 changes: 8 additions & 0 deletions man/gce_set_metadata.Rd

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

16 changes: 16 additions & 0 deletions man/gce_set_mincpuplatform.Rd

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

1 change: 1 addition & 0 deletions man/gce_vm.Rd

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

4 changes: 3 additions & 1 deletion man/gce_vm_create.Rd

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

3 changes: 0 additions & 3 deletions man/gce_wait.Rd

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

0 comments on commit b6dc442

Please sign in to comment.