diff --git a/Docs/PluginImplementation.md b/Docs/PluginImplementation.md index a261edd..1628f5b 100644 --- a/Docs/PluginImplementation.md +++ b/Docs/PluginImplementation.md @@ -26,6 +26,7 @@ plugin |___ |___ 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": +} +``` + ## 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. diff --git a/Docs/ServerImplementation.md b/Docs/ServerImplementation.md index 8e63354..045ec10 100644 --- a/Docs/ServerImplementation.md +++ b/Docs/ServerImplementation.md @@ -178,6 +178,8 @@ Format of the ports.json file "PortName": "", "InternalPort": , "Type": "", + "ExternalPort": , + "IsUsed": "", "Description": "" }, ... n ] diff --git a/client/GroupTrackContainer.go b/client/GroupTrackContainer.go index e4ffa49..908b287 100644 --- a/client/GroupTrackContainer.go +++ b/client/GroupTrackContainer.go @@ -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 { diff --git a/plugin/plugin.go b/plugin/plugin.go index 7265d62..b632461 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -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 }