Merge pull request #48 from Akilan1999/plugins

Detection of plugins
This commit is contained in:
Akilan Selvacoumar
2021-07-13 23:39:13 +04:00
committed by GitHub
11 changed files with 97 additions and 9 deletions

4
.gitignore vendored
View File

@@ -10,4 +10,6 @@ config.json
.vscode/
#ignore generated iptables
p2p/iptable/
p2p/iptable/
#ignore plugins added
plugin/deploy

View File

@@ -5,6 +5,7 @@ import (
"git.sr.ht/~akilan1999/p2p-rendering-computation/client"
"git.sr.ht/~akilan1999/p2p-rendering-computation/config"
"git.sr.ht/~akilan1999/p2p-rendering-computation/p2p"
"git.sr.ht/~akilan1999/p2p-rendering-computation/plugin"
"git.sr.ht/~akilan1999/p2p-rendering-computation/server"
"github.com/urfave/cli/v2"
)
@@ -124,6 +125,16 @@ var CliAction = func(ctx *cli.Context) error {
}
}
// 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)
}
return nil
}

View File

@@ -20,6 +20,7 @@ var (
ServerList bool
SetDefaultConfig bool
NetworkInterface bool
ViewPlugin bool
)
var AppConfigFlags = []cli.Flag{
@@ -122,4 +123,11 @@ var AppConfigFlags = []cli.Flag{
EnvVars: []string{"NETWORK_INTERFACE"},
Destination: &NetworkInterface,
},
&cli.BoolFlag{
Name: "ViewPlugins",
Aliases: []string{"vp"},
Usage: "Shows plugins available to be executed",
EnvVars: []string{"VIEW_PLUGIN"},
Destination: &ViewPlugin,
},
}

View File

@@ -26,6 +26,7 @@ type Config struct {
DefaultDockerFile string
SpeedTestFile string
IPV6Address string
PluginPath string
//NetworkInterface string
//NetworkInterfaceIPV6Index int
}
@@ -86,6 +87,7 @@ func SetDefaults() error {
defaults["DockerContainers"] = defaultPath + "server/docker/containers/"
defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin"
defaults["IPV6Address"] = ""
defaults["PluginPath"] = defaultPath + "plugin/deploy"
//defaults["NetworkInterface"] = "wlp0s20f3"
//defaults["NetworkInterfaceIPV6Index"] = "2"

View File

@@ -15,8 +15,8 @@
state: started
when: inventory_hostname == rsync.master
# Synchronize the data folder across hosts
- name: synchronize the data folder
# Synchronize the data deploy across hosts
- name: synchronize the data deploy
delegate_to: "{{ rsync.master }}"
synchronize:
src: "{{ sync.source }}"

View File

@@ -8,7 +8,7 @@ import (
)
// VERSION specifies the version of the platform
var VERSION = "1.0.0"
var VERSION = "beta-1.0.0"
var mode string
// Varaibles if mode is client

0
plugin/deploy/.gitkeep Normal file
View File

54
plugin/plugin.go Normal file
View 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
}

11
plugin/plugin_test.go Normal file
View File

@@ -0,0 +1,11 @@
package plugin
import "testing"
// Test if the dummy plugin added is detected
func TestDetectPlugins(t *testing.T) {
_, err := DetectPlugins()
if err != nil {
t.Fail()
}
}

View File

@@ -15,8 +15,8 @@
state: started
when: inventory_hostname == rsync.master
# Synchronize the data folder across hosts
- name: synchronize the data folder
# Synchronize the data deploy across hosts
- name: synchronize the data deploy
delegate_to: "{{ rsync.master }}"
synchronize:
src: "{{ sync.source }}"

View File

@@ -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 {
ctx, _ := context.WithTimeout(context.Background(), time.Second*2000)
//defer cancel()
@@ -298,7 +298,7 @@ func StopAndRemoveContainer(containername string) error {
// ViewAllContainers returns all containers runnable and which can be built
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()
if err != nil {
return nil,err
@@ -317,7 +317,7 @@ func ViewAllContainers() (*DockerContainers, error){
//Declare variable DockerContainer of type struct
var Container DockerContainer
// Setting container name to folder name
// Setting container name to deploy name
Container.ContainerName = f.Name()
// Getting Description from file description.txt
Description, err := ioutil.ReadFile(config.DockerContainers + "/" + Container.ContainerName + "/description.txt")