added feature to detect if a port is used by a plugin or not
This commit is contained in:
@@ -26,6 +26,7 @@ plugin
|
||||
|___<plugin name>
|
||||
|___ site.yml
|
||||
|___ hosts
|
||||
|___ ports.json
|
||||
|___ description.txt
|
||||
.
|
||||
.
|
||||
@@ -70,6 +71,16 @@ main:
|
||||
ansible_sudo_pass: password
|
||||
```
|
||||
|
||||
## Ports.json
|
||||
The ```ports.json``` file is intended to mention the number of ports required
|
||||
by the plugin.
|
||||
|
||||
```
|
||||
{
|
||||
"NumOfPorts": <number of ports>
|
||||
}
|
||||
```
|
||||
|
||||
## Description file
|
||||
This is a simple text file used to describe what the module does.
|
||||
When the client is looking at various commands via the ClI.
|
||||
|
||||
@@ -178,6 +178,8 @@ Format of the ports.json file
|
||||
"PortName": "<Port name>",
|
||||
"InternalPort": <internal port>,
|
||||
"Type": "<tcp/udp>",
|
||||
"ExternalPort": <external port>,
|
||||
"IsUsed": "<boolean value (i.e true or false)>",
|
||||
"Description": "<description about the port>"
|
||||
}, ... n
|
||||
]
|
||||
|
||||
@@ -281,6 +281,8 @@ func (grp *Groups)RemoveContainerGroups(Container *TrackContainer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ModifyContainerGroups Modifies container information is all groups
|
||||
// available
|
||||
func (TC *TrackContainer)ModifyContainerGroups() error {
|
||||
group, err := ReadGroup()
|
||||
if err != nil {
|
||||
|
||||
@@ -262,6 +262,7 @@ func ReadHost(filename string) (*Host, error) {
|
||||
|
||||
// RunPluginContainer Runs ansible plugin based on plugin name and container name which
|
||||
// is derived from the tracked containers file
|
||||
// We pass in the group ID as a parameter because when we modify the ports taken
|
||||
func RunPluginContainer(PluginName string, ContainerID string) error {
|
||||
// Gets container information based on container ID
|
||||
ContainerInformation, err := client.GetContainerInformation(ContainerID)
|
||||
@@ -361,17 +362,24 @@ func (p *Plugin)AutoSetPorts(containerID string) error {
|
||||
// variable that would have a list of ports
|
||||
// to be allocated to the plugin system
|
||||
var ports []int
|
||||
// Counted that increments when a port is taken
|
||||
PortTaken := 0
|
||||
// setting all external ports available in an array
|
||||
for _, port := range container.Container.Ports.PortSet {
|
||||
for i, port := range container.Container.Ports.PortSet {
|
||||
if port.IsUsed == false {
|
||||
ports = append(ports, port.ExternalPort)
|
||||
// Ensuring we break outside the loop once the ports
|
||||
// are set.
|
||||
if PortTaken >= p.NumOfPorts {
|
||||
break
|
||||
}
|
||||
// Setting the following port flag to true
|
||||
port.IsUsed = true
|
||||
container.Container.Ports.PortSet[i].IsUsed = true
|
||||
// Incrementing the variable PortTaken
|
||||
PortTaken++
|
||||
ports = append(ports, port.ExternalPort)
|
||||
}
|
||||
}
|
||||
|
||||
client
|
||||
|
||||
// parses the site.yml file in the tmp directory
|
||||
t, err := template.ParseFiles(p.path + "/" + p.FolderName + "/site.yml")
|
||||
if err != nil {
|
||||
@@ -387,6 +395,18 @@ func (p *Plugin)AutoSetPorts(containerID string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Once the following is done set port to taken
|
||||
// n tracked container list
|
||||
err = container.ModifyContainerInformation()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Once the following is done set port to taken
|
||||
// I(Groups)
|
||||
err = container.ModifyContainerGroups()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user