cdn_domains.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/cloudmux/pkg/cloudprovider"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type CDNDomainListOptions struct {
  21. options.BaseListOptions
  22. }
  23. func (opts *CDNDomainListOptions) Params() (jsonutils.JSONObject, error) {
  24. return options.ListStructToParams(opts)
  25. }
  26. type CDNDomainCreateOptions struct {
  27. DOMAIN string `help:"Domain Name"`
  28. MANAGER string `help:"Cloudprovider Id"`
  29. AREA string `help:"Area" choices:"mainland|overseas|global"`
  30. SERVICE_TYPE string `help:"Service Type" choices:"web|download|media"`
  31. ORIGIN_TYPE string `help:"Origin Type" choices:"domain|ip|bucket|third_party"`
  32. ORIGIN string `help:"Origin Addr"`
  33. ServerName string `help:"Cdn Server Name"`
  34. }
  35. func (opts *CDNDomainCreateOptions) Params() (jsonutils.JSONObject, error) {
  36. params := jsonutils.NewDict()
  37. params.Add(jsonutils.NewString(opts.DOMAIN), "name")
  38. params.Add(jsonutils.NewString(opts.MANAGER), "cloudprovider_id")
  39. params.Add(jsonutils.NewString(opts.AREA), "area")
  40. params.Add(jsonutils.NewString(opts.SERVICE_TYPE), "service_type")
  41. params.Add(jsonutils.Marshal([]interface{}{
  42. map[string]string{
  43. "origin": opts.ORIGIN,
  44. "type": opts.ORIGIN_TYPE,
  45. "server_name": opts.ServerName,
  46. },
  47. }), "origins")
  48. return params, nil
  49. }
  50. type CDNDomainUpdateOptions struct {
  51. options.BaseIdOptions
  52. Description string
  53. Delete string `help:"Lock or not lock cdn domain" choices:"enable|disable"`
  54. }
  55. func (opts *CDNDomainUpdateOptions) Params() (jsonutils.JSONObject, error) {
  56. params, err := options.StructToParams(opts)
  57. if err != nil {
  58. return nil, err
  59. }
  60. if len(opts.Delete) > 0 {
  61. if opts.Delete == "disable" {
  62. params.Add(jsonutils.JSONTrue, "disable_delete")
  63. } else {
  64. params.Add(jsonutils.JSONFalse, "disable_delete")
  65. }
  66. }
  67. return params, nil
  68. }
  69. type CDNClearCacheOptions struct {
  70. options.BaseIdOptions
  71. cloudprovider.CacheClearOptions
  72. }
  73. func (opts *CDNClearCacheOptions) Params() (jsonutils.JSONObject, error) {
  74. return jsonutils.Marshal(opts.CacheClearOptions), nil
  75. }
  76. type CDNChangeConfigOptions struct {
  77. options.BaseIdOptions
  78. cloudprovider.CacheConfig
  79. }
  80. func (opts *CDNChangeConfigOptions) Params() (jsonutils.JSONObject, error) {
  81. return jsonutils.Marshal(opts.CacheConfig), nil
  82. }
  83. type CDNDeleteCustomHostnameOptions struct {
  84. options.BaseIdOptions
  85. CustomHostnameId string
  86. }
  87. func (opts *CDNDeleteCustomHostnameOptions) Params() (jsonutils.JSONObject, error) {
  88. return jsonutils.Marshal(map[string]string{"id": opts.CustomHostnameId}), nil
  89. }
  90. type CDNCustomHostnameOptions struct {
  91. options.BaseIdOptions
  92. }