diff --git a/plugin/TestAnsible/description.txt b/plugin/TestAnsible/description.txt new file mode 100644 index 0000000..b0a0a8f --- /dev/null +++ b/plugin/TestAnsible/description.txt @@ -0,0 +1 @@ +Test if it's detected \ No newline at end of file diff --git a/plugin/TestAnsible/site.yml b/plugin/TestAnsible/site.yml new file mode 100644 index 0000000..3dc78ac --- /dev/null +++ b/plugin/TestAnsible/site.yml @@ -0,0 +1,8 @@ +--- + +- hosts: all + + tasks: + - name: simple-ansibleplaybook + debug: + msg: Your are running 'simple-ansibleplaybook' example \ No newline at end of file diff --git a/plugin/generate_test_case.sh b/plugin/generate_test_case.sh new file mode 100644 index 0000000..605c2c7 --- /dev/null +++ b/plugin/generate_test_case.sh @@ -0,0 +1 @@ +cp -r TestAnsible/ deploy/TestAnsbile diff --git a/plugin/plugin.go b/plugin/plugin.go index aa75eaf..d5866fb 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -2,6 +2,7 @@ package plugin import ( "context" + "errors" "git.sr.ht/~akilan1999/p2p-rendering-computation/config" "io/ioutil" @@ -67,6 +68,36 @@ func DetectPlugins()(*Plugins,error){ return plugins,nil } +// RunPlugin Executes plugins based on the plugin name provided +func RunPlugin(pluginName string ,IPAddresses []*ExecuteIP) (*Plugin,error) { + plugins, err := DetectPlugins() + if err != nil { + return nil,err + } + + // Variable to store struct information about the plugin + var plugindetected *Plugin + for _,plugin := range plugins.PluginsDetected { + if plugin.FolderName == pluginName { + plugindetected = plugin + plugindetected.Execute = IPAddresses + break + } + } + + if plugindetected == nil { + return nil, errors.New("Plugin not detected") + } + + // Executing the plugin + err = plugindetected.ExecutePlugin() + if err != nil { + return nil,err + } + + return plugindetected,nil +} + // ExecutePlugin Function to execute plugins that are called func (p *Plugin) ExecutePlugin() error { // Get Execute plugin path from config file diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go index 6820dab..b1fb654 100644 --- a/plugin/plugin_test.go +++ b/plugin/plugin_test.go @@ -8,4 +8,22 @@ func TestDetectPlugins(t *testing.T) { if err != nil { t.Fail() } +} + +func TestRunPlugin(t *testing.T) { + var testips []*ExecuteIP + var testip1,testip2 ExecuteIP + + //Test IP 1 configuration + testip1.IPAddress = "0.0.0.0" + testip1.SSHPortNo = "41289" + + //Test IP 2 configuration + testip2.IPAddress = "0.0.0.0" + testip1.SSHPortNo = "34447" + + testips = append(testips, &testip1) + testips = append(testips, &testip2) + + RunPlugin("test",testips) } \ No newline at end of file