Skip to content

Commit 8d53837

Browse files
eybergIan Eyberg
and
Ian Eyberg
authored
show labels for images output (#1395)
Co-authored-by: Ian Eyberg <[email protected]>
1 parent cb5f8dd commit 8d53837

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

aws/aws_image.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,19 @@ func (p *AWS) GetImages(ctx *lepton.Context) ([]lepton.CloudImage, error) {
607607
tagName = &ec2.Tag{Value: aws.String("n/a")}
608608
}
609609

610+
labels := []string{}
611+
for _, tag := range image.Tags {
612+
labels = append(labels, *tag.Key+":"+*tag.Value)
613+
}
614+
610615
imageCreatedAt, _ := time.Parse("2006-01-02T15:04:05Z", *image.CreationDate)
611616

612617
cimage := lepton.CloudImage{
613618
Tag: *tagName.Value,
614619
Name: *image.Name,
615620
ID: *image.ImageId,
616621
Status: *image.State,
622+
Labels: labels,
617623
Created: imageCreatedAt,
618624
}
619625

@@ -638,12 +644,13 @@ func (p *AWS) ListImages(ctx *lepton.Context) error {
638644
} else {
639645
// default of table output
640646
table := tablewriter.NewWriter(os.Stdout)
641-
table.SetHeader([]string{"AmiID", "AmiName", "Name", "Status", "Created"})
647+
table.SetHeader([]string{"AmiID", "AmiName", "Name", "Status", "Created", "Labels"})
642648
table.SetHeaderColor(
643649
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
644650
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
645651
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
646652
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
653+
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
647654
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor})
648655
table.SetRowLine(true)
649656

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

659667
table.Append(row)
660668
}

gcp/gcp_image.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,16 @@ func (p *GCloud) GetImages(ctx *lepton.Context) ([]lepton.CloudImage, error) {
144144
if val, ok := image.Labels["createdby"]; ok && val == "ops" {
145145
imageCreatedAt, _ := time.Parse("2006-01-02T15:04:05-07:00", image.CreationTimestamp)
146146

147+
labels := []string{}
148+
for k, v := range image.Labels {
149+
labels = append(labels, k+":"+v)
150+
}
151+
147152
ci := lepton.CloudImage{
148153
Name: image.Name,
149154
Status: fmt.Sprintf("%v", image.Status),
150155
Created: imageCreatedAt,
156+
Labels: labels,
151157
}
152158

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

170176
table := tablewriter.NewWriter(os.Stdout)
171-
table.SetHeader([]string{"Name", "Status", "Created"})
177+
table.SetHeader([]string{"Name", "Status", "Created", "Labels"})
172178
table.SetHeaderColor(
179+
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
173180
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
174181
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor},
175182
tablewriter.Colors{tablewriter.Bold, tablewriter.FgCyanColor})
@@ -180,6 +187,7 @@ func (p *GCloud) ListImages(ctx *lepton.Context) error {
180187
row = append(row, image.Name)
181188
row = append(row, image.Status)
182189
row = append(row, lepton.Time2Human(image.Created))
190+
row = append(row, strings.Join(image.Labels[:], ","))
183191
table.Append(row)
184192
}
185193

lepton/cloud.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ type CloudImage struct {
1010
Size int64
1111
Path string
1212
Created time.Time
13-
Tag string
13+
Tag string // could merge w/below
14+
Labels []string
1415
}
1516

1617
// CloudInstance represents the instance that widely use in different

0 commit comments

Comments
 (0)