image.go 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 glance
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient/options"
  18. )
  19. type ImageListOptions struct {
  20. options.BaseListOptions
  21. IsPublic string `help:"filter images public or not(True, False or None)" choices:"true|false"`
  22. IsStandard string `help:"filter images standard or non-standard" choices:"true|false"`
  23. Protected string `help:"filter images by protected" choices:"true|false"`
  24. IsUefi bool `help:"list uefi image"`
  25. Format []string `help:"Disk formats"`
  26. SubFormats []string `help:"Sub formats"`
  27. Name string `help:"Name filter"`
  28. OsType []string `help:"Type of OS filter e.g. 'Windows, Linux, Freebsd, Android, macOS, VMWare'"`
  29. OsTypePreciseMatch bool `help:"OS precise match"`
  30. OsArch []string `help:"Type of OS arch filter e.g. 'x86, arm, arm64, x86_64'"`
  31. OsArchPreciseMatch bool `help:"OS arch precise match"`
  32. Distribution []string `help:"Distribution filter, e.g. 'CentOS, Ubuntu, Debian, Windows'"`
  33. DistributionPreciseMatch bool `help:"Distribution precise match"`
  34. }
  35. func (o *ImageListOptions) Params() (jsonutils.JSONObject, error) {
  36. params, err := o.BaseListOptions.Params()
  37. if err != nil {
  38. return nil, err
  39. }
  40. if len(o.IsPublic) > 0 {
  41. params.Add(jsonutils.NewString(o.IsPublic), "is_public")
  42. }
  43. if len(o.IsStandard) > 0 {
  44. params.Add(jsonutils.NewString(o.IsStandard), "is_standard")
  45. }
  46. if len(o.Protected) > 0 {
  47. params.Add(jsonutils.NewString(o.Protected), "protected")
  48. }
  49. if o.IsUefi {
  50. params.Add(jsonutils.JSONTrue, "uefi")
  51. }
  52. if len(o.Tenant) > 0 {
  53. params.Add(jsonutils.NewString(o.Tenant), "owner")
  54. }
  55. if len(o.Name) > 0 {
  56. params.Add(jsonutils.NewString(o.Name), "name")
  57. }
  58. if len(o.Format) > 0 {
  59. fs := jsonutils.NewArray()
  60. for _, f := range o.Format {
  61. fs.Add(jsonutils.NewString(f))
  62. }
  63. params.Add(fs, "disk_formats")
  64. }
  65. if len(o.SubFormats) > 0 {
  66. params.Add(jsonutils.Marshal(o.SubFormats), "sub_formats")
  67. }
  68. if len(o.OsType) > 0 {
  69. params.Add(jsonutils.NewStringArray(o.OsType), "os_types")
  70. }
  71. if o.OsTypePreciseMatch {
  72. params.Add(jsonutils.JSONTrue, "os_type_precise_match")
  73. }
  74. if len(o.OsArch) > 0 {
  75. params.Add(jsonutils.NewStringArray(o.OsArch), "os_archs")
  76. }
  77. if o.OsArchPreciseMatch {
  78. params.Add(jsonutils.JSONTrue, "os_arch_precise_match")
  79. }
  80. if len(o.Distribution) > 0 {
  81. params.Add(jsonutils.NewStringArray(o.Distribution), "distributions")
  82. }
  83. if o.DistributionPreciseMatch {
  84. params.Add(jsonutils.JSONTrue, "distribution_precise_match")
  85. }
  86. return params, nil
  87. }
  88. type ImageStatusStatisticsOptions struct {
  89. ImageListOptions
  90. options.StatusStatisticsOptions
  91. }