Skip to content

Commit

Permalink
add get_app_info
Browse files Browse the repository at this point in the history
  • Loading branch information
JermzV committed Feb 27, 2019
1 parent 267be0d commit 83670bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion cmd/commands_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -609,3 +609,19 @@ func serversListApplications(cmd *cli.Cmd) {
tabsFlush()
}
}
func serversAppInfo(cmd *cli.Cmd) {
id := cmd.StringArg("SUBID", "", "SUBID of virtual machine (see <servers>)")
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)
}
}
13 changes: 13 additions & 0 deletions lib/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit 83670bc

Please sign in to comment.