diff --git a/R/az_resource.R b/R/az_resource.R index 83773fa..dc34a27 100644 --- a/R/az_resource.R +++ b/R/az_resource.R @@ -16,6 +16,7 @@ public=list( sku=NULL, tags=NULL, token=NULL, + is_synced=FALSE, # constructor overloads: # 1. deploy resource: resgroup, {provider, path}|type, name, ... @@ -73,6 +74,13 @@ public=list( invisible(private$api_version) }, + sync_fields=function(force=FALSE) + { + if(self$is_synced && !force) + return(invisible(NULL)) + self$initialize(self$token, self$subscription, id=self$id) + }, + delete=function() { # TODO: allow wait until complete @@ -95,7 +103,7 @@ private=list( api_version=NULL, # initialise identifier fields from multiple ways of constructing object - init_id_fields=function(resource_group, provider, path, type, name, id, parms) + init_id_fields=function(resource_group, provider, path, type, name, id, parms=list()) { # if this is supplied, fill in everything else from it if(!is_empty(parms)) @@ -131,7 +139,9 @@ private=list( init_from_host=function() { - private$res_op() + res <- private$res_op() + self$is_synced <- attr(res, "status") < 202 + res }, init_and_deploy=function(...) @@ -144,8 +154,12 @@ private=list( properties <- modifyList(properties, list(name=self$name, type=self$type)) private$validate_deploy_parms(properties) - + self$is_synced <- TRUE private$res_op(body=properties, encode="json", http_verb="PUT") + + # allow time for provisioning, then get properties + Sys.sleep(1) + private$init_from_host() }, validate_deploy_parms=function(parms) diff --git a/R/call_azure_rm.R b/R/call_azure_rm.R index 007f82d..fa23edf 100644 --- a/R/call_azure_rm.R +++ b/R/call_azure_rm.R @@ -37,7 +37,11 @@ call_azure_rm <- function(token, subscription, operation, ..., catch <- get(paste0(catch, "_for_status"), getNamespace("httr")) catch(res, paste0("complete Resource Manager operation. Message:\n", sub("\\.$", "", arm_error_message(res)))) - httr::content(res) + cont <- httr::content(res) + if(is.null(cont)) + cont <- list() + attr(cont, "status") <- httr::status_code(res) + cont } else res }