Merge pull request #77 from brnleehng/feature/batch
Added Azure Batch ARM functions
This commit is contained in:
Коммит
53111440e7
|
@ -6,15 +6,18 @@ S3method(summary,azureScriptActionHistory)
|
|||
export(AzureListRG)
|
||||
export(as.azureActiveContext)
|
||||
export(azureAuthenticate)
|
||||
export(azureBatchGetKey)
|
||||
export(azureBlobCD)
|
||||
export(azureBlobFind)
|
||||
export(azureBlobLS)
|
||||
export(azureCancelDeploy)
|
||||
export(azureCheckToken)
|
||||
export(azureCreateBatchAccount)
|
||||
export(azureCreateHDI)
|
||||
export(azureCreateResourceGroup)
|
||||
export(azureCreateStorageAccount)
|
||||
export(azureCreateStorageContainer)
|
||||
export(azureDeleteBatchAccount)
|
||||
export(azureDeleteBlob)
|
||||
export(azureDeleteDeploy)
|
||||
export(azureDeleteHDI)
|
||||
|
@ -30,6 +33,7 @@ export(azureHDIConf)
|
|||
export(azureHiveSQL)
|
||||
export(azureHiveStatus)
|
||||
export(azureListAllResources)
|
||||
export(azureListBatchAccounts)
|
||||
export(azureListHDI)
|
||||
export(azureListRG)
|
||||
export(azureListSA)
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
#' List batch accounts.
|
||||
#'
|
||||
#' @inheritParams setAzureContext
|
||||
#' @inheritParams azureAuthenticate
|
||||
#' @inheritParams azureBatchGetKey
|
||||
|
||||
#' @family Batch account functions
|
||||
#' @export
|
||||
azureListBatchAccounts <- function(azureActiveContext, resourceGroup, subscriptionID,
|
||||
verbose = FALSE) {
|
||||
assert_that(is.azureActiveContext(azureActiveContext))
|
||||
azureCheckToken(azureActiveContext)
|
||||
azToken <- azureActiveContext$Token
|
||||
|
||||
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
||||
assert_that(is_subscription_id(subscriptionID))
|
||||
verbosity <- set_verbosity(verbose)
|
||||
|
||||
type_batch <- "Microsoft.Batch/batchAccounts"
|
||||
|
||||
z <- if(missing(resourceGroup)) {
|
||||
azureListAllResources(azureActiveContext, type = type_batch)
|
||||
} else {
|
||||
azureListAllResources(azureActiveContext, type = type_batch, resourceGroup = resourceGroup, subscriptionID = subscriptionID)
|
||||
}
|
||||
rownames(z) <- NULL
|
||||
z$batchAccount <- extractStorageAccount(z$id)
|
||||
z
|
||||
}
|
||||
|
||||
#' Create an Azure Batch Account.
|
||||
#'
|
||||
#' @inheritParams setAzureContext
|
||||
#' @inheritParams azureAuthenticate
|
||||
#' @inheritParams azureBatchGetKey
|
||||
#' @param location A string for the location to create batch account
|
||||
#' @param asynchronous If TRUE, submits asynchronous request to Azure. Otherwise waits until batch account is created.
|
||||
#' @family Batch account functions
|
||||
#' @export
|
||||
azureCreateBatchAccount <- function(azureActiveContext, batchAccount,
|
||||
location = "northeurope",
|
||||
resourceGroup, subscriptionID,
|
||||
asynchronous = FALSE, verbose = FALSE) {
|
||||
assert_that(is.azureActiveContext(azureActiveContext))
|
||||
azureCheckToken(azureActiveContext)
|
||||
azToken <- azureActiveContext$Token
|
||||
|
||||
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
||||
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
||||
assert_that(is_resource_group(resourceGroup))
|
||||
assert_that(is_subscription_id(subscriptionID))
|
||||
assert_that(is_storage_account(batchAccount))
|
||||
|
||||
body <- paste0('{
|
||||
"location":"', location, '",
|
||||
}'
|
||||
)
|
||||
|
||||
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
||||
"/resourceGroups/", resourceGroup, "/providers/Microsoft.Batch/batchAccounts/",
|
||||
batchAccount, "?api-version=2017-05-01")
|
||||
|
||||
r <- call_azure_sm(azureActiveContext, uri = uri, body = body,
|
||||
verb = "PUT", verbose = verbose)
|
||||
|
||||
if (status_code(r) == 409) {
|
||||
message("409: Conflict : Account already exists with the same name")
|
||||
return(TRUE)
|
||||
}
|
||||
|
||||
if (status_code(r) == 200) {
|
||||
message("Account already exists with the same properties")
|
||||
}
|
||||
stopWithAzureError(r)
|
||||
|
||||
rl <- content(r, "text", encoding = "UTF-8")
|
||||
azureActiveContext$batchAccount <- batchAccount
|
||||
azureActiveContext$resourceGroup <- resourceGroup
|
||||
message("Create request Accepted. It can take a few moments to provision the batch account")
|
||||
|
||||
if (!asynchronous) {
|
||||
wait_for_azure(
|
||||
batchAccount %in% azureListBatchAccounts(azureActiveContext, subscriptionID = subscriptionID)$name
|
||||
)
|
||||
}
|
||||
TRUE
|
||||
}
|
||||
|
||||
#' Delete an Azure Batch Account.
|
||||
#'
|
||||
#' @inheritParams setAzureContext
|
||||
#' @inheritParams azureAuthenticate
|
||||
#' @inheritParams azureBatchGetKey
|
||||
|
||||
#' @family Batch account functions
|
||||
#' @export
|
||||
azureDeleteBatchAccount <- function(azureActiveContext, batchAccount,
|
||||
resourceGroup, subscriptionID, verbose = FALSE) {
|
||||
assert_that(is.azureActiveContext(azureActiveContext))
|
||||
azureCheckToken(azureActiveContext)
|
||||
azToken <- azureActiveContext$Token
|
||||
|
||||
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
||||
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
||||
|
||||
assert_that(is_storage_account(batchAccount))
|
||||
assert_that(is_resource_group(resourceGroup))
|
||||
assert_that(is_subscription_id(subscriptionID))
|
||||
|
||||
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
||||
"/resourceGroups/", resourceGroup, "/providers/Microsoft.Batch/batchAccounts/",
|
||||
batchAccount, "?api-version=2017-05-01")
|
||||
|
||||
r <- call_azure_sm(azureActiveContext, uri = uri,
|
||||
verb = "DELETE", verbose = verbose)
|
||||
|
||||
if (status_code(r) == 204) {
|
||||
warning("Batch Account not found")
|
||||
return(FALSE)
|
||||
}
|
||||
if (status_code(r) != 200) stopWithAzureError(r)
|
||||
|
||||
azureActiveContext$batchAccount <- batchAccount
|
||||
azureActiveContext$resourceGroup <- resourceGroup
|
||||
TRUE
|
||||
}
|
||||
|
||||
#' Get the Batch Keys for Specified Batch Account.
|
||||
#'
|
||||
#' @inheritParams setAzureContext
|
||||
#' @inheritParams azureAuthenticate
|
||||
#'
|
||||
#' @family Batch account functions
|
||||
#' @export
|
||||
azureBatchGetKey <- function(azureActiveContext, batchAccount,
|
||||
resourceGroup, subscriptionID, verbose = FALSE) {
|
||||
assert_that(is.azureActiveContext(azureActiveContext))
|
||||
azureCheckToken(azureActiveContext)
|
||||
azToken <- azureActiveContext$Token
|
||||
|
||||
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
||||
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
||||
|
||||
assert_that(is_storage_account(batchAccount))
|
||||
assert_that(is_resource_group(resourceGroup))
|
||||
assert_that(is_subscription_id(subscriptionID))
|
||||
|
||||
message("Fetching Batch Key..")
|
||||
|
||||
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
||||
"/resourceGroups/", resourceGroup,
|
||||
"/providers/Microsoft.Batch/batchAccounts/", batchAccount,
|
||||
"/listkeys?api-version=2017-05-01")
|
||||
|
||||
r <- call_azure_sm(azureActiveContext, uri = uri,
|
||||
verb = "POST", verbose = verbose)
|
||||
stopWithAzureError(r)
|
||||
|
||||
rl <- content(r, "text", encoding = "UTF-8")
|
||||
df <- fromJSON(rl)
|
||||
azureActiveContext$batchAccount <- batchAccount
|
||||
azureActiveContext$resourceGroup <- resourceGroup
|
||||
azureActiveContext$batchKey <- df$primary
|
||||
|
||||
return(azureActiveContext$batchKey)
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/AzureBatch.R
|
||||
\name{azureBatchGetKey}
|
||||
\alias{azureBatchGetKey}
|
||||
\title{Get the Batch Keys for Specified Batch Account.}
|
||||
\usage{
|
||||
azureBatchGetKey(azureActiveContext, batchAccount, resourceGroup,
|
||||
subscriptionID, verbose = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{azureActiveContext}{A container used for caching variables used by `AzureSMR`}
|
||||
|
||||
\item{resourceGroup}{Name of the resource group}
|
||||
|
||||
\item{subscriptionID}{Subscription ID. This is obtained automatically by [azureAuthenticate()] when only a single subscriptionID is available via Active Directory}
|
||||
|
||||
\item{verbose}{Print Tracing information (Default False)}
|
||||
}
|
||||
\description{
|
||||
Get the Batch Keys for Specified Batch Account.
|
||||
}
|
||||
\seealso{
|
||||
Other Batch account functions: \code{\link{azureCreateBatchAccount}},
|
||||
\code{\link{azureDeleteBatchAccount}},
|
||||
\code{\link{azureListBatchAccounts}}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/AzureBatch.R
|
||||
\name{azureCreateBatchAccount}
|
||||
\alias{azureCreateBatchAccount}
|
||||
\title{Create an Azure Batch Account.}
|
||||
\usage{
|
||||
azureCreateBatchAccount(azureActiveContext, batchAccount,
|
||||
location = "northeurope", resourceGroup, subscriptionID,
|
||||
asynchronous = FALSE, verbose = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{azureActiveContext}{A container used for caching variables used by `AzureSMR`}
|
||||
|
||||
\item{location}{A string for the location to create batch account}
|
||||
|
||||
\item{resourceGroup}{Name of the resource group}
|
||||
|
||||
\item{subscriptionID}{Subscription ID. This is obtained automatically by [azureAuthenticate()] when only a single subscriptionID is available via Active Directory}
|
||||
|
||||
\item{asynchronous}{If TRUE, submits asynchronous request to Azure. Otherwise waits until batch account is created.}
|
||||
|
||||
\item{verbose}{Print Tracing information (Default False)}
|
||||
}
|
||||
\description{
|
||||
Create an Azure Batch Account.
|
||||
}
|
||||
\seealso{
|
||||
Other Batch account functions: \code{\link{azureBatchGetKey}},
|
||||
\code{\link{azureDeleteBatchAccount}},
|
||||
\code{\link{azureListBatchAccounts}}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/AzureBatch.R
|
||||
\name{azureDeleteBatchAccount}
|
||||
\alias{azureDeleteBatchAccount}
|
||||
\title{Delete an Azure Batch Account.}
|
||||
\usage{
|
||||
azureDeleteBatchAccount(azureActiveContext, batchAccount, resourceGroup,
|
||||
subscriptionID, verbose = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{azureActiveContext}{A container used for caching variables used by `AzureSMR`}
|
||||
|
||||
\item{resourceGroup}{Name of the resource group}
|
||||
|
||||
\item{subscriptionID}{Subscription ID. This is obtained automatically by [azureAuthenticate()] when only a single subscriptionID is available via Active Directory}
|
||||
|
||||
\item{verbose}{Print Tracing information (Default False)}
|
||||
}
|
||||
\description{
|
||||
Delete an Azure Batch Account.
|
||||
}
|
||||
\seealso{
|
||||
Other Batch account functions: \code{\link{azureBatchGetKey}},
|
||||
\code{\link{azureCreateBatchAccount}},
|
||||
\code{\link{azureListBatchAccounts}}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/AzureBatch.R
|
||||
\name{azureListBatchAccounts}
|
||||
\alias{azureListBatchAccounts}
|
||||
\title{List batch accounts.}
|
||||
\usage{
|
||||
azureListBatchAccounts(azureActiveContext, resourceGroup, subscriptionID,
|
||||
verbose = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{azureActiveContext}{A container used for caching variables used by `AzureSMR`}
|
||||
|
||||
\item{resourceGroup}{Name of the resource group}
|
||||
|
||||
\item{subscriptionID}{Subscription ID. This is obtained automatically by [azureAuthenticate()] when only a single subscriptionID is available via Active Directory}
|
||||
|
||||
\item{verbose}{Print Tracing information (Default False)}
|
||||
}
|
||||
\description{
|
||||
List batch accounts.
|
||||
}
|
||||
\seealso{
|
||||
Other Batch account functions: \code{\link{azureBatchGetKey}},
|
||||
\code{\link{azureCreateBatchAccount}},
|
||||
\code{\link{azureDeleteBatchAccount}}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче