diff --git a/cloudstack/ConfigurationService.go b/cloudstack/ConfigurationService.go index ee60f392..80394440 100644 --- a/cloudstack/ConfigurationService.go +++ b/cloudstack/ConfigurationService.go @@ -34,6 +34,8 @@ type ConfigurationServiceIface interface { NewListDeploymentPlannersParams() *ListDeploymentPlannersParams UpdateConfiguration(p *UpdateConfigurationParams) (*UpdateConfigurationResponse, error) NewUpdateConfigurationParams(name string) *UpdateConfigurationParams + ResetConfiguration(p *ResetConfigurationParams) (*ResetConfigurationResponse, error) + NewResetConfigurationParams(name string) *ResetConfigurationParams } type ListCapabilitiesParams struct { @@ -649,3 +651,177 @@ type UpdateConfigurationResponse struct { Scope string `json:"scope"` Value string `json:"value"` } + +type ResetConfigurationParams struct { + p map[string]interface{} +} + +func (p *ResetConfigurationParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["accountid"]; found { + u.Set("accountid", v.(string)) + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["imagestoreid"]; found { + u.Set("imagestoreid", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["storageid"]; found { + u.Set("storageid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ResetConfigurationParams) SetAccountid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accountid"] = v +} + +func (p *ResetConfigurationParams) GetAccountid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["accountid"].(string) + return value, ok +} + +func (p *ResetConfigurationParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v +} + +func (p *ResetConfigurationParams) GetClusterid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["clusterid"].(string) + return value, ok +} + +func (p *ResetConfigurationParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v +} + +func (p *ResetConfigurationParams) GetDomainid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["domainid"].(string) + return value, ok +} + +func (p *ResetConfigurationParams) SetImagestoreid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["imagestoreid"] = v +} + +func (p *ResetConfigurationParams) GetImagestoreid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["imagestoreid"].(string) + return value, ok +} + +func (p *ResetConfigurationParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v +} + +func (p *ResetConfigurationParams) GetName() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["name"].(string) + return value, ok +} + +func (p *ResetConfigurationParams) SetStorageid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["storageid"] = v +} + +func (p *ResetConfigurationParams) GetStorageid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["storageid"].(string) + return value, ok +} + +func (p *ResetConfigurationParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v +} + +func (p *ResetConfigurationParams) 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 ResetConfigurationParams instance, +// as then you are sure you have configured all required params +func (s *ConfigurationService) NewResetConfigurationParams(name string) *ResetConfigurationParams { + p := &ResetConfigurationParams{} + p.p = make(map[string]interface{}) + p.p["name"] = name + return p +} + +// 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 +func (s *ConfigurationService) ResetConfiguration(p *ResetConfigurationParams) (*ResetConfigurationResponse, error) { + resp, err := s.cs.newRequest("resetConfiguration", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ResetConfigurationResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ResetConfigurationResponse struct { + Category string `json:"category"` + Description string `json:"description"` + Id int64 `json:"id"` + Isdynamic bool `json:"isdynamic"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Name string `json:"name"` + Scope string `json:"scope"` + Value string `json:"value"` +} diff --git a/cloudstack/ConfigurationService_mock.go b/cloudstack/ConfigurationService_mock.go index 7c593059..ac31e8ee 100644 --- a/cloudstack/ConfigurationService_mock.go +++ b/cloudstack/ConfigurationService_mock.go @@ -139,6 +139,20 @@ func (mr *MockConfigurationServiceIfaceMockRecorder) NewListDeploymentPlannersPa return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewListDeploymentPlannersParams", reflect.TypeOf((*MockConfigurationServiceIface)(nil).NewListDeploymentPlannersParams)) } +// NewResetConfigurationParams mocks base method. +func (m *MockConfigurationServiceIface) NewResetConfigurationParams(name string) *ResetConfigurationParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewResetConfigurationParams", name) + ret0, _ := ret[0].(*ResetConfigurationParams) + return ret0 +} + +// NewResetConfigurationParams indicates an expected call of NewResetConfigurationParams. +func (mr *MockConfigurationServiceIfaceMockRecorder) NewResetConfigurationParams(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewResetConfigurationParams", reflect.TypeOf((*MockConfigurationServiceIface)(nil).NewResetConfigurationParams), name) +} + // NewUpdateConfigurationParams mocks base method. func (m *MockConfigurationServiceIface) NewUpdateConfigurationParams(name string) *UpdateConfigurationParams { m.ctrl.T.Helper() @@ -153,6 +167,21 @@ func (mr *MockConfigurationServiceIfaceMockRecorder) NewUpdateConfigurationParam return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewUpdateConfigurationParams", reflect.TypeOf((*MockConfigurationServiceIface)(nil).NewUpdateConfigurationParams), name) } +// ResetConfiguration mocks base method. +func (m *MockConfigurationServiceIface) ResetConfiguration(p *ResetConfigurationParams) (*ResetConfigurationResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ResetConfiguration", p) + ret0, _ := ret[0].(*ResetConfigurationResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ResetConfiguration indicates an expected call of ResetConfiguration. +func (mr *MockConfigurationServiceIfaceMockRecorder) ResetConfiguration(p interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResetConfiguration", reflect.TypeOf((*MockConfigurationServiceIface)(nil).ResetConfiguration), p) +} + // UpdateConfiguration mocks base method. func (m *MockConfigurationServiceIface) UpdateConfiguration(p *UpdateConfigurationParams) (*UpdateConfigurationResponse, error) { m.ctrl.T.Helper() diff --git a/generate/layout.go b/generate/layout.go index a7ec89dd..197de1c4 100644 --- a/generate/layout.go +++ b/generate/layout.go @@ -596,6 +596,7 @@ var layout = apiInfo{ "listConfigurations", "listDeploymentPlanners", "updateConfiguration", + "resetConfiguration", }, "BrocadeVCSService": { "addBrocadeVcsDevice", diff --git a/test/ConfigurationService_test.go b/test/ConfigurationService_test.go index 355fb730..456d8ddc 100644 --- a/test/ConfigurationService_test.go +++ b/test/ConfigurationService_test.go @@ -83,4 +83,16 @@ func TestConfigurationService(t *testing.T) { } t.Run("UpdateConfiguration", testupdateConfiguration) + testresetConfiguration := func(t *testing.T) { + if _, ok := response["resetConfiguration"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.Configuration.NewResetConfigurationParams("name") + _, err := client.Configuration.ResetConfiguration(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("ResetConfiguration", testresetConfiguration) + } diff --git a/test/testdata/ConfigurationService.json b/test/testdata/ConfigurationService.json index ef13ddef..5f237aca 100644 --- a/test/testdata/ConfigurationService.json +++ b/test/testdata/ConfigurationService.json @@ -47,5 +47,16 @@ "isdynamic": false } } + }, + "resetConfiguration": { + "resetconfigurationresponse":{ + "configuration":{ + "category":"Project Defaults", + "name":"allow.user.create.projects", + "value":"true", + "description":"If regular user can create a project; true by default", + "isdynamic":false + } + } } } \ No newline at end of file