better deletion of resources, templates

This commit is contained in:
hong-revo 2018-05-07 06:37:36 +10:00
Родитель 8517488205
Коммит 1e2ad8a961
3 изменённых файлов: 49 добавлений и 10 удалений

Просмотреть файл

@ -38,7 +38,7 @@ public=list(
{
# TODO: allow wait until complete
private$rg_op(http_verb="DELETE")
message("Resource group '", self$name, "' will be deleted. This operation may take some time to complete.")
message("Deleting resource group '", self$name, "'. This operation may take some time to complete.")
private$is_valid <- FALSE
invisible(NULL)
},

Просмотреть файл

@ -82,11 +82,18 @@ public=list(
invisible(NULL)
},
delete=function()
delete=function(wait=FALSE)
{
# TODO: allow wait until complete
private$res_op(http_verb="DELETE")
message("Resource '", self$name, "' will be deleted. This operation may take some time to complete.")
message("Deleting resource '", file.path(self$type, self$name), "'")
status <- 200
while(wait && status < 300)
{
res <- private$res_op(http_status_handler="pass")
status <- httr::status_code(res)
}
private$is_valid <- FALSE
invisible(NULL)
},

Просмотреть файл

@ -32,16 +32,26 @@ public=list(
NULL
},
cancel=function(free_resources=FALSE)
{
message("Cancelling deployment of template '", self$name, "'")
if(free_resources)
private$free_resources()
else message("Associated resources have not been freed.")
private$tpl_op("cancel", http_verb="POST")
private$is_valid <- FALSE
invisible(NULL)
},
delete=function(free_resources=FALSE)
{
message("Deleting template '", self$name, "'")
if(free_resources)
{
message("Deleting resources for template '", self$name, "'...'")
# TODO: recursively delete all resources for this template
}
private$free_resources()
else message("Associated resources have not been freed.")
private$tpl_op(http_verb="DELETE")
message("Template '", self$name, "' deleted")
private$is_valid <- FALSE
invisible(NULL)
},
@ -113,6 +123,28 @@ private=list(
validate_object_names(names(properties), required_names, optional_names)
},
free_resources=function()
{
free_dependency <- function(id)
{
res <- try(az_resource$new(self$token, self$subscription, id=id), silent=TRUE)
if(!inherits(res, "try-error"))
res$delete(wait=TRUE)
}
# assumptions:
# - this is a flattened 2-level list of dependencies, not an actual tree
# - earlier dependencies depend on later ones
# - later entries in list will have been deleted in earlier entries
deps <- self$properties$dependencies
for(d in deps)
{
free_dependency(d$id)
for(d2 in d$dependsOn)
free_dependency(d2$id)
}
},
tpl_op=function(op="", ...)
{
op <- file.path("resourcegroups", self$resource_group, "providers/Microsoft.Resources/deployments", self$name, op)