forked from cloudyr/aws.ec2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes cloudyr#42 Add create template, remove template, describe template
- Loading branch information
1 parent
62e3244
commit ae5fe56
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#' @title Create Launch Template | ||
#' @description Create Instance Template, templates can be sent to run_instance() | ||
#' @param name A name for the launch template, String, Minchar:3, Max:128 | ||
#' @param desc A description for the first version of the template. | ||
#' @param templateData A named list of template data. See reference | ||
#' @param clientToken Identifier to ensure idempotency. | ||
#' @template dots | ||
#' @example | ||
#' \dontrun{ | ||
#' create_template(tempName = "testTemplate", tempDesc = "newDesc", | ||
#' templateData = list(ImageId = "ami-1a2b3c4d", InstanceType = "t1.micro"), | ||
#' clientToken = "123") | ||
#' describe_template(tempName = "testTemplate") | ||
#' delete_template(tempDesc = "testTemplate") | ||
#' } | ||
#' @keywords template | ||
#' @references | ||
#' <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateLaunchTemplate.html> | ||
#' <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RequestLaunchTemplateData.html> | ||
#' @export | ||
|
||
|
||
create_template <- | ||
function( | ||
tempName = NULL, | ||
tempDesc = NULL, | ||
templateData = NULL, | ||
clientToken = NULL, | ||
... | ||
|
||
) { | ||
query <- list(Action = "CreateLaunchTemplate") | ||
if(!is.null(tempName)) { | ||
names(tempName) <- "LaunchTemplateName" | ||
query <- c(query, tempName) | ||
} | ||
if(!is.null(tempDesc)) { | ||
names(tempDesc) <- "VersionDescription" | ||
query <- c(query, tempDesc) | ||
} | ||
if(!is.null(clientToken)) { | ||
names(clientToken) <- "ClientToken" | ||
query <- c(query, clientToken) | ||
} | ||
if(!is.null(templateData)) { | ||
names(templateData) <- paste0("LaunchTemplateData.", names(templateData)) | ||
query <- c(query, templateData) | ||
} | ||
|
||
r <- ec2HTTP(query = query, ...) | ||
return(unname(lapply(r, function(z) { | ||
structure(flatten_list(z), class = "ec2_template") | ||
}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#' @title Delete Launch Template | ||
#' @description Delete Instance Template | ||
#' @param name The name of the launch template to delete. | ||
#' @param tempId The ID of the launch template to delete. Must specify | ||
#' name or ID. | ||
#' @template dots | ||
#' @example | ||
#' \dontrun{ | ||
#' create_template(tempName = "testTemplate", tempDesc = "newDesc", | ||
#' templateData = list(ImageId = "ami-1a2b3c4d", InstanceType = "t1.micro"), | ||
#' clientToken = "123") | ||
#' describe_template(tempName = "testTemplate") | ||
#' delete_template(tempDesc = "testTemplate") | ||
#' } | ||
#' @keywords template | ||
#' @references | ||
#' <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateLaunchTemplate.html> | ||
#' <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RequestLaunchTemplateData.html> | ||
#' @export | ||
|
||
delete_template <- function( | ||
tempName = NULL, | ||
tempId = NULL, | ||
... | ||
) { | ||
query <- list(Action = "DeleteLaunchTemplate") | ||
|
||
if(!is.null(tempId)) { | ||
names(tempId) <- "LaunchTemplateId" | ||
query <- c(query, tempId) | ||
} | ||
else if(!is.null(tempName)) { | ||
names(tempName) <- "LaunchTemplateName" | ||
query <- c(query, tempName) | ||
} else { | ||
stop("delete_template wasn't passed a name or ID") | ||
} | ||
|
||
r <- ec2HTTP(query = query, ...) | ||
return(unname(lapply(r, function(z) { | ||
structure(flatten_list(z), class = "ec2_template_del") | ||
}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#' @title Describe Launch Template | ||
#' @description Describe Instance Template | ||
#' @param tempName The name of the launch template to describe | ||
#' @param tempId The ID of the launch template to delete. Must specify | ||
#' name or ID. | ||
#' @param filter One or more filters | ||
#' @template dots | ||
#' @example | ||
#' \dontrun{ | ||
#' create_template(tempName = "testTemplate", tempDesc = "newDesc", | ||
#' templateData = list(ImageId = "ami-1a2b3c4d", InstanceType = "t1.micro"), | ||
#' clientToken = "123") | ||
#' describe_template(tempName = "testTemplate") | ||
#' delete_template(tempDesc = "testTemplate") | ||
#' } | ||
#' @keywords template | ||
#' @references | ||
#' <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateLaunchTemplate.html> | ||
#' <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RequestLaunchTemplateData.html> | ||
#' <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_Filter.html> | ||
#' @export | ||
|
||
describe_template <- | ||
function( | ||
tempName = NULL, | ||
tempId = NULL, | ||
filter = NULL, | ||
... | ||
){ | ||
|
||
query <- list(Action = "DescribeLaunchTemplates") | ||
|
||
if(!is.null(tempId)) { | ||
names(tempId) <- "LaunchTemplateId.1" | ||
query <- c(query, tempId) | ||
} | ||
else if(!is.null(tempName)) { | ||
names(tempName) <- "LaunchTemplateName.1" | ||
query <- c(query, tempName) | ||
} | ||
else { | ||
stop("describe_template wasn't passed a name/Id") | ||
} | ||
if(!is.null(filter)) { | ||
names(filter) <- "Filter.1" | ||
query <- c(query, filter) | ||
} | ||
|
||
r <- ec2HTTP(query = query, ...) | ||
return(unname(lapply(r, function(z) { | ||
structure(flatten_list(z), class = "ec2_template_desc") | ||
}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
context("Templates") | ||
|
||
test_that("delete/describe stops if Id/Name isn't passed", { | ||
expect_error(delete_template(), "delete_template wasn't passed") | ||
expect_error(describe_template(), "describe_template wasn't passed") | ||
}) |