vishesh92 commented on code in PR #88: URL: https://github.com/apache/cloudstack-go/pull/88#discussion_r1639281442
########## cloudstack/HostService.go: ########## @@ -4753,3 +4772,1202 @@ func (r *UpdateHostPasswordResponse) UnmarshalJSON(b []byte) error { type alias UpdateHostPasswordResponse return json.Unmarshal(b, (*alias)(r)) } + +type MigrateSecondaryStorageDataParams struct { + p map[string]interface{} +} + +func (p *MigrateSecondaryStorageDataParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["destpools"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("destpools", vv) + } + if v, found := p.p["migrationtype"]; found { + u.Set("migrationtype", v.(string)) + } + if v, found := p.p["srcpool"]; found { + u.Set("srcpool", v.(string)) + } + return u +} + +func (p *MigrateSecondaryStorageDataParams) SetDestpools(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["destpools"] = v +} + +func (p *MigrateSecondaryStorageDataParams) ResetDestpools() { + if p.p != nil && p.p["destpools"] != nil { + delete(p.p, "destpools") + } +} + +func (p *MigrateSecondaryStorageDataParams) GetDestpools() ([]string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["destpools"].([]string) + return value, ok +} + +func (p *MigrateSecondaryStorageDataParams) SetMigrationtype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["migrationtype"] = v +} + +func (p *MigrateSecondaryStorageDataParams) ResetMigrationtype() { + if p.p != nil && p.p["migrationtype"] != nil { + delete(p.p, "migrationtype") + } +} + +func (p *MigrateSecondaryStorageDataParams) GetMigrationtype() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["migrationtype"].(string) + return value, ok +} + +func (p *MigrateSecondaryStorageDataParams) SetSrcpool(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["srcpool"] = v +} + +func (p *MigrateSecondaryStorageDataParams) ResetSrcpool() { + if p.p != nil && p.p["srcpool"] != nil { + delete(p.p, "srcpool") + } +} + +func (p *MigrateSecondaryStorageDataParams) GetSrcpool() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["srcpool"].(string) + return value, ok +} + +// You should always use this function to get a new MigrateSecondaryStorageDataParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewMigrateSecondaryStorageDataParams(destpools []string, srcpool string) *MigrateSecondaryStorageDataParams { + p := &MigrateSecondaryStorageDataParams{} + p.p = make(map[string]interface{}) + p.p["destpools"] = destpools + p.p["srcpool"] = srcpool + return p +} + +// migrates data objects from one secondary storage to destination image store(s) +func (s *HostService) MigrateSecondaryStorageData(p *MigrateSecondaryStorageDataParams) (*MigrateSecondaryStorageDataResponse, error) { + resp, err := s.cs.newRequest("migrateSecondaryStorageData", p.toURLValues()) + if err != nil { + return nil, err + } + + var r MigrateSecondaryStorageDataResponse + 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 MigrateSecondaryStorageDataResponse struct { + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Message string `json:"message"` + Migrationtype string `json:"migrationtype"` + Success bool `json:"success"` +} + +type CancelHostAsDegradedParams struct { + p map[string]interface{} +} + +func (p *CancelHostAsDegradedParams) 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 *CancelHostAsDegradedParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *CancelHostAsDegradedParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *CancelHostAsDegradedParams) 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 CancelHostAsDegradedParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewCancelHostAsDegradedParams(id string) *CancelHostAsDegradedParams { + p := &CancelHostAsDegradedParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Cancel host status from 'Degraded'. Host will transit back to status 'Enabled'. +func (s *HostService) CancelHostAsDegraded(p *CancelHostAsDegradedParams) (*CancelHostAsDegradedResponse, error) { + resp, err := s.cs.newRequest("cancelHostAsDegraded", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CancelHostAsDegradedResponse + 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 CancelHostAsDegradedResponse struct { + Annotation string `json:"annotation"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpuallocatedpercentage string `json:"cpuallocatedpercentage"` + Cpuallocatedvalue int64 `json:"cpuallocatedvalue"` + Cpuallocatedwithoverprovisioning string `json:"cpuallocatedwithoverprovisioning"` + Cpuloadaverage float64 `json:"cpuloadaverage"` + Cpunumber int `json:"cpunumber"` + Cpusockets int `json:"cpusockets"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Encryptionsupported bool `json:"encryptionsupported"` + Events string `json:"events"` + Gpugroup []CancelHostAsDegradedResponseGpugroup `json:"gpugroup"` + Hahost bool `json:"hahost"` + Hasannotations bool `json:"hasannotations"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hostha HAForHostResponse `json:"hostha"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Istagarule bool `json:"istagarule"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Lastannotated string `json:"lastannotated"` + Lastpinged string `json:"lastpinged"` + Managementserverid UUID `json:"managementserverid"` + Memoryallocated int64 `json:"memoryallocated"` + Memoryallocatedbytes int64 `json:"memoryallocatedbytes"` + Memoryallocatedpercentage string `json:"memoryallocatedpercentage"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Outofbandmanagement OutOfBandManagementResponse `json:"outofbandmanagement"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Ueficapability bool `json:"ueficapability"` + Username string `json:"username"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type CancelHostAsDegradedResponseGpugroup struct { + Gpugroupname string `json:"gpugroupname"` + Vgpu []CancelHostAsDegradedResponseGpugroupVgpu `json:"vgpu"` +} + +type CancelHostAsDegradedResponseGpugroupVgpu struct { + Maxcapacity int64 `json:"maxcapacity"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu"` + Remainingcapacity int64 `json:"remainingcapacity"` + Vgputype string `json:"vgputype"` + Videoram int64 `json:"videoram"` +} + +type ListHostHAProvidersParams struct { + p map[string]interface{} +} + +func (p *ListHostHAProvidersParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["hypervisor"]; found { + u.Set("hypervisor", v.(string)) + } + return u +} + +func (p *ListHostHAProvidersParams) SetHypervisor(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hypervisor"] = v +} + +func (p *ListHostHAProvidersParams) ResetHypervisor() { + if p.p != nil && p.p["hypervisor"] != nil { + delete(p.p, "hypervisor") + } +} + +func (p *ListHostHAProvidersParams) GetHypervisor() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["hypervisor"].(string) + return value, ok +} + +// You should always use this function to get a new ListHostHAProvidersParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewListHostHAProvidersParams(hypervisor string) *ListHostHAProvidersParams { + p := &ListHostHAProvidersParams{} + p.p = make(map[string]interface{}) + p.p["hypervisor"] = hypervisor + return p +} + +// Lists HA providers +func (s *HostService) ListHostHAProviders(p *ListHostHAProvidersParams) (*ListHostHAProvidersResponse, error) { + resp, err := s.cs.newRequest("listHostHAProviders", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListHostHAProvidersResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListHostHAProvidersResponse struct { + Count int `json:"count"` + HostHAProviders []*HostHAProvider `json:"haprovider"` +} + +type HostHAProvider struct { + Haenable bool `json:"haenable"` + Haprovider string `json:"haprovider"` + Hastate string `json:"hastate"` + Hostid string `json:"hostid"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Status bool `json:"status"` +} + +type ListSecondaryStorageSelectorsParams struct { + p map[string]interface{} +} + +func (p *ListSecondaryStorageSelectorsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + 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) + } + if v, found := p.p["showremoved"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("showremoved", vv) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListSecondaryStorageSelectorsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v +} + +func (p *ListSecondaryStorageSelectorsParams) ResetKeyword() { + if p.p != nil && p.p["keyword"] != nil { + delete(p.p, "keyword") + } +} + +func (p *ListSecondaryStorageSelectorsParams) GetKeyword() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["keyword"].(string) + return value, ok +} + +func (p *ListSecondaryStorageSelectorsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v +} + +func (p *ListSecondaryStorageSelectorsParams) ResetPage() { + if p.p != nil && p.p["page"] != nil { + delete(p.p, "page") + } +} + +func (p *ListSecondaryStorageSelectorsParams) GetPage() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["page"].(int) + return value, ok +} + +func (p *ListSecondaryStorageSelectorsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v +} + +func (p *ListSecondaryStorageSelectorsParams) ResetPagesize() { + if p.p != nil && p.p["pagesize"] != nil { + delete(p.p, "pagesize") + } +} + +func (p *ListSecondaryStorageSelectorsParams) GetPagesize() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["pagesize"].(int) + return value, ok +} + +func (p *ListSecondaryStorageSelectorsParams) SetShowremoved(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["showremoved"] = v +} + +func (p *ListSecondaryStorageSelectorsParams) ResetShowremoved() { + if p.p != nil && p.p["showremoved"] != nil { + delete(p.p, "showremoved") + } +} + +func (p *ListSecondaryStorageSelectorsParams) GetShowremoved() (bool, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["showremoved"].(bool) + return value, ok +} + +func (p *ListSecondaryStorageSelectorsParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v +} + +func (p *ListSecondaryStorageSelectorsParams) ResetType() { + if p.p != nil && p.p["type"] != nil { + delete(p.p, "type") + } +} + +func (p *ListSecondaryStorageSelectorsParams) GetType() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["type"].(string) + return value, ok +} + +func (p *ListSecondaryStorageSelectorsParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v +} + +func (p *ListSecondaryStorageSelectorsParams) ResetZoneid() { + if p.p != nil && p.p["zoneid"] != nil { + delete(p.p, "zoneid") + } +} + +func (p *ListSecondaryStorageSelectorsParams) 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 ListSecondaryStorageSelectorsParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewListSecondaryStorageSelectorsParams(zoneid string) *ListSecondaryStorageSelectorsParams { + p := &ListSecondaryStorageSelectorsParams{} + p.p = make(map[string]interface{}) + p.p["zoneid"] = zoneid + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *HostService) GetSecondaryStorageSelectorID(keyword string, zoneid string, opts ...OptionFunc) (string, int, error) { + p := &ListSecondaryStorageSelectorsParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + p.p["zoneid"] = zoneid + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListSecondaryStorageSelectors(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.SecondaryStorageSelectors[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.SecondaryStorageSelectors { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// Lists the secondary storage selectors and their rules. +func (s *HostService) ListSecondaryStorageSelectors(p *ListSecondaryStorageSelectorsParams) (*ListSecondaryStorageSelectorsResponse, error) { + resp, err := s.cs.newRequest("listSecondaryStorageSelectors", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListSecondaryStorageSelectorsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListSecondaryStorageSelectorsResponse struct { + Count int `json:"count"` + SecondaryStorageSelectors []*SecondaryStorageSelector `json:"heuristics"` +} + +type SecondaryStorageSelector struct { + Created string `json:"created"` + Description string `json:"description"` + Heuristicrule string `json:"heuristicrule"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Name string `json:"name"` + Removed string `json:"removed"` + Type string `json:"type"` + Zoneid string `json:"zoneid"` +} + +type CreateSecondaryStorageSelectorParams struct { + p map[string]interface{} +} + +func (p *CreateSecondaryStorageSelectorParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["heuristicrule"]; found { + u.Set("heuristicrule", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *CreateSecondaryStorageSelectorParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v +} + +func (p *CreateSecondaryStorageSelectorParams) ResetDescription() { + if p.p != nil && p.p["description"] != nil { + delete(p.p, "description") + } +} + +func (p *CreateSecondaryStorageSelectorParams) GetDescription() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["description"].(string) + return value, ok +} + +func (p *CreateSecondaryStorageSelectorParams) SetHeuristicrule(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["heuristicrule"] = v +} + +func (p *CreateSecondaryStorageSelectorParams) ResetHeuristicrule() { + if p.p != nil && p.p["heuristicrule"] != nil { + delete(p.p, "heuristicrule") + } +} + +func (p *CreateSecondaryStorageSelectorParams) GetHeuristicrule() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["heuristicrule"].(string) + return value, ok +} + +func (p *CreateSecondaryStorageSelectorParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v +} + +func (p *CreateSecondaryStorageSelectorParams) ResetName() { + if p.p != nil && p.p["name"] != nil { + delete(p.p, "name") + } +} + +func (p *CreateSecondaryStorageSelectorParams) GetName() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["name"].(string) + return value, ok +} + +func (p *CreateSecondaryStorageSelectorParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v +} + +func (p *CreateSecondaryStorageSelectorParams) ResetType() { + if p.p != nil && p.p["type"] != nil { + delete(p.p, "type") + } +} + +func (p *CreateSecondaryStorageSelectorParams) GetType() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["type"].(string) + return value, ok +} + +func (p *CreateSecondaryStorageSelectorParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v +} + +func (p *CreateSecondaryStorageSelectorParams) ResetZoneid() { + if p.p != nil && p.p["zoneid"] != nil { + delete(p.p, "zoneid") + } +} + +func (p *CreateSecondaryStorageSelectorParams) 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 CreateSecondaryStorageSelectorParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewCreateSecondaryStorageSelectorParams(description string, heuristicrule string, name string, hostType string, zoneid string) *CreateSecondaryStorageSelectorParams { + p := &CreateSecondaryStorageSelectorParams{} + p.p = make(map[string]interface{}) + p.p["description"] = description + p.p["heuristicrule"] = heuristicrule + p.p["name"] = name + p.p["type"] = hostType + p.p["zoneid"] = zoneid + return p +} + +// Creates a secondary storage selector, described by the heuristic rule. +func (s *HostService) CreateSecondaryStorageSelector(p *CreateSecondaryStorageSelectorParams) (*CreateSecondaryStorageSelectorResponse, error) { + resp, err := s.cs.newRequest("createSecondaryStorageSelector", p.toURLValues()) + if err != nil { + return nil, err + } + fmt.Println(string(resp)) Review Comment: ```suggestion ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org