This is an automated email from the ASF dual-hosted git repository. dahn pushed a commit to branch pr90 in repository https://gitbox.apache.org/repos/asf/cloudstack-go.git
commit 3232dc6ab626d494415de5cb85afe51278e2e509 Author: tonymmm1 <t...@mail.magnatox.com> AuthorDate: Mon Jul 22 04:12:14 2024 -0500 implement QuotaBalance --- cloudstack/QuotaService.go | 174 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 1 deletion(-) diff --git a/cloudstack/QuotaService.go b/cloudstack/QuotaService.go index d01eacd..d242291 100644 --- a/cloudstack/QuotaService.go +++ b/cloudstack/QuotaService.go @@ -25,7 +25,8 @@ import ( ) type QuotaServiceIface interface { - //CreateBalance(p *CreateBalanceParams) (*CreateBalanceResponse, error) + QuotaBalance(p *QuotaBalanceParams) (*QuotaBalanceResponse, error) + NewQuotaBalanceParams(account string, domainid string) *QuotaBalanceParams //CreateCredit(p *CreateCreditParams) (*CreateCreditResponse, error) QuotaIsEnabled(p *QuotaIsEnabledParams) (*QuotaIsEnabledResponse, error) NewQuotaIsEnabledParams() *QuotaIsEnabledParams @@ -38,6 +39,177 @@ type QuotaServiceIface interface { //UpdateQuota(p *UpdateQuotaParams) (*UpdateQuotaResponse, error) } +type QuotaBalanceParams struct { + p map[string]interface{} +} + +func (p *QuotaBalanceParams) 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["accountid"]; found { + u.Set("accountid", v.(string)) + } + if v, found := p.p["enddate"]; found { + u.Set("enddate", v.(string)) + } + if v, found := p.p["startdate"]; found { + u.Set("startdate", v.(string)) + } + return u +} + +func (p *QuotaBalanceParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v +} + +func (p *QuotaBalanceParams) ResetAccount() { + if p.p == nil { + p.p = make(map[string]interface{}) + } + delete(p.p, "account") +} + +func (p *QuotaBalanceParams) GetAccount() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["account"].(string) + return value, ok +} + +func (p *QuotaBalanceParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v +} + +func (p *QuotaBalanceParams) ResetDomainid() { + if p.p == nil { + p.p = make(map[string]interface{}) + } + delete(p.p, "domainid") +} + +func (p *QuotaBalanceParams) GetDomainid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["domainid"].(string) + return value, ok +} + +func (p *QuotaBalanceParams) SetAccountid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accountid"] = v +} + +func (p *QuotaBalanceParams) ResetAccountid() { + if p.p == nil { + p.p = make(map[string]interface{}) + } + delete(p.p, "accountid") +} + +func (p *QuotaBalanceParams) GetAccountid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["accountid"].(string) + return value, ok +} + +func (p *QuotaBalanceParams) SetEnddate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["enddate"] = v +} + +func (p *QuotaBalanceParams) ResetEnddate() { + if p.p == nil { + p.p = make(map[string]interface{}) + } + delete(p.p, "enddate") +} + +func (p *QuotaBalanceParams) GetEnddate() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["enddate"].(string) + return value, ok +} + +func (p *QuotaBalanceParams) SetStartdate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startdate"] = v +} + +func (p *QuotaBalanceParams) ResetStartdate() { + if p.p == nil { + p.p = make(map[string]interface{}) + } + delete(p.p, "startdate") +} + +func (p *QuotaBalanceParams) GetStartdate() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["startdate"].(string) + return value, ok +} + +// You should always use this function to get a new QuotaBalanceParams instance, +// as then you are sure you have configured all required params +func (s *QuotaService) NewQuotaBalanceParams(account string, domainid string) *QuotaBalanceParams { + p := &QuotaBalanceParams{} + p.p = make(map[string]interface{}) + p.p["account"] = account + p.p["domainid"] = domainid + return p +} + +func (s *QuotaService) QuotaBalance(p *QuotaBalanceParams) (*QuotaBalanceResponse, error) { + resp, err := s.cs.newRequest("quotaBalance", p.toURLValues()) + if err != nil { + return nil, err + } + + var r QuotaBalanceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type QuotaBalanceResponse struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Domain string `json:"domain"` + Name string `json:"name"` + Quota string `json:"quota"` + Type string `json:"type"` + Unit string `json:"unit"` +} + type QuotaIsEnabledParams struct { p map[string]interface{} }