added base code for plugin system
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -10,4 +10,6 @@ config.json
|
|||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
#ignore generated iptables
|
#ignore generated iptables
|
||||||
p2p/iptable/
|
p2p/iptable/
|
||||||
|
#ignore plugins added
|
||||||
|
plugin/deploy
|
||||||
@@ -26,6 +26,7 @@ type Config struct {
|
|||||||
DefaultDockerFile string
|
DefaultDockerFile string
|
||||||
SpeedTestFile string
|
SpeedTestFile string
|
||||||
IPV6Address string
|
IPV6Address string
|
||||||
|
PluginPath string
|
||||||
//NetworkInterface string
|
//NetworkInterface string
|
||||||
//NetworkInterfaceIPV6Index int
|
//NetworkInterfaceIPV6Index int
|
||||||
}
|
}
|
||||||
@@ -86,6 +87,7 @@ func SetDefaults() error {
|
|||||||
defaults["DockerContainers"] = defaultPath + "server/docker/containers/"
|
defaults["DockerContainers"] = defaultPath + "server/docker/containers/"
|
||||||
defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin"
|
defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin"
|
||||||
defaults["IPV6Address"] = ""
|
defaults["IPV6Address"] = ""
|
||||||
|
defaults["PluginPath"] = defaultPath + "plugin/deploy"
|
||||||
//defaults["NetworkInterface"] = "wlp0s20f3"
|
//defaults["NetworkInterface"] = "wlp0s20f3"
|
||||||
//defaults["NetworkInterfaceIPV6Index"] = "2"
|
//defaults["NetworkInterfaceIPV6Index"] = "2"
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
state: started
|
state: started
|
||||||
when: inventory_hostname == rsync.master
|
when: inventory_hostname == rsync.master
|
||||||
|
|
||||||
# Synchronize the data folder across hosts
|
# Synchronize the data deploy across hosts
|
||||||
- name: synchronize the data folder
|
- name: synchronize the data deploy
|
||||||
delegate_to: "{{ rsync.master }}"
|
delegate_to: "{{ rsync.master }}"
|
||||||
synchronize:
|
synchronize:
|
||||||
src: "{{ sync.source }}"
|
src: "{{ sync.source }}"
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// VERSION specifies the version of the platform
|
// VERSION specifies the version of the platform
|
||||||
var VERSION = "1.0.0"
|
var VERSION = "beta-1.0.0"
|
||||||
var mode string
|
var mode string
|
||||||
|
|
||||||
// Varaibles if mode is client
|
// Varaibles if mode is client
|
||||||
|
|||||||
0
plugin/deploy/.gitkeep
Normal file
0
plugin/deploy/.gitkeep
Normal file
54
plugin/plugin.go
Normal file
54
plugin/plugin.go
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.sr.ht/~akilan1999/p2p-rendering-computation/config"
|
||||||
|
"io/ioutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Plugins Array of all plugins detected
|
||||||
|
type Plugins struct {
|
||||||
|
PluginsDetected []*Plugin
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin Information about the plugins available
|
||||||
|
type Plugin struct {
|
||||||
|
FolderName string
|
||||||
|
PluginDescription string
|
||||||
|
}
|
||||||
|
|
||||||
|
// DetectPlugins Detects all the plugins available
|
||||||
|
func DetectPlugins()(*Plugins,error){
|
||||||
|
config, err:= config.ConfigInit()
|
||||||
|
if err != nil {
|
||||||
|
return nil,err
|
||||||
|
}
|
||||||
|
folders, err := ioutil.ReadDir(config.PluginPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var plugins *Plugins = new(Plugins)
|
||||||
|
|
||||||
|
for _, f := range folders {
|
||||||
|
if f.IsDir() {
|
||||||
|
//Declare variable plugin of type Plugin
|
||||||
|
var plugin Plugin
|
||||||
|
|
||||||
|
// Setting name of folder to plugin
|
||||||
|
plugin.FolderName = f.Name()
|
||||||
|
// Getting Description from file description.txt
|
||||||
|
Description, err := ioutil.ReadFile(config.PluginPath + "/" + plugin.FolderName + "/description.txt")
|
||||||
|
// if we os.Open returns an error then handle it
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Description from description.txt
|
||||||
|
plugin.PluginDescription = string(Description)
|
||||||
|
|
||||||
|
plugins.PluginsDetected = append(plugins.PluginsDetected, &plugin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugins,nil
|
||||||
|
}
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
state: started
|
state: started
|
||||||
when: inventory_hostname == rsync.master
|
when: inventory_hostname == rsync.master
|
||||||
|
|
||||||
# Synchronize the data folder across hosts
|
# Synchronize the data deploy across hosts
|
||||||
- name: synchronize the data folder
|
- name: synchronize the data deploy
|
||||||
delegate_to: "{{ rsync.master }}"
|
delegate_to: "{{ rsync.master }}"
|
||||||
synchronize:
|
synchronize:
|
||||||
src: "{{ sync.source }}"
|
src: "{{ sync.source }}"
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Builds docker image (TODO: relative path for Dockerfile folder)
|
//Builds docker image (TODO: relative path for Dockerfile deploy)
|
||||||
func (d *DockerVM)imageBuild(dockerClient *client.Client) error {
|
func (d *DockerVM)imageBuild(dockerClient *client.Client) error {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*2000)
|
ctx, _ := context.WithTimeout(context.Background(), time.Second*2000)
|
||||||
//defer cancel()
|
//defer cancel()
|
||||||
@@ -298,7 +298,7 @@ func StopAndRemoveContainer(containername string) error {
|
|||||||
|
|
||||||
// ViewAllContainers returns all containers runnable and which can be built
|
// ViewAllContainers returns all containers runnable and which can be built
|
||||||
func ViewAllContainers() (*DockerContainers, error){
|
func ViewAllContainers() (*DockerContainers, error){
|
||||||
// Traverse the folder path as per given in the config file
|
// Traverse the deploy path as per given in the config file
|
||||||
config, err := config.ConfigInit()
|
config, err := config.ConfigInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil,err
|
||||||
@@ -317,7 +317,7 @@ func ViewAllContainers() (*DockerContainers, error){
|
|||||||
//Declare variable DockerContainer of type struct
|
//Declare variable DockerContainer of type struct
|
||||||
var Container DockerContainer
|
var Container DockerContainer
|
||||||
|
|
||||||
// Setting container name to folder name
|
// Setting container name to deploy name
|
||||||
Container.ContainerName = f.Name()
|
Container.ContainerName = f.Name()
|
||||||
// Getting Description from file description.txt
|
// Getting Description from file description.txt
|
||||||
Description, err := ioutil.ReadFile(config.DockerContainers + "/" + Container.ContainerName + "/description.txt")
|
Description, err := ioutil.ReadFile(config.DockerContainers + "/" + Container.ContainerName + "/description.txt")
|
||||||
|
|||||||
Reference in New Issue
Block a user