modified config file
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// UpdateIpTable Does the following to update it's IP table
|
||||
func UpdateIpTable(IpAddress string) error {
|
||||
func UpdateIpTable(IpAddress string, serverPort string) error {
|
||||
|
||||
config, err := config.ConfigInit()
|
||||
if err != nil {
|
||||
@@ -22,16 +22,17 @@ func UpdateIpTable(IpAddress string) error {
|
||||
|
||||
client := http.Client{}
|
||||
|
||||
|
||||
var resp []byte
|
||||
|
||||
version := p2p.Ip4or6(IpAddress)
|
||||
if version == "version 6" {
|
||||
resp, err = UploadMultipartFile(client,"http://["+IpAddress+"]:8088/IpTable","json",config.IPTable)
|
||||
resp, err = UploadMultipartFile(client,"http://[" + IpAddress + "]:" + serverPort + "/IpTable","json",config.IPTable)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
resp, err = UploadMultipartFile(client,"http://"+IpAddress+":8088/IpTable","json",config.IPTable)
|
||||
resp, err = UploadMultipartFile(client,"http://" + IpAddress + ":" + serverPort + "/IpTable","json",config.IPTable)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -114,9 +115,9 @@ func UpdateIpTableListClient() error {
|
||||
//}
|
||||
|
||||
if Addresses.IpAddress[j].Ipv6 != "" {
|
||||
err = UpdateIpTable(Addresses.IpAddress[j].Ipv6)
|
||||
err = UpdateIpTable(Addresses.IpAddress[j].Ipv6, Addresses.IpAddress[j].ServerPort)
|
||||
} else {
|
||||
err = UpdateIpTable(Addresses.IpAddress[j].Ipv4)
|
||||
err = UpdateIpTable(Addresses.IpAddress[j].Ipv4, Addresses.IpAddress[j].ServerPort)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -15,6 +15,13 @@ import (
|
||||
func GetSpecs(IP string)(*server.SysInfo,error) {
|
||||
var URL string
|
||||
version := p2p.Ip4or6(IP)
|
||||
|
||||
//Get port number of the server
|
||||
serverPort, err := GetServerPort(IP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if version == "version 6" {
|
||||
URL = "http://[" + IP + "]:" + serverPort + "/server_info"
|
||||
} else {
|
||||
|
||||
@@ -10,13 +10,11 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
var (
|
||||
serverPort = "8088"
|
||||
client = http.Client{}
|
||||
)
|
||||
|
||||
|
||||
var client = http.Client{}
|
||||
|
||||
// StartContainer Start container using REST api Implementation
|
||||
// From the selected server IP address
|
||||
// TODO: Test cases for this function
|
||||
@@ -25,6 +23,13 @@ func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*d
|
||||
// Passes URL with number of TCP ports to allocated and to give GPU access to the docker container
|
||||
var URL string
|
||||
version := p2p.Ip4or6(IP)
|
||||
|
||||
//Get port number of the server
|
||||
serverPort, err := GetServerPort(IP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if version == "version 6" {
|
||||
URL = "http://[" + IP + "]:" + serverPort + "/startcontainer?ports=" + fmt.Sprint(NumPorts) + "&GPU=" + strconv.FormatBool(GPU) + "&ContainerName=" + ContainerName
|
||||
} else {
|
||||
@@ -64,6 +69,13 @@ func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*d
|
||||
func RemoveContianer(IP string,ID string) error {
|
||||
var URL string
|
||||
version := p2p.Ip4or6(IP)
|
||||
|
||||
//Get port number of the server
|
||||
serverPort, err := GetServerPort(IP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if version == "version 6" {
|
||||
URL = "http://[" + IP + "]:" + serverPort + "/RemoveContainer?id=" + ID
|
||||
} else {
|
||||
@@ -99,6 +111,13 @@ func ViewContainers(IP string)(*docker.DockerContainers, error){
|
||||
// Passes URL with route /ShowImages
|
||||
var URL string
|
||||
version := p2p.Ip4or6(IP)
|
||||
|
||||
//Get port number of the server
|
||||
serverPort, err := GetServerPort(IP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if version == "version 6" {
|
||||
URL = "http://[" + IP + "]:" + serverPort + "/ShowImages"
|
||||
} else {
|
||||
@@ -127,6 +146,28 @@ func ViewContainers(IP string)(*docker.DockerContainers, error){
|
||||
return &Result, nil
|
||||
}
|
||||
|
||||
// GetServerPort Helper function to do find out server port information
|
||||
func GetServerPort(IpAddress string) (string,error) {
|
||||
// Getting information from the clients ip table
|
||||
ipTable, err := p2p.ReadIpTable()
|
||||
if err != nil {
|
||||
return "",err
|
||||
}
|
||||
|
||||
// Iterate thorough ip table struct and find
|
||||
// out which port is for the ip address provided
|
||||
// in the parameter of the function
|
||||
for _, address := range ipTable.IpAddress {
|
||||
// If we found a match then return a port
|
||||
if address.Ipv4 == IpAddress || address.Ipv6 == IpAddress {
|
||||
return address.ServerPort, nil
|
||||
}
|
||||
}
|
||||
|
||||
// We return default port
|
||||
return "8088",nil
|
||||
}
|
||||
|
||||
// PrintStartContainer Prints results Generated container
|
||||
//func PrintStartContainer(d *docker.DockerVM){
|
||||
// fmt.Println("ID : " + fmt.Sprint(d.ID))
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"TrackContainer": []
|
||||
}
|
||||
@@ -23,13 +23,24 @@ var CliAction = func(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
|
||||
p2p.PrintIpTable()
|
||||
// Reads from ip table and passes it
|
||||
// on to struct print function
|
||||
Servers, err := p2p.ReadIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client.PrettyPrint(Servers)
|
||||
}
|
||||
|
||||
// Displays the IP table
|
||||
if ServerList {
|
||||
p2p.PrintIpTable()
|
||||
// Reads from ip table and passes it
|
||||
// on to struct print function
|
||||
Servers, err := p2p.ReadIpTable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client.PrettyPrint(Servers)
|
||||
}
|
||||
|
||||
// Add provided IP to the IP table
|
||||
@@ -51,6 +62,13 @@ var CliAction = func(ctx *cli.Context) error {
|
||||
} else {
|
||||
IpAddr.Ipv4 = AddServer
|
||||
}
|
||||
|
||||
// If a server port is provided then set it
|
||||
if Ports != "" {
|
||||
IpAddr.ServerPort = Ports
|
||||
} else {
|
||||
IpAddr.ServerPort = "8088"
|
||||
}
|
||||
// Append IP address to variable result which
|
||||
// is a list
|
||||
res.IpAddress = append(res.IpAddress, IpAddr)
|
||||
|
||||
@@ -28,6 +28,7 @@ type Config struct {
|
||||
IPV6Address string
|
||||
PluginPath string
|
||||
TrackContainersPath string
|
||||
ServerPort string
|
||||
//NetworkInterface string
|
||||
//NetworkInterfaceIPV6Index int
|
||||
}
|
||||
@@ -96,6 +97,7 @@ func SetDefaults() error {
|
||||
defaults["IPV6Address"] = ""
|
||||
defaults["PluginPath"] = defaultPath + "plugin/deploy"
|
||||
defaults["TrackContainersPath"] = defaultPath + "client/trackcontainers/trackcontainers.json"
|
||||
defaults["ServerPort"] = "8088"
|
||||
//defaults["NetworkInterface"] = "wlp0s20f3"
|
||||
//defaults["NetworkInterfaceIPV6Index"] = "2"
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"ip_address": [
|
||||
{
|
||||
"ipv4": "172.104.44.195",
|
||||
"ipv4": "139.162.246.221",
|
||||
"ipv6": "",
|
||||
"latency": 0,
|
||||
"download": 0,
|
||||
"upload": 0
|
||||
"upload": 0,
|
||||
"serverport": "8088"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -23,6 +23,7 @@ type IpAddress struct {
|
||||
Latency time.Duration `json:"latency"`
|
||||
Download float64 `json:"download"`
|
||||
Upload float64 `json:"upload"`
|
||||
ServerPort string `json:"serverport"`
|
||||
}
|
||||
|
||||
type IP struct {
|
||||
@@ -69,6 +70,7 @@ func ReadIpTable()(*IpAddresses ,error){
|
||||
}
|
||||
PublicIP.Ipv4 = ip
|
||||
PublicIP.Ipv6 = ipv6
|
||||
PublicIP.ServerPort = config.ServerPort
|
||||
|
||||
// Updates current machine IP address to the IP table
|
||||
ipAddresses.IpAddress = append(ipAddresses.IpAddress, PublicIP)
|
||||
@@ -120,6 +122,7 @@ func PrintIpTable() error {
|
||||
"-----------------\n",table.IpAddress[i].Ipv4,table.IpAddress[i].Ipv6,
|
||||
table.IpAddress[i].Latency)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ func (s *IpAddress)UploadSpeed() error {
|
||||
|
||||
b, w := createMultipartFormData("file",config.SpeedTestFile)
|
||||
|
||||
req, err := http.NewRequest("GET", "http://" + s.Ipv4 + ":8088/upload", &b)
|
||||
req, err := http.NewRequest("GET", "http://" + s.Ipv4 + ":" + s.ServerPort + "/upload", &b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -152,10 +152,10 @@ func (s *IpAddress) PingTest() error {
|
||||
//pingURL := strings.Split(s.URL, "/upload")[0] + "/latency.txt"
|
||||
var pingURL string
|
||||
if s.Ipv6 != "" {
|
||||
pingURL = "http://[" + s.Ipv6 + "]:8088/server_info"
|
||||
pingURL = "http://[" + s.Ipv6 + "]:" + s.ServerPort + "/server_info"
|
||||
s.Ipv4 = ""
|
||||
} else {
|
||||
pingURL = "http://" + s.Ipv4 + ":8088/server_info"
|
||||
pingURL = "http://" + s.Ipv4 + ":" + s.ServerPort + "/server_info"
|
||||
}
|
||||
|
||||
l := time.Duration(100000000000) // 10sec
|
||||
|
||||
@@ -122,7 +122,7 @@ func Server() error{
|
||||
c.String(http.StatusOK, "success")
|
||||
})
|
||||
|
||||
//Show images avaliable
|
||||
//Show images available
|
||||
r.GET("/ShowImages", func(c *gin.Context) {
|
||||
resp, err := docker.ViewAllContainers()
|
||||
if err != nil {
|
||||
@@ -131,8 +131,14 @@ func Server() error{
|
||||
c.JSON(http.StatusOK, resp)
|
||||
})
|
||||
|
||||
//Port running on
|
||||
err := r.Run(":8088")
|
||||
//Get Server port based on the config file
|
||||
config, err := config.ConfigInit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Run gin server on the specified port
|
||||
err = r.Run(":" + config.ServerPort)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user