Skip to content

Commit

Permalink
Merge pull request #89 from suecodelabs/feature_add_more_apis
Browse files Browse the repository at this point in the history
add +30 more apis
  • Loading branch information
DaanHoogland authored Dec 13, 2024
2 parents 2b21240 + 9994d40 commit 4f01bd9
Show file tree
Hide file tree
Showing 67 changed files with 16,436 additions and 14 deletions.
206 changes: 206 additions & 0 deletions cloudstack/CertificateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import (
type CertificateServiceIface interface {
UploadCustomCertificate(p *UploadCustomCertificateParams) (*UploadCustomCertificateResponse, error)
NewUploadCustomCertificateParams(certificate string, domainsuffix string) *UploadCustomCertificateParams
ListCAProviders(p *ListCAProvidersParams) (*ListCAProvidersResponse, error)
NewListCAProvidersParams() *ListCAProvidersParams
ProvisionCertificate(p *ProvisionCertificateParams) (*ProvisionCertificateResponse, error)
NewProvisionCertificateParams(hostid string) *ProvisionCertificateParams
}

type UploadCustomCertificateParams struct {
Expand Down Expand Up @@ -213,3 +217,205 @@ type UploadCustomCertificateResponse struct {
Jobstatus int `json:"jobstatus"`
Message string `json:"message"`
}

type ListCAProvidersParams struct {
p map[string]interface{}
}

func (p *ListCAProvidersParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
return u
}

func (p *ListCAProvidersParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
}

func (p *ListCAProvidersParams) ResetName() {
if p.p != nil && p.p["name"] != nil {
delete(p.p, "name")
}
}

func (p *ListCAProvidersParams) GetName() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["name"].(string)
return value, ok
}

// You should always use this function to get a new ListCAProvidersParams instance,
// as then you are sure you have configured all required params
func (s *CertificateService) NewListCAProvidersParams() *ListCAProvidersParams {
p := &ListCAProvidersParams{}
p.p = make(map[string]interface{})
return p
}

// Lists available certificate authority providers in CloudStack
func (s *CertificateService) ListCAProviders(p *ListCAProvidersParams) (*ListCAProvidersResponse, error) {
resp, err := s.cs.newRequest("listCAProviders", p.toURLValues())
if err != nil {
return nil, err
}

var r ListCAProvidersResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}

return &r, nil
}

type ListCAProvidersResponse struct {
Count int `json:"count"`
CAProviders []*CAProvider `json:"caprovider"`
}

type CAProvider struct {
Description string `json:"description"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Name string `json:"name"`
}

type ProvisionCertificateParams struct {
p map[string]interface{}
}

func (p *ProvisionCertificateParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["hostid"]; found {
u.Set("hostid", v.(string))
}
if v, found := p.p["provider"]; found {
u.Set("provider", v.(string))
}
if v, found := p.p["reconnect"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("reconnect", vv)
}
return u
}

func (p *ProvisionCertificateParams) SetHostid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hostid"] = v
}

func (p *ProvisionCertificateParams) ResetHostid() {
if p.p != nil && p.p["hostid"] != nil {
delete(p.p, "hostid")
}
}

func (p *ProvisionCertificateParams) GetHostid() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["hostid"].(string)
return value, ok
}

func (p *ProvisionCertificateParams) SetProvider(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["provider"] = v
}

func (p *ProvisionCertificateParams) ResetProvider() {
if p.p != nil && p.p["provider"] != nil {
delete(p.p, "provider")
}
}

func (p *ProvisionCertificateParams) GetProvider() (string, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["provider"].(string)
return value, ok
}

func (p *ProvisionCertificateParams) SetReconnect(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["reconnect"] = v
}

func (p *ProvisionCertificateParams) ResetReconnect() {
if p.p != nil && p.p["reconnect"] != nil {
delete(p.p, "reconnect")
}
}

func (p *ProvisionCertificateParams) GetReconnect() (bool, bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
value, ok := p.p["reconnect"].(bool)
return value, ok
}

// You should always use this function to get a new ProvisionCertificateParams instance,
// as then you are sure you have configured all required params
func (s *CertificateService) NewProvisionCertificateParams(hostid string) *ProvisionCertificateParams {
p := &ProvisionCertificateParams{}
p.p = make(map[string]interface{})
p.p["hostid"] = hostid
return p
}

// Issues and propagates client certificate on a connected host/agent using configured CA plugin
func (s *CertificateService) ProvisionCertificate(p *ProvisionCertificateParams) (*ProvisionCertificateResponse, error) {
resp, err := s.cs.newRequest("provisionCertificate", p.toURLValues())
if err != nil {
return nil, err
}

var r ProvisionCertificateResponse
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 ProvisionCertificateResponse struct {
Displaytext string `json:"displaytext"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Success bool `json:"success"`
}
58 changes: 58 additions & 0 deletions cloudstack/CertificateService_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions cloudstack/ConfigurationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type ConfigurationServiceIface interface {
NewUpdateConfigurationParams(name string) *UpdateConfigurationParams
ResetConfiguration(p *ResetConfigurationParams) (*ResetConfigurationResponse, error)
NewResetConfigurationParams(name string) *ResetConfigurationParams
UpdateStorageCapabilities(p *UpdateStorageCapabilitiesParams) (*UpdateStorageCapabilitiesResponse, error)
NewUpdateStorageCapabilitiesParams(id string) *UpdateStorageCapabilitiesParams
}

type ListCapabilitiesParams struct {
Expand Down Expand Up @@ -1100,3 +1102,95 @@ type ResetConfigurationResponse struct {
Type string `json:"type"`
Value string `json:"value"`
}

type UpdateStorageCapabilitiesParams struct {
p map[string]interface{}
}

func (p *UpdateStorageCapabilitiesParams) 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 *UpdateStorageCapabilitiesParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
}

func (p *UpdateStorageCapabilitiesParams) ResetId() {
if p.p != nil && p.p["id"] != nil {
delete(p.p, "id")
}
}

func (p *UpdateStorageCapabilitiesParams) 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 UpdateStorageCapabilitiesParams instance,
// as then you are sure you have configured all required params
func (s *ConfigurationService) NewUpdateStorageCapabilitiesParams(id string) *UpdateStorageCapabilitiesParams {
p := &UpdateStorageCapabilitiesParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}

// Syncs capabilities of storage pools
func (s *ConfigurationService) UpdateStorageCapabilities(p *UpdateStorageCapabilitiesParams) (*UpdateStorageCapabilitiesResponse, error) {
resp, err := s.cs.newRequest("updateStorageCapabilities", p.toURLValues())
if err != nil {
return nil, err
}

var r UpdateStorageCapabilitiesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}

return &r, nil
}

type UpdateStorageCapabilitiesResponse 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"`
Name string `json:"name"`
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"`
Suitableformigration bool `json:"suitableformigration"`
Tags string `json:"tags"`
Type string `json:"type"`
Zoneid string `json:"zoneid"`
Zonename string `json:"zonename"`
}
Loading

0 comments on commit 4f01bd9

Please sign in to comment.