Skip to content

Commit

Permalink
Fix vm headers
Browse files Browse the repository at this point in the history
  • Loading branch information
PratikJethe committed Nov 3, 2023
1 parent a7539ce commit 2ff1be5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
31 changes: 28 additions & 3 deletions internal/gcp/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package gcp

import (
"context"
"strings"
"time"

compute "cloud.google.com/go/compute/apiv1"
"cloud.google.com/go/compute/apiv1/computepb"
"github.com/one2nc/cloudlens/internal"
"github.com/one2nc/cloudlens/internal/config"
"github.com/rs/zerolog/log"
"google.golang.org/api/iterator"
)

Expand Down Expand Up @@ -36,12 +40,33 @@ func ListInstances(ctx context.Context) ([]VMResp, error) {
return vmResp, err
}

splittedZoneURL := strings.Split(*instance.Zone, "/")
zone := splittedZoneURL[len(splittedZoneURL)-1]

splittedMachineURL := strings.Split(*instance.MachineType, "/")
machineType := splittedMachineURL[len(splittedMachineURL)-1]

createdTime := *instance.CreationTimestamp
launchTime, err := time.Parse("2006-01-02T15:04:05.999-07:00", createdTime)
if err != nil {
log.Print("Error parsing timestamp :", err)
return vmResp, err
}
localZone, err := config.GetLocalTimeZone()
if err != nil {
log.Print("Error loading local timezone:", err)
return vmResp, err
}
loc, _ := time.LoadLocation(localZone)
IST := launchTime.In(loc)


vm := VMResp{
InstanceId: *instance.Name,
InstanceType: *instance.MachineType,
AvailabilityZone: *instance.Zone,
InstanceType: machineType,
AvailabilityZone: zone,
InstanceState: *instance.Status,
LaunchTime: *instance.CreationTimestamp,
LaunchTime: IST.Format("Mon Jan _2 15:04:05 2006"),
}
vmResp = append(vmResp, vm)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/render/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (vm VM) Header() Header {
return Header{
HeaderColumn{Name: "Instance-Id", SortIndicatorIdx: 9, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false},
HeaderColumn{Name: "Instance-State", SortIndicatorIdx: 9, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false},
// HeaderColumn{Name: "Instance-Type", SortIndicatorIdx: 9, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false},
HeaderColumn{Name: "Instance-Type", SortIndicatorIdx: 9, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false},
// HeaderColumn{Name: "Monitoring-State", SortIndicatorIdx: 0, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false},
HeaderColumn{Name: "Launch-Time", SortIndicatorIdx: 0, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: true},
// HeaderColumn{Name: "Public-DNS", SortIndicatorIdx: 0, Align: tview.AlignLeft, Hide: false, Wide: true, MX: false, Time: false},
Expand All @@ -34,7 +34,7 @@ func (vm VM) Render(o interface{}, ns string, row *Row) error {
row.Fields = Fields{
vmResp.InstanceId,
vmResp.InstanceState,
// vmResp.InstanceType,
vmResp.InstanceType,
// ec2Resp.MonitoringState,
vmResp.LaunchTime,
// ec2Resp.PublicDNS,
Expand Down

0 comments on commit 2ff1be5

Please sign in to comment.