volcengine.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 regiondrivers
  15. import (
  16. "context"
  17. "yunion.io/x/jsonutils"
  18. api "yunion.io/x/onecloud/pkg/apis/compute"
  19. "yunion.io/x/onecloud/pkg/cloudcommon/validators"
  20. "yunion.io/x/onecloud/pkg/compute/models"
  21. "yunion.io/x/onecloud/pkg/httperrors"
  22. "yunion.io/x/onecloud/pkg/mcclient"
  23. )
  24. type SVolcengineRegionDriver struct {
  25. SManagedVirtualizationRegionDriver
  26. }
  27. func init() {
  28. driver := SVolcengineRegionDriver{}
  29. models.RegisterRegionDriver(&driver)
  30. }
  31. func (self *SVolcengineRegionDriver) GetProvider() string {
  32. return api.CLOUD_PROVIDER_VOLCENGINE
  33. }
  34. func (self *SVolcengineRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
  35. var cidrV = validators.NewIPv4PrefixValidator("cidr_block")
  36. if err := cidrV.Validate(ctx, jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
  37. return input, err
  38. }
  39. err := IsInPrivateIpRange(cidrV.Value.ToIPRange())
  40. if err != nil {
  41. return input, err
  42. }
  43. if cidrV.Value.MaskLen > 29 {
  44. return input, httperrors.NewInputParameterError("%s request the mask range should be less than or equal to 29", self.GetProvider())
  45. }
  46. return input, nil
  47. }
  48. func (self *SVolcengineRegionDriver) ValidateCreateSecurityGroupInput(ctx context.Context, userCred mcclient.TokenCredential, input *api.SSecgroupCreateInput) (*api.SSecgroupCreateInput, error) {
  49. for i := range input.Rules {
  50. if input.Rules[i].Priority == nil {
  51. return nil, httperrors.NewMissingParameterError("priority")
  52. }
  53. if *input.Rules[i].Priority < 1 || *input.Rules[i].Priority > 100 {
  54. return nil, httperrors.NewInputParameterError("invalid priority %d, range 1-100", *input.Rules[i].Priority)
  55. }
  56. }
  57. return input, nil
  58. }
  59. func (self *SVolcengineRegionDriver) ValidateUpdateSecurityGroupRuleInput(ctx context.Context, userCred mcclient.TokenCredential, input *api.SSecgroupRuleUpdateInput) (*api.SSecgroupRuleUpdateInput, error) {
  60. return nil, httperrors.NewNotSupportedError("not support update security group rule")
  61. }