ansibleplaybooks_v2.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 ansible
  15. import (
  16. "yunion.io/x/onecloud/pkg/mcclient"
  17. modules "yunion.io/x/onecloud/pkg/mcclient/modules/ansible"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. func init() {
  21. type AnsiblePlaybookV2IdOptions struct {
  22. ID string `help:"name/id of the playbook"`
  23. }
  24. type AnsiblePlaybookV2ListOptions struct {
  25. options.BaseListOptions
  26. }
  27. R(&AnsiblePlaybookV2IdOptions{}, "ansibleplaybookv2-show", "Show ansible playbook", func(s *mcclient.ClientSession, opts *AnsiblePlaybookV2IdOptions) error {
  28. apb, err := modules.AnsiblePlaybooksV2.Get(s, opts.ID, nil)
  29. if err != nil {
  30. return err
  31. }
  32. printObject(apb)
  33. return nil
  34. })
  35. R(&AnsiblePlaybookV2ListOptions{}, "ansibleplaybookv2-list", "List ansible playbooks", func(s *mcclient.ClientSession, opts *AnsiblePlaybookV2ListOptions) error {
  36. params, err := opts.Params()
  37. if err != nil {
  38. return err
  39. }
  40. apbs, err := modules.AnsiblePlaybooksV2.List(s, params)
  41. if err != nil {
  42. return err
  43. }
  44. printList(apbs, modules.AnsiblePlaybooksV2.GetColumns(s))
  45. return nil
  46. })
  47. R(&AnsiblePlaybookV2IdOptions{}, "ansibleplaybookv2-run", "Run ansible playbook",
  48. func(s *mcclient.ClientSession, opts *AnsiblePlaybookV2IdOptions) error {
  49. apb, err := modules.AnsiblePlaybooksV2.PerformAction(s, opts.ID, "run", nil)
  50. if err != nil {
  51. return err
  52. }
  53. printObject(apb)
  54. return nil
  55. },
  56. )
  57. R(&AnsiblePlaybookV2IdOptions{}, "ansibleplaybookv2-stop", "Stop ansible playbook",
  58. func(s *mcclient.ClientSession, opts *AnsiblePlaybookV2IdOptions) error {
  59. apb, err := modules.AnsiblePlaybooksV2.PerformAction(s, opts.ID, "stop", nil)
  60. if err != nil {
  61. return err
  62. }
  63. printObject(apb)
  64. return nil
  65. },
  66. )
  67. R(&AnsiblePlaybookV2IdOptions{}, "ansibleplaybookv2-delete", "Delete ansible playbook",
  68. func(s *mcclient.ClientSession, opts *AnsiblePlaybookV2IdOptions) error {
  69. apb, err := modules.AnsiblePlaybooksV2.Delete(s, opts.ID, nil)
  70. if err != nil {
  71. return err
  72. }
  73. printObject(apb)
  74. return nil
  75. },
  76. )
  77. }