ConfigurationService.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. //
  2. // Copyright 2016, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package cloudstack
  17. import (
  18. "encoding/json"
  19. "net/url"
  20. "strconv"
  21. )
  22. type UpdateConfigurationParams struct {
  23. p map[string]interface{}
  24. }
  25. func (p *UpdateConfigurationParams) toURLValues() url.Values {
  26. u := url.Values{}
  27. if p.p == nil {
  28. return u
  29. }
  30. if v, found := p.p["accountid"]; found {
  31. u.Set("accountid", v.(string))
  32. }
  33. if v, found := p.p["clusterid"]; found {
  34. u.Set("clusterid", v.(string))
  35. }
  36. if v, found := p.p["name"]; found {
  37. u.Set("name", v.(string))
  38. }
  39. if v, found := p.p["storageid"]; found {
  40. u.Set("storageid", v.(string))
  41. }
  42. if v, found := p.p["value"]; found {
  43. u.Set("value", v.(string))
  44. }
  45. if v, found := p.p["zoneid"]; found {
  46. u.Set("zoneid", v.(string))
  47. }
  48. return u
  49. }
  50. func (p *UpdateConfigurationParams) SetAccountid(v string) {
  51. if p.p == nil {
  52. p.p = make(map[string]interface{})
  53. }
  54. p.p["accountid"] = v
  55. return
  56. }
  57. func (p *UpdateConfigurationParams) SetClusterid(v string) {
  58. if p.p == nil {
  59. p.p = make(map[string]interface{})
  60. }
  61. p.p["clusterid"] = v
  62. return
  63. }
  64. func (p *UpdateConfigurationParams) SetName(v string) {
  65. if p.p == nil {
  66. p.p = make(map[string]interface{})
  67. }
  68. p.p["name"] = v
  69. return
  70. }
  71. func (p *UpdateConfigurationParams) SetStorageid(v string) {
  72. if p.p == nil {
  73. p.p = make(map[string]interface{})
  74. }
  75. p.p["storageid"] = v
  76. return
  77. }
  78. func (p *UpdateConfigurationParams) SetValue(v string) {
  79. if p.p == nil {
  80. p.p = make(map[string]interface{})
  81. }
  82. p.p["value"] = v
  83. return
  84. }
  85. func (p *UpdateConfigurationParams) SetZoneid(v string) {
  86. if p.p == nil {
  87. p.p = make(map[string]interface{})
  88. }
  89. p.p["zoneid"] = v
  90. return
  91. }
  92. // You should always use this function to get a new UpdateConfigurationParams instance,
  93. // as then you are sure you have configured all required params
  94. func (s *ConfigurationService) NewUpdateConfigurationParams(name string) *UpdateConfigurationParams {
  95. p := &UpdateConfigurationParams{}
  96. p.p = make(map[string]interface{})
  97. p.p["name"] = name
  98. return p
  99. }
  100. // Updates a configuration.
  101. func (s *ConfigurationService) UpdateConfiguration(p *UpdateConfigurationParams) (*UpdateConfigurationResponse, error) {
  102. resp, err := s.cs.newRequest("updateConfiguration", p.toURLValues())
  103. if err != nil {
  104. return nil, err
  105. }
  106. var r UpdateConfigurationResponse
  107. if err := json.Unmarshal(resp, &r); err != nil {
  108. return nil, err
  109. }
  110. return &r, nil
  111. }
  112. type UpdateConfigurationResponse struct {
  113. Category string `json:"category,omitempty"`
  114. Description string `json:"description,omitempty"`
  115. Id int64 `json:"id,omitempty"`
  116. Name string `json:"name,omitempty"`
  117. Scope string `json:"scope,omitempty"`
  118. Value string `json:"value,omitempty"`
  119. }
  120. type ListConfigurationsParams struct {
  121. p map[string]interface{}
  122. }
  123. func (p *ListConfigurationsParams) toURLValues() url.Values {
  124. u := url.Values{}
  125. if p.p == nil {
  126. return u
  127. }
  128. if v, found := p.p["accountid"]; found {
  129. u.Set("accountid", v.(string))
  130. }
  131. if v, found := p.p["category"]; found {
  132. u.Set("category", v.(string))
  133. }
  134. if v, found := p.p["clusterid"]; found {
  135. u.Set("clusterid", v.(string))
  136. }
  137. if v, found := p.p["keyword"]; found {
  138. u.Set("keyword", v.(string))
  139. }
  140. if v, found := p.p["name"]; found {
  141. u.Set("name", v.(string))
  142. }
  143. if v, found := p.p["page"]; found {
  144. vv := strconv.Itoa(v.(int))
  145. u.Set("page", vv)
  146. }
  147. if v, found := p.p["pagesize"]; found {
  148. vv := strconv.Itoa(v.(int))
  149. u.Set("pagesize", vv)
  150. }
  151. if v, found := p.p["storageid"]; found {
  152. u.Set("storageid", v.(string))
  153. }
  154. if v, found := p.p["zoneid"]; found {
  155. u.Set("zoneid", v.(string))
  156. }
  157. return u
  158. }
  159. func (p *ListConfigurationsParams) SetAccountid(v string) {
  160. if p.p == nil {
  161. p.p = make(map[string]interface{})
  162. }
  163. p.p["accountid"] = v
  164. return
  165. }
  166. func (p *ListConfigurationsParams) SetCategory(v string) {
  167. if p.p == nil {
  168. p.p = make(map[string]interface{})
  169. }
  170. p.p["category"] = v
  171. return
  172. }
  173. func (p *ListConfigurationsParams) SetClusterid(v string) {
  174. if p.p == nil {
  175. p.p = make(map[string]interface{})
  176. }
  177. p.p["clusterid"] = v
  178. return
  179. }
  180. func (p *ListConfigurationsParams) SetKeyword(v string) {
  181. if p.p == nil {
  182. p.p = make(map[string]interface{})
  183. }
  184. p.p["keyword"] = v
  185. return
  186. }
  187. func (p *ListConfigurationsParams) SetName(v string) {
  188. if p.p == nil {
  189. p.p = make(map[string]interface{})
  190. }
  191. p.p["name"] = v
  192. return
  193. }
  194. func (p *ListConfigurationsParams) SetPage(v int) {
  195. if p.p == nil {
  196. p.p = make(map[string]interface{})
  197. }
  198. p.p["page"] = v
  199. return
  200. }
  201. func (p *ListConfigurationsParams) SetPagesize(v int) {
  202. if p.p == nil {
  203. p.p = make(map[string]interface{})
  204. }
  205. p.p["pagesize"] = v
  206. return
  207. }
  208. func (p *ListConfigurationsParams) SetStorageid(v string) {
  209. if p.p == nil {
  210. p.p = make(map[string]interface{})
  211. }
  212. p.p["storageid"] = v
  213. return
  214. }
  215. func (p *ListConfigurationsParams) SetZoneid(v string) {
  216. if p.p == nil {
  217. p.p = make(map[string]interface{})
  218. }
  219. p.p["zoneid"] = v
  220. return
  221. }
  222. // You should always use this function to get a new ListConfigurationsParams instance,
  223. // as then you are sure you have configured all required params
  224. func (s *ConfigurationService) NewListConfigurationsParams() *ListConfigurationsParams {
  225. p := &ListConfigurationsParams{}
  226. p.p = make(map[string]interface{})
  227. return p
  228. }
  229. // Lists all configurations.
  230. func (s *ConfigurationService) ListConfigurations(p *ListConfigurationsParams) (*ListConfigurationsResponse, error) {
  231. resp, err := s.cs.newRequest("listConfigurations", p.toURLValues())
  232. if err != nil {
  233. return nil, err
  234. }
  235. var r ListConfigurationsResponse
  236. if err := json.Unmarshal(resp, &r); err != nil {
  237. return nil, err
  238. }
  239. return &r, nil
  240. }
  241. type ListConfigurationsResponse struct {
  242. Count int `json:"count"`
  243. Configurations []*Configuration `json:"configuration"`
  244. }
  245. type Configuration struct {
  246. Category string `json:"category,omitempty"`
  247. Description string `json:"description,omitempty"`
  248. Id int64 `json:"id,omitempty"`
  249. Name string `json:"name,omitempty"`
  250. Scope string `json:"scope,omitempty"`
  251. Value string `json:"value,omitempty"`
  252. }
  253. type ListCapabilitiesParams struct {
  254. p map[string]interface{}
  255. }
  256. func (p *ListCapabilitiesParams) toURLValues() url.Values {
  257. u := url.Values{}
  258. if p.p == nil {
  259. return u
  260. }
  261. return u
  262. }
  263. // You should always use this function to get a new ListCapabilitiesParams instance,
  264. // as then you are sure you have configured all required params
  265. func (s *ConfigurationService) NewListCapabilitiesParams() *ListCapabilitiesParams {
  266. p := &ListCapabilitiesParams{}
  267. p.p = make(map[string]interface{})
  268. return p
  269. }
  270. // Lists capabilities
  271. func (s *ConfigurationService) ListCapabilities(p *ListCapabilitiesParams) (*ListCapabilitiesResponse, error) {
  272. resp, err := s.cs.newRequest("listCapabilities", p.toURLValues())
  273. if err != nil {
  274. return nil, err
  275. }
  276. var r ListCapabilitiesResponse
  277. if err := json.Unmarshal(resp, &r); err != nil {
  278. return nil, err
  279. }
  280. return &r, nil
  281. }
  282. type ListCapabilitiesResponse struct {
  283. Count int `json:"count"`
  284. Capabilities []*Capability `json:"capability"`
  285. }
  286. type Capability struct {
  287. Allowusercreateprojects bool `json:"allowusercreateprojects,omitempty"`
  288. Allowuserexpungerecovervm bool `json:"allowuserexpungerecovervm,omitempty"`
  289. Allowuserviewdestroyedvm bool `json:"allowuserviewdestroyedvm,omitempty"`
  290. Apilimitinterval int `json:"apilimitinterval,omitempty"`
  291. Apilimitmax int `json:"apilimitmax,omitempty"`
  292. Cloudstackversion string `json:"cloudstackversion,omitempty"`
  293. Customdiskofferingmaxsize int64 `json:"customdiskofferingmaxsize,omitempty"`
  294. Customdiskofferingminsize int64 `json:"customdiskofferingminsize,omitempty"`
  295. Kvmsnapshotenabled bool `json:"kvmsnapshotenabled,omitempty"`
  296. Projectinviterequired bool `json:"projectinviterequired,omitempty"`
  297. Regionsecondaryenabled bool `json:"regionsecondaryenabled,omitempty"`
  298. Securitygroupsenabled bool `json:"securitygroupsenabled,omitempty"`
  299. SupportELB string `json:"supportELB,omitempty"`
  300. Userpublictemplateenabled bool `json:"userpublictemplateenabled,omitempty"`
  301. }
  302. type ListDeploymentPlannersParams struct {
  303. p map[string]interface{}
  304. }
  305. func (p *ListDeploymentPlannersParams) toURLValues() url.Values {
  306. u := url.Values{}
  307. if p.p == nil {
  308. return u
  309. }
  310. if v, found := p.p["keyword"]; found {
  311. u.Set("keyword", v.(string))
  312. }
  313. if v, found := p.p["page"]; found {
  314. vv := strconv.Itoa(v.(int))
  315. u.Set("page", vv)
  316. }
  317. if v, found := p.p["pagesize"]; found {
  318. vv := strconv.Itoa(v.(int))
  319. u.Set("pagesize", vv)
  320. }
  321. return u
  322. }
  323. func (p *ListDeploymentPlannersParams) SetKeyword(v string) {
  324. if p.p == nil {
  325. p.p = make(map[string]interface{})
  326. }
  327. p.p["keyword"] = v
  328. return
  329. }
  330. func (p *ListDeploymentPlannersParams) SetPage(v int) {
  331. if p.p == nil {
  332. p.p = make(map[string]interface{})
  333. }
  334. p.p["page"] = v
  335. return
  336. }
  337. func (p *ListDeploymentPlannersParams) SetPagesize(v int) {
  338. if p.p == nil {
  339. p.p = make(map[string]interface{})
  340. }
  341. p.p["pagesize"] = v
  342. return
  343. }
  344. // You should always use this function to get a new ListDeploymentPlannersParams instance,
  345. // as then you are sure you have configured all required params
  346. func (s *ConfigurationService) NewListDeploymentPlannersParams() *ListDeploymentPlannersParams {
  347. p := &ListDeploymentPlannersParams{}
  348. p.p = make(map[string]interface{})
  349. return p
  350. }
  351. // Lists all DeploymentPlanners available.
  352. func (s *ConfigurationService) ListDeploymentPlanners(p *ListDeploymentPlannersParams) (*ListDeploymentPlannersResponse, error) {
  353. resp, err := s.cs.newRequest("listDeploymentPlanners", p.toURLValues())
  354. if err != nil {
  355. return nil, err
  356. }
  357. var r ListDeploymentPlannersResponse
  358. if err := json.Unmarshal(resp, &r); err != nil {
  359. return nil, err
  360. }
  361. return &r, nil
  362. }
  363. type ListDeploymentPlannersResponse struct {
  364. Count int `json:"count"`
  365. DeploymentPlanners []*DeploymentPlanner `json:"deploymentplanner"`
  366. }
  367. type DeploymentPlanner struct {
  368. Name string `json:"name,omitempty"`
  369. }
  370. type ListLdapConfigurationsParams struct {
  371. p map[string]interface{}
  372. }
  373. func (p *ListLdapConfigurationsParams) toURLValues() url.Values {
  374. u := url.Values{}
  375. if p.p == nil {
  376. return u
  377. }
  378. if v, found := p.p["hostname"]; found {
  379. u.Set("hostname", v.(string))
  380. }
  381. if v, found := p.p["keyword"]; found {
  382. u.Set("keyword", v.(string))
  383. }
  384. if v, found := p.p["page"]; found {
  385. vv := strconv.Itoa(v.(int))
  386. u.Set("page", vv)
  387. }
  388. if v, found := p.p["pagesize"]; found {
  389. vv := strconv.Itoa(v.(int))
  390. u.Set("pagesize", vv)
  391. }
  392. if v, found := p.p["port"]; found {
  393. vv := strconv.Itoa(v.(int))
  394. u.Set("port", vv)
  395. }
  396. return u
  397. }
  398. func (p *ListLdapConfigurationsParams) SetHostname(v string) {
  399. if p.p == nil {
  400. p.p = make(map[string]interface{})
  401. }
  402. p.p["hostname"] = v
  403. return
  404. }
  405. func (p *ListLdapConfigurationsParams) SetKeyword(v string) {
  406. if p.p == nil {
  407. p.p = make(map[string]interface{})
  408. }
  409. p.p["keyword"] = v
  410. return
  411. }
  412. func (p *ListLdapConfigurationsParams) SetPage(v int) {
  413. if p.p == nil {
  414. p.p = make(map[string]interface{})
  415. }
  416. p.p["page"] = v
  417. return
  418. }
  419. func (p *ListLdapConfigurationsParams) SetPagesize(v int) {
  420. if p.p == nil {
  421. p.p = make(map[string]interface{})
  422. }
  423. p.p["pagesize"] = v
  424. return
  425. }
  426. func (p *ListLdapConfigurationsParams) SetPort(v int) {
  427. if p.p == nil {
  428. p.p = make(map[string]interface{})
  429. }
  430. p.p["port"] = v
  431. return
  432. }
  433. // You should always use this function to get a new ListLdapConfigurationsParams instance,
  434. // as then you are sure you have configured all required params
  435. func (s *ConfigurationService) NewListLdapConfigurationsParams() *ListLdapConfigurationsParams {
  436. p := &ListLdapConfigurationsParams{}
  437. p.p = make(map[string]interface{})
  438. return p
  439. }
  440. // Lists all LDAP configurations
  441. func (s *ConfigurationService) ListLdapConfigurations(p *ListLdapConfigurationsParams) (*ListLdapConfigurationsResponse, error) {
  442. resp, err := s.cs.newRequest("listLdapConfigurations", p.toURLValues())
  443. if err != nil {
  444. return nil, err
  445. }
  446. var r ListLdapConfigurationsResponse
  447. if err := json.Unmarshal(resp, &r); err != nil {
  448. return nil, err
  449. }
  450. return &r, nil
  451. }
  452. type ListLdapConfigurationsResponse struct {
  453. Count int `json:"count"`
  454. LdapConfigurations []*LdapConfiguration `json:"ldapconfiguration"`
  455. }
  456. type LdapConfiguration struct {
  457. Hostname string `json:"hostname,omitempty"`
  458. Port int `json:"port,omitempty"`
  459. }
  460. type AddLdapConfigurationParams struct {
  461. p map[string]interface{}
  462. }
  463. func (p *AddLdapConfigurationParams) toURLValues() url.Values {
  464. u := url.Values{}
  465. if p.p == nil {
  466. return u
  467. }
  468. if v, found := p.p["hostname"]; found {
  469. u.Set("hostname", v.(string))
  470. }
  471. if v, found := p.p["port"]; found {
  472. vv := strconv.Itoa(v.(int))
  473. u.Set("port", vv)
  474. }
  475. return u
  476. }
  477. func (p *AddLdapConfigurationParams) SetHostname(v string) {
  478. if p.p == nil {
  479. p.p = make(map[string]interface{})
  480. }
  481. p.p["hostname"] = v
  482. return
  483. }
  484. func (p *AddLdapConfigurationParams) SetPort(v int) {
  485. if p.p == nil {
  486. p.p = make(map[string]interface{})
  487. }
  488. p.p["port"] = v
  489. return
  490. }
  491. // You should always use this function to get a new AddLdapConfigurationParams instance,
  492. // as then you are sure you have configured all required params
  493. func (s *ConfigurationService) NewAddLdapConfigurationParams(hostname string, port int) *AddLdapConfigurationParams {
  494. p := &AddLdapConfigurationParams{}
  495. p.p = make(map[string]interface{})
  496. p.p["hostname"] = hostname
  497. p.p["port"] = port
  498. return p
  499. }
  500. // Add a new Ldap Configuration
  501. func (s *ConfigurationService) AddLdapConfiguration(p *AddLdapConfigurationParams) (*AddLdapConfigurationResponse, error) {
  502. resp, err := s.cs.newRequest("addLdapConfiguration", p.toURLValues())
  503. if err != nil {
  504. return nil, err
  505. }
  506. var r AddLdapConfigurationResponse
  507. if err := json.Unmarshal(resp, &r); err != nil {
  508. return nil, err
  509. }
  510. return &r, nil
  511. }
  512. type AddLdapConfigurationResponse struct {
  513. Hostname string `json:"hostname,omitempty"`
  514. Port int `json:"port,omitempty"`
  515. }
  516. type DeleteLdapConfigurationParams struct {
  517. p map[string]interface{}
  518. }
  519. func (p *DeleteLdapConfigurationParams) toURLValues() url.Values {
  520. u := url.Values{}
  521. if p.p == nil {
  522. return u
  523. }
  524. if v, found := p.p["hostname"]; found {
  525. u.Set("hostname", v.(string))
  526. }
  527. return u
  528. }
  529. func (p *DeleteLdapConfigurationParams) SetHostname(v string) {
  530. if p.p == nil {
  531. p.p = make(map[string]interface{})
  532. }
  533. p.p["hostname"] = v
  534. return
  535. }
  536. // You should always use this function to get a new DeleteLdapConfigurationParams instance,
  537. // as then you are sure you have configured all required params
  538. func (s *ConfigurationService) NewDeleteLdapConfigurationParams(hostname string) *DeleteLdapConfigurationParams {
  539. p := &DeleteLdapConfigurationParams{}
  540. p.p = make(map[string]interface{})
  541. p.p["hostname"] = hostname
  542. return p
  543. }
  544. // Remove an Ldap Configuration
  545. func (s *ConfigurationService) DeleteLdapConfiguration(p *DeleteLdapConfigurationParams) (*DeleteLdapConfigurationResponse, error) {
  546. resp, err := s.cs.newRequest("deleteLdapConfiguration", p.toURLValues())
  547. if err != nil {
  548. return nil, err
  549. }
  550. var r DeleteLdapConfigurationResponse
  551. if err := json.Unmarshal(resp, &r); err != nil {
  552. return nil, err
  553. }
  554. return &r, nil
  555. }
  556. type DeleteLdapConfigurationResponse struct {
  557. Hostname string `json:"hostname,omitempty"`
  558. Port int `json:"port,omitempty"`
  559. }