Skip to content

Commit b034b7b

Browse files
Merge pull request #51 from indigo-dc/add_new_command
Add new command
2 parents ee99788 + 6de4e78 commit b034b7b

File tree

2 files changed

+106
-45
lines changed

2 files changed

+106
-45
lines changed

README.md

+20-11
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,26 @@ orchent helps you as much as possible:
2828
```
2929
usage: orchent [<flags>] <command> [<args> ...]
3030
31-
The orchestrator client. Please store your access token in the 'ORCHENT_TOKEN' environment
32-
variable: 'export ORCHENT_TOKEN=<your access token>'. If you need to specify the file
33-
containing the trusted root CAs use the 'ORCHENT_CAFILE' environment variable:
34-
'export ORCHENT_CAFILE=<path to file containing trusted CAs>'.
31+
The orchestrator client.
32+
33+
34+
35+
Please 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:
36+
37+
export ORCHENT_TOKEN=<your access token>
38+
OR
39+
export OIDC_SOCK=<path to the oidc-agent socket> (usually this is already exported)
40+
export ORCHENT_AGENT_ACCOUNT=<account to use>
41+
42+
If you need to specify the file containing the trusted root CAs use the 'ORCHENT_CAFILE' environment variable:
43+
44+
export ORCHENT_CAFILE=<path to file containing trusted CAs>
45+
3546
3647
Flags:
3748
--help Show context-sensitive help (also try --help-long and --help-man).
3849
--version Show application version.
39-
-u, --url=URL the base url of the orchestrator rest interface. Alternative the environment
40-
variable 'ORCHENT_URL' can be used: 'export ORCHENT_URL=<the_url>'
50+
-u, --url=URL the base url of the orchestrator rest interface. Alternative the environment variable 'ORCHENT_URL' can be used: 'export ORCHENT_URL=<the_url>'
4151
4252
Commands:
4353
help [<command>...]
@@ -46,7 +56,7 @@ Commands:
4656
depls [<flags>]
4757
list deployments
4858
49-
depshow <uuid>
59+
depshow [<flags>] <uuid>
5060
show a specific deployment
5161
5262
depcreate [<flags>] <template> <parameter>
@@ -68,11 +78,10 @@ Commands:
6878
show a specific resource of a given deployment
6979
7080
test
71-
test if the given url is pointing to an orchestrator, please use this to ensure
72-
there is no typo in the url.
73-
74-
81+
test if the given url is pointing to an orchestrator, please use this to ensure there is no typo in the url.
7582
83+
showconf
84+
list the endpoints used by the current orchestrator.
7685
```
7786

7887
Before using the orchestrator with orchent you need to export your IAM access token:

orchent.go

+86-34
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ var (
3030
lsDepBefore = lsDep.Flag("before", "filter the deployments, they must be created before the given date/time, the format is YYYYMMDDHHMM").Short('b').String()
3131
lsDepAfter = lsDep.Flag("after", "filter the deployments, they must be created after the given date/time, the format is YYYYMMDDHHMM").Short('a').String()
3232

33-
showDep = app.Command("depshow", "show a specific deployment")
34-
showDepUuid = showDep.Arg("uuid", "the uuid of the deployment to display").Required().String()
33+
showDep = app.Command("depshow", "show a specific deployment")
34+
showDepUuid = showDep.Arg("uuid", "the uuid of the deployment to display").Required().String()
35+
showDepVerbose = showDep.Flag("verbose", "enable verbose output").Default("false").Bool()
3536

3637
createDep = app.Command("depcreate", "create a new deployment")
3738
createDepCallback = createDep.Flag("callback", "the callback url").Default("").String()
@@ -62,6 +63,7 @@ var (
6263
showResResUuid = showRes.Arg("resource uuid", "the uuid of the resource to show").Required().String()
6364

6465
testUrl = app.Command("test", "test if the given url is pointing to an orchestrator, please use this to ensure there is no typo in the url.")
66+
getConfig = app.Command("showconf", "list the endpoints used by the current orchestrator.")
6567
)
6668

6769
type OrchentError struct {
@@ -129,17 +131,25 @@ func deployment_time_to_number(time string) int {
129131
return value
130132
}
131133

134+
type OrchentCreatedBy struct {
135+
Issuer string `json:"issuer"`
136+
Subject string `json:"subject"`
137+
}
138+
132139
type OrchentDeployment struct {
133-
Uuid string `json:"uuid"`
134-
CreationTime string `json:"creationTime"`
135-
UpdateTime string `json:"updateTime"`
136-
Status string `json:"status"`
137-
StatusReason string `json:"statusReason"`
138-
Task string `json:"task"`
139-
CloudProviderName string `json:"CloudProviderName"`
140-
Callback string `json:"callback"`
141-
Outputs map[string]interface{} `json:"outputs"`
142-
Links []OrchentLink `json:"links"`
140+
Uuid string `json:"uuid"`
141+
CreationTime string `json:"creationTime"`
142+
UpdateTime string `json:"updateTime"`
143+
CreatedBy OrchentCreatedBy `json:"createdBy"`
144+
PhysicalId string `json:"physicalId"`
145+
Status string `json:"status"`
146+
StatusReason string `json:"statusReason"`
147+
Task string `json:"task"`
148+
CloudProviderName string `json:"cloudProviderName"`
149+
CloudProviderEndpoint map[string]interface{} `json:"cloudProviderEndpoint"`
150+
Callback string `json:"callback"`
151+
Outputs map[string]interface{} `json:"outputs"`
152+
Links []OrchentLink `json:"links"`
143153
}
144154

145155
type OrchentResource struct {
@@ -198,42 +208,56 @@ func (depList OrchentDeploymentList) String() string {
198208
}
199209
output = output + fmt.Sprintln("\n")
200210
for _, dep := range depList.Deployments {
201-
output = output + deployment_to_string(dep, true)
211+
output = output + deployment_to_string(dep, 0)
202212
}
203213
return output
204214
}
205215

206216
func (dep OrchentDeployment) String() string {
207-
output := deployment_to_string(dep, false)
217+
output := deployment_to_string(dep, 1)
208218
return output
209219
}
210220

211-
func deployment_to_string(dep OrchentDeployment, short bool) string {
221+
func (createdby OrchentCreatedBy) String() string {
222+
output := ""
223+
output = output + fmt.Sprintf(" { issuer: %s;", createdby.Issuer)
224+
output = output + fmt.Sprintf(" subject: %s }", createdby.Subject)
225+
return output
226+
}
227+
228+
229+
func deployment_to_string(dep OrchentDeployment, verboseLevel int) string {
212230
output := ""
213-
lines := []string{"Deployment [" + dep.Uuid + "]:",
214-
" status: " + dep.Status,
215-
" creation time: " + dep.CreationTime,
216-
" update time: " + dep.UpdateTime,
217-
" callback: " + dep.Callback,
218-
}
219-
if !short {
220-
outputs, _ := json.MarshalIndent(dep.Outputs, " ", " ")
231+
outputs, _ := json.MarshalIndent(dep.Outputs, " ", " ")
232+
lines := []string{"Deployment [" + dep.Uuid + "]:",
233+
" status: " + dep.Status,
234+
" creation time: " + dep.CreationTime,
235+
" update time: " + dep.UpdateTime,
236+
}
237+
switch verboseLevel {
238+
case 0:
239+
case 1:
240+
lines = append(lines, []string { " outputs: \n " + fmt.Sprintf("%s", outputs) }...)
241+
case 2:
242+
endpoint, _ := json.MarshalIndent(dep.CloudProviderEndpoint, " ", " ")
221243
more_lines := []string{
244+
" physical id: " + dep.PhysicalId,
245+
" created by: " + fmt.Sprintf("%s", dep.CreatedBy),
222246
" status reason: " + dep.StatusReason,
223247
" task: " + dep.Task,
248+
" callback: " + dep.Callback,
224249
" CloudProviderName: " + dep.CloudProviderName,
225-
" outputs: \n " + fmt.Sprintf("%s", outputs),
250+
" CloudProviderEndpoint: " + fmt.Sprintf("%s", endpoint),
226251
" links:"}
227252
lines = append(lines, more_lines...)
228-
}
229-
for _, line := range lines {
230-
output = output + fmt.Sprintf("%s\n", line)
231-
}
232-
if !short {
233253
for _, link := range dep.Links {
234-
output = output + fmt.Sprintf(" %s\n", link)
254+
lines = append(lines, []string { output + fmt.Sprintf(" %s\n", link) }...)
235255
}
236256
}
257+
258+
for _, line := range lines {
259+
output = output + fmt.Sprintf("%s\n", line)
260+
}
237261
return output
238262

239263
}
@@ -433,7 +457,7 @@ func deployment_create_update(templateFile *os.File, parameter string, callback
433457
}
434458
}
435459

436-
func deployment_show(uuid string, base *sling.Sling) {
460+
func deployment_show(uuid string, verbose bool, base *sling.Sling) {
437461
deployment := new(OrchentDeployment)
438462
orchentError := new(OrchentError)
439463
base = base.Get("./deployments/" + uuid)
@@ -445,7 +469,11 @@ func deployment_show(uuid string, base *sling.Sling) {
445469
if is_error(orchentError) {
446470
fmt.Printf("error requesting deployment %s:\n %s\n", uuid, orchentError)
447471
} else {
448-
fmt.Printf("%s\n", deployment)
472+
if verbose {
473+
fmt.Printf("%s\n", deployment_to_string(*deployment, 2) )
474+
} else {
475+
fmt.Printf("%s\n", deployment_to_string(*deployment, 1) )
476+
}
449477
}
450478
}
451479

@@ -551,6 +579,25 @@ func test_url(base *sling.Sling) {
551579
}
552580
}
553581

582+
func get_conf(base *sling.Sling) {
583+
fmt.Println("retrieving orchestrator configuration:")
584+
config := make(map[string]string)
585+
orchentError := new(OrchentError)
586+
base = base.Get("./configuration")
587+
_, err := base.Receive(&config, orchentError)
588+
if err != nil {
589+
fmt.Println("error requesting orchestrator configuration: %s\n", err)
590+
return
591+
}
592+
if is_error(orchentError) {
593+
fmt.Println("error requesting orchestrator configuration: %s\n", orchentError)
594+
} else {
595+
for key, value := range config {
596+
fmt.Printf(" %s: %s\n", key, value)
597+
}
598+
}
599+
}
600+
554601
func settings() map[string]string {
555602
emptyset := make(map[string]string)
556603
user, err := user.Current()
@@ -673,7 +720,7 @@ func main() {
673720
baseUrl := get_base_url()
674721
base := base_connection(baseUrl)
675722
uuid := try_alias_uuid(*showDepUuid, aliases)
676-
deployment_show(uuid, base)
723+
deployment_show(uuid, *showDepVerbose, base)
677724

678725
case createDep.FullCommand():
679726
baseUrl := get_base_url()
@@ -715,5 +762,10 @@ func main() {
715762
baseUrl := get_base_url()
716763
base := base_connection(baseUrl)
717764
test_url(base)
718-
}
765+
766+
case getConfig.FullCommand():
767+
baseUrl := get_base_url()
768+
base := base_connection(baseUrl)
769+
get_conf(base)
770+
}
719771
}

0 commit comments

Comments
 (0)