Skip to content

Commit 3a1384d

Browse files
authored
Fix CNI Configuration as it internally uses UserData (#125)
1 parent cff4f1b commit 3a1384d

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

cloudstack/ConfigurationService.go

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ type ConfigurationServiceIface interface {
4747
ListCniConfiguration(p *ListCniConfigurationParams) (*ListCniConfigurationResponse, error)
4848
NewListCniConfigurationParams() *ListCniConfigurationParams
4949
GetCniConfigurationID(name string, opts ...OptionFunc) (string, int, error)
50-
GetCniConfigurationByName(name string, opts ...OptionFunc) (*CniConfiguration, int, error)
51-
GetCniConfigurationByID(id string, opts ...OptionFunc) (*CniConfiguration, int, error)
50+
GetCniConfigurationByName(name string, opts ...OptionFunc) (*UserData, int, error)
51+
GetCniConfigurationByID(id string, opts ...OptionFunc) (*UserData, int, error)
5252
DeleteCniConfiguration(p *DeleteCniConfigurationParams) (*DeleteCniConfigurationResponse, error)
5353
NewDeleteCniConfigurationParams(id string) *DeleteCniConfigurationParams
5454
}
@@ -1553,13 +1553,17 @@ func (s *ConfigurationService) RegisterCniConfiguration(p *RegisterCniConfigurat
15531553
}
15541554

15551555
type RegisterCniConfigurationResponse struct {
1556+
CniConfiguration *UserData `json:"cniconfig"`
1557+
}
1558+
1559+
type RegisterCniConfiguration struct {
15561560
Displaytext string `json:"displaytext"`
15571561
JobID string `json:"jobid"`
15581562
Jobstatus int `json:"jobstatus"`
15591563
Success bool `json:"success"`
15601564
}
15611565

1562-
func (r *RegisterCniConfigurationResponse) UnmarshalJSON(b []byte) error {
1566+
func (r *RegisterCniConfiguration) UnmarshalJSON(b []byte) error {
15631567
var m map[string]interface{}
15641568
err := json.Unmarshal(b, &m)
15651569
if err != nil {
@@ -1582,7 +1586,7 @@ func (r *RegisterCniConfigurationResponse) UnmarshalJSON(b []byte) error {
15821586
}
15831587
}
15841588

1585-
type alias RegisterCniConfigurationResponse
1589+
type alias RegisterCniConfiguration
15861590
return json.Unmarshal(b, (*alias)(r))
15871591
}
15881592

@@ -1887,7 +1891,7 @@ func (s *ConfigurationService) GetCniConfigurationID(name string, opts ...Option
18871891
}
18881892

18891893
// This is a courtesy helper function, which in some cases may not work as expected!
1890-
func (s *ConfigurationService) GetCniConfigurationByName(name string, opts ...OptionFunc) (*CniConfiguration, int, error) {
1894+
func (s *ConfigurationService) GetCniConfigurationByName(name string, opts ...OptionFunc) (*UserData, int, error) {
18911895
id, count, err := s.GetCniConfigurationID(name, opts...)
18921896
if err != nil {
18931897
return nil, count, err
@@ -1901,7 +1905,7 @@ func (s *ConfigurationService) GetCniConfigurationByName(name string, opts ...Op
19011905
}
19021906

19031907
// This is a courtesy helper function, which in some cases may not work as expected!
1904-
func (s *ConfigurationService) GetCniConfigurationByID(id string, opts ...OptionFunc) (*CniConfiguration, int, error) {
1908+
func (s *ConfigurationService) GetCniConfigurationByID(id string, opts ...OptionFunc) (*UserData, int, error) {
19051909
p := &ListCniConfigurationParams{}
19061910
p.p = make(map[string]interface{})
19071911

@@ -1949,25 +1953,8 @@ func (s *ConfigurationService) ListCniConfiguration(p *ListCniConfigurationParam
19491953
}
19501954

19511955
type ListCniConfigurationResponse struct {
1952-
Count int `json:"count"`
1953-
CniConfiguration []*CniConfiguration `json:"cniconfiguration"`
1954-
}
1955-
1956-
type CniConfiguration struct {
1957-
Account string `json:"account"`
1958-
Accountid string `json:"accountid"`
1959-
Domain string `json:"domain"`
1960-
Domainid string `json:"domainid"`
1961-
Domainpath string `json:"domainpath"`
1962-
Hasannotations bool `json:"hasannotations"`
1963-
Id string `json:"id"`
1964-
JobID string `json:"jobid"`
1965-
Jobstatus int `json:"jobstatus"`
1966-
Name string `json:"name"`
1967-
Params string `json:"params"`
1968-
Project string `json:"project"`
1969-
Projectid string `json:"projectid"`
1970-
Userdata string `json:"userdata"`
1956+
Count int `json:"count"`
1957+
CniConfiguration []*UserData `json:"cniconfig"`
19711958
}
19721959

19731960
type DeleteCniConfigurationParams struct {

cloudstack/ConfigurationService_mock.go

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

generate/generate.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,11 @@ func (s *service) generateInterfaceType() {
13021302
if parseSingular(ln) == "Template" || parseSingular(ln) == "Iso" {
13031303
p("zoneid string, ")
13041304
}
1305-
pn("opts ...OptionFunc) (*%s, int, error)", parseSingular(ln))
1305+
if parseSingular(ln) == "CniConfiguration" {
1306+
pn("opts ...OptionFunc) (*UserData, int, error)")
1307+
} else {
1308+
pn("opts ...OptionFunc) (*%s, int, error)", parseSingular(ln))
1309+
}
13061310
}
13071311
}
13081312

@@ -1318,6 +1322,8 @@ func (s *service) generateInterfaceType() {
13181322
}
13191323
if ln == "LoadBalancerRuleInstances" {
13201324
pn("opts ...OptionFunc) (*VirtualMachine, int, error)")
1325+
} else if ln == "CniConfiguration" {
1326+
pn("opts ...OptionFunc) (*UserData, int, error)")
13211327
} else {
13221328
pn("opts ...OptionFunc) (*%s, int, error)", parseSingular(ln))
13231329
}
@@ -1630,7 +1636,11 @@ func (s *service) generateHelperFuncs(a *API) {
16301636
if parseSingular(ln) == "Template" || parseSingular(ln) == "Iso" {
16311637
p("zoneid string, ")
16321638
}
1633-
pn("opts ...OptionFunc) (*%s, int, error) {", parseSingular(ln))
1639+
if parseSingular(ln) == "CniConfiguration" {
1640+
pn("opts ...OptionFunc) (*UserData, int, error) {")
1641+
} else {
1642+
pn("opts ...OptionFunc) (*%s, int, error) {", parseSingular(ln))
1643+
}
16341644

16351645
// Generate the function body
16361646
p(" id, count, err := s.Get%sID(name, ", parseSingular(ln))
@@ -1679,6 +1689,8 @@ func (s *service) generateHelperFuncs(a *API) {
16791689
}
16801690
if ln == "LoadBalancerRuleInstances" {
16811691
pn("opts ...OptionFunc) (*VirtualMachine, int, error) {")
1692+
} else if ln == "CniConfiguration" {
1693+
pn("opts ...OptionFunc) (*UserData, int, error) {")
16821694
} else {
16831695
pn("opts ...OptionFunc) (*%s, int, error) {", parseSingular(ln))
16841696
}
@@ -1978,14 +1990,22 @@ func (s *service) generateResponseType(a *API) {
19781990
pn("")
19791991
return
19801992
}
1993+
if a.Name == "listCniConfiguration" {
1994+
pn("type ListCniConfigurationResponse struct {")
1995+
pn(" Count int `json:\"count\"`")
1996+
pn(" CniConfiguration []*UserData `json:\"cniconfig\"`")
1997+
pn("}")
1998+
pn("")
1999+
return
2000+
}
19812001

19822002
ln := capitalize(strings.TrimPrefix(a.Name, "list"))
19832003

19842004
// If this is a 'list' response, we need an separate list struct. There seem to be other
19852005
// types of responses that also need a separate list struct, so checking on exact matches
19862006
// for those once.
19872007
if strings.HasPrefix(a.Name, "list") || a.Name == "registerTemplate" || a.Name == "findHostsForMigration" || a.Name == "registerUserData" ||
1988-
a.Name == "quotaBalance" || a.Name == "quotaSummary" || a.Name == "quotaTariffList" {
2008+
a.Name == "registerCniConfiguration" || a.Name == "quotaBalance" || a.Name == "quotaSummary" || a.Name == "quotaTariffList" {
19892009
pn("type %s struct {", tn)
19902010

19912011
// This nasty check is for some specific response that do not behave consistent
@@ -2034,6 +2054,8 @@ func (s *service) generateResponseType(a *API) {
20342054
pn(" Name string `json:\"name\"`")
20352055
pn(" Params string `json:\"params\"`")
20362056
pn(" Userdata string `json:\"userdata\"`")
2057+
case "registerCniConfiguration":
2058+
pn(" CniConfiguration *UserData `json:\"cniconfig\"`")
20372059
case "listObjectStoragePools":
20382060
pn(" Count int `json:\"count\"`")
20392061
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "objectstore")

0 commit comments

Comments
 (0)