Skip to content

Commit

Permalink
Autogenerate user_data if cloud_config template set.
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Oct 21, 2014
1 parent a93f499 commit 317297f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions R/droplet-actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
#' droplet.
#' @param user_data (character) Gets passed to the droplet at boot time. Not
#' all regions have this enabled, and is not used by all images.
#' @param cloud_config (character) Specify the name of a cloud config template
#' to automatically generate \code{\link{cloud_config}} and submit in
#' user metadata. Setting this is best practice: the built-in templates
#' use security best practices (disabling root log-in, security autoupdates)
#' to make it harder to hack your droplet.
#' @param wait If \code{TRUE}, wait until droplet has been initialised and
#' is ready for use.
#' @param ... Additional options passed down to \code{\link[httr]{POST}}
Expand All @@ -49,6 +54,7 @@ droplet_create <- function(name = random_name(),
ipv6 = getOption("do_ipv6", NULL),
private_networking = getOption("do_private_networking", NULL),
user_data = NULL,
cloud_config = NULL,
wait = TRUE,
...) {

Expand All @@ -59,6 +65,17 @@ droplet_create <- function(name = random_name(),
call. = FALSE)
}

# Generate user_data if cloud_config specified
if (!is.null(cloud_config)) {
if (!is.null(user_data)) {
stop("You may only specify one of cloud_config and user_data.",
call. = FALSE)
}

config <- cloud_config(cloud_config, ssh_keys)
user_data <- yaml::as.yaml(config)
}

res <- do_POST('droplets',
body = list(
name = unbox(name),
Expand Down
8 changes: 7 additions & 1 deletion man/droplet_create.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ droplet_create(name = random_name(), size = getOption("do_size", "512mb"),
ssh_keys = getOption("do_ssh_keys", NULL),
backups = getOption("do_backups", NULL), ipv6 = getOption("do_ipv6",
NULL), private_networking = getOption("do_private_networking", NULL),
user_data = NULL, wait = TRUE, ...)
user_data = NULL, cloud_config = NULL, wait = TRUE, ...)
}
\arguments{
\item{name}{(character) Name of the droplet. Default: picks a random name
Expand Down Expand Up @@ -47,6 +47,12 @@ networking is currently only available in certain regions. Default: FALSE}
\item{user_data}{(character) Gets passed to the droplet at boot time. Not
all regions have this enabled, and is not used by all images.}
\item{cloud_config}{(character) Specify the name of a cloud config template
to automatically generate \code{\link{cloud_config}} and submit in
user metadata. Setting this is best practice: the built-in templates
use security best practices (disabling root log-in, security autoupdates)
to make it harder to hack your droplet.}
\item{wait}{If \code{TRUE}, wait until droplet has been initialised and
is ready for use.}
Expand Down

0 comments on commit 317297f

Please sign in to comment.