snapshotpolicy.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. "strings"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/httperrors"
  19. "yunion.io/x/onecloud/pkg/mcclient/options"
  20. )
  21. type SnapshotPolicyListOptions struct {
  22. options.BaseListOptions
  23. ResourceId []string `help:"resource id"`
  24. OrderByBindDiskCount string
  25. OrderBySnapshotCount string
  26. }
  27. func (opts *SnapshotPolicyListOptions) Params() (jsonutils.JSONObject, error) {
  28. return options.ListStructToParams(opts)
  29. }
  30. type SnapshotPolicyCreateOptions struct {
  31. options.BaseCreateOptions
  32. CloudregionId string
  33. ManagerId string
  34. Type string `help:"snapshot type" default:"disk" choices:"disk|server"`
  35. RetentionDays int `help:"snapshot retention days" default:"-1"`
  36. RetentionCount int `help:"snapshot retention count" default:"-1"`
  37. RepeatWeekdays []int `help:"snapshot create days on week"`
  38. TimePoints []int `help:"snapshot create time points on one day"`
  39. }
  40. func (opts *SnapshotPolicyCreateOptions) Params() (jsonutils.JSONObject, error) {
  41. return jsonutils.Marshal(opts), nil
  42. }
  43. type SnapshotPolicyDisksOptions struct {
  44. options.BaseIdOptions
  45. Disks []string `help:"ids of disk"`
  46. }
  47. func (opts *SnapshotPolicyDisksOptions) Params() (jsonutils.JSONObject, error) {
  48. return jsonutils.Marshal(map[string]interface{}{"disks": opts.Disks}), nil
  49. }
  50. type SnapshotPolicyResourcesOptions struct {
  51. options.BaseIdOptions
  52. Resources []string `help:"resource info etc: disk:id,server:id"`
  53. }
  54. func (opts *SnapshotPolicyResourcesOptions) Params() (jsonutils.JSONObject, error) {
  55. resources := []struct {
  56. Id string `json:"id"`
  57. Type string `json:"type"`
  58. }{}
  59. for _, resource := range opts.Resources {
  60. parts := strings.SplitN(resource, ":", 2)
  61. if len(parts) != 2 {
  62. return nil, httperrors.NewBadRequestError("Invalid resource info: %s", resource)
  63. }
  64. resources = append(resources, struct {
  65. Id string `json:"id"`
  66. Type string `json:"type"`
  67. }{
  68. Id: parts[1],
  69. Type: parts[0],
  70. })
  71. }
  72. return jsonutils.Marshal(map[string]interface{}{"resources": resources}), nil
  73. }