added tracker to cli abd into add and remove container on the client side

This commit is contained in:
2021-07-18 12:12:31 +04:00
parent 51110c235b
commit 489ffd6d0c
4 changed files with 46 additions and 0 deletions

View File

@@ -116,6 +116,20 @@ func RemoveTrackedContainer(id string) error {
return nil
}
// ViewTrackedContainers View Containers currently tracked
func ViewTrackedContainers() (error,*TrackContainers) {
config,err := config.ConfigInit()
if err != nil {
return err,nil
}
trackedContianers, err := ReadTrackContainers(config.TrackContainersPath)
if err != nil {
return err,nil
}
return nil,trackedContianers
}
// ReadTrackContainers Reads containers which are currently tracked
func ReadTrackContainers(filename string) (*TrackContainers, error) {
buf, err := ioutil.ReadFile(filename)

View File

@@ -51,6 +51,12 @@ func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string) (*d
return nil,err
}
// Adds the container to the tracked list
err = AddTrackContainer(&dockerResult, IP)
if err != nil {
return nil, err
}
return &dockerResult, nil
}
@@ -77,6 +83,13 @@ func RemoveContianer(IP string,ID string) error {
if string(byteValue[:]) == "success" {
fmt.Println("success")
}
// Remove container created from the tracked list
err = RemoveTrackedContainer(ID)
if err != nil {
return err
}
return nil
}