Reuse GetClusterRegInfo from mc (#3270)
This commit is contained in:
@@ -204,44 +204,7 @@ func subnetPostReq(client xhttp.ClientI, reqURL string, payload interface{}, hea
|
||||
}
|
||||
|
||||
func GetClusterRegInfo(admInfo madmin.InfoMessage) mc.ClusterRegistrationInfo {
|
||||
noOfPools := 1
|
||||
noOfDrives := 0
|
||||
for _, srvr := range admInfo.Servers {
|
||||
if srvr.PoolNumber > noOfPools {
|
||||
noOfPools = srvr.PoolNumber
|
||||
}
|
||||
noOfDrives += len(srvr.Disks)
|
||||
}
|
||||
|
||||
totalSpace, usedSpace := getDriveSpaceInfo(admInfo)
|
||||
|
||||
return mc.ClusterRegistrationInfo{
|
||||
DeploymentID: admInfo.DeploymentID,
|
||||
ClusterName: admInfo.DeploymentID,
|
||||
UsedCapacity: admInfo.Usage.Size,
|
||||
Info: mc.ClusterInfo{
|
||||
MinioVersion: admInfo.Servers[0].Version,
|
||||
NoOfServerPools: noOfPools,
|
||||
NoOfServers: len(admInfo.Servers),
|
||||
NoOfDrives: noOfDrives,
|
||||
TotalDriveSpace: totalSpace,
|
||||
UsedDriveSpace: usedSpace,
|
||||
NoOfBuckets: admInfo.Buckets.Count,
|
||||
NoOfObjects: admInfo.Objects.Count,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getDriveSpaceInfo(admInfo madmin.InfoMessage) (uint64, uint64) {
|
||||
total := uint64(0)
|
||||
used := uint64(0)
|
||||
for _, srvr := range admInfo.Servers {
|
||||
for _, d := range srvr.Disks {
|
||||
total += d.TotalSpace
|
||||
used += d.UsedSpace
|
||||
}
|
||||
}
|
||||
return total, used
|
||||
return mc.GetClusterRegInfo(admInfo, admInfo.DeploymentID)
|
||||
}
|
||||
|
||||
func GetSubnetAPIKeyUsingLicense(lic string) (string, error) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/cmd"
|
||||
)
|
||||
|
||||
@@ -480,128 +479,3 @@ func Test_subnetAuthHeaders(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getDriveSpaceInfo(t *testing.T) {
|
||||
type args struct {
|
||||
admInfo madmin.InfoMessage
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want uint64
|
||||
want1 uint64
|
||||
}{
|
||||
{
|
||||
name: "basic",
|
||||
args: args{
|
||||
admInfo: madmin.InfoMessage{
|
||||
Servers: []madmin.ServerProperties{
|
||||
{
|
||||
Disks: []madmin.Disk{
|
||||
{
|
||||
TotalSpace: 1,
|
||||
UsedSpace: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: 1,
|
||||
want1: 1,
|
||||
},
|
||||
{
|
||||
name: "basic two disks",
|
||||
args: args{
|
||||
admInfo: madmin.InfoMessage{
|
||||
Servers: []madmin.ServerProperties{
|
||||
{
|
||||
Disks: []madmin.Disk{
|
||||
{
|
||||
TotalSpace: 1,
|
||||
UsedSpace: 1,
|
||||
},
|
||||
{
|
||||
TotalSpace: 1,
|
||||
UsedSpace: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: 2,
|
||||
want1: 2,
|
||||
},
|
||||
{
|
||||
name: "basic two servers two disks",
|
||||
args: args{
|
||||
admInfo: madmin.InfoMessage{
|
||||
Servers: []madmin.ServerProperties{
|
||||
{
|
||||
Disks: []madmin.Disk{
|
||||
{
|
||||
TotalSpace: 1,
|
||||
UsedSpace: 1,
|
||||
},
|
||||
{
|
||||
TotalSpace: 1,
|
||||
UsedSpace: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Disks: []madmin.Disk{
|
||||
{
|
||||
TotalSpace: 1,
|
||||
UsedSpace: 1,
|
||||
},
|
||||
{
|
||||
TotalSpace: 1,
|
||||
UsedSpace: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: 4,
|
||||
want1: 4,
|
||||
},
|
||||
{
|
||||
name: "no servers",
|
||||
args: args{
|
||||
admInfo: madmin.InfoMessage{
|
||||
Servers: nil,
|
||||
},
|
||||
},
|
||||
want: 0,
|
||||
want1: 0,
|
||||
},
|
||||
{
|
||||
name: "no disks",
|
||||
args: args{
|
||||
admInfo: madmin.InfoMessage{
|
||||
Servers: []madmin.ServerProperties{
|
||||
{
|
||||
Disks: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: 0,
|
||||
want1: 0,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(_ *testing.T) {
|
||||
got, got1 := getDriveSpaceInfo(tt.args.admInfo)
|
||||
if got != tt.want {
|
||||
t.Errorf("getDriveSpaceInfo() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
if got1 != tt.want1 {
|
||||
t.Errorf("getDriveSpaceInfo() got1 = %v, want %v", got1, tt.want1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user