From 83670bc2113e39f87f89bb759ddb70962ef674cf Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 27 Feb 2019 22:02:46 +1100 Subject: [PATCH] add get_app_info --- cmd/commands.go | 3 ++- cmd/commands_servers.go | 18 +++++++++++++++++- lib/servers.go | 13 +++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cmd/commands.go b/cmd/commands.go index 33741a7..8e48169 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -5,7 +5,7 @@ import ( "runtime" vultr "github.com/JamesClonk/vultr/lib" - "github.com/jawher/mow.cli" + cli "github.com/jawher/mow.cli" ) // RegisterCommands registers all CLI commands @@ -86,6 +86,7 @@ func (c *CLI) RegisterCommands() { cmd.Command("app", "show and change application on a virtual machine", func(cmd *cli.Cmd) { cmd.Command("change", "change application of virtual machine (all data will be lost)", serversChangeApplication) cmd.Command("list", "show a list of available applications to which can be changed to", serversListApplications) + cmd.Command("info", "retrieves application information of virtual machine", serversAppInfo) }) cmd.Command("iso", "attach/detach ISO of a virtual machine", func(cmd *cli.Cmd) { cmd.Command("attach", "attach ISO to a virtual machine (server will hard reboot)", serversAttachISO) diff --git a/cmd/commands_servers.go b/cmd/commands_servers.go index 8338437..a2461db 100644 --- a/cmd/commands_servers.go +++ b/cmd/commands_servers.go @@ -8,7 +8,7 @@ import ( "strings" vultr "github.com/JamesClonk/vultr/lib" - "github.com/jawher/mow.cli" + cli "github.com/jawher/mow.cli" ) func serversCreate(cmd *cli.Cmd) { @@ -609,3 +609,19 @@ func serversListApplications(cmd *cli.Cmd) { tabsFlush() } } +func serversAppInfo(cmd *cli.Cmd) { + id := cmd.StringArg("SUBID", "", "SUBID of virtual machine (see )") + cmd.Action = func() { + app, err := GetClient().GetApplicationInfo(*id) + if err != nil { + log.Fatal(err) + } + + if app.Info == "" { + fmt.Printf("Could not retrieve application information of virtual machine with SUBID %v!\n", *id) + return + } + + fmt.Printf("%s", app.Info) + } +} diff --git a/lib/servers.go b/lib/servers.go index 3f84ce2..a3a2082 100644 --- a/lib/servers.go +++ b/lib/servers.go @@ -77,6 +77,11 @@ func (s servers) Less(i, j int) bool { return s[i].MainIP < s[j].MainIP } +// AppInfo represents the application information of a Vultr server +type AppInfo struct { + Info string `json:"app_info"` +} + // V6Network represents a IPv6 network of a Vultr server type V6Network struct { Network string `json:"v6_network"` @@ -593,6 +598,14 @@ func (c *Client) ListApplicationsforServer(id string) (apps []Application, err e return apps, nil } +// GetApplicationInfo retrieves the application information for the existing virtual machine +func (c *Client) GetApplicationInfo(id string) (appInfo AppInfo, err error) { + if err := c.get(`server/get_app_info?SUBID=`+id, &appInfo); err != nil { + return AppInfo{}, err + } + return appInfo, nil +} + // PrivateNetwork on Vultr type PrivateNetwork struct { ID string `json:"NETWORKID"`