added ports and fixed docker ID not returning back
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
serverPort = "8089"
|
||||
serverPort = "8088"
|
||||
)
|
||||
|
||||
|
||||
@@ -18,12 +18,16 @@ var client = http.Client{}
|
||||
|
||||
// Start container using REST api Implementation
|
||||
// From the selected server IP address
|
||||
func StartContainer(Ip string) (*docker.DockerVM ,error) {
|
||||
URL := "http://" + Ip + ":8088/startcontainer"
|
||||
// TODO: Test cases for this function
|
||||
func StartContainer(Ip string,Num_ports int) (*docker.DockerVM ,error) {
|
||||
URL := "http://" + Ip + ":" + serverPort + "/startcontainer?ports=" + fmt.Sprint(Num_ports)
|
||||
resp, err := http.Get(URL)
|
||||
|
||||
// Convert response to byte value
|
||||
byteValue, _ := ioutil.ReadAll(resp.Body)
|
||||
byteValue, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil,err
|
||||
}
|
||||
|
||||
// Create variable for result response type
|
||||
var dockerResult docker.DockerVM
|
||||
@@ -45,7 +49,7 @@ func PrintStartContainer(d *docker.DockerVM){
|
||||
fmt.Println("SSH password: " + fmt.Sprint(d.SSHPassword))
|
||||
fmt.Println("VNC port: " + fmt.Sprint(d.VNCPort))
|
||||
fmt.Println("VNC password: " + fmt.Sprint(d.VNCPassword))
|
||||
fmt.Println("Ports Open")
|
||||
fmt.Println("Ports Open (All TCP ports):")
|
||||
for i := range d.Ports {
|
||||
fmt.Println(d.Ports[i])
|
||||
}
|
||||
|
||||
@@ -28,7 +28,16 @@ var CliAction = func(ctx *cli.Context) error {
|
||||
|
||||
//Call function to create Docker container
|
||||
if IpAddress != "" {
|
||||
imageRes, err := client.StartContainer(IpAddress)
|
||||
|
||||
var PortsInt int
|
||||
PortsInt = 0
|
||||
|
||||
if Ports != "" {
|
||||
// Convert Get Request value to int
|
||||
fmt.Sscanf(Ports, "%d", &PortsInt)
|
||||
}
|
||||
|
||||
imageRes, err := client.StartContainer(IpAddress,PortsInt)
|
||||
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
|
||||
18
cmd/flags.go
18
cmd/flags.go
@@ -4,8 +4,12 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var Mode,IpAddress string
|
||||
var ListServers, Ip_table, Abspath bool
|
||||
var (
|
||||
IpAddress string
|
||||
Ports string
|
||||
Mode string
|
||||
)
|
||||
var ListServers bool
|
||||
|
||||
var AppConfigFlags = []cli.Flag{
|
||||
// Deprecated to be implemented using GRPC
|
||||
@@ -28,10 +32,10 @@ var AppConfigFlags = []cli.Flag{
|
||||
EnvVars: []string{"CREATE_VM"},
|
||||
Destination: &IpAddress,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "FilePath",
|
||||
Usage: "Testing for absolute path",
|
||||
Destination: &Abspath,
|
||||
&cli.StringFlag{
|
||||
Name: "Ports",
|
||||
Usage: "Number of ports to open for the Docker Container",
|
||||
EnvVars: []string{"NUM_PORTS"},
|
||||
Destination: &Ports,
|
||||
},
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -60,8 +60,6 @@ func (ip *IpAddresses)SpeedTestUpdatedIPTable() error{
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Print("lol")
|
||||
|
||||
ip.IpAddress = append(ip.IpAddress, targets.IpAddress[i])
|
||||
}
|
||||
|
||||
|
||||
@@ -187,6 +187,9 @@ func (d *DockerVM)runContainer(dockerClient *client.Client) error{
|
||||
res, err := dockerClient.ContainerCreate(ctx,config,hostConfig,
|
||||
nil,nil,"")
|
||||
|
||||
// Set response ID
|
||||
d.ID = res.ID
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -200,6 +203,8 @@ func (d *DockerVM)runContainer(dockerClient *client.Client) error{
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Implement and remove docker instance running
|
||||
|
||||
|
||||
func print(rd io.Reader) error {
|
||||
var lastLine string
|
||||
|
||||
Reference in New Issue
Block a user