fixed errors when providing docker container name in the parameter
This commit is contained in:
@@ -19,6 +19,7 @@ var client = http.Client{}
|
|||||||
// StartContainer Start container using REST api Implementation
|
// StartContainer Start container using REST api Implementation
|
||||||
// From the selected server IP address
|
// From the selected server IP address
|
||||||
// TODO: Test cases for this function
|
// TODO: Test cases for this function
|
||||||
|
//Calls URL ex: http://0.0.0.0:8088/startcontainer?ports=0&GPU=false&ContainerName=docker-ubuntu-sshd
|
||||||
func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*docker.DockerVM ,error) {
|
func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*docker.DockerVM ,error) {
|
||||||
// Passes URL with number of TCP ports to allocated and to give GPU access to the docker container
|
// Passes URL with number of TCP ports to allocated and to give GPU access to the docker container
|
||||||
URL := "http://" + IP + ":" + serverPort + "/startcontainer?ports=" + fmt.Sprint(NumPorts) + "&GPU=" + strconv.FormatBool(GPU) + "&ContainerName=" + ContainerName
|
URL := "http://" + IP + ":" + serverPort + "/startcontainer?ports=" + fmt.Sprint(NumPorts) + "&GPU=" + strconv.FormatBool(GPU) + "&ContainerName=" + ContainerName
|
||||||
|
|||||||
@@ -93,11 +93,14 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV
|
|||||||
}
|
}
|
||||||
RespDocker.ImagePath = config.DefaultDockerFile
|
RespDocker.ImagePath = config.DefaultDockerFile
|
||||||
|
|
||||||
if ContainerName != "" {
|
// We are checking if the container name is not nil and not equal to the default one used
|
||||||
|
// which is docker-ubuntu-sshd
|
||||||
|
if ContainerName != "" && ContainerName != "docker-ubuntu-sshd" {
|
||||||
Containers, err := ViewAllContainers()
|
Containers, err := ViewAllContainers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil,err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dockerContainer := range Containers.DockerContainer {
|
for _, dockerContainer := range Containers.DockerContainer {
|
||||||
if dockerContainer.ContainerName == ContainerName {
|
if dockerContainer.ContainerName == ContainerName {
|
||||||
RespDocker.ImagePath = config.DockerContainers + ContainerName + "/"
|
RespDocker.ImagePath = config.DockerContainers + ContainerName + "/"
|
||||||
@@ -311,7 +314,6 @@ func ViewAllContainers() (*DockerContainers, error){
|
|||||||
|
|
||||||
for _, f := range folders {
|
for _, f := range folders {
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
fmt.Print(f.Name())
|
|
||||||
//Declare variable DockerContainer of type struct
|
//Declare variable DockerContainer of type struct
|
||||||
var Container DockerContainer
|
var Container DockerContainer
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDocker(t *testing.T) {
|
func TestDocker(t *testing.T) {
|
||||||
//TODO overwrite with custom docker paths
|
// Testing by providing default container name
|
||||||
resp,err := BuildRunContainer(2,"true","")
|
_,err := BuildRunContainer(2,"false","docker-ubuntu-sshd")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Testing if no container name is provided if default is used
|
||||||
|
_,err = BuildRunContainer(2,"false","")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(resp.VNCPort)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestViewAllContainers(t *testing.T) {
|
func TestViewAllContainers(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user