SSHService.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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 ResetSSHKeyForVirtualMachineParams struct {
  23. p map[string]interface{}
  24. }
  25. func (p *ResetSSHKeyForVirtualMachineParams) toURLValues() url.Values {
  26. u := url.Values{}
  27. if p.p == nil {
  28. return u
  29. }
  30. if v, found := p.p["account"]; found {
  31. u.Set("account", v.(string))
  32. }
  33. if v, found := p.p["domainid"]; found {
  34. u.Set("domainid", v.(string))
  35. }
  36. if v, found := p.p["id"]; found {
  37. u.Set("id", v.(string))
  38. }
  39. if v, found := p.p["keypair"]; found {
  40. u.Set("keypair", v.(string))
  41. }
  42. if v, found := p.p["projectid"]; found {
  43. u.Set("projectid", v.(string))
  44. }
  45. return u
  46. }
  47. func (p *ResetSSHKeyForVirtualMachineParams) SetAccount(v string) {
  48. if p.p == nil {
  49. p.p = make(map[string]interface{})
  50. }
  51. p.p["account"] = v
  52. return
  53. }
  54. func (p *ResetSSHKeyForVirtualMachineParams) SetDomainid(v string) {
  55. if p.p == nil {
  56. p.p = make(map[string]interface{})
  57. }
  58. p.p["domainid"] = v
  59. return
  60. }
  61. func (p *ResetSSHKeyForVirtualMachineParams) SetId(v string) {
  62. if p.p == nil {
  63. p.p = make(map[string]interface{})
  64. }
  65. p.p["id"] = v
  66. return
  67. }
  68. func (p *ResetSSHKeyForVirtualMachineParams) SetKeypair(v string) {
  69. if p.p == nil {
  70. p.p = make(map[string]interface{})
  71. }
  72. p.p["keypair"] = v
  73. return
  74. }
  75. func (p *ResetSSHKeyForVirtualMachineParams) SetProjectid(v string) {
  76. if p.p == nil {
  77. p.p = make(map[string]interface{})
  78. }
  79. p.p["projectid"] = v
  80. return
  81. }
  82. // You should always use this function to get a new ResetSSHKeyForVirtualMachineParams instance,
  83. // as then you are sure you have configured all required params
  84. func (s *SSHService) NewResetSSHKeyForVirtualMachineParams(id string, keypair string) *ResetSSHKeyForVirtualMachineParams {
  85. p := &ResetSSHKeyForVirtualMachineParams{}
  86. p.p = make(map[string]interface{})
  87. p.p["id"] = id
  88. p.p["keypair"] = keypair
  89. return p
  90. }
  91. // Resets the SSH Key for virtual machine. The virtual machine must be in a "Stopped" state. [async]
  92. func (s *SSHService) ResetSSHKeyForVirtualMachine(p *ResetSSHKeyForVirtualMachineParams) (*ResetSSHKeyForVirtualMachineResponse, error) {
  93. resp, err := s.cs.newRequest("resetSSHKeyForVirtualMachine", p.toURLValues())
  94. if err != nil {
  95. return nil, err
  96. }
  97. var r ResetSSHKeyForVirtualMachineResponse
  98. if err := json.Unmarshal(resp, &r); err != nil {
  99. return nil, err
  100. }
  101. // If we have a async client, we need to wait for the async result
  102. if s.cs.async {
  103. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  104. if err != nil {
  105. if err == AsyncTimeoutErr {
  106. return &r, err
  107. }
  108. return nil, err
  109. }
  110. b, err = getRawValue(b)
  111. if err != nil {
  112. return nil, err
  113. }
  114. if err := json.Unmarshal(b, &r); err != nil {
  115. return nil, err
  116. }
  117. }
  118. return &r, nil
  119. }
  120. type ResetSSHKeyForVirtualMachineResponse struct {
  121. JobID string `json:"jobid,omitempty"`
  122. Account string `json:"account,omitempty"`
  123. Affinitygroup []struct {
  124. Account string `json:"account,omitempty"`
  125. Description string `json:"description,omitempty"`
  126. Domain string `json:"domain,omitempty"`
  127. Domainid string `json:"domainid,omitempty"`
  128. Id string `json:"id,omitempty"`
  129. Name string `json:"name,omitempty"`
  130. Project string `json:"project,omitempty"`
  131. Projectid string `json:"projectid,omitempty"`
  132. Type string `json:"type,omitempty"`
  133. VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
  134. } `json:"affinitygroup,omitempty"`
  135. Cpunumber int `json:"cpunumber,omitempty"`
  136. Cpuspeed int `json:"cpuspeed,omitempty"`
  137. Cpuused string `json:"cpuused,omitempty"`
  138. Created string `json:"created,omitempty"`
  139. Details map[string]string `json:"details,omitempty"`
  140. Diskioread int64 `json:"diskioread,omitempty"`
  141. Diskiowrite int64 `json:"diskiowrite,omitempty"`
  142. Diskkbsread int64 `json:"diskkbsread,omitempty"`
  143. Diskkbswrite int64 `json:"diskkbswrite,omitempty"`
  144. Diskofferingid string `json:"diskofferingid,omitempty"`
  145. Diskofferingname string `json:"diskofferingname,omitempty"`
  146. Displayname string `json:"displayname,omitempty"`
  147. Displayvm bool `json:"displayvm,omitempty"`
  148. Domain string `json:"domain,omitempty"`
  149. Domainid string `json:"domainid,omitempty"`
  150. Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
  151. Group string `json:"group,omitempty"`
  152. Groupid string `json:"groupid,omitempty"`
  153. Guestosid string `json:"guestosid,omitempty"`
  154. Haenable bool `json:"haenable,omitempty"`
  155. Hostid string `json:"hostid,omitempty"`
  156. Hostname string `json:"hostname,omitempty"`
  157. Hypervisor string `json:"hypervisor,omitempty"`
  158. Id string `json:"id,omitempty"`
  159. Instancename string `json:"instancename,omitempty"`
  160. Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
  161. Isodisplaytext string `json:"isodisplaytext,omitempty"`
  162. Isoid string `json:"isoid,omitempty"`
  163. Isoname string `json:"isoname,omitempty"`
  164. Keypair string `json:"keypair,omitempty"`
  165. Memory int `json:"memory,omitempty"`
  166. Name string `json:"name,omitempty"`
  167. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  168. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  169. Nic []struct {
  170. Broadcasturi string `json:"broadcasturi,omitempty"`
  171. Deviceid string `json:"deviceid,omitempty"`
  172. Gateway string `json:"gateway,omitempty"`
  173. Id string `json:"id,omitempty"`
  174. Ip6address string `json:"ip6address,omitempty"`
  175. Ip6cidr string `json:"ip6cidr,omitempty"`
  176. Ip6gateway string `json:"ip6gateway,omitempty"`
  177. Ipaddress string `json:"ipaddress,omitempty"`
  178. Isdefault bool `json:"isdefault,omitempty"`
  179. Isolationuri string `json:"isolationuri,omitempty"`
  180. Macaddress string `json:"macaddress,omitempty"`
  181. Netmask string `json:"netmask,omitempty"`
  182. Networkid string `json:"networkid,omitempty"`
  183. Networkname string `json:"networkname,omitempty"`
  184. Secondaryip []struct {
  185. Id string `json:"id,omitempty"`
  186. Ipaddress string `json:"ipaddress,omitempty"`
  187. } `json:"secondaryip,omitempty"`
  188. Traffictype string `json:"traffictype,omitempty"`
  189. Type string `json:"type,omitempty"`
  190. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  191. } `json:"nic,omitempty"`
  192. Ostypeid int64 `json:"ostypeid,omitempty"`
  193. Password string `json:"password,omitempty"`
  194. Passwordenabled bool `json:"passwordenabled,omitempty"`
  195. Project string `json:"project,omitempty"`
  196. Projectid string `json:"projectid,omitempty"`
  197. Publicip string `json:"publicip,omitempty"`
  198. Publicipid string `json:"publicipid,omitempty"`
  199. Rootdeviceid int64 `json:"rootdeviceid,omitempty"`
  200. Rootdevicetype string `json:"rootdevicetype,omitempty"`
  201. Securitygroup []struct {
  202. Account string `json:"account,omitempty"`
  203. Description string `json:"description,omitempty"`
  204. Domain string `json:"domain,omitempty"`
  205. Domainid string `json:"domainid,omitempty"`
  206. Egressrule []struct {
  207. Account string `json:"account,omitempty"`
  208. Cidr string `json:"cidr,omitempty"`
  209. Endport int `json:"endport,omitempty"`
  210. Icmpcode int `json:"icmpcode,omitempty"`
  211. Icmptype int `json:"icmptype,omitempty"`
  212. Protocol string `json:"protocol,omitempty"`
  213. Ruleid string `json:"ruleid,omitempty"`
  214. Securitygroupname string `json:"securitygroupname,omitempty"`
  215. Startport int `json:"startport,omitempty"`
  216. Tags []struct {
  217. Account string `json:"account,omitempty"`
  218. Customer string `json:"customer,omitempty"`
  219. Domain string `json:"domain,omitempty"`
  220. Domainid string `json:"domainid,omitempty"`
  221. Key string `json:"key,omitempty"`
  222. Project string `json:"project,omitempty"`
  223. Projectid string `json:"projectid,omitempty"`
  224. Resourceid string `json:"resourceid,omitempty"`
  225. Resourcetype string `json:"resourcetype,omitempty"`
  226. Value string `json:"value,omitempty"`
  227. } `json:"tags,omitempty"`
  228. } `json:"egressrule,omitempty"`
  229. Id string `json:"id,omitempty"`
  230. Ingressrule []struct {
  231. Account string `json:"account,omitempty"`
  232. Cidr string `json:"cidr,omitempty"`
  233. Endport int `json:"endport,omitempty"`
  234. Icmpcode int `json:"icmpcode,omitempty"`
  235. Icmptype int `json:"icmptype,omitempty"`
  236. Protocol string `json:"protocol,omitempty"`
  237. Ruleid string `json:"ruleid,omitempty"`
  238. Securitygroupname string `json:"securitygroupname,omitempty"`
  239. Startport int `json:"startport,omitempty"`
  240. Tags []struct {
  241. Account string `json:"account,omitempty"`
  242. Customer string `json:"customer,omitempty"`
  243. Domain string `json:"domain,omitempty"`
  244. Domainid string `json:"domainid,omitempty"`
  245. Key string `json:"key,omitempty"`
  246. Project string `json:"project,omitempty"`
  247. Projectid string `json:"projectid,omitempty"`
  248. Resourceid string `json:"resourceid,omitempty"`
  249. Resourcetype string `json:"resourcetype,omitempty"`
  250. Value string `json:"value,omitempty"`
  251. } `json:"tags,omitempty"`
  252. } `json:"ingressrule,omitempty"`
  253. Name string `json:"name,omitempty"`
  254. Project string `json:"project,omitempty"`
  255. Projectid string `json:"projectid,omitempty"`
  256. Tags []struct {
  257. Account string `json:"account,omitempty"`
  258. Customer string `json:"customer,omitempty"`
  259. Domain string `json:"domain,omitempty"`
  260. Domainid string `json:"domainid,omitempty"`
  261. Key string `json:"key,omitempty"`
  262. Project string `json:"project,omitempty"`
  263. Projectid string `json:"projectid,omitempty"`
  264. Resourceid string `json:"resourceid,omitempty"`
  265. Resourcetype string `json:"resourcetype,omitempty"`
  266. Value string `json:"value,omitempty"`
  267. } `json:"tags,omitempty"`
  268. Virtualmachinecount int `json:"virtualmachinecount,omitempty"`
  269. Virtualmachineids []string `json:"virtualmachineids,omitempty"`
  270. } `json:"securitygroup,omitempty"`
  271. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  272. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  273. Servicestate string `json:"servicestate,omitempty"`
  274. State string `json:"state,omitempty"`
  275. Tags []struct {
  276. Account string `json:"account,omitempty"`
  277. Customer string `json:"customer,omitempty"`
  278. Domain string `json:"domain,omitempty"`
  279. Domainid string `json:"domainid,omitempty"`
  280. Key string `json:"key,omitempty"`
  281. Project string `json:"project,omitempty"`
  282. Projectid string `json:"projectid,omitempty"`
  283. Resourceid string `json:"resourceid,omitempty"`
  284. Resourcetype string `json:"resourcetype,omitempty"`
  285. Value string `json:"value,omitempty"`
  286. } `json:"tags,omitempty"`
  287. Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
  288. Templateid string `json:"templateid,omitempty"`
  289. Templatename string `json:"templatename,omitempty"`
  290. Userid string `json:"userid,omitempty"`
  291. Username string `json:"username,omitempty"`
  292. Vgpu string `json:"vgpu,omitempty"`
  293. Zoneid string `json:"zoneid,omitempty"`
  294. Zonename string `json:"zonename,omitempty"`
  295. }
  296. type RegisterSSHKeyPairParams struct {
  297. p map[string]interface{}
  298. }
  299. func (p *RegisterSSHKeyPairParams) toURLValues() url.Values {
  300. u := url.Values{}
  301. if p.p == nil {
  302. return u
  303. }
  304. if v, found := p.p["account"]; found {
  305. u.Set("account", v.(string))
  306. }
  307. if v, found := p.p["domainid"]; found {
  308. u.Set("domainid", v.(string))
  309. }
  310. if v, found := p.p["name"]; found {
  311. u.Set("name", v.(string))
  312. }
  313. if v, found := p.p["projectid"]; found {
  314. u.Set("projectid", v.(string))
  315. }
  316. if v, found := p.p["publickey"]; found {
  317. u.Set("publickey", v.(string))
  318. }
  319. return u
  320. }
  321. func (p *RegisterSSHKeyPairParams) SetAccount(v string) {
  322. if p.p == nil {
  323. p.p = make(map[string]interface{})
  324. }
  325. p.p["account"] = v
  326. return
  327. }
  328. func (p *RegisterSSHKeyPairParams) SetDomainid(v string) {
  329. if p.p == nil {
  330. p.p = make(map[string]interface{})
  331. }
  332. p.p["domainid"] = v
  333. return
  334. }
  335. func (p *RegisterSSHKeyPairParams) SetName(v string) {
  336. if p.p == nil {
  337. p.p = make(map[string]interface{})
  338. }
  339. p.p["name"] = v
  340. return
  341. }
  342. func (p *RegisterSSHKeyPairParams) SetProjectid(v string) {
  343. if p.p == nil {
  344. p.p = make(map[string]interface{})
  345. }
  346. p.p["projectid"] = v
  347. return
  348. }
  349. func (p *RegisterSSHKeyPairParams) SetPublickey(v string) {
  350. if p.p == nil {
  351. p.p = make(map[string]interface{})
  352. }
  353. p.p["publickey"] = v
  354. return
  355. }
  356. // You should always use this function to get a new RegisterSSHKeyPairParams instance,
  357. // as then you are sure you have configured all required params
  358. func (s *SSHService) NewRegisterSSHKeyPairParams(name string, publickey string) *RegisterSSHKeyPairParams {
  359. p := &RegisterSSHKeyPairParams{}
  360. p.p = make(map[string]interface{})
  361. p.p["name"] = name
  362. p.p["publickey"] = publickey
  363. return p
  364. }
  365. // Register a public key in a keypair under a certain name
  366. func (s *SSHService) RegisterSSHKeyPair(p *RegisterSSHKeyPairParams) (*RegisterSSHKeyPairResponse, error) {
  367. resp, err := s.cs.newRequest("registerSSHKeyPair", p.toURLValues())
  368. if err != nil {
  369. return nil, err
  370. }
  371. if resp, err = getRawValue(resp); err != nil {
  372. return nil, err
  373. }
  374. var r RegisterSSHKeyPairResponse
  375. if err := json.Unmarshal(resp, &r); err != nil {
  376. return nil, err
  377. }
  378. return &r, nil
  379. }
  380. type RegisterSSHKeyPairResponse struct {
  381. Account string `json:"account,omitempty"`
  382. Domain string `json:"domain,omitempty"`
  383. Domainid string `json:"domainid,omitempty"`
  384. Fingerprint string `json:"fingerprint,omitempty"`
  385. Name string `json:"name,omitempty"`
  386. }
  387. type CreateSSHKeyPairParams struct {
  388. p map[string]interface{}
  389. }
  390. func (p *CreateSSHKeyPairParams) toURLValues() url.Values {
  391. u := url.Values{}
  392. if p.p == nil {
  393. return u
  394. }
  395. if v, found := p.p["account"]; found {
  396. u.Set("account", v.(string))
  397. }
  398. if v, found := p.p["domainid"]; found {
  399. u.Set("domainid", v.(string))
  400. }
  401. if v, found := p.p["name"]; found {
  402. u.Set("name", v.(string))
  403. }
  404. if v, found := p.p["projectid"]; found {
  405. u.Set("projectid", v.(string))
  406. }
  407. return u
  408. }
  409. func (p *CreateSSHKeyPairParams) SetAccount(v string) {
  410. if p.p == nil {
  411. p.p = make(map[string]interface{})
  412. }
  413. p.p["account"] = v
  414. return
  415. }
  416. func (p *CreateSSHKeyPairParams) SetDomainid(v string) {
  417. if p.p == nil {
  418. p.p = make(map[string]interface{})
  419. }
  420. p.p["domainid"] = v
  421. return
  422. }
  423. func (p *CreateSSHKeyPairParams) SetName(v string) {
  424. if p.p == nil {
  425. p.p = make(map[string]interface{})
  426. }
  427. p.p["name"] = v
  428. return
  429. }
  430. func (p *CreateSSHKeyPairParams) SetProjectid(v string) {
  431. if p.p == nil {
  432. p.p = make(map[string]interface{})
  433. }
  434. p.p["projectid"] = v
  435. return
  436. }
  437. // You should always use this function to get a new CreateSSHKeyPairParams instance,
  438. // as then you are sure you have configured all required params
  439. func (s *SSHService) NewCreateSSHKeyPairParams(name string) *CreateSSHKeyPairParams {
  440. p := &CreateSSHKeyPairParams{}
  441. p.p = make(map[string]interface{})
  442. p.p["name"] = name
  443. return p
  444. }
  445. // Create a new keypair and returns the private key
  446. func (s *SSHService) CreateSSHKeyPair(p *CreateSSHKeyPairParams) (*CreateSSHKeyPairResponse, error) {
  447. resp, err := s.cs.newRequest("createSSHKeyPair", p.toURLValues())
  448. if err != nil {
  449. return nil, err
  450. }
  451. if resp, err = getRawValue(resp); err != nil {
  452. return nil, err
  453. }
  454. var r CreateSSHKeyPairResponse
  455. if err := json.Unmarshal(resp, &r); err != nil {
  456. return nil, err
  457. }
  458. return &r, nil
  459. }
  460. type CreateSSHKeyPairResponse struct {
  461. Privatekey string `json:"privatekey,omitempty"`
  462. }
  463. type DeleteSSHKeyPairParams struct {
  464. p map[string]interface{}
  465. }
  466. func (p *DeleteSSHKeyPairParams) toURLValues() url.Values {
  467. u := url.Values{}
  468. if p.p == nil {
  469. return u
  470. }
  471. if v, found := p.p["account"]; found {
  472. u.Set("account", v.(string))
  473. }
  474. if v, found := p.p["domainid"]; found {
  475. u.Set("domainid", v.(string))
  476. }
  477. if v, found := p.p["name"]; found {
  478. u.Set("name", v.(string))
  479. }
  480. if v, found := p.p["projectid"]; found {
  481. u.Set("projectid", v.(string))
  482. }
  483. return u
  484. }
  485. func (p *DeleteSSHKeyPairParams) SetAccount(v string) {
  486. if p.p == nil {
  487. p.p = make(map[string]interface{})
  488. }
  489. p.p["account"] = v
  490. return
  491. }
  492. func (p *DeleteSSHKeyPairParams) SetDomainid(v string) {
  493. if p.p == nil {
  494. p.p = make(map[string]interface{})
  495. }
  496. p.p["domainid"] = v
  497. return
  498. }
  499. func (p *DeleteSSHKeyPairParams) SetName(v string) {
  500. if p.p == nil {
  501. p.p = make(map[string]interface{})
  502. }
  503. p.p["name"] = v
  504. return
  505. }
  506. func (p *DeleteSSHKeyPairParams) SetProjectid(v string) {
  507. if p.p == nil {
  508. p.p = make(map[string]interface{})
  509. }
  510. p.p["projectid"] = v
  511. return
  512. }
  513. // You should always use this function to get a new DeleteSSHKeyPairParams instance,
  514. // as then you are sure you have configured all required params
  515. func (s *SSHService) NewDeleteSSHKeyPairParams(name string) *DeleteSSHKeyPairParams {
  516. p := &DeleteSSHKeyPairParams{}
  517. p.p = make(map[string]interface{})
  518. p.p["name"] = name
  519. return p
  520. }
  521. // Deletes a keypair by name
  522. func (s *SSHService) DeleteSSHKeyPair(p *DeleteSSHKeyPairParams) (*DeleteSSHKeyPairResponse, error) {
  523. resp, err := s.cs.newRequest("deleteSSHKeyPair", p.toURLValues())
  524. if err != nil {
  525. return nil, err
  526. }
  527. var r DeleteSSHKeyPairResponse
  528. if err := json.Unmarshal(resp, &r); err != nil {
  529. return nil, err
  530. }
  531. return &r, nil
  532. }
  533. type DeleteSSHKeyPairResponse struct {
  534. Displaytext string `json:"displaytext,omitempty"`
  535. Success string `json:"success,omitempty"`
  536. }
  537. type ListSSHKeyPairsParams struct {
  538. p map[string]interface{}
  539. }
  540. func (p *ListSSHKeyPairsParams) toURLValues() url.Values {
  541. u := url.Values{}
  542. if p.p == nil {
  543. return u
  544. }
  545. if v, found := p.p["account"]; found {
  546. u.Set("account", v.(string))
  547. }
  548. if v, found := p.p["domainid"]; found {
  549. u.Set("domainid", v.(string))
  550. }
  551. if v, found := p.p["fingerprint"]; found {
  552. u.Set("fingerprint", v.(string))
  553. }
  554. if v, found := p.p["isrecursive"]; found {
  555. vv := strconv.FormatBool(v.(bool))
  556. u.Set("isrecursive", vv)
  557. }
  558. if v, found := p.p["keyword"]; found {
  559. u.Set("keyword", v.(string))
  560. }
  561. if v, found := p.p["listall"]; found {
  562. vv := strconv.FormatBool(v.(bool))
  563. u.Set("listall", vv)
  564. }
  565. if v, found := p.p["name"]; found {
  566. u.Set("name", v.(string))
  567. }
  568. if v, found := p.p["page"]; found {
  569. vv := strconv.Itoa(v.(int))
  570. u.Set("page", vv)
  571. }
  572. if v, found := p.p["pagesize"]; found {
  573. vv := strconv.Itoa(v.(int))
  574. u.Set("pagesize", vv)
  575. }
  576. if v, found := p.p["projectid"]; found {
  577. u.Set("projectid", v.(string))
  578. }
  579. return u
  580. }
  581. func (p *ListSSHKeyPairsParams) SetAccount(v string) {
  582. if p.p == nil {
  583. p.p = make(map[string]interface{})
  584. }
  585. p.p["account"] = v
  586. return
  587. }
  588. func (p *ListSSHKeyPairsParams) SetDomainid(v string) {
  589. if p.p == nil {
  590. p.p = make(map[string]interface{})
  591. }
  592. p.p["domainid"] = v
  593. return
  594. }
  595. func (p *ListSSHKeyPairsParams) SetFingerprint(v string) {
  596. if p.p == nil {
  597. p.p = make(map[string]interface{})
  598. }
  599. p.p["fingerprint"] = v
  600. return
  601. }
  602. func (p *ListSSHKeyPairsParams) SetIsrecursive(v bool) {
  603. if p.p == nil {
  604. p.p = make(map[string]interface{})
  605. }
  606. p.p["isrecursive"] = v
  607. return
  608. }
  609. func (p *ListSSHKeyPairsParams) SetKeyword(v string) {
  610. if p.p == nil {
  611. p.p = make(map[string]interface{})
  612. }
  613. p.p["keyword"] = v
  614. return
  615. }
  616. func (p *ListSSHKeyPairsParams) SetListall(v bool) {
  617. if p.p == nil {
  618. p.p = make(map[string]interface{})
  619. }
  620. p.p["listall"] = v
  621. return
  622. }
  623. func (p *ListSSHKeyPairsParams) SetName(v string) {
  624. if p.p == nil {
  625. p.p = make(map[string]interface{})
  626. }
  627. p.p["name"] = v
  628. return
  629. }
  630. func (p *ListSSHKeyPairsParams) SetPage(v int) {
  631. if p.p == nil {
  632. p.p = make(map[string]interface{})
  633. }
  634. p.p["page"] = v
  635. return
  636. }
  637. func (p *ListSSHKeyPairsParams) SetPagesize(v int) {
  638. if p.p == nil {
  639. p.p = make(map[string]interface{})
  640. }
  641. p.p["pagesize"] = v
  642. return
  643. }
  644. func (p *ListSSHKeyPairsParams) SetProjectid(v string) {
  645. if p.p == nil {
  646. p.p = make(map[string]interface{})
  647. }
  648. p.p["projectid"] = v
  649. return
  650. }
  651. // You should always use this function to get a new ListSSHKeyPairsParams instance,
  652. // as then you are sure you have configured all required params
  653. func (s *SSHService) NewListSSHKeyPairsParams() *ListSSHKeyPairsParams {
  654. p := &ListSSHKeyPairsParams{}
  655. p.p = make(map[string]interface{})
  656. return p
  657. }
  658. // List registered keypairs
  659. func (s *SSHService) ListSSHKeyPairs(p *ListSSHKeyPairsParams) (*ListSSHKeyPairsResponse, error) {
  660. resp, err := s.cs.newRequest("listSSHKeyPairs", p.toURLValues())
  661. if err != nil {
  662. return nil, err
  663. }
  664. var r ListSSHKeyPairsResponse
  665. if err := json.Unmarshal(resp, &r); err != nil {
  666. return nil, err
  667. }
  668. return &r, nil
  669. }
  670. type ListSSHKeyPairsResponse struct {
  671. Count int `json:"count"`
  672. SSHKeyPairs []*SSHKeyPair `json:"sshkeypair"`
  673. }
  674. type SSHKeyPair struct {
  675. Account string `json:"account,omitempty"`
  676. Domain string `json:"domain,omitempty"`
  677. Domainid string `json:"domainid,omitempty"`
  678. Fingerprint string `json:"fingerprint,omitempty"`
  679. Name string `json:"name,omitempty"`
  680. }