Skip to content
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

Add ImageFSInfo method #417

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions cmd/crictl/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,58 @@ var removeImageCommand = cli.Command{
},
}

var imageFsInfoCommand = cli.Command{
Name: "imagefsinfo",
Usage: "Return image filesystem info",
SkipArgReorder: true,
UseShortOptionHandling: true,
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Usage: "Output format, One of: json|yaml|table",
},
},
Action: func(context *cli.Context) error {
if err := getImageClient(context); err != nil {
return err
}
output := context.String("output")
if output == "" { // default to json output
output = "json"
}

r, err := ImageFsInfo(imageClient)
if err != nil {
return fmt.Errorf("image filesystem info request failed: %v", err)
}
for _, info := range r.ImageFilesystems {
status, err := protobufObjectToJSON(info)
if err != nil {
return fmt.Errorf("failed to marshal image filesystem info to json: %v", err)
}

switch output {
case "json", "yaml":
if err := outputStatusInfo(status, nil, output); err != nil {
return fmt.Errorf("failed to output image filesystem info %v", err)
}
continue
case "table": // table output is after this switch block
default:
return fmt.Errorf("output option cannot be %s", output)
}

// otherwise output in table format
fmt.Printf("TimeStamp: %d\n", info.Timestamp)
fmt.Printf("UsedBytes: %s\n", info.UsedBytes)
fmt.Printf("Mountpoint: %s\n", info.FsId.Mountpoint)
}

return nil

},
}

func parseCreds(creds string) (string, string, error) {
if creds == "" {
return "", "", errors.New("credentials can't be empty")
Expand Down Expand Up @@ -439,3 +491,13 @@ func RemoveImage(client pb.ImageServiceClient, image string) (resp *pb.RemoveIma
logrus.Debugf("RemoveImageResponse: %v", resp)
return
}

// ImageFsInfo sends an ImageStatusRequest to the server, and parses
// the returned ImageFsInfoResponse.
func ImageFsInfo(client pb.ImageServiceClient) (resp *pb.ImageFsInfoResponse, err error) {
request := &pb.ImageFsInfoRequest{}
logrus.Debugf("ImageFsInfoRequest: %v", request)
resp, err = client.ImageFsInfo(context.Background(), request)
logrus.Debugf("ImageFsInfoResponse: %v", resp)
return
}
1 change: 1 addition & 0 deletions cmd/crictl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func main() {
listImageCommand,
containerStatusCommand,
imageStatusCommand,
imageFsInfoCommand,
podStatusCommand,
logsCommand,
runtimePortForwardCommand,
Expand Down