-
Notifications
You must be signed in to change notification settings - Fork 2.3k
adds list command #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adds list command #507
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // +build linux | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
| "path/filepath" | ||
| "text/tabwriter" | ||
| "time" | ||
|
|
||
| "github.com/Sirupsen/logrus" | ||
| "github.com/codegangsta/cli" | ||
| ) | ||
|
|
||
| var listCommand = cli.Command{ | ||
| Name: "list", | ||
| Usage: "lists containers started by runc with the given root", | ||
| Action: func(context *cli.Context) { | ||
|
|
||
| // preload the container factory | ||
| if factory == nil { | ||
| err := factoryPreload(context) | ||
| if err != nil { | ||
| logrus.Fatal(err) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // get the list of containers | ||
| root := context.GlobalString("root") | ||
| absRoot, err := filepath.Abs(root) | ||
| if err != nil { | ||
| logrus.Fatal(err) | ||
| return | ||
| } | ||
| list, err := ioutil.ReadDir(absRoot) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use a reference: https://github.com/docker/containerd/blob/master/ctr/container.go#L64
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good will redo it using tabwritter in the morning. |
||
| w := tabwriter.NewWriter(os.Stdout, 12, 1, 3, ' ', 0) | ||
| fmt.Fprint(w, "ID\tPID\tSTATUS\tCREATED\n") | ||
|
|
||
| // output containers | ||
| for _, item := range list { | ||
| switch { | ||
| case !item.IsDir(): | ||
| // do nothing with misc files in the containers directory | ||
| case item.IsDir(): | ||
| outputListInfo(item.Name(), w) | ||
| } | ||
| } | ||
|
|
||
| if err := w.Flush(); err != nil { | ||
| logrus.Fatal(err) | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| func outputListInfo(id string, w *tabwriter.Writer) { | ||
| container, err := factory.Load(id) | ||
| if err != nil { | ||
| logrus.Fatal(err) | ||
| return | ||
| } | ||
|
|
||
| containerStatus, err := container.Status() | ||
| if err != nil { | ||
| logrus.Fatal(err) | ||
| return | ||
| } | ||
|
|
||
| state, err := container.State() | ||
| if err != nil { | ||
| logrus.Fatal(err) | ||
| return | ||
| } | ||
|
|
||
| fmt.Fprintf(w, "%s\t%d\t%s\t%s\n", container.ID(), | ||
| state.BaseState.InitProcessPid, | ||
| containerStatus.String(), | ||
| state.BaseState.CreatedTime.Format(time.RFC3339Nano)) | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we instead say
System Time?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the new one to creation timestamp per your suggestion..
This old one for init process start is a legacy naming issue.. in so far as it's been named and used this way for a while... I was just updating the comment to be more explanatory