monitor.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 monitor
  15. import (
  16. "fmt"
  17. "yunion.io/x/onecloud/pkg/mcclient"
  18. "yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
  19. options "yunion.io/x/onecloud/pkg/mcclient/options/monitor"
  20. )
  21. func cmdN(suffix string) func(action string) string {
  22. return func(action string) string {
  23. return fmt.Sprintf("monitor-%s-%s", suffix, action)
  24. }
  25. }
  26. func init() {
  27. dsN := cmdN("datasource")
  28. R(&options.DataSourceListOptions{}, dsN("list"), "List all monitor data source",
  29. func(s *mcclient.ClientSession, args *options.DataSourceListOptions) error {
  30. params, err := args.Params()
  31. if err != nil {
  32. return err
  33. }
  34. ret, err := monitor.DataSources.List(s, params)
  35. if err != nil {
  36. return err
  37. }
  38. printList(ret, monitor.DataSources.GetColumns(s))
  39. return nil
  40. })
  41. R(&options.DataSourceDeleteOptions{}, dsN("delete"), "Delete monitor data source",
  42. func(s *mcclient.ClientSession, args *options.DataSourceDeleteOptions) error {
  43. ret, err := monitor.DataSources.Delete(s, args.ID, nil)
  44. if err != nil {
  45. return err
  46. }
  47. printObject(ret)
  48. return nil
  49. })
  50. }