diff --git a/client/TrackContainers.go b/client/TrackContainers.go index 4d15cf3..2c6222f 100644 --- a/client/TrackContainers.go +++ b/client/TrackContainers.go @@ -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) diff --git a/client/container.go b/client/container.go index 968a1bf..4b4c113 100644 --- a/client/container.go +++ b/client/container.go @@ -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 } diff --git a/cmd/action.go b/cmd/action.go index 714566b..7a3f7c5 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -135,6 +135,16 @@ var CliAction = func(ctx *cli.Context) error { client.PrettyPrint(plugins) } + // If the flag Tracked Container is called or the flag + // --tc + if TrackedContainers { + err, trackedContainers := client.ViewTrackedContainers() + if err != nil { + fmt.Print(err) + } + client.PrettyPrint(trackedContainers) + } + return nil } diff --git a/cmd/flags.go b/cmd/flags.go index a0e0ba9..fee32ff 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -21,6 +21,7 @@ var ( SetDefaultConfig bool NetworkInterface bool ViewPlugin bool + TrackedContainers bool ) var AppConfigFlags = []cli.Flag{ @@ -130,4 +131,12 @@ var AppConfigFlags = []cli.Flag{ EnvVars: []string{"VIEW_PLUGIN"}, Destination: &ViewPlugin, }, + &cli.BoolFlag{ + Name: "TrackedContainers", + Aliases: []string{"tc"}, + Usage: "View containers which have " + + "been created from the client side ", + EnvVars: []string{"TRACKED_CONTAINERS"}, + Destination: &TrackedContainers, + }, } \ No newline at end of file