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

@@ -8,6 +8,9 @@ import (
"net/http"
)
// GetSpecs Gets Specs from the server such CPU, GPU usage
// and other basic information which helps set a
// cluster of computer
func GetSpecs(IP string)(*server.SysInfo,error) {
URL := "http://" + IP + ":" + serverPort + "/server_info"
resp, err := http.Get(URL)
@@ -33,7 +36,8 @@ func GetSpecs(IP string)(*server.SysInfo,error) {
return &serverSpecsResult, nil
}
// print the contents of the obj
// PrettyPrint print the contents of the obj (
// Reference: https://stackoverflow.com/questions/24512112/how-to-print-struct-variables-in-console
func PrettyPrint(data interface{}) {
var p []byte
// var err := error

View File

@@ -19,10 +19,13 @@ var client = http.Client{}
// StartContainer Start container using REST api Implementation
// From the selected server IP address
// TODO: Test cases for this function
func StartContainer(Ip string, NumPorts int, GPU bool) (*docker.DockerVM ,error) {
func StartContainer(IP string, NumPorts int, GPU bool) (*docker.DockerVM ,error) {
// 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)
URL := "http://" + IP + ":" + serverPort + "/startcontainer?ports=" + fmt.Sprint(NumPorts) + "&GPU=" + strconv.FormatBool(GPU)
resp, err := http.Get(URL)
if err != nil {
return nil,err
}
// Convert response to byte value
byteValue, err := ioutil.ReadAll(resp.Body)
@@ -42,6 +45,26 @@ func StartContainer(Ip string, NumPorts int, GPU bool) (*docker.DockerVM ,error)
return &dockerResult, nil
}
// RemoveContianer Stops and removes container from the server
func RemoveContianer(IP string,ID string) error {
URL := "http://" + IP + ":" + serverPort + "/RemoveContainer?id=" + ID
resp, err := http.Get(URL)
if err != nil {
return err
}
// Convert response to byte value
byteValue, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
if string(byteValue[:]) == "success" {
fmt.Println("success")
}
return nil
}
// PrintStartContainer Prints results Generated container
func PrintStartContainer(d *docker.DockerVM){
fmt.Println("ID : " + fmt.Sprint(d.ID))