2016-10-07 10:39:28 -04:00
|
|
|
//
|
2019-02-01 14:26:40 -05:00
|
|
|
// Copyright 2018, Sander van Harmelen
|
2016-10-07 10:39:28 -04:00
|
|
|
//
|
|
|
|
// Licensed 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"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AddResourceDetailParams struct {
|
|
|
|
p map[string]interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *AddResourceDetailParams) toURLValues() url.Values {
|
|
|
|
u := url.Values{}
|
|
|
|
if p.p == nil {
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
if v, found := p.p["details"]; found {
|
|
|
|
i := 0
|
|
|
|
for k, vv := range v.(map[string]string) {
|
2019-02-01 14:26:40 -05:00
|
|
|
u.Set(fmt.Sprintf("details[%d].%s", i, k), vv)
|
2016-10-07 10:39:28 -04:00
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, found := p.p["fordisplay"]; found {
|
|
|
|
vv := strconv.FormatBool(v.(bool))
|
|
|
|
u.Set("fordisplay", vv)
|
|
|
|
}
|
|
|
|
if v, found := p.p["resourceid"]; found {
|
|
|
|
u.Set("resourceid", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["resourcetype"]; found {
|
|
|
|
u.Set("resourcetype", v.(string))
|
|
|
|
}
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *AddResourceDetailParams) SetDetails(v map[string]string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["details"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *AddResourceDetailParams) SetFordisplay(v bool) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["fordisplay"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *AddResourceDetailParams) SetResourceid(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["resourceid"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *AddResourceDetailParams) SetResourcetype(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["resourcetype"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// You should always use this function to get a new AddResourceDetailParams instance,
|
|
|
|
// as then you are sure you have configured all required params
|
|
|
|
func (s *ResourcemetadataService) NewAddResourceDetailParams(details map[string]string, resourceid string, resourcetype string) *AddResourceDetailParams {
|
|
|
|
p := &AddResourceDetailParams{}
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
p.p["details"] = details
|
|
|
|
p.p["resourceid"] = resourceid
|
|
|
|
p.p["resourcetype"] = resourcetype
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds detail for the Resource.
|
|
|
|
func (s *ResourcemetadataService) AddResourceDetail(p *AddResourceDetailParams) (*AddResourceDetailResponse, error) {
|
|
|
|
resp, err := s.cs.newRequest("addResourceDetail", p.toURLValues())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r AddResourceDetailResponse
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(b, &r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2019-02-01 14:26:40 -05:00
|
|
|
|
2016-10-07 10:39:28 -04:00
|
|
|
return &r, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type AddResourceDetailResponse struct {
|
2019-02-01 14:26:40 -05:00
|
|
|
Displaytext string `json:"displaytext"`
|
2019-05-26 05:58:26 -04:00
|
|
|
JobID string `json:"jobid"`
|
|
|
|
Jobstatus int `json:"jobstatus"`
|
2019-02-01 14:26:40 -05:00
|
|
|
Success bool `json:"success"`
|
2016-10-07 10:39:28 -04:00
|
|
|
}
|
|
|
|
|
2019-02-01 14:26:40 -05:00
|
|
|
type GetVolumeSnapshotDetailsParams struct {
|
2016-10-07 10:39:28 -04:00
|
|
|
p map[string]interface{}
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:26:40 -05:00
|
|
|
func (p *GetVolumeSnapshotDetailsParams) toURLValues() url.Values {
|
2016-10-07 10:39:28 -04:00
|
|
|
u := url.Values{}
|
|
|
|
if p.p == nil {
|
|
|
|
return u
|
|
|
|
}
|
2019-02-01 14:26:40 -05:00
|
|
|
if v, found := p.p["snapshotid"]; found {
|
|
|
|
u.Set("snapshotid", v.(string))
|
2016-10-07 10:39:28 -04:00
|
|
|
}
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:26:40 -05:00
|
|
|
func (p *GetVolumeSnapshotDetailsParams) SetSnapshotid(v string) {
|
2016-10-07 10:39:28 -04:00
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
2019-02-01 14:26:40 -05:00
|
|
|
p.p["snapshotid"] = v
|
2016-10-07 10:39:28 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:26:40 -05:00
|
|
|
// You should always use this function to get a new GetVolumeSnapshotDetailsParams instance,
|
2016-10-07 10:39:28 -04:00
|
|
|
// as then you are sure you have configured all required params
|
2019-02-01 14:26:40 -05:00
|
|
|
func (s *ResourcemetadataService) NewGetVolumeSnapshotDetailsParams(snapshotid string) *GetVolumeSnapshotDetailsParams {
|
|
|
|
p := &GetVolumeSnapshotDetailsParams{}
|
2016-10-07 10:39:28 -04:00
|
|
|
p.p = make(map[string]interface{})
|
2019-02-01 14:26:40 -05:00
|
|
|
p.p["snapshotid"] = snapshotid
|
2016-10-07 10:39:28 -04:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:26:40 -05:00
|
|
|
// Get Volume Snapshot Details
|
|
|
|
func (s *ResourcemetadataService) GetVolumeSnapshotDetails(p *GetVolumeSnapshotDetailsParams) (*GetVolumeSnapshotDetailsResponse, error) {
|
|
|
|
resp, err := s.cs.newRequest("getVolumeSnapshotDetails", p.toURLValues())
|
2016-10-07 10:39:28 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:26:40 -05:00
|
|
|
var r GetVolumeSnapshotDetailsResponse
|
2016-10-07 10:39:28 -04:00
|
|
|
if err := json.Unmarshal(resp, &r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &r, nil
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:26:40 -05:00
|
|
|
type GetVolumeSnapshotDetailsResponse struct {
|
2019-05-26 05:58:26 -04:00
|
|
|
JobID string `json:"jobid"`
|
|
|
|
Jobstatus int `json:"jobstatus"`
|
2019-02-01 14:26:40 -05:00
|
|
|
VolumeiScsiName string `json:"volumeiScsiName"`
|
2016-10-07 10:39:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type ListResourceDetailsParams struct {
|
|
|
|
p map[string]interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) toURLValues() url.Values {
|
|
|
|
u := url.Values{}
|
|
|
|
if p.p == nil {
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
if v, found := p.p["account"]; found {
|
|
|
|
u.Set("account", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["domainid"]; found {
|
|
|
|
u.Set("domainid", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["fordisplay"]; found {
|
|
|
|
vv := strconv.FormatBool(v.(bool))
|
|
|
|
u.Set("fordisplay", vv)
|
|
|
|
}
|
|
|
|
if v, found := p.p["isrecursive"]; found {
|
|
|
|
vv := strconv.FormatBool(v.(bool))
|
|
|
|
u.Set("isrecursive", vv)
|
|
|
|
}
|
|
|
|
if v, found := p.p["key"]; found {
|
|
|
|
u.Set("key", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["keyword"]; found {
|
|
|
|
u.Set("keyword", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["listall"]; found {
|
|
|
|
vv := strconv.FormatBool(v.(bool))
|
|
|
|
u.Set("listall", vv)
|
|
|
|
}
|
|
|
|
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["projectid"]; found {
|
|
|
|
u.Set("projectid", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["resourceid"]; found {
|
|
|
|
u.Set("resourceid", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["resourcetype"]; found {
|
|
|
|
u.Set("resourcetype", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["value"]; found {
|
|
|
|
u.Set("value", v.(string))
|
|
|
|
}
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetAccount(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["account"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetDomainid(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["domainid"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetFordisplay(v bool) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["fordisplay"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetIsrecursive(v bool) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["isrecursive"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetKey(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["key"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetKeyword(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["keyword"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetListall(v bool) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["listall"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetPage(v int) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["page"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetPagesize(v int) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["pagesize"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetProjectid(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["projectid"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetResourceid(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["resourceid"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetResourcetype(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["resourcetype"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ListResourceDetailsParams) SetValue(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["value"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// You should always use this function to get a new ListResourceDetailsParams instance,
|
|
|
|
// as then you are sure you have configured all required params
|
|
|
|
func (s *ResourcemetadataService) NewListResourceDetailsParams(resourcetype string) *ListResourceDetailsParams {
|
|
|
|
p := &ListResourceDetailsParams{}
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
p.p["resourcetype"] = resourcetype
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// List resource detail(s)
|
|
|
|
func (s *ResourcemetadataService) ListResourceDetails(p *ListResourceDetailsParams) (*ListResourceDetailsResponse, error) {
|
|
|
|
resp, err := s.cs.newRequest("listResourceDetails", p.toURLValues())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r ListResourceDetailsResponse
|
|
|
|
if err := json.Unmarshal(resp, &r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-02-01 14:26:40 -05:00
|
|
|
|
2016-10-07 10:39:28 -04:00
|
|
|
return &r, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ListResourceDetailsResponse struct {
|
|
|
|
Count int `json:"count"`
|
|
|
|
ResourceDetails []*ResourceDetail `json:"resourcedetail"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResourceDetail struct {
|
2019-02-01 14:26:40 -05:00
|
|
|
Account string `json:"account"`
|
|
|
|
Customer string `json:"customer"`
|
|
|
|
Domain string `json:"domain"`
|
|
|
|
Domainid string `json:"domainid"`
|
2019-05-26 05:58:26 -04:00
|
|
|
JobID string `json:"jobid"`
|
|
|
|
Jobstatus int `json:"jobstatus"`
|
2019-02-01 14:26:40 -05:00
|
|
|
Key string `json:"key"`
|
|
|
|
Project string `json:"project"`
|
|
|
|
Projectid string `json:"projectid"`
|
|
|
|
Resourceid string `json:"resourceid"`
|
|
|
|
Resourcetype string `json:"resourcetype"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RemoveResourceDetailParams struct {
|
|
|
|
p map[string]interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *RemoveResourceDetailParams) toURLValues() url.Values {
|
|
|
|
u := url.Values{}
|
|
|
|
if p.p == nil {
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
if v, found := p.p["key"]; found {
|
|
|
|
u.Set("key", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["resourceid"]; found {
|
|
|
|
u.Set("resourceid", v.(string))
|
|
|
|
}
|
|
|
|
if v, found := p.p["resourcetype"]; found {
|
|
|
|
u.Set("resourcetype", v.(string))
|
|
|
|
}
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *RemoveResourceDetailParams) SetKey(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["key"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *RemoveResourceDetailParams) SetResourceid(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["resourceid"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *RemoveResourceDetailParams) SetResourcetype(v string) {
|
|
|
|
if p.p == nil {
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
p.p["resourcetype"] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// You should always use this function to get a new RemoveResourceDetailParams instance,
|
|
|
|
// as then you are sure you have configured all required params
|
|
|
|
func (s *ResourcemetadataService) NewRemoveResourceDetailParams(resourceid string, resourcetype string) *RemoveResourceDetailParams {
|
|
|
|
p := &RemoveResourceDetailParams{}
|
|
|
|
p.p = make(map[string]interface{})
|
|
|
|
p.p["resourceid"] = resourceid
|
|
|
|
p.p["resourcetype"] = resourcetype
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removes detail for the Resource.
|
|
|
|
func (s *ResourcemetadataService) RemoveResourceDetail(p *RemoveResourceDetailParams) (*RemoveResourceDetailResponse, error) {
|
|
|
|
resp, err := s.cs.newRequest("removeResourceDetail", p.toURLValues())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r RemoveResourceDetailResponse
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(b, &r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &r, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type RemoveResourceDetailResponse struct {
|
|
|
|
Displaytext string `json:"displaytext"`
|
2019-05-26 05:58:26 -04:00
|
|
|
JobID string `json:"jobid"`
|
|
|
|
Jobstatus int `json:"jobstatus"`
|
2019-02-01 14:26:40 -05:00
|
|
|
Success bool `json:"success"`
|
2016-10-07 10:39:28 -04:00
|
|
|
}
|