Added create docker image route and intergrated with the client

This commit is contained in:
2021-04-02 02:33:16 +04:00
parent a7dc4cbce4
commit 53ba23ebf9
11 changed files with 172 additions and 55 deletions

77
client/container.go Normal file
View File

@@ -0,0 +1,77 @@
package client
import (
"encoding/json"
"fmt"
"git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker"
"io/ioutil"
"net/http"
)
const (
serverPort = "8089"
)
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"
resp, err := http.Get(URL)
// Convert response to byte value
byteValue, _ := ioutil.ReadAll(resp.Body)
// Create variable for result response type
var dockerResult docker.DockerVM
// Adds byte value to docker.DockerVM struct
json.Unmarshal(byteValue, &dockerResult)
if err != nil {
return nil,err
}
return &dockerResult, nil
}
// 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))
}
// TODO implementation using RPC calls
//func StartContainer(Ip string) (*docker.DockerVM,error){
// client, err := rpc.DialHTTP("tcp",Ip + ":" + serverPort)
//
// if err != nil {
// return nil,err
// }
//
// in := bufio.NewReader(os.Stdin)
//
// for {
// line, _, err := in.ReadLine()
// if err != nil {
// return nil,err
// }
//
// var reply Docker
//
// err = client.Call("Listener.StartContainer", line, &reply)
// if err != nil {
// return nil,err
// }
// log.Printf("Reply: %v, Data: %v", reply, reply.docker)
// return reply.docker, nil
// }
//
//}

View File

@@ -1,3 +0,0 @@
package client
func