From 8ab8f992f33c134f92209141875a375b508afe0e Mon Sep 17 00:00:00 2001 From: Marica Antonacci Date: Tue, 16 Oct 2018 13:04:09 +0200 Subject: [PATCH] Added flags for keepLastAttempt, maxProvidersRetry --- orchent.go | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/orchent.go b/orchent.go index 6cc9a60..86983ab 100644 --- a/orchent.go +++ b/orchent.go @@ -18,7 +18,7 @@ import ( "strings" ) -const OrchentVersion string = "1.2.0" +const OrchentVersion string = "1.2.1" var ( app = kingpin.New("orchent", "The orchestrator client. \n \nPlease either store your access token in 'ORCHENT_TOKEN' or set the account to use with oidc-agent in the 'ORCHENT_AGENT_ACCOUNT' and the socket of the oidc-agent in the 'OIDC_SOCK' environment variable: \n export ORCHENT_TOKEN= \n OR \n export OIDC_SOCK= (usually this is already exported) \n export ORCHENT_AGENT_ACCOUNT= \nIf you need to specify the file containing the trusted root CAs use the 'ORCHENT_CAFILE' environment variable: \n export ORCHENT_CAFILE=\n \n").Version(OrchentVersion) @@ -32,16 +32,20 @@ var ( showDep = app.Command("depshow", "show a specific deployment") showDepUuid = showDep.Arg("uuid", "the uuid of the deployment to display").Required().String() - createDep = app.Command("depcreate", "create a new deployment") - createDepCallback = createDep.Flag("callback", "the callback url").Default("").String() - createDepTemplate = createDep.Arg("template", "the tosca template file").Required().File() - createDepParameter = createDep.Arg("parameter", "the parameter to set (json object)").Required().String() - - updateDep = app.Command("depupdate", "update the given deployment") - updateDepCallback = updateDep.Flag("callback", "the callback url").Default("").String() - updateDepUuid = updateDep.Arg("uuid", "the uuid of the deployment to update").Required().String() - updateDepTemplate = updateDep.Arg("template", "the tosca template file").Required().File() - updateDepParameter = updateDep.Arg("parameter", "the parameter to set (json object)").Required().String() + createDep = app.Command("depcreate", "create a new deployment") + createDepCallback = createDep.Flag("callback", "the callback url").Default("").String() + createDepMaxProvidersRetry = createDep.Flag("maxProvidersRetry", "Maximum number of cloud providers to be used in case of failure (Default: UNBOUNDED).").Uint8() + createDepKeepLastAttempt = createDep.Flag("keepLastAttempt", "In case of failure, keep the resources allocated in the last try (Default: true).").Default("true").Enum("true", "false") + createDepTemplate = createDep.Arg("template", "the tosca template file").Required().File() + createDepParameter = createDep.Arg("parameter", "the parameter to set (json object)").Required().String() + + updateDep = app.Command("depupdate", "update the given deployment") + updateDepCallback = updateDep.Flag("callback", "the callback url").Default("").String() + updateDepMaxProvidersRetry = updateDep.Flag("maxProvidersRetry", "Maximum number of cloud providers to be used in case of failure (Default: UNBOUNDED).").Uint8() + updateDepKeepLastAttempt = updateDep.Flag("keepLastAttempt", "In case of failure, keep the resources allocated in the last try (Default: true).").Default("true").Enum("true", "false") + updateDepUuid = updateDep.Arg("uuid", "the uuid of the deployment to update").Required().String() + updateDepTemplate = updateDep.Arg("template", "the tosca template file").Required().File() + updateDepParameter = updateDep.Arg("parameter", "the parameter to set (json object)").Required().String() depTemplate = app.Command("deptemplate", "show the template of the given deployment") templateDepUuid = depTemplate.Arg("uuid", "the uuid of the deployment to get the template").Required().String() @@ -177,9 +181,11 @@ type OrchentResourceList struct { } type OrchentCreateRequest struct { - Template string `json:"template"` - Parameters map[string]interface{} `json:"parameters"` - Callback string `json:"callback,omitempty"` + Template string `json:"template"` + Parameters map[string]interface{} `json:"parameters"` + Callback string `json:"callback,omitempty"` + MaxProvidersRetry uint8 `json:"maxProvidersRetry,omitempty"` + KeepLastAttempt string `json:"keepLastAttempt,omitempty"` } func (depList OrchentDeploymentList) String() string { @@ -371,7 +377,8 @@ func receive_and_print_deploymentlist(complete *sling.Sling, before int, after i } } -func deployment_create_update(templateFile *os.File, parameter string, callback string, depUuid *string, base *sling.Sling) { +func deployment_create_update(templateFile *os.File, parameter string, callback string, maxProvidersRetry uint8, keepLastAttempt string, depUuid *string, base *sling.Sling) { + var parameterMap map[string]interface{} paramErr := json.Unmarshal([]byte(parameter), ¶meterMap) if paramErr != nil { @@ -396,6 +403,8 @@ func deployment_create_update(templateFile *os.File, parameter string, callback Template: template, Parameters: parameterMap, Callback: callback, + MaxProvidersRetry: maxProvidersRetry, + KeepLastAttempt: keepLastAttempt, } deployment := new(OrchentDeployment) orchentError := new(OrchentError) @@ -700,13 +709,13 @@ func main() { case createDep.FullCommand(): baseUrl := get_base_url() base := base_connection(baseUrl) - deployment_create_update(*createDepTemplate, *createDepParameter, *createDepCallback, nil, base) + deployment_create_update(*createDepTemplate, *createDepParameter, *createDepCallback, *createDepMaxProvidersRetry, *createDepKeepLastAttempt, nil, base) case updateDep.FullCommand(): baseUrl := get_base_url() base := base_connection(baseUrl) uuid := try_alias_uuid(*updateDepUuid, aliases) - deployment_create_update(*updateDepTemplate, *updateDepParameter, *updateDepCallback, &uuid, base) + deployment_create_update(*updateDepTemplate, *updateDepParameter, *updateDepCallback, *updateDepMaxProvidersRetry, *updateDepKeepLastAttempt, &uuid, base) case depTemplate.FullCommand(): baseUrl := get_base_url()