Skip to content
Snippets Groups Projects
Commit a0b4d1ee authored by Florent Gluck's avatar Florent Gluck
Browse files

Doh! Forgot src/client/cmdVM/vmListSingle.go

parent bb4bda9c
Branches
No related tags found
No related merge requests found
package cmdVM
import (
u "nexus-client/utils"
g "nexus-client/globals"
)
type ListSingle struct {
Name string
}
func (cmd *ListSingle)GetName() string {
return cmd.Name
}
func (cmd *ListSingle)GetDesc() []string {
return []string{
"Lists details about a VM.",
"Requires VM_LIST VM access capability or VM_LIST_ANY user capability."}
}
func (cmd *ListSingle)PrintUsage() {
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
u.PrintlnErr("USAGE: ",cmd.GetName(), " ID")
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
}
func (cmd *ListSingle)Run(args []string) int {
client := g.GetInstance().Client
host := g.GetInstance().Host
argc := len(args)
if argc < 1 {
cmd.PrintUsage()
return 1
}
uuid := args[0]
resp, err := client.R().Get(host+"/vms/"+uuid)
if err != nil {
u.PrintlnErr("Failed retrieving VM \""+uuid+"\": "+err.Error())
return 1
} else {
if resp.IsSuccess() {
vm, err := getVM(resp)
if err != nil {
u.PrintlnErr("Failed retrieving server's response: "+err.Error())
return 1
}
str, err := vm.String()
if err != nil {
u.PrintlnErr("Failed decoding VM "+vm.ID.String()+" to string. Skipped.")
} else {
u.Println(str)
}
} else {
u.PrintlnErr("Failed retrieving VM \""+uuid+"\": "+resp.Status()+": "+resp.String())
return 1
}
}
return 0
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment