forked from Telmate/proxmox-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e16a79f
commit a12c5c5
Showing
8 changed files
with
159 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package guest | ||
|
||
import ( | ||
"github.com/Telmate/proxmox-api-go/cli" | ||
"github.com/Telmate/proxmox-api-go/proxmox" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var guest_shutdownCmd = &cobra.Command{ | ||
Use: "shutdown GUESTID", | ||
Short: "Shuts the speciefid guest down", | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
vmr := proxmox.NewVmRef(cli.ValidateIntIDset(args, "GuestID")) | ||
c := cli.NewClient() | ||
_, err = c.ShutdownVm(vmr) | ||
if err == nil { | ||
cli.PrintGuestStatus(GuestCmd.OutOrStdout(), vmr.VmId(), "stopped") | ||
} | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
GuestCmd.AddCommand(guest_shutdownCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package guest | ||
|
||
import ( | ||
"github.com/Telmate/proxmox-api-go/cli" | ||
"github.com/Telmate/proxmox-api-go/proxmox" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var guest_statusCmd = &cobra.Command{ | ||
Use: "start GUESTID", | ||
Short: "Starts the speciefid guest", | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
vmr := proxmox.NewVmRef(cli.ValidateIntIDset(args, "GuestID")) | ||
c := cli.NewClient() | ||
_, err = c.StartVm(vmr) | ||
if err == nil { | ||
cli.PrintGuestStatus(GuestCmd.OutOrStdout(), vmr.VmId(), "started") | ||
} | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
GuestCmd.AddCommand(guest_statusCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package guest | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Telmate/proxmox-api-go/cli" | ||
"github.com/Telmate/proxmox-api-go/proxmox" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var guest_startCmd = &cobra.Command{ | ||
Use: "status GUESTID", | ||
Short: "Gets the status of the speciefid guest", | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
vmr := proxmox.NewVmRef(cli.ValidateIntIDset(args, "GuestID")) | ||
c := cli.NewClient() | ||
vmState, err := c.GetVmState(vmr) | ||
if err == nil { | ||
fmt.Fprintf(GuestCmd.OutOrStdout(), "Status of guest with id (%d) is %s\n", vmr.VmId(), vmState["status"].(string)) | ||
} | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
GuestCmd.AddCommand(guest_startCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package guest | ||
|
||
import ( | ||
"github.com/Telmate/proxmox-api-go/cli" | ||
"github.com/Telmate/proxmox-api-go/proxmox" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var guest_stopCmd = &cobra.Command{ | ||
Use: "stop GUESTID", | ||
Short: "Stops the speciefid guest", | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
vmr := proxmox.NewVmRef(cli.ValidateIntIDset(args, "GuestID")) | ||
c := cli.NewClient() | ||
_, err = c.StopVm(vmr) | ||
if err == nil { | ||
cli.PrintGuestStatus(GuestCmd.OutOrStdout(), vmr.VmId(), "stopped") | ||
} | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
GuestCmd.AddCommand(guest_stopCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package guest | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Telmate/proxmox-api-go/cli" | ||
"github.com/Telmate/proxmox-api-go/proxmox" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var guest_uptimeCmd = &cobra.Command{ | ||
Use: "uptime GUESTID", | ||
Short: "Gets the uptime of the speciefid guest", | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
vmr := proxmox.NewVmRef(cli.ValidateIntIDset(args, "GuestID")) | ||
c := cli.NewClient() | ||
vmState, err := c.GetVmState(vmr) | ||
if err == nil { | ||
fmt.Fprintf(GuestCmd.OutOrStdout(), "Uptime of guest with id (%d) is %d\n", vmr.VmId(), int(vmState["uptime"].(float64))) | ||
} | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
GuestCmd.AddCommand(guest_uptimeCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package guest | ||
|
||
import ( | ||
"github.com/Telmate/proxmox-api-go/cli" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var GuestCmd = &cobra.Command{ | ||
Use: "guest", | ||
Short: "Commands to interact with the qemu and LXC guests on Proxmox", | ||
} | ||
|
||
func init() { | ||
cli.RootCmd.AddCommand(GuestCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"encoding/json" | ||
) | ||
|
||
func PrintItemCreated(out io.Writer, id, text string){ | ||
func PrintGuestStatus(out io.Writer, id int, text string) { | ||
fmt.Fprintf(out, "Guest with id (%d) has been %s\n", id, text) | ||
} | ||
|
||
func PrintItemCreated(out io.Writer, id, text string) { | ||
fmt.Fprintf(out, "%s (%s) has been created\n", text, id) | ||
} | ||
|
||
func PrintItemUpdated(out io.Writer, id, text string){ | ||
func PrintItemUpdated(out io.Writer, id, text string) { | ||
fmt.Fprintf(out, "%s (%s) has been updated\n", text, id) | ||
} | ||
|
||
func PrintItemDeleted(out io.Writer, id, text string){ | ||
func PrintItemDeleted(out io.Writer, id, text string) { | ||
fmt.Fprintf(out, "%s (%s) has been deleted\n", text, id) | ||
} | ||
|
||
func PrintItemSet(out io.Writer, id, text string){ | ||
func PrintItemSet(out io.Writer, id, text string) { | ||
fmt.Fprintf(out, "%s (%s) has been configured\n", text, id) | ||
} | ||
|
||
func PrintRawJson(out io.Writer, input interface{}){ | ||
func PrintRawJson(out io.Writer, input interface{}) { | ||
list, err := json.Marshal(input) | ||
LogFatalError(err) | ||
fmt.Fprintln(out,string(list)) | ||
fmt.Fprintln(out, string(list)) | ||
} | ||
|
||
func PrintFormattedJson(out io.Writer, input interface{}){ | ||
func PrintFormattedJson(out io.Writer, input interface{}) { | ||
list, err := json.MarshalIndent(input, "", " ") | ||
LogFatalError(err) | ||
fmt.Fprintln(out,string(list)) | ||
} | ||
fmt.Fprintln(out, string(list)) | ||
} |