Skip to content

Commit

Permalink
Print usage table
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumatag committed Oct 12, 2020
1 parent c00b7db commit 7b72939
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/purge/vms/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package vms

import (
"fmt"
"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_instances"
"github.com/ppc64le-cloud/pvsadm/pkg"
"github.com/ppc64le-cloud/pvsadm/pkg/audit"
"github.com/ppc64le-cloud/pvsadm/pkg/client"
"github.com/ppc64le-cloud/pvsadm/pkg/utils"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
"strconv"
"strings"
)

Expand All @@ -30,6 +34,28 @@ var Cmd = &cobra.Command{
return err
}

param := p_cloud_instances.NewPcloudCloudinstancesGetParamsWithTimeout(pkg.TIMEOUT).WithCloudInstanceID(pvmclient.InstanceID)
resp, err := pvmclient.PISession.Power.PCloudInstances.PcloudCloudinstancesGet(param, ibmpisession.NewAuth(pvmclient.PISession, pvmclient.InstanceID))

if err != nil || resp.Payload == nil {
klog.Infof("Failed to perform the operation... %v", err)
return errors.ToError(err)
}
usage := resp.Payload.Usage

fmt.Println("Usage:")
tu := utils.NewTable()
tu.SetHeader([]string{"Instances", "Memory", "Proc Units", "processors", "storage", "storageSSD", "storageStandard"})
tu.Append([]string{strconv.FormatFloat(*usage.Instances, 'f', -1, 64),
strconv.FormatFloat(*usage.Memory, 'f', -1, 64),
strconv.FormatFloat(*usage.ProcUnits, 'f', 1, 64),
strconv.FormatFloat(*usage.Processors, 'f', -1, 64),
strconv.FormatFloat(*usage.Storage, 'f', 2, 64),
strconv.FormatFloat(*usage.StorageSSD, 'f', 2, 64),
strconv.FormatFloat(*usage.StorageStandard, 'f', 2, 64),
})
tu.Table.Render()

instances, err := pvmclient.InstanceClient.GetAllPurgeable(pkg.Options.Before, pkg.Options.Since)
if err != nil {
return err
Expand Down

0 comments on commit 7b72939

Please sign in to comment.