@@ -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,61 @@ 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 != nil && blockVol .Specs .PerfIops != nil {
445
+ switch * blockVol .Specs .PerfIops {
446
+ case 5000 :
447
+ customVol .IOPS = "5K"
448
+ case 15000 :
449
+ customVol .IOPS = "15K"
450
+ }
451
+ }
452
+ } else {
453
+ instanceVol , err := instance .NewAPI (client ).GetVolume (& instance.GetVolumeRequest {
454
+ VolumeID : volume .ID ,
455
+ Zone : volume .Zone ,
456
+ })
457
+ if err != nil {
458
+ return nil , err
459
+ }
460
+ customVol .Name = instanceVol .Volume .Name
461
+ customVol .Size = instanceVol .Volume .Size
462
+ customVol .VolumeType = instanceVol .Volume .VolumeType .String ()
463
+ customVol .State = instanceVol .Volume .State .String ()
464
+ customVol .CreationDate = instanceVol .Volume .CreationDate
465
+ customVol .ModificationDate = instanceVol .Volume .ModificationDate
466
+ }
467
+
468
+ volumes [volume .ID ] = customVol
469
+ }
470
+
410
471
return & struct {
411
472
* instance.Server
412
- Volumes []* instance. VolumeServer
473
+ Volumes []* customVolume
413
474
PrivateNics []customNICs `json:"private_nics"`
414
475
}{
415
476
getServerResp .Server ,
416
- orderVolumes (getServerResp . Server . Volumes ),
477
+ orderVolumes (volumes ),
417
478
nics ,
418
479
}, nil
419
480
}
0 commit comments