This is an automated email from the ASF dual-hosted git repository.
vishesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack-go.git
The following commit(s) were added to refs/heads/main by this push:
new 3a1384d Fix CNI Configuration as it internally uses UserData (#125)
3a1384d is described below
commit 3a1384d8bb88f2d1befdae979b3772f449492e6e
Author: Pearl Dsilva <[email protected]>
AuthorDate: Fri Sep 26 06:54:43 2025 -0400
Fix CNI Configuration as it internally uses UserData (#125)
---
cloudstack/ConfigurationService.go | 37 +++++++++++----------------------
cloudstack/ConfigurationService_mock.go | 8 +++----
generate/generate.go | 28 ++++++++++++++++++++++---
3 files changed, 41 insertions(+), 32 deletions(-)
diff --git a/cloudstack/ConfigurationService.go
b/cloudstack/ConfigurationService.go
index 914322d..7e9cfd6 100644
--- a/cloudstack/ConfigurationService.go
+++ b/cloudstack/ConfigurationService.go
@@ -47,8 +47,8 @@ type ConfigurationServiceIface interface {
ListCniConfiguration(p *ListCniConfigurationParams)
(*ListCniConfigurationResponse, error)
NewListCniConfigurationParams() *ListCniConfigurationParams
GetCniConfigurationID(name string, opts ...OptionFunc) (string, int,
error)
- GetCniConfigurationByName(name string, opts ...OptionFunc)
(*CniConfiguration, int, error)
- GetCniConfigurationByID(id string, opts ...OptionFunc)
(*CniConfiguration, int, error)
+ GetCniConfigurationByName(name string, opts ...OptionFunc) (*UserData,
int, error)
+ GetCniConfigurationByID(id string, opts ...OptionFunc) (*UserData, int,
error)
DeleteCniConfiguration(p *DeleteCniConfigurationParams)
(*DeleteCniConfigurationResponse, error)
NewDeleteCniConfigurationParams(id string) *DeleteCniConfigurationParams
}
@@ -1553,13 +1553,17 @@ func (s *ConfigurationService)
RegisterCniConfiguration(p *RegisterCniConfigurat
}
type RegisterCniConfigurationResponse struct {
+ CniConfiguration *UserData `json:"cniconfig"`
+}
+
+type RegisterCniConfiguration struct {
Displaytext string `json:"displaytext"`
JobID string `json:"jobid"`
Jobstatus int `json:"jobstatus"`
Success bool `json:"success"`
}
-func (r *RegisterCniConfigurationResponse) UnmarshalJSON(b []byte) error {
+func (r *RegisterCniConfiguration) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
@@ -1582,7 +1586,7 @@ func (r *RegisterCniConfigurationResponse)
UnmarshalJSON(b []byte) error {
}
}
- type alias RegisterCniConfigurationResponse
+ type alias RegisterCniConfiguration
return json.Unmarshal(b, (*alias)(r))
}
@@ -1887,7 +1891,7 @@ func (s *ConfigurationService) GetCniConfigurationID(name
string, opts ...Option
}
// This is a courtesy helper function, which in some cases may not work as
expected!
-func (s *ConfigurationService) GetCniConfigurationByName(name string, opts
...OptionFunc) (*CniConfiguration, int, error) {
+func (s *ConfigurationService) GetCniConfigurationByName(name string, opts
...OptionFunc) (*UserData, int, error) {
id, count, err := s.GetCniConfigurationID(name, opts...)
if err != nil {
return nil, count, err
@@ -1901,7 +1905,7 @@ func (s *ConfigurationService)
GetCniConfigurationByName(name string, opts ...Op
}
// This is a courtesy helper function, which in some cases may not work as
expected!
-func (s *ConfigurationService) GetCniConfigurationByID(id string, opts
...OptionFunc) (*CniConfiguration, int, error) {
+func (s *ConfigurationService) GetCniConfigurationByID(id string, opts
...OptionFunc) (*UserData, int, error) {
p := &ListCniConfigurationParams{}
p.p = make(map[string]interface{})
@@ -1949,25 +1953,8 @@ func (s *ConfigurationService) ListCniConfiguration(p
*ListCniConfigurationParam
}
type ListCniConfigurationResponse struct {
- Count int `json:"count"`
- CniConfiguration []*CniConfiguration `json:"cniconfiguration"`
-}
-
-type CniConfiguration struct {
- Account string `json:"account"`
- Accountid string `json:"accountid"`
- Domain string `json:"domain"`
- Domainid string `json:"domainid"`
- Domainpath string `json:"domainpath"`
- Hasannotations bool `json:"hasannotations"`
- Id string `json:"id"`
- JobID string `json:"jobid"`
- Jobstatus int `json:"jobstatus"`
- Name string `json:"name"`
- Params string `json:"params"`
- Project string `json:"project"`
- Projectid string `json:"projectid"`
- Userdata string `json:"userdata"`
+ Count int `json:"count"`
+ CniConfiguration []*UserData `json:"cniconfig"`
}
type DeleteCniConfigurationParams struct {
diff --git a/cloudstack/ConfigurationService_mock.go
b/cloudstack/ConfigurationService_mock.go
index 668403a..4b1b037 100644
--- a/cloudstack/ConfigurationService_mock.go
+++ b/cloudstack/ConfigurationService_mock.go
@@ -74,14 +74,14 @@ func (mr *MockConfigurationServiceIfaceMockRecorder)
DeleteCniConfiguration(p an
}
// GetCniConfigurationByID mocks base method.
-func (m *MockConfigurationServiceIface) GetCniConfigurationByID(id string,
opts ...OptionFunc) (*CniConfiguration, int, error) {
+func (m *MockConfigurationServiceIface) GetCniConfigurationByID(id string,
opts ...OptionFunc) (*UserData, int, error) {
m.ctrl.T.Helper()
varargs := []any{id}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetCniConfigurationByID", varargs...)
- ret0, _ := ret[0].(*CniConfiguration)
+ ret0, _ := ret[0].(*UserData)
ret1, _ := ret[1].(int)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
@@ -95,14 +95,14 @@ func (mr *MockConfigurationServiceIfaceMockRecorder)
GetCniConfigurationByID(id
}
// GetCniConfigurationByName mocks base method.
-func (m *MockConfigurationServiceIface) GetCniConfigurationByName(name string,
opts ...OptionFunc) (*CniConfiguration, int, error) {
+func (m *MockConfigurationServiceIface) GetCniConfigurationByName(name string,
opts ...OptionFunc) (*UserData, int, error) {
m.ctrl.T.Helper()
varargs := []any{name}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetCniConfigurationByName", varargs...)
- ret0, _ := ret[0].(*CniConfiguration)
+ ret0, _ := ret[0].(*UserData)
ret1, _ := ret[1].(int)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
diff --git a/generate/generate.go b/generate/generate.go
index 0a5d5ec..f011368 100644
--- a/generate/generate.go
+++ b/generate/generate.go
@@ -1302,7 +1302,11 @@ func (s *service) generateInterfaceType() {
if parseSingular(ln) == "Template" ||
parseSingular(ln) == "Iso" {
p("zoneid string, ")
}
- pn("opts ...OptionFunc) (*%s, int,
error)", parseSingular(ln))
+ if parseSingular(ln) ==
"CniConfiguration" {
+ pn("opts ...OptionFunc)
(*UserData, int, error)")
+ } else {
+ pn("opts ...OptionFunc) (*%s,
int, error)", parseSingular(ln))
+ }
}
}
@@ -1318,6 +1322,8 @@ func (s *service) generateInterfaceType() {
}
if ln == "LoadBalancerRuleInstances" {
pn("opts ...OptionFunc)
(*VirtualMachine, int, error)")
+ } else if ln == "CniConfiguration" {
+ pn("opts ...OptionFunc) (*UserData,
int, error)")
} else {
pn("opts ...OptionFunc) (*%s, int,
error)", parseSingular(ln))
}
@@ -1630,7 +1636,11 @@ func (s *service) generateHelperFuncs(a *API) {
if parseSingular(ln) == "Template" ||
parseSingular(ln) == "Iso" {
p("zoneid string, ")
}
- pn("opts ...OptionFunc) (*%s, int, error) {",
parseSingular(ln))
+ if parseSingular(ln) == "CniConfiguration" {
+ pn("opts ...OptionFunc) (*UserData,
int, error) {")
+ } else {
+ pn("opts ...OptionFunc) (*%s, int,
error) {", parseSingular(ln))
+ }
// Generate the function body
p(" id, count, err := s.Get%sID(name, ",
parseSingular(ln))
@@ -1679,6 +1689,8 @@ func (s *service) generateHelperFuncs(a *API) {
}
if ln == "LoadBalancerRuleInstances" {
pn("opts ...OptionFunc) (*VirtualMachine, int,
error) {")
+ } else if ln == "CniConfiguration" {
+ pn("opts ...OptionFunc) (*UserData, int, error)
{")
} else {
pn("opts ...OptionFunc) (*%s, int, error) {",
parseSingular(ln))
}
@@ -1978,6 +1990,14 @@ func (s *service) generateResponseType(a *API) {
pn("")
return
}
+ if a.Name == "listCniConfiguration" {
+ pn("type ListCniConfigurationResponse struct {")
+ pn(" Count int `json:\"count\"`")
+ pn(" CniConfiguration []*UserData `json:\"cniconfig\"`")
+ pn("}")
+ pn("")
+ return
+ }
ln := capitalize(strings.TrimPrefix(a.Name, "list"))
@@ -1985,7 +2005,7 @@ func (s *service) generateResponseType(a *API) {
// types of responses that also need a separate list struct, so
checking on exact matches
// for those once.
if strings.HasPrefix(a.Name, "list") || a.Name == "registerTemplate" ||
a.Name == "findHostsForMigration" || a.Name == "registerUserData" ||
- a.Name == "quotaBalance" || a.Name == "quotaSummary" || a.Name
== "quotaTariffList" {
+ a.Name == "registerCniConfiguration" || a.Name ==
"quotaBalance" || a.Name == "quotaSummary" || a.Name == "quotaTariffList" {
pn("type %s struct {", tn)
// This nasty check is for some specific response that do not
behave consistent
@@ -2034,6 +2054,8 @@ func (s *service) generateResponseType(a *API) {
pn(" Name string `json:\"name\"`")
pn(" Params string `json:\"params\"`")
pn(" Userdata string `json:\"userdata\"`")
+ case "registerCniConfiguration":
+ pn(" CniConfiguration *UserData
`json:\"cniconfig\"`")
case "listObjectStoragePools":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln),
"objectstore")