Merge v1.2.1-master
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
a590155b0b
commit
aeb17182b4
396 changed files with 27271 additions and 9969 deletions
22
vendor/github.com/JamesClonk/vultr/lib/block_storage.go
generated
vendored
22
vendor/github.com/JamesClonk/vultr/lib/block_storage.go
generated
vendored
|
@ -4,7 +4,9 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// BlockStorage on Vultr account
|
||||
|
@ -19,6 +21,25 @@ type BlockStorage struct {
|
|||
AttachedTo string `json:"attached_to_SUBID"`
|
||||
}
|
||||
|
||||
type blockstorages []BlockStorage
|
||||
|
||||
func (b blockstorages) Len() int { return len(b) }
|
||||
func (b blockstorages) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
func (b blockstorages) Less(i, j int) bool {
|
||||
// sort order: name, size, status
|
||||
if strings.ToLower(b[i].Name) < strings.ToLower(b[j].Name) {
|
||||
return true
|
||||
} else if strings.ToLower(b[i].Name) > strings.ToLower(b[j].Name) {
|
||||
return false
|
||||
}
|
||||
if b[i].SizeGB < b[j].SizeGB {
|
||||
return true
|
||||
} else if b[i].SizeGB > b[j].SizeGB {
|
||||
return false
|
||||
}
|
||||
return b[i].Status < b[j].Status
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaller on BlockStorage.
|
||||
// This is needed because the Vultr API is inconsistent in it's JSON responses.
|
||||
// Some fields can change type, from JSON number to JSON string and vice-versa.
|
||||
|
@ -87,6 +108,7 @@ func (c *Client) GetBlockStorages() (storages []BlockStorage, err error) {
|
|||
if err := c.get(`block/list`, &storages); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sort.Sort(blockstorages(storages))
|
||||
return storages, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue