added possibility to allocate internal ports inside docker containers

This commit is contained in:
2021-07-19 03:35:43 +04:00
parent e98f4119da
commit c22f73ad28
3 changed files with 30 additions and 19 deletions

View File

@@ -128,18 +128,18 @@ func ViewContainers(IP string)(*docker.DockerContainers, error){
}
// PrintStartContainer Prints results Generated container
func PrintStartContainer(d *docker.DockerVM){
fmt.Println("ID : " + fmt.Sprint(d.ID))
fmt.Println("SSH port: " + fmt.Sprint(d.SSHPort))
fmt.Println("SSH username: " + fmt.Sprint(d.SSHUsername))
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 (All TCP ports):")
for i := range d.Ports {
fmt.Println(d.Ports[i])
}
}
//func PrintStartContainer(d *docker.DockerVM){
// fmt.Println("ID : " + fmt.Sprint(d.ID))
// fmt.Println("SSH port: " + fmt.Sprint(d.SSHPort))
// fmt.Println("SSH username: " + fmt.Sprint(d.SSHUsername))
// 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 (All TCP ports):")
// for i := range d.Ports {
// fmt.Println(d.Ports[i])
// }
//}
// TODO implementation using RPC calls

View File

@@ -1,10 +1,9 @@
{
"ports": [
"Port": [
{
"port_name": "SSH",
"internal_port": 22,
"type": "tcp",
"Allocated port": 0,
"PortName": "SSH",
"InternalPort": 22,
"Type": "tcp",
"Description": "SSH Port"
}
]

View File

@@ -65,7 +65,6 @@ var dockerRegistryUserID = ""
// BuildRunContainer Function is incharge to invoke building and running contianer and also allocating external
// ports
func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerVM,error) {
//Docker Struct Variable
var RespDocker *DockerVM = new(DockerVM)
@@ -123,10 +122,23 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV
if err != nil {
return nil,err
}
// Allocate external ports
// Allocate external ports to ports available in the ports.json file
for i := range PortsInformation.PortSet {
PortsInformation.PortSet[i].ExternalPort = OpenPorts[i]
}
//Length of Ports allocated from thr port file
portFileLength := len(PortsInformation.PortSet)
// Allocate New ports the user wants to generate
for i := 0; i < NumPorts; i++ {
var TempPort Port
TempPort.PortName = "AutoGen Port"
TempPort.Type = "tcp"
TempPort.InternalPort = OpenPorts[portFileLength + i]
TempPort.ExternalPort = OpenPorts[portFileLength + i]
TempPort.Description = "Auto generated TCP port"
//Append temp port to port information
PortsInformation.PortSet = append(PortsInformation.PortSet, TempPort)
}
// Setting ports to the docker VM struct
RespDocker.Ports = *PortsInformation