Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: get_app_info #63

Merged
merged 2 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -95,6 +95,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 @@ -647,3 +647,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