Added create docker image route and intergrated with the client
This commit is contained in:
@@ -18,7 +18,10 @@ import (
|
||||
|
||||
type DockerVM struct {
|
||||
SSHPort int `json:"SSHPort"`
|
||||
SSHUsername string `json:"SSHUsername"`
|
||||
SSHPassword string `json:"SSHPassword"`
|
||||
VNCPort int `json:"VNCPort"`
|
||||
VNCPassword string `json:"VNCPassword"`
|
||||
ID string `json:"ID"`
|
||||
TagName string `json:"TagName"`
|
||||
ImagePath string `json:"ImagePath"`
|
||||
@@ -50,10 +53,15 @@ func BuildRunContainer() (*DockerVM,error) {
|
||||
// Sets Free port to Struct
|
||||
RespDocker.SSHPort = Ports[0]
|
||||
RespDocker.VNCPort = Ports[1]
|
||||
// Sets appropriate username and password to the
|
||||
// variables in the struct
|
||||
RespDocker.SSHUsername = "master"
|
||||
RespDocker.SSHPassword = "password"
|
||||
RespDocker.VNCPassword = "vncpassword"
|
||||
|
||||
//Default parameters
|
||||
RespDocker.TagName = "p2p-ubuntu"
|
||||
RespDocker.ImagePath = "./containers/docker-ubuntu-sshd/"
|
||||
RespDocker.ImagePath = "server/docker/containers/docker-ubuntu-sshd/"
|
||||
|
||||
// Gets docker information from env variables
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
|
||||
47
server/rpc.go
Normal file
47
server/rpc.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker"
|
||||
"net"
|
||||
"net/rpc"
|
||||
)
|
||||
|
||||
const (
|
||||
port = "8089"
|
||||
)
|
||||
|
||||
type Listener int
|
||||
|
||||
type Docker struct {
|
||||
docker *docker.DockerVM
|
||||
}
|
||||
|
||||
// Starts container using RPC calls
|
||||
func (l *Listener) StartContainer( reply *Docker) error {
|
||||
fmt.Print("here")
|
||||
vm, err := docker.BuildRunContainer()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Receive: %v\n", vm)
|
||||
*reply = Docker{vm}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
func Rpc() {
|
||||
rpcServer, err := net.ResolveTCPAddr("tcp", "0.0.0.0:"+port)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
inbound, err := net.ListenTCP("tcp", rpcServer)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
listener := new(Listener)
|
||||
rpc.Register(listener)
|
||||
rpc.Accept(inbound)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
//"fmt"
|
||||
@@ -31,7 +32,18 @@ func Server() {
|
||||
})
|
||||
|
||||
|
||||
r.GET("/startcontainer", func(c *gin.Context) {
|
||||
|
||||
resp, err := docker.BuildRunContainer()
|
||||
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
})
|
||||
|
||||
// Future feature
|
||||
/*r.GET("/create_vm/:virtualization", func(c *gin.Context) {
|
||||
virtualization := c.Param("virtualization")
|
||||
// Runs based on Preallocated VM size
|
||||
|
||||
Reference in New Issue
Block a user