modified config file

This commit is contained in:
2021-07-22 13:04:25 +04:00
parent c3647c2fe7
commit 4e0fd09d73
10 changed files with 99 additions and 23 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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))

View File

@@ -1,3 +0,0 @@
{
"TrackContainer": []
}