cloudstack/PoolService.go (1,485 lines of code) (raw):
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type PoolServiceIface interface {
CreateStoragePool(p *CreateStoragePoolParams) (*CreateStoragePoolResponse, error)
NewCreateStoragePoolParams(name string, url string, zoneid string) *CreateStoragePoolParams
DeleteStoragePool(p *DeleteStoragePoolParams) (*DeleteStoragePoolResponse, error)
NewDeleteStoragePoolParams(id string) *DeleteStoragePoolParams
FindStoragePoolsForMigration(p *FindStoragePoolsForMigrationParams) (*FindStoragePoolsForMigrationResponse, error)
NewFindStoragePoolsForMigrationParams(id string) *FindStoragePoolsForMigrationParams
ListElastistorPool(p *ListElastistorPoolParams) (*ListElastistorPoolResponse, error)
NewListElastistorPoolParams() *ListElastistorPoolParams
ListStoragePools(p *ListStoragePoolsParams) (*ListStoragePoolsResponse, error)
NewListStoragePoolsParams() *ListStoragePoolsParams
GetStoragePoolID(name string, opts ...OptionFunc) (string, int, error)
GetStoragePoolByName(name string, opts ...OptionFunc) (*StoragePool, int, error)
GetStoragePoolByID(id string, opts ...OptionFunc) (*StoragePool, int, error)
SyncStoragePool(p *SyncStoragePoolParams) (*SyncStoragePoolResponse, error)
NewSyncStoragePoolParams(id string) *SyncStoragePoolParams
UpdateStoragePool(p *UpdateStoragePoolParams) (*UpdateStoragePoolResponse, error)
NewUpdateStoragePoolParams(id string) *UpdateStoragePoolParams
}
type CreateStoragePoolParams struct {
p map[string]interface{}
}
func (p *CreateStoragePoolParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["capacitybytes"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("capacitybytes", vv)
}
if v, found := p.p["capacityiops"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("capacityiops", vv)
}
if v, found := p.p["clusterid"]; found {
u.Set("clusterid", v.(string))
}
if v, found := p.p["details"]; found {
m := v.(map[string]string)
for i, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("details[%d].%s", i, k), m[k])
}
}
if v, found := p.p["hypervisor"]; found {
u.Set("hypervisor", v.(string))
}
if v, found := p.p["istagarule"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("istagarule", vv)
}
if v, found := p.p["managed"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("managed", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["provider"]; found {
u.Set("provider", v.(string))
}
if v, found := p.p["scope"]; found {
u.Set("scope", v.(string))
}
if v, found := p.p["tags"]; found {
u.Set("tags", v.(string))
}
if v, found := p.p["url"]; found {
u.Set("url", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *CreateStoragePoolParams) SetCapacitybytes(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["capacitybytes"] = v
}
func (p *CreateStoragePoolParams) ResetCapacitybytes() {
if p.p != nil && p.p["capacitybytes"] != nil {
delete(p.p, "capacitybytes")
}
}
func (p *CreateStoragePoolParams) GetCapacitybytes() (int64, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["capacitybytes"].(int64)
return value, ok
}
func (p *CreateStoragePoolParams) SetCapacityiops(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["capacityiops"] = v
}
func (p *CreateStoragePoolParams) ResetCapacityiops() {
if p.p != nil && p.p["capacityiops"] != nil {
delete(p.p, "capacityiops")
}
}
func (p *CreateStoragePoolParams) GetCapacityiops() (int64, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["capacityiops"].(int64)
return value, ok
}
func (p *CreateStoragePoolParams) SetClusterid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["clusterid"] = v
}
func (p *CreateStoragePoolParams) ResetClusterid() {
if p.p != nil && p.p["clusterid"] != nil {
delete(p.p, "clusterid")
}
}
func (p *CreateStoragePoolParams) GetClusterid() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["clusterid"].(string)
return value, ok
}
func (p *CreateStoragePoolParams) SetDetails(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["details"] = v
}
func (p *CreateStoragePoolParams) ResetDetails() {
if p.p != nil && p.p["details"] != nil {
delete(p.p, "details")
}
}
func (p *CreateStoragePoolParams) GetDetails() (map[string]string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["details"].(map[string]string)
return value, ok
}
func (p *CreateStoragePoolParams) SetHypervisor(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hypervisor"] = v
}
func (p *CreateStoragePoolParams) ResetHypervisor() {
if p.p != nil && p.p["hypervisor"] != nil {
delete(p.p, "hypervisor")
}
}
func (p *CreateStoragePoolParams) GetHypervisor() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["hypervisor"].(string)
return value, ok
}
func (p *CreateStoragePoolParams) SetIstagarule(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["istagarule"] = v
}
func (p *CreateStoragePoolParams) ResetIstagarule() {
if p.p != nil && p.p["istagarule"] != nil {
delete(p.p, "istagarule")
}
}
func (p *CreateStoragePoolParams) GetIstagarule() (bool, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["istagarule"].(bool)
return value, ok
}
func (p *CreateStoragePoolParams) SetManaged(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["managed"] = v
}
func (p *CreateStoragePoolParams) ResetManaged() {
if p.p != nil && p.p["managed"] != nil {
delete(p.p, "managed")
}
}
func (p *CreateStoragePoolParams) GetManaged() (bool, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["managed"].(bool)
return value, ok
}
func (p *CreateStoragePoolParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
}
func (p *CreateStoragePoolParams) ResetName() {
if p.p != nil && p.p["name"] != nil {
delete(p.p, "name")
}
}
func (p *CreateStoragePoolParams) GetName() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["name"].(string)
return value, ok
}
func (p *CreateStoragePoolParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
}
func (p *CreateStoragePoolParams) ResetPodid() {
if p.p != nil && p.p["podid"] != nil {
delete(p.p, "podid")
}
}
func (p *CreateStoragePoolParams) GetPodid() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["podid"].(string)
return value, ok
}
func (p *CreateStoragePoolParams) SetProvider(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["provider"] = v
}
func (p *CreateStoragePoolParams) ResetProvider() {
if p.p != nil && p.p["provider"] != nil {
delete(p.p, "provider")
}
}
func (p *CreateStoragePoolParams) GetProvider() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["provider"].(string)
return value, ok
}
func (p *CreateStoragePoolParams) SetScope(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["scope"] = v
}
func (p *CreateStoragePoolParams) ResetScope() {
if p.p != nil && p.p["scope"] != nil {
delete(p.p, "scope")
}
}
func (p *CreateStoragePoolParams) GetScope() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["scope"].(string)
return value, ok
}
func (p *CreateStoragePoolParams) SetTags(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
}
func (p *CreateStoragePoolParams) ResetTags() {
if p.p != nil && p.p["tags"] != nil {
delete(p.p, "tags")
}
}
func (p *CreateStoragePoolParams) GetTags() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["tags"].(string)
return value, ok
}
func (p *CreateStoragePoolParams) SetUrl(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["url"] = v
}
func (p *CreateStoragePoolParams) ResetUrl() {
if p.p != nil && p.p["url"] != nil {
delete(p.p, "url")
}
}
func (p *CreateStoragePoolParams) GetUrl() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["url"].(string)
return value, ok
}
func (p *CreateStoragePoolParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
}
func (p *CreateStoragePoolParams) ResetZoneid() {
if p.p != nil && p.p["zoneid"] != nil {
delete(p.p, "zoneid")
}
}
func (p *CreateStoragePoolParams) GetZoneid() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["zoneid"].(string)
return value, ok
}
// You should always use this function to get a new CreateStoragePoolParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewCreateStoragePoolParams(name string, url string, zoneid string) *CreateStoragePoolParams {
p := &CreateStoragePoolParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
p.p["url"] = url
p.p["zoneid"] = zoneid
return p
}
// Creates a storage pool.
func (s *PoolService) CreateStoragePool(p *CreateStoragePoolParams) (*CreateStoragePoolResponse, error) {
resp, err := s.cs.newRequest("createStoragePool", p.toURLValues())
if err != nil {
return nil, err
}
if resp, err = getRawValue(resp); err != nil {
return nil, err
}
var r CreateStoragePoolResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type CreateStoragePoolResponse struct {
Allocatediops int64 `json:"allocatediops"`
Capacityiops int64 `json:"capacityiops"`
Clusterid string `json:"clusterid"`
Clustername string `json:"clustername"`
Created string `json:"created"`
Disksizeallocated int64 `json:"disksizeallocated"`
Disksizetotal int64 `json:"disksizetotal"`
Disksizeused int64 `json:"disksizeused"`
Hasannotations bool `json:"hasannotations"`
Hypervisor string `json:"hypervisor"`
Id string `json:"id"`
Ipaddress string `json:"ipaddress"`
Istagarule bool `json:"istagarule"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Managed bool `json:"managed"`
Name string `json:"name"`
Nfsmountopts string `json:"nfsmountopts"`
Overprovisionfactor string `json:"overprovisionfactor"`
Path string `json:"path"`
Podid string `json:"podid"`
Podname string `json:"podname"`
Provider string `json:"provider"`
Scope string `json:"scope"`
State string `json:"state"`
Storagecapabilities map[string]string `json:"storagecapabilities"`
Storagecustomstats map[string]string `json:"storagecustomstats"`
Suitableformigration bool `json:"suitableformigration"`
Tags string `json:"tags"`
Type string `json:"type"`
Zoneid string `json:"zoneid"`
Zonename string `json:"zonename"`
}
type DeleteStoragePoolParams struct {
p map[string]interface{}
}
func (p *DeleteStoragePoolParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["forced"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("forced", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeleteStoragePoolParams) SetForced(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["forced"] = v
}
func (p *DeleteStoragePoolParams) ResetForced() {
if p.p != nil && p.p["forced"] != nil {
delete(p.p, "forced")
}
}
func (p *DeleteStoragePoolParams) GetForced() (bool, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["forced"].(bool)
return value, ok
}
func (p *DeleteStoragePoolParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
}
func (p *DeleteStoragePoolParams) ResetId() {
if p.p != nil && p.p["id"] != nil {
delete(p.p, "id")
}
}
func (p *DeleteStoragePoolParams) GetId() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["id"].(string)
return value, ok
}
// You should always use this function to get a new DeleteStoragePoolParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewDeleteStoragePoolParams(id string) *DeleteStoragePoolParams {
p := &DeleteStoragePoolParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Deletes a storage pool.
func (s *PoolService) DeleteStoragePool(p *DeleteStoragePoolParams) (*DeleteStoragePoolResponse, error) {
resp, err := s.cs.newRequest("deleteStoragePool", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteStoragePoolResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteStoragePoolResponse struct {
Displaytext string `json:"displaytext"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Success bool `json:"success"`
}
func (r *DeleteStoragePoolResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}
if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}
if ostypeid, ok := m["ostypeid"].(float64); ok {
m["ostypeid"] = strconv.Itoa(int(ostypeid))
b, err = json.Marshal(m)
if err != nil {
return err
}
}
type alias DeleteStoragePoolResponse
return json.Unmarshal(b, (*alias)(r))
}
type FindStoragePoolsForMigrationParams struct {
p map[string]interface{}
}
func (p *FindStoragePoolsForMigrationParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *FindStoragePoolsForMigrationParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
}
func (p *FindStoragePoolsForMigrationParams) ResetId() {
if p.p != nil && p.p["id"] != nil {
delete(p.p, "id")
}
}
func (p *FindStoragePoolsForMigrationParams) GetId() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["id"].(string)
return value, ok
}
func (p *FindStoragePoolsForMigrationParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
}
func (p *FindStoragePoolsForMigrationParams) ResetKeyword() {
if p.p != nil && p.p["keyword"] != nil {
delete(p.p, "keyword")
}
}
func (p *FindStoragePoolsForMigrationParams) GetKeyword() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["keyword"].(string)
return value, ok
}
func (p *FindStoragePoolsForMigrationParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
}
func (p *FindStoragePoolsForMigrationParams) ResetPage() {
if p.p != nil && p.p["page"] != nil {
delete(p.p, "page")
}
}
func (p *FindStoragePoolsForMigrationParams) GetPage() (int, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["page"].(int)
return value, ok
}
func (p *FindStoragePoolsForMigrationParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
}
func (p *FindStoragePoolsForMigrationParams) ResetPagesize() {
if p.p != nil && p.p["pagesize"] != nil {
delete(p.p, "pagesize")
}
}
func (p *FindStoragePoolsForMigrationParams) GetPagesize() (int, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["pagesize"].(int)
return value, ok
}
// You should always use this function to get a new FindStoragePoolsForMigrationParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewFindStoragePoolsForMigrationParams(id string) *FindStoragePoolsForMigrationParams {
p := &FindStoragePoolsForMigrationParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Lists storage pools available for migration of a volume.
func (s *PoolService) FindStoragePoolsForMigration(p *FindStoragePoolsForMigrationParams) (*FindStoragePoolsForMigrationResponse, error) {
resp, err := s.cs.newRequest("findStoragePoolsForMigration", p.toURLValues())
if err != nil {
return nil, err
}
var r FindStoragePoolsForMigrationResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type FindStoragePoolsForMigrationResponse struct {
Allocatediops int64 `json:"allocatediops"`
Capacityiops int64 `json:"capacityiops"`
Clusterid string `json:"clusterid"`
Clustername string `json:"clustername"`
Created string `json:"created"`
Disksizeallocated int64 `json:"disksizeallocated"`
Disksizetotal int64 `json:"disksizetotal"`
Disksizeused int64 `json:"disksizeused"`
Hasannotations bool `json:"hasannotations"`
Hypervisor string `json:"hypervisor"`
Id string `json:"id"`
Ipaddress string `json:"ipaddress"`
Istagarule bool `json:"istagarule"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Managed bool `json:"managed"`
Name string `json:"name"`
Nfsmountopts string `json:"nfsmountopts"`
Overprovisionfactor string `json:"overprovisionfactor"`
Path string `json:"path"`
Podid string `json:"podid"`
Podname string `json:"podname"`
Provider string `json:"provider"`
Scope string `json:"scope"`
State string `json:"state"`
Storagecapabilities map[string]string `json:"storagecapabilities"`
Storagecustomstats map[string]string `json:"storagecustomstats"`
Suitableformigration bool `json:"suitableformigration"`
Tags string `json:"tags"`
Type string `json:"type"`
Zoneid string `json:"zoneid"`
Zonename string `json:"zonename"`
}
type ListElastistorPoolParams struct {
p map[string]interface{}
}
func (p *ListElastistorPoolParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("id", vv)
}
return u
}
func (p *ListElastistorPoolParams) SetId(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
}
func (p *ListElastistorPoolParams) ResetId() {
if p.p != nil && p.p["id"] != nil {
delete(p.p, "id")
}
}
func (p *ListElastistorPoolParams) GetId() (int64, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["id"].(int64)
return value, ok
}
// You should always use this function to get a new ListElastistorPoolParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewListElastistorPoolParams() *ListElastistorPoolParams {
p := &ListElastistorPoolParams{}
p.p = make(map[string]interface{})
return p
}
// Lists the pools of elastistor
func (s *PoolService) ListElastistorPool(p *ListElastistorPoolParams) (*ListElastistorPoolResponse, error) {
resp, err := s.cs.newRequest("listElastistorPool", p.toURLValues())
if err != nil {
return nil, err
}
var r ListElastistorPoolResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListElastistorPoolResponse struct {
Count int `json:"count"`
ElastistorPool []*ElastistorPool `json:"elastistorpool"`
}
type ElastistorPool struct {
Controllerid string `json:"controllerid"`
Gateway string `json:"gateway"`
Id string `json:"id"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Maxiops int64 `json:"maxiops"`
Name string `json:"name"`
Size int64 `json:"size"`
State string `json:"state"`
}
type ListStoragePoolsParams struct {
p map[string]interface{}
}
func (p *ListStoragePoolsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["clusterid"]; found {
u.Set("clusterid", v.(string))
}
if v, found := p.p["hostid"]; found {
u.Set("hostid", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["ipaddress"]; found {
u.Set("ipaddress", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["path"]; found {
u.Set("path", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["scope"]; found {
u.Set("scope", v.(string))
}
if v, found := p.p["status"]; found {
u.Set("status", v.(string))
}
if v, found := p.p["storagecustomstats"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("storagecustomstats", vv)
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *ListStoragePoolsParams) SetClusterid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["clusterid"] = v
}
func (p *ListStoragePoolsParams) ResetClusterid() {
if p.p != nil && p.p["clusterid"] != nil {
delete(p.p, "clusterid")
}
}
func (p *ListStoragePoolsParams) GetClusterid() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["clusterid"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetHostid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hostid"] = v
}
func (p *ListStoragePoolsParams) ResetHostid() {
if p.p != nil && p.p["hostid"] != nil {
delete(p.p, "hostid")
}
}
func (p *ListStoragePoolsParams) GetHostid() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["hostid"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
}
func (p *ListStoragePoolsParams) ResetId() {
if p.p != nil && p.p["id"] != nil {
delete(p.p, "id")
}
}
func (p *ListStoragePoolsParams) GetId() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["id"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetIpaddress(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddress"] = v
}
func (p *ListStoragePoolsParams) ResetIpaddress() {
if p.p != nil && p.p["ipaddress"] != nil {
delete(p.p, "ipaddress")
}
}
func (p *ListStoragePoolsParams) GetIpaddress() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["ipaddress"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
}
func (p *ListStoragePoolsParams) ResetKeyword() {
if p.p != nil && p.p["keyword"] != nil {
delete(p.p, "keyword")
}
}
func (p *ListStoragePoolsParams) GetKeyword() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["keyword"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
}
func (p *ListStoragePoolsParams) ResetName() {
if p.p != nil && p.p["name"] != nil {
delete(p.p, "name")
}
}
func (p *ListStoragePoolsParams) GetName() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["name"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
}
func (p *ListStoragePoolsParams) ResetPage() {
if p.p != nil && p.p["page"] != nil {
delete(p.p, "page")
}
}
func (p *ListStoragePoolsParams) GetPage() (int, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["page"].(int)
return value, ok
}
func (p *ListStoragePoolsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
}
func (p *ListStoragePoolsParams) ResetPagesize() {
if p.p != nil && p.p["pagesize"] != nil {
delete(p.p, "pagesize")
}
}
func (p *ListStoragePoolsParams) GetPagesize() (int, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["pagesize"].(int)
return value, ok
}
func (p *ListStoragePoolsParams) SetPath(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["path"] = v
}
func (p *ListStoragePoolsParams) ResetPath() {
if p.p != nil && p.p["path"] != nil {
delete(p.p, "path")
}
}
func (p *ListStoragePoolsParams) GetPath() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["path"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
}
func (p *ListStoragePoolsParams) ResetPodid() {
if p.p != nil && p.p["podid"] != nil {
delete(p.p, "podid")
}
}
func (p *ListStoragePoolsParams) GetPodid() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["podid"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetScope(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["scope"] = v
}
func (p *ListStoragePoolsParams) ResetScope() {
if p.p != nil && p.p["scope"] != nil {
delete(p.p, "scope")
}
}
func (p *ListStoragePoolsParams) GetScope() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["scope"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetStatus(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["status"] = v
}
func (p *ListStoragePoolsParams) ResetStatus() {
if p.p != nil && p.p["status"] != nil {
delete(p.p, "status")
}
}
func (p *ListStoragePoolsParams) GetStatus() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["status"].(string)
return value, ok
}
func (p *ListStoragePoolsParams) SetStoragecustomstats(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["storagecustomstats"] = v
}
func (p *ListStoragePoolsParams) ResetStoragecustomstats() {
if p.p != nil && p.p["storagecustomstats"] != nil {
delete(p.p, "storagecustomstats")
}
}
func (p *ListStoragePoolsParams) GetStoragecustomstats() (bool, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["storagecustomstats"].(bool)
return value, ok
}
func (p *ListStoragePoolsParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
}
func (p *ListStoragePoolsParams) ResetZoneid() {
if p.p != nil && p.p["zoneid"] != nil {
delete(p.p, "zoneid")
}
}
func (p *ListStoragePoolsParams) GetZoneid() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["zoneid"].(string)
return value, ok
}
// You should always use this function to get a new ListStoragePoolsParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewListStoragePoolsParams() *ListStoragePoolsParams {
p := &ListStoragePoolsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PoolService) GetStoragePoolID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListStoragePoolsParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListStoragePools(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.StoragePools[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.StoragePools {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PoolService) GetStoragePoolByName(name string, opts ...OptionFunc) (*StoragePool, int, error) {
id, count, err := s.GetStoragePoolID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetStoragePoolByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PoolService) GetStoragePoolByID(id string, opts ...OptionFunc) (*StoragePool, int, error) {
p := &ListStoragePoolsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListStoragePools(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.StoragePools[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for StoragePool UUID: %s!", id)
}
// Lists storage pools.
func (s *PoolService) ListStoragePools(p *ListStoragePoolsParams) (*ListStoragePoolsResponse, error) {
resp, err := s.cs.newRequest("listStoragePools", p.toURLValues())
if err != nil {
return nil, err
}
var r ListStoragePoolsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListStoragePoolsResponse struct {
Count int `json:"count"`
StoragePools []*StoragePool `json:"storagepool"`
}
type StoragePool struct {
Allocatediops int64 `json:"allocatediops"`
Capacityiops int64 `json:"capacityiops"`
Clusterid string `json:"clusterid"`
Clustername string `json:"clustername"`
Created string `json:"created"`
Disksizeallocated int64 `json:"disksizeallocated"`
Disksizetotal int64 `json:"disksizetotal"`
Disksizeused int64 `json:"disksizeused"`
Hasannotations bool `json:"hasannotations"`
Hypervisor string `json:"hypervisor"`
Id string `json:"id"`
Ipaddress string `json:"ipaddress"`
Istagarule bool `json:"istagarule"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Managed bool `json:"managed"`
Name string `json:"name"`
Nfsmountopts string `json:"nfsmountopts"`
Overprovisionfactor string `json:"overprovisionfactor"`
Path string `json:"path"`
Podid string `json:"podid"`
Podname string `json:"podname"`
Provider string `json:"provider"`
Scope string `json:"scope"`
State string `json:"state"`
Storagecapabilities map[string]string `json:"storagecapabilities"`
Storagecustomstats map[string]string `json:"storagecustomstats"`
Suitableformigration bool `json:"suitableformigration"`
Tags string `json:"tags"`
Type string `json:"type"`
Zoneid string `json:"zoneid"`
Zonename string `json:"zonename"`
}
type SyncStoragePoolParams struct {
p map[string]interface{}
}
func (p *SyncStoragePoolParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *SyncStoragePoolParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
}
func (p *SyncStoragePoolParams) ResetId() {
if p.p != nil && p.p["id"] != nil {
delete(p.p, "id")
}
}
func (p *SyncStoragePoolParams) GetId() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["id"].(string)
return value, ok
}
// You should always use this function to get a new SyncStoragePoolParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewSyncStoragePoolParams(id string) *SyncStoragePoolParams {
p := &SyncStoragePoolParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Sync storage pool with management server (currently supported for Datastore Cluster in VMware and syncs the datastores in it)
func (s *PoolService) SyncStoragePool(p *SyncStoragePoolParams) (*SyncStoragePoolResponse, error) {
resp, err := s.cs.newRequest("syncStoragePool", p.toURLValues())
if err != nil {
return nil, err
}
var r SyncStoragePoolResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type SyncStoragePoolResponse struct {
Allocatediops int64 `json:"allocatediops"`
Capacityiops int64 `json:"capacityiops"`
Clusterid string `json:"clusterid"`
Clustername string `json:"clustername"`
Created string `json:"created"`
Disksizeallocated int64 `json:"disksizeallocated"`
Disksizetotal int64 `json:"disksizetotal"`
Disksizeused int64 `json:"disksizeused"`
Hasannotations bool `json:"hasannotations"`
Hypervisor string `json:"hypervisor"`
Id string `json:"id"`
Ipaddress string `json:"ipaddress"`
Istagarule bool `json:"istagarule"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Managed bool `json:"managed"`
Name string `json:"name"`
Nfsmountopts string `json:"nfsmountopts"`
Overprovisionfactor string `json:"overprovisionfactor"`
Path string `json:"path"`
Podid string `json:"podid"`
Podname string `json:"podname"`
Provider string `json:"provider"`
Scope string `json:"scope"`
State string `json:"state"`
Storagecapabilities map[string]string `json:"storagecapabilities"`
Storagecustomstats map[string]string `json:"storagecustomstats"`
Suitableformigration bool `json:"suitableformigration"`
Tags string `json:"tags"`
Type string `json:"type"`
Zoneid string `json:"zoneid"`
Zonename string `json:"zonename"`
}
type UpdateStoragePoolParams struct {
p map[string]interface{}
}
func (p *UpdateStoragePoolParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["capacitybytes"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("capacitybytes", vv)
}
if v, found := p.p["capacityiops"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("capacityiops", vv)
}
if v, found := p.p["details"]; found {
m := v.(map[string]string)
for i, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("details[%d].%s", i, k), m[k])
}
}
if v, found := p.p["enabled"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("enabled", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["istagarule"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("istagarule", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["tags"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("tags", vv)
}
if v, found := p.p["url"]; found {
u.Set("url", v.(string))
}
return u
}
func (p *UpdateStoragePoolParams) SetCapacitybytes(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["capacitybytes"] = v
}
func (p *UpdateStoragePoolParams) ResetCapacitybytes() {
if p.p != nil && p.p["capacitybytes"] != nil {
delete(p.p, "capacitybytes")
}
}
func (p *UpdateStoragePoolParams) GetCapacitybytes() (int64, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["capacitybytes"].(int64)
return value, ok
}
func (p *UpdateStoragePoolParams) SetCapacityiops(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["capacityiops"] = v
}
func (p *UpdateStoragePoolParams) ResetCapacityiops() {
if p.p != nil && p.p["capacityiops"] != nil {
delete(p.p, "capacityiops")
}
}
func (p *UpdateStoragePoolParams) GetCapacityiops() (int64, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["capacityiops"].(int64)
return value, ok
}
func (p *UpdateStoragePoolParams) SetDetails(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["details"] = v
}
func (p *UpdateStoragePoolParams) ResetDetails() {
if p.p != nil && p.p["details"] != nil {
delete(p.p, "details")
}
}
func (p *UpdateStoragePoolParams) GetDetails() (map[string]string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["details"].(map[string]string)
return value, ok
}
func (p *UpdateStoragePoolParams) SetEnabled(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enabled"] = v
}
func (p *UpdateStoragePoolParams) ResetEnabled() {
if p.p != nil && p.p["enabled"] != nil {
delete(p.p, "enabled")
}
}
func (p *UpdateStoragePoolParams) GetEnabled() (bool, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["enabled"].(bool)
return value, ok
}
func (p *UpdateStoragePoolParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
}
func (p *UpdateStoragePoolParams) ResetId() {
if p.p != nil && p.p["id"] != nil {
delete(p.p, "id")
}
}
func (p *UpdateStoragePoolParams) GetId() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["id"].(string)
return value, ok
}
func (p *UpdateStoragePoolParams) SetIstagarule(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["istagarule"] = v
}
func (p *UpdateStoragePoolParams) ResetIstagarule() {
if p.p != nil && p.p["istagarule"] != nil {
delete(p.p, "istagarule")
}
}
func (p *UpdateStoragePoolParams) GetIstagarule() (bool, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["istagarule"].(bool)
return value, ok
}
func (p *UpdateStoragePoolParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
}
func (p *UpdateStoragePoolParams) ResetName() {
if p.p != nil && p.p["name"] != nil {
delete(p.p, "name")
}
}
func (p *UpdateStoragePoolParams) GetName() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["name"].(string)
return value, ok
}
func (p *UpdateStoragePoolParams) SetTags(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
}
func (p *UpdateStoragePoolParams) ResetTags() {
if p.p != nil && p.p["tags"] != nil {
delete(p.p, "tags")
}
}
func (p *UpdateStoragePoolParams) GetTags() ([]string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["tags"].([]string)
return value, ok
}
func (p *UpdateStoragePoolParams) SetUrl(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["url"] = v
}
func (p *UpdateStoragePoolParams) ResetUrl() {
if p.p != nil && p.p["url"] != nil {
delete(p.p, "url")
}
}
func (p *UpdateStoragePoolParams) GetUrl() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["url"].(string)
return value, ok
}
// You should always use this function to get a new UpdateStoragePoolParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewUpdateStoragePoolParams(id string) *UpdateStoragePoolParams {
p := &UpdateStoragePoolParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates a storage pool.
func (s *PoolService) UpdateStoragePool(p *UpdateStoragePoolParams) (*UpdateStoragePoolResponse, error) {
resp, err := s.cs.newRequest("updateStoragePool", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateStoragePoolResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateStoragePoolResponse struct {
Allocatediops int64 `json:"allocatediops"`
Capacityiops int64 `json:"capacityiops"`
Clusterid string `json:"clusterid"`
Clustername string `json:"clustername"`
Created string `json:"created"`
Disksizeallocated int64 `json:"disksizeallocated"`
Disksizetotal int64 `json:"disksizetotal"`
Disksizeused int64 `json:"disksizeused"`
Hasannotations bool `json:"hasannotations"`
Hypervisor string `json:"hypervisor"`
Id string `json:"id"`
Ipaddress string `json:"ipaddress"`
Istagarule bool `json:"istagarule"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Managed bool `json:"managed"`
Name string `json:"name"`
Nfsmountopts string `json:"nfsmountopts"`
Overprovisionfactor string `json:"overprovisionfactor"`
Path string `json:"path"`
Podid string `json:"podid"`
Podname string `json:"podname"`
Provider string `json:"provider"`
Scope string `json:"scope"`
State string `json:"state"`
Storagecapabilities map[string]string `json:"storagecapabilities"`
Storagecustomstats map[string]string `json:"storagecustomstats"`
Suitableformigration bool `json:"suitableformigration"`
Tags string `json:"tags"`
Type string `json:"type"`
Zoneid string `json:"zoneid"`
Zonename string `json:"zonename"`
}