wrote a function to detect the number of plugins available for a plugin
This commit is contained in:
@@ -2,6 +2,7 @@ package plugin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/client"
|
"git.sr.ht/~akilan1999/p2p-rendering-computation/client"
|
||||||
@@ -31,6 +32,7 @@ type Plugin struct {
|
|||||||
PluginDescription string
|
PluginDescription string
|
||||||
path string
|
path string
|
||||||
Execute []*ExecuteIP
|
Execute []*ExecuteIP
|
||||||
|
NumOfPorts int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteIP IP Address to execute Ansible instruction
|
// ExecuteIP IP Address to execute Ansible instruction
|
||||||
@@ -91,8 +93,15 @@ func DetectPlugins()(*Plugins,error){
|
|||||||
|
|
||||||
// Get Description from description.txt
|
// Get Description from description.txt
|
||||||
plugin.PluginDescription = string(Description)
|
plugin.PluginDescription = string(Description)
|
||||||
|
// Set plugin path
|
||||||
|
plugin.path = config.PluginPath + "/" + plugin.FolderName
|
||||||
|
|
||||||
plugins.PluginsDetected = append(plugins.PluginsDetected, &plugin)
|
plugins.PluginsDetected = append(plugins.PluginsDetected, &plugin)
|
||||||
|
// Get the number of ports the plugin needs
|
||||||
|
err = plugin.NumPorts()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,6 +384,26 @@ func (p *Plugin)AutoSetPorts(containerID string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumPorts Gets the Number the ports the
|
||||||
|
// plugin requires
|
||||||
|
func (p *Plugin)NumPorts() error {
|
||||||
|
jsonFile, err := os.Open(p.path + "/ports.json")
|
||||||
|
// if we os.Open returns an error then handle it
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// defer the closing of our jsonFile so that we can parse it later on
|
||||||
|
defer jsonFile.Close()
|
||||||
|
|
||||||
|
// read our opened xmlFile as a byte array.
|
||||||
|
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||||
|
|
||||||
|
// we unmarshal our byteArray which contains our
|
||||||
|
// jsonFile's content into 'users' which we defined above
|
||||||
|
json.Unmarshal(byteValue, &p)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user