added command delete VM

This commit is contained in:
2021-04-10 18:20:24 +04:00
parent 30c126da91
commit f6653de158
6 changed files with 95 additions and 13 deletions

View File

@@ -26,8 +26,16 @@ var CliAction = func(ctx *cli.Context) error {
p2p.PrintIpTable()
}
// Function called to stop and remove server from Docker
if RemoveVM != "" && ID != "" {
err := client.RemoveContianer(RemoveVM,ID)
if err != nil {
fmt.Print(err)
}
}
//Call function to create Docker container
if IpAddress != "" {
if CreateVM != "" {
var PortsInt int
PortsInt = 0
@@ -37,7 +45,7 @@ var CliAction = func(ctx *cli.Context) error {
fmt.Sscanf(Ports, "%d", &PortsInt)
}
imageRes, err := client.StartContainer(IpAddress,PortsInt,GPU)
imageRes, err := client.StartContainer(CreateVM,PortsInt,GPU)
if err != nil {
fmt.Print(err)

View File

@@ -6,10 +6,12 @@ import (
// Variables declared for CLI
var (
IpAddress string
Ports string
Mode string
Specs string
CreateVM string
Ports string
Mode string
RemoveVM string
ID string
Specs string
GPU bool
ListServers bool
)
@@ -33,13 +35,25 @@ var AppConfigFlags = []cli.Flag{
Name: "CreateVM",
Usage: "Creates Docker container on the selected server",
EnvVars: []string{"CREATE_VM"},
Destination: &IpAddress,
Destination: &CreateVM,
},
&cli.StringFlag{
Name: "RemoveVM",
Usage: "Stop and Remove Docker container",
EnvVars: []string{"REMOVE_VM"},
Destination: &RemoveVM,
},
&cli.StringFlag{
Name: "ID",
Usage: "Docker Container ID",
EnvVars: []string{"ID"},
Destination: &ID,
},
&cli.StringFlag{
Name: "Ports",
Usage: "Number of ports to open for the Docker Container",
EnvVars: []string{"NUM_PORTS"},
Destination: &Ports,
Destination: &ID,
},
&cli.BoolFlag{
Name: "GPU",