Merge pull request #92 from Akilan1999/abstracted-functions

changes to configuration
This commit is contained in:
Akilan Selvacoumar
2023-02-24 02:54:10 +00:00
committed by GitHub
6 changed files with 518 additions and 502 deletions

View File

@@ -1,26 +1,27 @@
package abstractions
import (
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
"github.com/Akilan1999/p2p-rendering-computation/server"
"github.com/gin-gonic/gin"
"github.com/Akilan1999/p2p-rendering-computation/config"
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
"github.com/Akilan1999/p2p-rendering-computation/server"
"github.com/gin-gonic/gin"
)
// Init Initialises p2prc
func Init(name string) (err error) {
// set the config file with default paths
err = generate.SetDefaults(name, false)
if err != nil {
return
}
return
func Init(name string) (config *config.Config, err error) {
// set the config file with default paths
config, err = generate.SetDefaults(name, false)
if err != nil {
return
}
return
}
// Start p2prc in a server mode
func Start() (*gin.Engine, error) {
engine, err := server.Server()
if err != nil {
return nil, err
}
return engine, nil
engine, err := server.Server()
if err != nil {
return nil, err
}
return engine, nil
}

View File

@@ -1,274 +1,274 @@
package cmd
import (
"fmt"
"github.com/Akilan1999/p2p-rendering-computation/client"
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
"github.com/Akilan1999/p2p-rendering-computation/p2p"
"github.com/Akilan1999/p2p-rendering-computation/plugin"
"github.com/Akilan1999/p2p-rendering-computation/server"
"github.com/urfave/cli/v2"
"fmt"
"github.com/Akilan1999/p2p-rendering-computation/client"
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
"github.com/Akilan1999/p2p-rendering-computation/p2p"
"github.com/Akilan1999/p2p-rendering-computation/plugin"
"github.com/Akilan1999/p2p-rendering-computation/server"
"github.com/urfave/cli/v2"
)
var CliAction = func(ctx *cli.Context) error {
if Server {
_, err := server.Server()
if err != nil {
fmt.Print(err)
}
if Server {
_, err := server.Server()
if err != nil {
fmt.Print(err)
}
for {
for {
}
//server.Rpc()
}
}
//server.Rpc()
}
//Listing servers and also updates IP tables (Default 3 hops)
if UpdateServerList {
err := clientIPTable.UpdateIpTableListClient()
if err != nil {
fmt.Print(err)
}
// Reads from ip table and passes it
// on to struct print function
//Servers, err := p2p.ReadIpTable()
//if err != nil {
// return err
//}
//client.PrettyPrint(Servers)
p2p.PrintIpTable()
}
//Listing servers and also updates IP tables (Default 3 hops)
if UpdateServerList {
err := clientIPTable.UpdateIpTableListClient()
if err != nil {
fmt.Print(err)
}
// Reads from ip table and passes it
// on to struct print function
//Servers, err := p2p.ReadIpTable()
//if err != nil {
// return err
//}
//client.PrettyPrint(Servers)
p2p.PrintIpTable()
}
// Displays the IP table
if ServerList {
// Reads from ip table and passes it
// on to struct print function
//Servers, err := p2p.ReadIpTable()
//if err != nil {
// return err
//}
p2p.PrintIpTable()
}
// Displays the IP table
if ServerList {
// Reads from ip table and passes it
// on to struct print function
//Servers, err := p2p.ReadIpTable()
//if err != nil {
// return err
//}
p2p.PrintIpTable()
}
// Add provided IP to the IP table
if AddServer != "" {
res, err := p2p.ReadIpTable()
if err != nil {
fmt.Println(err)
}
// Add provided IP to the IP table
if AddServer != "" {
res, err := p2p.ReadIpTable()
if err != nil {
fmt.Println(err)
}
//Create variable of type IpAddress and set IP address
// to it
var IpAddr p2p.IpAddress
//Create variable of type IpAddress and set IP address
// to it
var IpAddr p2p.IpAddress
//Checking if the address is a ipv4
// or ipv6 address
ip4Orip6 := p2p.Ip4or6(AddServer)
if ip4Orip6 == "version 6" {
IpAddr.Ipv6 = AddServer
} else {
IpAddr.Ipv4 = AddServer
}
//Checking if the address is a ipv4
// or ipv6 address
ip4Orip6 := p2p.Ip4or6(AddServer)
if ip4Orip6 == "version 6" {
IpAddr.Ipv6 = AddServer
} 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)
// Adds the new server IP to the iptable
res.WriteIpTable()
// 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)
// Adds the new server IP to the iptable
res.WriteIpTable()
}
}
// Displays all images available on the server side
if ViewImages != "" {
imageRes, err := client.ViewContainers(ViewImages)
// Displays all images available on the server side
if ViewImages != "" {
imageRes, err := client.ViewContainers(ViewImages)
if err != nil {
fmt.Print(err)
}
client.PrettyPrint(imageRes)
}
if err != nil {
fmt.Print(err)
}
client.PrettyPrint(imageRes)
}
// Function called to stop and remove server from Docker
if RemoveVM != "" && ID != "" {
err := client.RemoveContianer(RemoveVM, ID)
if err != nil {
fmt.Print(err)
}
}
// Function called to stop and remove server from Docker
if RemoveVM != "" && ID != "" {
err := client.RemoveContianer(RemoveVM, ID)
if err != nil {
fmt.Print(err)
}
}
//Call function to create Docker container
if CreateVM != "" {
//Call function to create Docker container
if CreateVM != "" {
var PortsInt int
var PortsInt int
if Ports != "" {
// Convert Get Request value to int
fmt.Sscanf(Ports, "%d", &PortsInt)
}
if Ports != "" {
// Convert Get Request value to int
fmt.Sscanf(Ports, "%d", &PortsInt)
}
// Calls function to do Api call to start the container on the server side
imageRes, err := client.StartContainer(CreateVM, PortsInt, GPU, ContainerName)
// Calls function to do Api call to start the container on the server side
imageRes, err := client.StartContainer(CreateVM, PortsInt, GPU, ContainerName)
if err != nil {
fmt.Print(err)
}
client.PrettyPrint(imageRes)
}
if err != nil {
fmt.Print(err)
}
client.PrettyPrint(imageRes)
}
//Call if specs flag is called
if Specs != "" {
specs, err := client.GetSpecs(Specs)
if err != nil {
return err
}
//Call if specs flag is called
if Specs != "" {
specs, err := client.GetSpecs(Specs)
if err != nil {
return err
}
// Pretty print
client.PrettyPrint(specs)
}
// Pretty print
client.PrettyPrint(specs)
}
//Sets default paths to the config file
if SetDefaultConfig {
err := generate.SetDefaults("P2PRC", false)
if err != nil {
fmt.Print(err)
}
}
//Sets default paths to the config file
if SetDefaultConfig {
_, err := generate.SetDefaults("P2PRC", false)
if err != nil {
fmt.Print(err)
}
}
//If the network interface flag is called
// Then all the network interfaces are displayed
if NetworkInterface {
err := p2p.ViewNetworkInterface()
if err != nil {
fmt.Print(err)
}
}
//If the network interface flag is called
// Then all the network interfaces are displayed
if NetworkInterface {
err := p2p.ViewNetworkInterface()
if err != nil {
fmt.Print(err)
}
}
// If the view plugin flag is called then display all
// plugins available
if ViewPlugin {
plugins, err := plugin.DetectPlugins()
if err != nil {
fmt.Print(err)
}
client.PrettyPrint(plugins)
}
// If the view plugin flag is called then display all
// plugins available
if ViewPlugin {
plugins, err := plugin.DetectPlugins()
if err != nil {
fmt.Print(err)
}
client.PrettyPrint(plugins)
}
// If the flag Tracked Container is called or the flag
// --tc
if TrackedContainers {
err, trackedContainers := client.ViewTrackedContainers()
if err != nil {
fmt.Print(err)
}
client.PrettyPrint(trackedContainers)
}
// If the flag Tracked Container is called or the flag
// --tc
if TrackedContainers {
err, trackedContainers := client.ViewTrackedContainers()
if err != nil {
fmt.Print(err)
}
client.PrettyPrint(trackedContainers)
}
//Executing plugin when the plugin flag is called
// --plugin
if ExecutePlugin != "" {
// To execute plugin requires the container ID or group ID provided when being executed
if ID != "" {
err := plugin.CheckRunPlugin(ExecutePlugin, ID)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Success")
}
} else {
fmt.Println("provide container ID")
}
//Executing plugin when the plugin flag is called
// --plugin
if ExecutePlugin != "" {
// To execute plugin requires the container ID or group ID provided when being executed
if ID != "" {
err := plugin.CheckRunPlugin(ExecutePlugin, ID)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Success")
}
} else {
fmt.Println("provide container ID")
}
}
}
// Executing function to create new group
// Creates new group and outputs JSON file
if CreateGroup {
group, err := client.CreateGroup()
if err != nil {
return err
}
client.PrettyPrint(group)
}
// Executing function to create new group
// Creates new group and outputs JSON file
if CreateGroup {
group, err := client.CreateGroup()
if err != nil {
return err
}
client.PrettyPrint(group)
}
// Actions to be performed when the
// group flag is called
// --group <Group ID>
if Group != "" {
// Remove container from group based on group ID provided
// --rmcgroup --id <contianer id>
if RemoveContainerGroup && ID != "" {
group, err := client.RemoveContainerGroup(ID, Group)
if err != nil {
fmt.Println(err)
} else {
client.PrettyPrint(group)
}
} else if ID != "" { // Add container to group based on group ID provided
// --id <Container ID>
group, err := client.AddContainerToGroup(ID, Group)
if err != nil {
fmt.Println(err)
} else {
client.PrettyPrint(group)
}
} else { // View all information about current group
group, err := client.GetGroup(Group)
if err != nil {
fmt.Println(err)
} else {
client.PrettyPrint(group)
}
}
}
// Actions to be performed when the
// group flag is called
// --group <Group ID>
if Group != "" {
// Remove container from group based on group ID provided
// --rmcgroup --id <contianer id>
if RemoveContainerGroup && ID != "" {
group, err := client.RemoveContainerGroup(ID, Group)
if err != nil {
fmt.Println(err)
} else {
client.PrettyPrint(group)
}
} else if ID != "" { // Add container to group based on group ID provided
// --id <Container ID>
group, err := client.AddContainerToGroup(ID, Group)
if err != nil {
fmt.Println(err)
} else {
client.PrettyPrint(group)
}
} else { // View all information about current group
group, err := client.GetGroup(Group)
if err != nil {
fmt.Println(err)
} else {
client.PrettyPrint(group)
}
}
}
// Execute function to remove entire group
// when remove group flag is called
// --rmgroup
if RemoveGroup != "" {
err := client.RemoveGroup(RemoveGroup)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Group Removed")
}
}
// Execute function to remove entire group
// when remove group flag is called
// --rmgroup
if RemoveGroup != "" {
err := client.RemoveGroup(RemoveGroup)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Group Removed")
}
}
// Execute Function to view all groups
if Groups {
groups, err := client.ReadGroup()
if err != nil {
fmt.Println(err)
} else {
client.PrettyPrint(groups)
}
}
// Execute Function to view all groups
if Groups {
groups, err := client.ReadGroup()
if err != nil {
fmt.Println(err)
} else {
client.PrettyPrint(groups)
}
}
//--------------------------------
//--------------------------------
if PullPlugin != "" {
err := plugin.DownloadPlugin(PullPlugin)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Success")
}
}
if PullPlugin != "" {
err := plugin.DownloadPlugin(PullPlugin)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Success")
}
}
if RemovePlugin != "" {
err := plugin.DeletePlugin(RemovePlugin)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Success")
}
}
if RemovePlugin != "" {
err := plugin.DeletePlugin(RemovePlugin)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Success")
}
}
return nil
return nil
}

View File

@@ -54,16 +54,16 @@ func SetEnvName(EnvName string) error {
return nil
}
func GetEnvName() string {
return defaultEnvName
}
// ConfigInit Pass environment name as an optional parameter
func ConfigInit(defaultsParameter map[string]interface{}, envNameOptional ...string) (*Config, error) {
if len(envNameOptional) > 0 {
defaultEnvName = envNameOptional[0]
}
if defaultsParameter != nil {
defaults = defaultsParameter
}
//Setting current directory to default path
defaultPath, err := GetPathP2PRC(defaultEnvName)
if err != nil {

View File

@@ -1,64 +1,64 @@
package config
import (
"fmt"
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
"os"
"testing"
"fmt"
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
"os"
"testing"
)
func TestConfigInit(t *testing.T) {
_, err := ConfigInit(nil)
if err != nil {
t.Error(err)
}
_, err := ConfigInit(nil)
if err != nil {
t.Error(err)
}
}
func TestSetDefaults(t *testing.T) {
err := generate.SetDefaults("")
if err != nil {
t.Error(err)
}
_, err := generate.SetDefaults("", false)
if err != nil {
t.Error(err)
}
}
func TestGetCurrentPath(t *testing.T) {
path, err := generate.GetCurrentPath()
if err != nil {
fmt.Println(err)
t.Error(err)
}
fmt.Println(path)
path, err := generate.GetCurrentPath()
if err != nil {
fmt.Println(err)
t.Error(err)
}
fmt.Println(path)
}
func TestGetPathP2PRC(t *testing.T) {
path, err := GetPathP2PRC("")
if err != nil {
fmt.Println(err)
t.Error(err)
}
fmt.Println(path)
path, err := GetPathP2PRC("")
if err != nil {
fmt.Println(err)
t.Error(err)
}
fmt.Println(path)
}
func TestSetEnvName(t *testing.T) {
// Create an Env variable TEST with the value "lol"
err := os.Setenv("TEST", "lol")
if err != nil {
fmt.Println(err)
t.Error(err)
}
// Sets the environment variable as the default to read
// for P2PRC
err = SetEnvName("TEST")
if err != nil {
fmt.Println(err)
t.Error(err)
}
// Create an Env variable TEST with the value "lol"
err := os.Setenv("TEST", "lol")
if err != nil {
fmt.Println(err)
t.Error(err)
}
// Sets the environment variable as the default to read
// for P2PRC
err = SetEnvName("TEST")
if err != nil {
fmt.Println(err)
t.Error(err)
}
// Checks if the output for the default read is "lol"
path, err := GetPathP2PRC("")
if err != nil {
fmt.Println(err)
t.Error(err)
}
fmt.Println(path)
// Checks if the output for the default read is "lol"
path, err := GetPathP2PRC("")
if err != nil {
fmt.Println(err)
t.Error(err)
}
fmt.Println(path)
}

View File

@@ -1,20 +1,20 @@
package generate
import (
"github.com/Akilan1999/p2p-rendering-computation/config"
"os"
"github.com/Akilan1999/p2p-rendering-computation/config"
"os"
)
var (
defaults = map[string]interface{}{}
configPaths []string
defaultEnvName = "P2PRC"
defaults = map[string]interface{}{}
configPaths []string
defaultEnvName = "P2PRC"
)
// GetPathP2PRC Getting P2PRC Directory from environment variable
func GetPathP2PRC() (string, error) {
curDir := os.Getenv(defaultEnvName)
return curDir + "/", nil
curDir := os.Getenv(defaultEnvName)
return curDir + "/", nil
}
// SetEnvName Sets the environment name
@@ -22,93 +22,108 @@ func GetPathP2PRC() (string, error) {
// your environment variable
// This is useful when extending the use case of P2PRC
func SetEnvName(EnvName string) error {
if EnvName != "" {
defaultEnvName = EnvName
}
// Handling error to be implemented only if needed
return nil
if EnvName != "" {
defaultEnvName = EnvName
}
// Handling error to be implemented only if needed
return nil
}
// GetCurrentPath Getting P2PRC Directory from environment variable
func GetCurrentPath() (string, error) {
curDir := os.Getenv("PWD")
return curDir + "/", nil
curDir := os.Getenv("PWD")
return curDir + "/", nil
}
// SetDefaults This function to be called only during a
// make install
func SetDefaults(envName string, forceDefault bool) error {
//Setting current directory to default path
defaultPath, err := GetCurrentPath()
if err != nil {
return err
}
func SetDefaults(envName string, forceDefault bool, ConfigUpdate ...*config.Config) (*config.Config, error) {
//Setting current directory to default path
defaultPath, err := GetCurrentPath()
if err != nil {
return nil, err
}
// Set Env name
err = SetEnvName(envName)
if err != nil {
return err
}
// Set Env name
err = config.SetEnvName(envName)
if err != nil {
return nil, err
}
////Creates ip_table.json in the json directory
//err = Copy("p2p/ip_table.json", "p2p/iptable/ip_table.json")
//if err != nil {
// return err
//}
//
////Creates a copy of trackcontainers.json in the appropriate directory
//err = Copy("client/trackcontainers.json", "client/trackcontainers/trackcontainers.json")
//if err != nil {
// return err
//}
//
////Creates a copy of trackcontainers.json in the appropriate directory
//err = Copy("client/grouptrackcontainers.json", "client/trackcontainers/grouptrackcontainers.json")
//if err != nil {
// return err
//}
////Creates ip_table.json in the json directory
//err = Copy("p2p/ip_table.json", "p2p/iptable/ip_table.json")
//if err != nil {
// return err
//}
//
////Creates a copy of trackcontainers.json in the appropriate directory
//err = Copy("client/trackcontainers.json", "client/trackcontainers/trackcontainers.json")
//if err != nil {
// return err
//}
//
////Creates a copy of trackcontainers.json in the appropriate directory
//err = Copy("client/grouptrackcontainers.json", "client/trackcontainers/grouptrackcontainers.json")
//if err != nil {
// return err
//}
//Setting default paths for the config file
defaults["IPTable"] = defaultPath + "p2p/iptable/ip_table.json"
defaults["DefaultDockerFile"] = defaultPath + "server/docker/containers/docker-ubuntu-sshd/"
defaults["DockerContainers"] = defaultPath + "server/docker/containers/"
defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin"
defaults["IPV6Address"] = ""
defaults["PluginPath"] = defaultPath + "plugin/deploy"
defaults["TrackContainersPath"] = defaultPath + "client/trackcontainers/trackcontainers.json"
defaults["GroupTrackContainersPath"] = defaultPath + "client/trackcontainers/grouptrackcontainers.json"
defaults["ServerPort"] = "8088"
defaults["FRPServerPort"] = "0"
defaults["BehindNAT"] = "True"
// Random name generator
hostname, err := os.Hostname()
if err != nil {
return err
}
if len(ConfigUpdate) == 0 {
//Setting default paths for the config file
defaults["IPTable"] = defaultPath + "p2p/iptable/ip_table.json"
defaults["DefaultDockerFile"] = defaultPath + "server/docker/containers/docker-ubuntu-sshd/"
defaults["DockerContainers"] = defaultPath + "server/docker/containers/"
defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin"
defaults["IPV6Address"] = ""
defaults["PluginPath"] = defaultPath + "plugin/deploy"
defaults["TrackContainersPath"] = defaultPath + "client/trackcontainers/trackcontainers.json"
defaults["GroupTrackContainersPath"] = defaultPath + "client/trackcontainers/grouptrackcontainers.json"
defaults["ServerPort"] = "8088"
defaults["FRPServerPort"] = "0"
defaults["BehindNAT"] = "True"
// Random name generator
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
defaults["MachineName"] = hostname
//defaults["NetworkInterface"] = "wlp0s20f3"
//defaults["NetworkInterfaceIPV6Index"] = "2"
defaults["MachineName"] = hostname
} else {
defaults["IPTable"] = ConfigUpdate[0].IPTable
defaults["DefaultDockerFile"] = ConfigUpdate[0].DefaultDockerFile
defaults["DockerContainers"] = ConfigUpdate[0].DockerContainers
defaults["SpeedTestFile"] = ConfigUpdate[0].SpeedTestFile
defaults["IPV6Address"] = ConfigUpdate[0].IPV6Address
defaults["PluginPath"] = ConfigUpdate[0].PluginPath
defaults["TrackContainersPath"] = ConfigUpdate[0].TrackContainersPath
defaults["GroupTrackContainersPath"] = ConfigUpdate[0].GroupTrackContainersPath
defaults["ServerPort"] = ConfigUpdate[0].ServerPort
defaults["FRPServerPort"] = ConfigUpdate[0].FRPServerPort
defaults["BehindNAT"] = ConfigUpdate[0].BehindNAT
}
//Paths to search for config file
configPaths = append(configPaths, defaultPath)
//defaults["NetworkInterface"] = "wlp0s20f3"
//defaults["NetworkInterfaceIPV6Index"] = "2"
if fileExists(defaultPath+"config.json") && forceDefault {
err := os.Remove(defaultPath + "config.json")
if err != nil {
return err
}
}
//Paths to search for config file
configPaths = append(configPaths, defaultPath)
//Calling configuration file
_, err = config.ConfigInit(defaults, envName)
if err != nil {
return err
}
if fileExists(defaultPath + "config.json") && forceDefault {
err := os.Remove(defaultPath + "config.json")
if err != nil {
return nil, err
}
}
err = GenerateFiles()
if err != nil {
return err
}
return nil
//Calling configuration file
Config, err := config.ConfigInit(defaults, envName)
if err != nil {
return nil, err
}
err = GenerateFiles()
if err != nil {
return nil, err
}
return Config, nil
}

View File

@@ -1,164 +1,164 @@
package generate
import (
"github.com/Akilan1999/p2p-rendering-computation/p2p"
"github.com/go-git/go-git/v5"
"os"
"github.com/Akilan1999/p2p-rendering-computation/p2p"
"github.com/go-git/go-git/v5"
"os"
)
// GenerateFiles Generates all the files needed to setup P2PRC
func GenerateFiles(rootNodes ...p2p.IpAddress) (err error) {
err = GenerateIPTableFile(rootNodes)
err = GenerateDockerFiles()
err = GeneratePluginDirectory()
err = GenerateClientTrackContainers()
return
err = GenerateIPTableFile(rootNodes)
err = GenerateDockerFiles()
err = GeneratePluginDirectory()
err = GenerateClientTrackContainers()
return
}
// GenerateIPTableFile Generates the IPTable file with the appropirate root node
func GenerateIPTableFile(rootNodes []p2p.IpAddress) (err error) {
var rootnodes p2p.IpAddresses
var rootnode p2p.IpAddress
var rootnodes p2p.IpAddresses
var rootnode p2p.IpAddress
err = CreateIPTableFolderStructure()
if err != nil {
return err
}
err = CreateIPTableFolderStructure()
if err != nil {
return err
}
// If root node addresses are not provided as optional parameters
if len(rootNodes) <= 0 {
rootnode.Name = "Node1"
rootnode.ServerPort = "8088"
rootnode.NAT = "False"
rootnode.Ipv4 = "64.227.168.102"
// If root node addresses are not provided as optional parameters
if len(rootNodes) <= 0 {
rootnode.Name = "Node1"
rootnode.ServerPort = "8088"
rootnode.NAT = "False"
rootnode.Ipv4 = "64.227.168.102"
rootnodes.IpAddress = append(rootnodes.IpAddress, rootnode)
} else {
// if root nodes are provided then override them as the optional parameter
for i := range rootNodes {
rootnodes.IpAddress = append(rootnodes.IpAddress, rootNodes[i])
}
}
rootnodes.IpAddress = append(rootnodes.IpAddress, rootnode)
} else {
// if root nodes are provided then override them as the optional parameter
for i := range rootNodes {
rootnodes.IpAddress = append(rootnodes.IpAddress, rootNodes[i])
}
}
err = rootnodes.WriteIpTable()
return
err = rootnodes.WriteIpTable()
return
}
// CreateIPTableFolderStructure Create folder structure for IPTable
func CreateIPTableFolderStructure() (err error) {
path, err := GetCurrentPath()
if err != nil {
return err
}
if _, err = os.Stat(path + "p2p"); os.IsNotExist(err) {
if err = os.Mkdir(path+"p2p", os.ModePerm); err != nil {
return err
}
if _, err = os.Stat(path + "p2p/iptable"); os.IsNotExist(err) {
if err = os.Mkdir(path+"p2p/iptable", os.ModePerm); err != nil {
return err
}
}
if _, err = os.Stat(path + "p2p/iptable/ip_table.json"); os.IsNotExist(err) {
_, err = os.Create(path + "p2p/iptable/ip_table.json")
if err != nil {
return err
}
}
path, err := GetCurrentPath()
if err != nil {
return err
}
if _, err = os.Stat(path + "p2p"); os.IsNotExist(err) {
if err = os.Mkdir(path+"p2p", os.ModePerm); err != nil {
return err
}
if _, err = os.Stat(path + "p2p/iptable"); os.IsNotExist(err) {
if err = os.Mkdir(path+"p2p/iptable", os.ModePerm); err != nil {
return err
}
}
if _, err = os.Stat(path + "p2p/iptable/ip_table.json"); os.IsNotExist(err) {
_, err = os.Create(path + "p2p/iptable/ip_table.json")
if err != nil {
return err
}
}
}
}
return
return
}
// GenerateDockerFiles Generate default docker files
func GenerateDockerFiles() (err error) {
path, err := GetCurrentPath()
if err != nil {
return err
}
if _, err = os.Stat(path + "server"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server", os.ModePerm); err != nil {
return err
}
if _, err = os.Stat(path + "server/docker"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server/docker", os.ModePerm); err != nil {
return err
}
}
if _, err = os.Stat(path + "server/docker/containers"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server/docker/containers", os.ModePerm); err != nil {
return err
}
}
if _, err = os.Stat(path + "server/docker/containers"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server/docker/containers", os.ModePerm); err != nil {
return err
}
}
if _, err = os.Stat(path + "server/docker/containers/docker-ubuntu-sshd"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server/docker/containers/docker-ubuntu-sshd", os.ModePerm); err != nil {
return err
}
}
path, err := GetCurrentPath()
if err != nil {
return err
}
if _, err = os.Stat(path + "server"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server", os.ModePerm); err != nil {
return err
}
if _, err = os.Stat(path + "server/docker"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server/docker", os.ModePerm); err != nil {
return err
}
}
if _, err = os.Stat(path + "server/docker/containers"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server/docker/containers", os.ModePerm); err != nil {
return err
}
}
if _, err = os.Stat(path + "server/docker/containers"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server/docker/containers", os.ModePerm); err != nil {
return err
}
}
if _, err = os.Stat(path + "server/docker/containers/docker-ubuntu-sshd"); os.IsNotExist(err) {
if err = os.Mkdir(path+"server/docker/containers/docker-ubuntu-sshd", os.ModePerm); err != nil {
return err
}
}
}
}
// Clone base docker image
_, err = git.PlainClone(path+"server/docker/containers/docker-ubuntu-sshd", false, &git.CloneOptions{
URL: "https://github.com/Akilan1999/docker-ubuntu-sshd",
Progress: os.Stdout,
})
if err != nil {
return err
}
// Clone base docker image
_, err = git.PlainClone(path+"server/docker/containers/docker-ubuntu-sshd", false, &git.CloneOptions{
URL: "https://github.com/Akilan1999/docker-ubuntu-sshd",
Progress: os.Stdout,
})
if err != nil {
return err
}
return
return
}
// GeneratePluginDirectory Generates plugin directory structure
func GeneratePluginDirectory() (err error) {
path, err := GetCurrentPath()
if err != nil {
return err
}
if _, err = os.Stat(path + "plugin"); os.IsNotExist(err) {
if err = os.Mkdir(path+"plugin", os.ModePerm); err != nil {
return err
}
if _, err = os.Stat(path + "plugin/deploy"); os.IsNotExist(err) {
if err = os.Mkdir(path+"plugin/deploy", os.ModePerm); err != nil {
return err
}
}
}
return
path, err := GetCurrentPath()
if err != nil {
return err
}
if _, err = os.Stat(path + "plugin"); os.IsNotExist(err) {
if err = os.Mkdir(path+"plugin", os.ModePerm); err != nil {
return err
}
if _, err = os.Stat(path + "plugin/deploy"); os.IsNotExist(err) {
if err = os.Mkdir(path+"plugin/deploy", os.ModePerm); err != nil {
return err
}
}
}
return
}
func GenerateClientTrackContainers() (err error) {
path, err := GetCurrentPath()
if err != nil {
return err
}
if _, err = os.Stat(path + "client"); os.IsNotExist(err) {
if err = os.Mkdir(path+"client", os.ModePerm); err != nil {
return err
}
path, err := GetCurrentPath()
if err != nil {
return err
}
if _, err = os.Stat(path + "client"); os.IsNotExist(err) {
if err = os.Mkdir(path+"client", os.ModePerm); err != nil {
return err
}
if _, err = os.Stat(path + "client/trackcontainers.json"); os.IsNotExist(err) {
_, err = os.Create(path + "client/trackcontainers.json")
if err != nil {
return err
}
}
if _, err = os.Stat(path + "client/trackcontainers.json"); os.IsNotExist(err) {
_, err = os.Create(path + "client/trackcontainers.json")
if err != nil {
return err
}
}
if _, err = os.Stat(path + "client/grouptrackcontainers.json"); os.IsNotExist(err) {
_, err = os.Create(path + "client/grouptrackcontainers.json")
if err != nil {
return err
}
}
if _, err = os.Stat(path + "client/grouptrackcontainers.json"); os.IsNotExist(err) {
_, err = os.Create(path + "client/grouptrackcontainers.json")
if err != nil {
return err
}
}
}
return
}
return
}