Skip to content

Commit

Permalink
show labels for images output (#1395)
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Eyberg <[email protected]>
  • Loading branch information
eyberg and Ian Eyberg authored Dec 13, 2022
1 parent cb5f8dd commit 8d53837
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion aws/aws_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,19 @@ func (p *AWS) GetImages(ctx *lepton.Context) ([]lepton.CloudImage, error) {
tagName = &ec2.Tag{Value: aws.String("n/a")}
}

labels := []string{}
for _, tag := range image.Tags {
labels = append(labels, *tag.Key+":"+*tag.Value)
}

imageCreatedAt, _ := time.Parse("2006-01-02T15:04:05Z", *image.CreationDate)

cimage := lepton.CloudImage{
Tag: *tagName.Value,
Name: *image.Name,
ID: *image.ImageId,
Status: *image.State,
Labels: labels,
Created: imageCreatedAt,
}

Expand All @@ -638,12 +644,13 @@ func (p *AWS) ListImages(ctx *lepton.Context) error {
} else {
// default of table output
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"AmiID", "AmiName", "Name", "Status", "Created"})
table.SetHeader([]string{"AmiID", "AmiName", "Name", "Status", "Created", "Labels"})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor})
table.SetRowLine(true)

Expand All @@ -655,6 +662,7 @@ func (p *AWS) ListImages(ctx *lepton.Context) error {
row = append(row, image.Tag)
row = append(row, image.Status)
row = append(row, lepton.Time2Human(image.Created))
row = append(row, strings.Join(image.Labels[:], ","))

table.Append(row)
}
Expand Down
10 changes: 9 additions & 1 deletion gcp/gcp_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,16 @@ func (p *GCloud) GetImages(ctx *lepton.Context) ([]lepton.CloudImage, error) {
if val, ok := image.Labels["createdby"]; ok && val == "ops" {
imageCreatedAt, _ := time.Parse("2006-01-02T15:04:05-07:00", image.CreationTimestamp)

labels := []string{}
for k, v := range image.Labels {
labels = append(labels, k+":"+v)
}

ci := lepton.CloudImage{
Name: image.Name,
Status: fmt.Sprintf("%v", image.Status),
Created: imageCreatedAt,
Labels: labels,
}

images = append(images, ci)
Expand All @@ -168,8 +174,9 @@ func (p *GCloud) ListImages(ctx *lepton.Context) error {
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Status", "Created"})
table.SetHeader([]string{"Name", "Status", "Created", "Labels"})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor})
Expand All @@ -180,6 +187,7 @@ func (p *GCloud) ListImages(ctx *lepton.Context) error {
row = append(row, image.Name)
row = append(row, image.Status)
row = append(row, lepton.Time2Human(image.Created))
row = append(row, strings.Join(image.Labels[:], ","))
table.Append(row)
}

Expand Down
3 changes: 2 additions & 1 deletion lepton/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type CloudImage struct {
Size int64
Path string
Created time.Time
Tag string
Tag string // could merge w/below
Labels []string
}

// CloudInstance represents the instance that widely use in different
Expand Down

0 comments on commit 8d53837

Please sign in to comment.