elasticcache.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/cmd/climc/shell"
  18. "yunion.io/x/onecloud/pkg/mcclient"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. "yunion.io/x/onecloud/pkg/mcclient/options/compute"
  22. )
  23. func init() {
  24. cmd := shell.NewResourceCmd(&modules.ElasticCache).WithKeyword("elastic-cache")
  25. cmd.List(&compute.ElasticCacheListOptions{})
  26. cmd.Show(&compute.ElasticCacheIdOption{})
  27. cmd.Create(&compute.ElasticCacheCreateOptions{})
  28. cmd.Delete(&compute.ElasticCacheIdOption{})
  29. cmd.Perform("restart", &compute.ElasticCacheIdOption{})
  30. cmd.Perform("flush-instance", &compute.ElasticCacheIdOption{})
  31. cmd.Perform("syncstatus", &compute.ElasticCacheIdOption{})
  32. cmd.Perform("sync", &compute.ElasticCacheIdOption{})
  33. cmd.Perform("change-spec", &compute.ElasticCacheChangeSpecOptions{})
  34. cmd.Perform("set-maintenance-time", &compute.ElasticCacheMainteananceTimeOptions{})
  35. cmd.Perform("allocate-public-connection", &compute.ElasticCacheIdOption{})
  36. cmd.PerformWithKeyword("enable-auth", "update-auth-mode", &compute.ElasticCacheEnableAuthOptions{})
  37. cmd.PerformWithKeyword("disable-auth", "update-auth-mode", &compute.ElasticCacheDisableAuthOptions{})
  38. type ElasticCacheAccountResetPasswordOptions struct {
  39. compute.ElasticCacheIdOptions
  40. PASSWORD string `help:"elastic cache account password."`
  41. }
  42. R(&ElasticCacheAccountResetPasswordOptions{}, "elastic-cache-account-reset-password", "Reset elastisc cache instance account password", func(s *mcclient.ClientSession, opts *ElasticCacheAccountResetPasswordOptions) error {
  43. params := jsonutils.NewDict()
  44. params.Set("password", jsonutils.NewString(opts.PASSWORD))
  45. result, err := modules.ElasticCacheAccount.PerformAction(s, opts.ID, "reset-password", params)
  46. if err != nil {
  47. return err
  48. }
  49. printObject(result)
  50. return nil
  51. })
  52. type ElasticCacheBaseListOptions struct {
  53. options.BaseListOptions
  54. ElasticcacheId string `help:"elastic cache id"`
  55. }
  56. R(&ElasticCacheBaseListOptions{}, "elastic-cache-account-list", "List elastisc cache account", func(s *mcclient.ClientSession, opts *ElasticCacheBaseListOptions) error {
  57. params, err := options.ListStructToParams(opts)
  58. if err != nil {
  59. return err
  60. }
  61. result, err := modules.ElasticCacheAccount.List(s, params)
  62. if err != nil {
  63. return err
  64. }
  65. printList(result, nil)
  66. return nil
  67. })
  68. R(&compute.ElasticCacheAccountCreateOptions{}, "elastic-cache-account-create", "Create elastisc cache account", func(s *mcclient.ClientSession, opts *compute.ElasticCacheAccountCreateOptions) error {
  69. params, err := options.ListStructToParams(opts)
  70. if err != nil {
  71. return err
  72. }
  73. result, err := modules.ElasticCacheAccount.Create(s, params)
  74. if err != nil {
  75. return err
  76. }
  77. printObject(result)
  78. return nil
  79. })
  80. R(&compute.ElasticCacheIdOptions{}, "elastic-cache-account-delete", "Delete elastisc cache account", func(s *mcclient.ClientSession, opts *compute.ElasticCacheIdOptions) error {
  81. result, err := modules.ElasticCacheAccount.Delete(s, opts.ID, nil)
  82. if err != nil {
  83. return err
  84. }
  85. printObject(result)
  86. return nil
  87. })
  88. R(&compute.ElasticCacheBackupCreateOptions{}, "elastic-cache-backup-create", "Create elastisc cache backup", func(s *mcclient.ClientSession, opts *compute.ElasticCacheBackupCreateOptions) error {
  89. params, err := options.ListStructToParams(opts)
  90. if err != nil {
  91. return err
  92. }
  93. result, err := modules.ElasticCacheBackup.Create(s, params)
  94. if err != nil {
  95. return err
  96. }
  97. printObject(result)
  98. return nil
  99. })
  100. R(&options.BaseListOptions{}, "elastic-cache-backup-list", "List elastisc cache backup", func(s *mcclient.ClientSession, opts *options.BaseListOptions) error {
  101. params, err := options.ListStructToParams(opts)
  102. if err != nil {
  103. return err
  104. }
  105. result, err := modules.ElasticCacheBackup.List(s, params)
  106. if err != nil {
  107. return err
  108. }
  109. printList(result, nil)
  110. return nil
  111. })
  112. R(&compute.ElasticCacheIdOptions{}, "elastic-cache-backup-delete", "Delete elastisc cache backup", func(s *mcclient.ClientSession, opts *compute.ElasticCacheIdOptions) error {
  113. result, err := modules.ElasticCacheBackup.Delete(s, opts.ID, nil)
  114. if err != nil {
  115. return err
  116. }
  117. printObject(result)
  118. return nil
  119. })
  120. R(&compute.ElasticCacheIdOptions{}, "elastic-cache-backup-restore", "Restore elastisc cache backup", func(s *mcclient.ClientSession, opts *compute.ElasticCacheIdOptions) error {
  121. result, err := modules.ElasticCacheBackup.PerformAction(s, opts.ID, "restore-instance", nil)
  122. if err != nil {
  123. return err
  124. }
  125. printObject(result)
  126. return nil
  127. })
  128. R(&compute.ElasticCacheAclCreateOptions{}, "elastic-cache-acl-create", "Create elastisc cache acl", func(s *mcclient.ClientSession, opts *compute.ElasticCacheAclCreateOptions) error {
  129. params, err := options.ListStructToParams(opts)
  130. if err != nil {
  131. return err
  132. }
  133. result, err := modules.ElasticCacheAcl.Create(s, params)
  134. if err != nil {
  135. return err
  136. }
  137. printObject(result)
  138. return nil
  139. })
  140. R(&compute.ElasticCacheIdOptions{}, "elastic-cache-acl-delete", "Delete elastisc cache acl", func(s *mcclient.ClientSession, opts *compute.ElasticCacheIdOptions) error {
  141. result, err := modules.ElasticCacheAcl.Delete(s, opts.ID, nil)
  142. if err != nil {
  143. return err
  144. }
  145. printObject(result)
  146. return nil
  147. })
  148. R(&options.BaseListOptions{}, "elastic-cache-acl-list", "List elastisc cache acl", func(s *mcclient.ClientSession, opts *options.BaseListOptions) error {
  149. params, err := options.ListStructToParams(opts)
  150. if err != nil {
  151. return err
  152. }
  153. result, err := modules.ElasticCacheAcl.List(s, params)
  154. if err != nil {
  155. return err
  156. }
  157. printList(result, nil)
  158. return nil
  159. })
  160. R(&compute.ElasticCacheAclUpdateOptions{}, "elastic-cache-acl-update", "Update elastisc cache acl", func(s *mcclient.ClientSession, opts *compute.ElasticCacheAclUpdateOptions) error {
  161. params, err := options.ListStructToParams(opts)
  162. if err != nil {
  163. return err
  164. }
  165. params.Remove("id")
  166. result, err := modules.ElasticCacheAcl.Update(s, opts.Id, params)
  167. if err != nil {
  168. return err
  169. }
  170. printObject(result)
  171. return nil
  172. })
  173. R(&options.BaseListOptions{}, "elastic-cache-parameter-list", "List elastisc cache parameters", func(s *mcclient.ClientSession, opts *options.BaseListOptions) error {
  174. params, err := options.ListStructToParams(opts)
  175. if err != nil {
  176. return err
  177. }
  178. result, err := modules.ElasticCacheParameter.List(s, params)
  179. if err != nil {
  180. return err
  181. }
  182. printList(result, nil)
  183. return nil
  184. })
  185. R(&compute.ElasticCacheParameterUpdateOptions{}, "elastic-cache-parameter-update", "Update elastisc cache parameter", func(s *mcclient.ClientSession, opts *compute.ElasticCacheParameterUpdateOptions) error {
  186. params, err := options.ListStructToParams(opts)
  187. if err != nil {
  188. return err
  189. }
  190. params.Remove("id")
  191. result, err := modules.ElasticCacheParameter.Update(s, opts.Id, params)
  192. if err != nil {
  193. return err
  194. }
  195. printObject(result)
  196. return nil
  197. })
  198. type ElasticCacheSkusListOptions struct {
  199. options.BaseListOptions
  200. Cloudregion string `help:"region Id or name"`
  201. Usable bool `help:"Filter usable sku"`
  202. Zone string `help:"zone Id or name"`
  203. City *string `help:"city name,eg. BeiJing"`
  204. LocalCategory *string `help:"local category,eg. single"`
  205. EngineVersion *string `help:"engine version,eg. 3.0"`
  206. Cpu *int `help:"Cpu core count" json:"cpu_core_count"`
  207. Mem *int `help:"Memory size in MB" json:"memory_size_mb"`
  208. Name string `help:"Name of Sku"`
  209. }
  210. R(&ElasticCacheSkusListOptions{}, "elastic-cache-sku-list", "List elastisc cache sku", func(s *mcclient.ClientSession, opts *ElasticCacheSkusListOptions) error {
  211. params, err := options.ListStructToParams(opts)
  212. if err != nil {
  213. return err
  214. }
  215. result, err := modules.ElasticcacheSkus.List(s, params)
  216. if err != nil {
  217. return err
  218. }
  219. printList(result, nil)
  220. return nil
  221. })
  222. R(&options.ResourceMetadataOptions{}, "elastic-cache-add-tag", "Set tag of a server", func(s *mcclient.ClientSession, opts *options.ResourceMetadataOptions) error {
  223. params, err := opts.Params()
  224. if err != nil {
  225. return err
  226. }
  227. result, err := modules.ElasticCache.PerformAction(s, opts.ID, "user-metadata", params)
  228. if err != nil {
  229. return err
  230. }
  231. printObject(result)
  232. return nil
  233. })
  234. R(&options.ResourceMetadataOptions{}, "elastic-cache-set-tag", "Set tag of a server", func(s *mcclient.ClientSession, opts *options.ResourceMetadataOptions) error {
  235. params, err := opts.Params()
  236. if err != nil {
  237. return err
  238. }
  239. result, err := modules.ElasticCache.PerformAction(s, opts.ID, "set-user-metadata", params)
  240. if err != nil {
  241. return err
  242. }
  243. printObject(result)
  244. return nil
  245. })
  246. R(&compute.ElasticCacheRemoteUpdateOptions{}, "elastic-cache-remote-update", "Restore elastisc cache backup", func(s *mcclient.ClientSession, opts *compute.ElasticCacheRemoteUpdateOptions) error {
  247. params, err := options.StructToParams(opts)
  248. if err != nil {
  249. return err
  250. }
  251. result, err := modules.ElasticCache.PerformAction(s, opts.ID, "remote-update", params)
  252. if err != nil {
  253. return err
  254. }
  255. printObject(result)
  256. return nil
  257. })
  258. R(&compute.ElasticCacheAutoRenewOptions{}, "elastic-cache-auto-renew", "Set elastisc cache auto renew", func(s *mcclient.ClientSession, opts *compute.ElasticCacheAutoRenewOptions) error {
  259. params, err := options.StructToParams(opts)
  260. if err != nil {
  261. return err
  262. }
  263. result, err := modules.ElasticCache.PerformAction(s, opts.ID, "set-auto-renew", params)
  264. if err != nil {
  265. return err
  266. }
  267. printObject(result)
  268. return nil
  269. })
  270. R(&compute.ElasticCacheRenewOptions{}, "elastic-cache-renew", "Renew elastisc cache", func(s *mcclient.ClientSession, opts *compute.ElasticCacheRenewOptions) error {
  271. params, err := options.StructToParams(opts)
  272. if err != nil {
  273. return err
  274. }
  275. result, err := modules.ElasticCache.PerformAction(s, opts.ID, "renew", params)
  276. if err != nil {
  277. return err
  278. }
  279. printObject(result)
  280. return nil
  281. })
  282. type ElasticcacheSecgroupListOptions struct {
  283. options.BaseListOptions
  284. Elasticcache string `help:"ID or Name of elastic cache" json:"elasticcache"`
  285. Secgroup string `help:"Secgroup ID or name"`
  286. }
  287. R(&ElasticcacheSecgroupListOptions{}, "elastic-cache-secgroup-list", "List elastisc cache secgroups", func(s *mcclient.ClientSession, opts *ElasticcacheSecgroupListOptions) error {
  288. params, err := options.ListStructToParams(opts)
  289. if err != nil {
  290. return err
  291. }
  292. result, err := modules.ElasticCacheSecgroup.List(s, params)
  293. if err != nil {
  294. return err
  295. }
  296. printList(result, nil)
  297. return nil
  298. })
  299. }