From 56be27575918cab3e41f0a15e14b1e90a7bca1d1 Mon Sep 17 00:00:00 2001 From: Akilan Selvacoumar Date: Sat, 9 Oct 2021 17:34:15 +0400 Subject: [PATCH] saving changes --- client/GroupTrackContainer.go | 27 +++++++++++++++++++++ client/TrackContainers.go | 44 +++++++++++++++++++++++++++++++++++ plugin/plugin.go | 7 +++++- server/docker/docker.go | 2 +- 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/client/GroupTrackContainer.go b/client/GroupTrackContainer.go index 9cbfb71..e4ffa49 100644 --- a/client/GroupTrackContainer.go +++ b/client/GroupTrackContainer.go @@ -278,5 +278,32 @@ func (grp *Groups)RemoveContainerGroups(Container *TrackContainer) error { // Set group information to list groups grp.GroupList[i] = group } + return nil +} + +func (TC *TrackContainer)ModifyContainerGroups() error { + group, err := ReadGroup() + if err != nil { + return err + } + // Iterate though all groups and modify the container + // information in groups where the modified container + // ID matches + for i, _ := range group.GroupList { + // Checking in each group if the modified container ID exists + for j, _:= range group.GroupList[i].TrackContainerList { + // If there is match then change them + if group.GroupList[i].TrackContainerList[j].Id == TC.Id { + group.GroupList[i].TrackContainerList[j] = TC + } + } + } + + // Write modified result to the Groups track container JSON file + err = group.WriteGroup() + if err != nil { + return err + } + return nil } \ No newline at end of file diff --git a/client/TrackContainers.go b/client/TrackContainers.go index b61d7f2..ca83594 100644 --- a/client/TrackContainers.go +++ b/client/TrackContainers.go @@ -146,6 +146,8 @@ func ReadTrackContainers(filename string) (*TrackContainers, error) { return c, nil } +//func ModifyTrackContainers() + // GetContainerInformation gets information about container based on // container ID provided func GetContainerInformation(ID string) (*TrackContainer, error) { @@ -164,6 +166,48 @@ func GetContainerInformation(ID string) (*TrackContainer, error) { return nil, errors.New("Container not found. ") } +// ModifyContainerInformation Modifies information inside the container +func (TC *TrackContainer)ModifyContainerInformation() error { + // Gets all the information of tracker containers + err, t := ViewTrackedContainers() + if err != nil { + return err + } + // Find the element where the containers match and + // change them + for i, container := range t.TrackContainerList { + if TC.Id == container.Id { + t.TrackContainerList[i] = *TC + break + } + } + // Write the modified information to the file + // write modified information to the tracked json file + err = t.WriteContainers() + if err != nil { + return err + } + + return nil +} + +// WriteContainers Write information back to the config file +func (TC *TrackContainers)WriteContainers() error { + // Initialize config file + config,err := config.ConfigInit() + // write modified information to the tracked json file + data,err := json.MarshalIndent(TC, "", "\t") + if err != nil { + return err + } + err = ioutil.WriteFile(config.TrackContainersPath,data,0777) + if err != nil { + return err + } + + return nil +} + // CheckID Checks if the ID belongs to a group or a single container func CheckID(ID string) (string,error) { // For group checks if the 1st characters is "grp" diff --git a/plugin/plugin.go b/plugin/plugin.go index 3b7671c..7265d62 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -363,10 +363,15 @@ func (p *Plugin)AutoSetPorts(containerID string) error { var ports []int // setting all external ports available in an array for _, port := range container.Container.Ports.PortSet { - if port.InternalPort == port.ExternalPort { + if port.IsUsed == false { ports = append(ports, port.ExternalPort) + // Setting the following port flag to true + port.IsUsed = true } } + + client + // parses the site.yml file in the tmp directory t, err := template.ParseFiles(p.path + "/" + p.FolderName + "/site.yml") if err != nil { diff --git a/server/docker/docker.go b/server/docker/docker.go index 0e816f7..e101e15 100644 --- a/server/docker/docker.go +++ b/server/docker/docker.go @@ -127,7 +127,7 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV for i := range PortsInformation.PortSet { // Setting external ports PortsInformation.PortSet[i].ExternalPort = OpenPorts[i] - PortsInformation.PortSet[i].IsUsed = true + PortsInformation.PortSet[i].IsUsed = true } //Length of Ports allocated from thr port file portFileLength := len(PortsInformation.PortSet)