@@ -120,15 +120,28 @@ func serversMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error)
120
120
return human .Marshal (humanServers , opt )
121
121
}
122
122
123
+ type customVolume struct {
124
+ ID string `json:"id"`
125
+ Name string `json:"name"`
126
+ Size scw.Size `json:"size"`
127
+ VolumeType string `json:"volume_type"`
128
+ IOPS string `json:"iops"`
129
+ State string `json:"state"`
130
+ CreationDate * time.Time `json:"creation_date"`
131
+ ModificationDate * time.Time `json:"modification_date"`
132
+ Boot bool `json:"boot"`
133
+ Zone string `json:"zone"`
134
+ }
135
+
123
136
// orderVolumes return an ordered slice based on the volume map key "0", "1", "2",...
124
- func orderVolumes (v map [string ]* instance. VolumeServer ) []* instance. VolumeServer {
137
+ func orderVolumes (v map [string ]* customVolume ) []* customVolume {
125
138
indexes := []string (nil )
126
139
for index := range v {
127
140
indexes = append (indexes , index )
128
141
}
129
142
sort .Strings (indexes )
130
143
131
- orderedVolumes := make ([]* instance. VolumeServer , 0 , len (indexes ))
144
+ orderedVolumes := make ([]* customVolume , 0 , len (indexes ))
132
145
for _ , index := range indexes {
133
146
orderedVolumes = append (orderedVolumes , v [index ])
134
147
}
@@ -407,13 +420,58 @@ func serverGetBuilder(c *core.Command) *core.Command {
407
420
})
408
421
}
409
422
423
+ volumes := map [string ]* customVolume {}
424
+ blockAPI := block .NewAPI (client )
425
+
426
+ for _ , volume := range getServerResp .Server .Volumes {
427
+ customVol := & customVolume {
428
+ ID : volume .ID ,
429
+ Zone : volume .Zone .String (),
430
+ Boot : volume .Boot ,
431
+ }
432
+
433
+ blockVol , _ := blockAPI .GetVolume (& block.GetVolumeRequest {
434
+ VolumeID : volume .ID ,
435
+ Zone : volume .Zone ,
436
+ })
437
+ if blockVol != nil {
438
+ customVol .Name = blockVol .Name
439
+ customVol .Size = blockVol .Size
440
+ customVol .VolumeType = blockVol .Type
441
+ customVol .State = blockVol .Status .String ()
442
+ customVol .CreationDate = blockVol .CreatedAt
443
+ customVol .ModificationDate = blockVol .UpdatedAt
444
+ if * blockVol .Specs .PerfIops == 5000 {
445
+ customVol .IOPS = "5K"
446
+ } else {
447
+ customVol .IOPS = "15K"
448
+ }
449
+ } else {
450
+ instanceVol , err := instance .NewAPI (client ).GetVolume (& instance.GetVolumeRequest {
451
+ VolumeID : volume .ID ,
452
+ Zone : volume .Zone ,
453
+ })
454
+ if err != nil {
455
+ return nil , err
456
+ }
457
+ customVol .Name = instanceVol .Volume .Name
458
+ customVol .Size = instanceVol .Volume .Size
459
+ customVol .VolumeType = instanceVol .Volume .VolumeType .String ()
460
+ customVol .State = instanceVol .Volume .State .String ()
461
+ customVol .CreationDate = instanceVol .Volume .CreationDate
462
+ customVol .ModificationDate = instanceVol .Volume .ModificationDate
463
+ }
464
+
465
+ volumes [volume .ID ] = customVol
466
+ }
467
+
410
468
return & struct {
411
469
* instance.Server
412
- Volumes []* instance. VolumeServer
470
+ Volumes []* customVolume
413
471
PrivateNics []customNICs `json:"private_nics"`
414
472
}{
415
473
getServerResp .Server ,
416
- orderVolumes (getServerResp . Server . Volumes ),
474
+ orderVolumes (volumes ),
417
475
nics ,
418
476
}, nil
419
477
}
0 commit comments