Skip to content

Commit 275fbdc

Browse files
author
Marcus Sorensen
authored
Merge pull request #47 from mp-forks/resetconfiguration
Resetconfiguration
2 parents 0106fc7 + 9bf003b commit 275fbdc

File tree

5 files changed

+229
-0
lines changed

5 files changed

+229
-0
lines changed

cloudstack/ConfigurationService.go

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type ConfigurationServiceIface interface {
3434
NewListDeploymentPlannersParams() *ListDeploymentPlannersParams
3535
UpdateConfiguration(p *UpdateConfigurationParams) (*UpdateConfigurationResponse, error)
3636
NewUpdateConfigurationParams(name string) *UpdateConfigurationParams
37+
ResetConfiguration(p *ResetConfigurationParams) (*ResetConfigurationResponse, error)
38+
NewResetConfigurationParams(name string) *ResetConfigurationParams
3739
}
3840

3941
type ListCapabilitiesParams struct {
@@ -649,3 +651,177 @@ type UpdateConfigurationResponse struct {
649651
Scope string `json:"scope"`
650652
Value string `json:"value"`
651653
}
654+
655+
type ResetConfigurationParams struct {
656+
p map[string]interface{}
657+
}
658+
659+
func (p *ResetConfigurationParams) toURLValues() url.Values {
660+
u := url.Values{}
661+
if p.p == nil {
662+
return u
663+
}
664+
if v, found := p.p["accountid"]; found {
665+
u.Set("accountid", v.(string))
666+
}
667+
if v, found := p.p["clusterid"]; found {
668+
u.Set("clusterid", v.(string))
669+
}
670+
if v, found := p.p["domainid"]; found {
671+
u.Set("domainid", v.(string))
672+
}
673+
if v, found := p.p["imagestoreid"]; found {
674+
u.Set("imagestoreid", v.(string))
675+
}
676+
if v, found := p.p["name"]; found {
677+
u.Set("name", v.(string))
678+
}
679+
if v, found := p.p["storageid"]; found {
680+
u.Set("storageid", v.(string))
681+
}
682+
if v, found := p.p["zoneid"]; found {
683+
u.Set("zoneid", v.(string))
684+
}
685+
return u
686+
}
687+
688+
func (p *ResetConfigurationParams) SetAccountid(v string) {
689+
if p.p == nil {
690+
p.p = make(map[string]interface{})
691+
}
692+
p.p["accountid"] = v
693+
}
694+
695+
func (p *ResetConfigurationParams) GetAccountid() (string, bool) {
696+
if p.p == nil {
697+
p.p = make(map[string]interface{})
698+
}
699+
value, ok := p.p["accountid"].(string)
700+
return value, ok
701+
}
702+
703+
func (p *ResetConfigurationParams) SetClusterid(v string) {
704+
if p.p == nil {
705+
p.p = make(map[string]interface{})
706+
}
707+
p.p["clusterid"] = v
708+
}
709+
710+
func (p *ResetConfigurationParams) GetClusterid() (string, bool) {
711+
if p.p == nil {
712+
p.p = make(map[string]interface{})
713+
}
714+
value, ok := p.p["clusterid"].(string)
715+
return value, ok
716+
}
717+
718+
func (p *ResetConfigurationParams) SetDomainid(v string) {
719+
if p.p == nil {
720+
p.p = make(map[string]interface{})
721+
}
722+
p.p["domainid"] = v
723+
}
724+
725+
func (p *ResetConfigurationParams) GetDomainid() (string, bool) {
726+
if p.p == nil {
727+
p.p = make(map[string]interface{})
728+
}
729+
value, ok := p.p["domainid"].(string)
730+
return value, ok
731+
}
732+
733+
func (p *ResetConfigurationParams) SetImagestoreid(v string) {
734+
if p.p == nil {
735+
p.p = make(map[string]interface{})
736+
}
737+
p.p["imagestoreid"] = v
738+
}
739+
740+
func (p *ResetConfigurationParams) GetImagestoreid() (string, bool) {
741+
if p.p == nil {
742+
p.p = make(map[string]interface{})
743+
}
744+
value, ok := p.p["imagestoreid"].(string)
745+
return value, ok
746+
}
747+
748+
func (p *ResetConfigurationParams) SetName(v string) {
749+
if p.p == nil {
750+
p.p = make(map[string]interface{})
751+
}
752+
p.p["name"] = v
753+
}
754+
755+
func (p *ResetConfigurationParams) GetName() (string, bool) {
756+
if p.p == nil {
757+
p.p = make(map[string]interface{})
758+
}
759+
value, ok := p.p["name"].(string)
760+
return value, ok
761+
}
762+
763+
func (p *ResetConfigurationParams) SetStorageid(v string) {
764+
if p.p == nil {
765+
p.p = make(map[string]interface{})
766+
}
767+
p.p["storageid"] = v
768+
}
769+
770+
func (p *ResetConfigurationParams) GetStorageid() (string, bool) {
771+
if p.p == nil {
772+
p.p = make(map[string]interface{})
773+
}
774+
value, ok := p.p["storageid"].(string)
775+
return value, ok
776+
}
777+
778+
func (p *ResetConfigurationParams) SetZoneid(v string) {
779+
if p.p == nil {
780+
p.p = make(map[string]interface{})
781+
}
782+
p.p["zoneid"] = v
783+
}
784+
785+
func (p *ResetConfigurationParams) GetZoneid() (string, bool) {
786+
if p.p == nil {
787+
p.p = make(map[string]interface{})
788+
}
789+
value, ok := p.p["zoneid"].(string)
790+
return value, ok
791+
}
792+
793+
// You should always use this function to get a new ResetConfigurationParams instance,
794+
// as then you are sure you have configured all required params
795+
func (s *ConfigurationService) NewResetConfigurationParams(name string) *ResetConfigurationParams {
796+
p := &ResetConfigurationParams{}
797+
p.p = make(map[string]interface{})
798+
p.p["name"] = name
799+
return p
800+
}
801+
802+
// Resets a configuration. The configuration will be set to default value for global setting, and removed from account_details or domain_details for Account/Domain settings
803+
func (s *ConfigurationService) ResetConfiguration(p *ResetConfigurationParams) (*ResetConfigurationResponse, error) {
804+
resp, err := s.cs.newRequest("resetConfiguration", p.toURLValues())
805+
if err != nil {
806+
return nil, err
807+
}
808+
809+
var r ResetConfigurationResponse
810+
if err := json.Unmarshal(resp, &r); err != nil {
811+
return nil, err
812+
}
813+
814+
return &r, nil
815+
}
816+
817+
type ResetConfigurationResponse struct {
818+
Category string `json:"category"`
819+
Description string `json:"description"`
820+
Id int64 `json:"id"`
821+
Isdynamic bool `json:"isdynamic"`
822+
JobID string `json:"jobid"`
823+
Jobstatus int `json:"jobstatus"`
824+
Name string `json:"name"`
825+
Scope string `json:"scope"`
826+
Value string `json:"value"`
827+
}

cloudstack/ConfigurationService_mock.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/layout.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ var layout = apiInfo{
596596
"listConfigurations",
597597
"listDeploymentPlanners",
598598
"updateConfiguration",
599+
"resetConfiguration",
599600
},
600601
"BrocadeVCSService": {
601602
"addBrocadeVcsDevice",

test/ConfigurationService_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,16 @@ func TestConfigurationService(t *testing.T) {
8383
}
8484
t.Run("UpdateConfiguration", testupdateConfiguration)
8585

86+
testresetConfiguration := func(t *testing.T) {
87+
if _, ok := response["resetConfiguration"]; !ok {
88+
t.Skipf("Skipping as no json response is provided in testdata")
89+
}
90+
p := client.Configuration.NewResetConfigurationParams("name")
91+
_, err := client.Configuration.ResetConfiguration(p)
92+
if err != nil {
93+
t.Errorf(err.Error())
94+
}
95+
}
96+
t.Run("ResetConfiguration", testresetConfiguration)
97+
8698
}

test/testdata/ConfigurationService.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,16 @@
4747
"isdynamic": false
4848
}
4949
}
50+
},
51+
"resetConfiguration": {
52+
"resetconfigurationresponse":{
53+
"configuration":{
54+
"category":"Project Defaults",
55+
"name":"allow.user.create.projects",
56+
"value":"true",
57+
"description":"If regular user can create a project; true by default",
58+
"isdynamic":false
59+
}
60+
}
5061
}
5162
}

0 commit comments

Comments
 (0)