bingocloud.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. "strings"
  18. "yunion.io/x/sqlchemy"
  19. api "yunion.io/x/onecloud/pkg/apis/compute"
  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 SBingoCloudRegionDriver struct {
  25. SManagedVirtualizationRegionDriver
  26. }
  27. func init() {
  28. driver := SBingoCloudRegionDriver{}
  29. models.RegisterRegionDriver(&driver)
  30. }
  31. func (self *SBingoCloudRegionDriver) GetProvider() string {
  32. return api.CLOUD_PROVIDER_BINGO_CLOUD
  33. }
  34. func (self *SBingoCloudRegionDriver) ValidateCreateSnapshotData(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, storage *models.SStorage, input *api.SnapshotCreateInput) error {
  35. return nil
  36. }
  37. func (self *SBingoCloudRegionDriver) ValidateCreateSecurityGroupInput(ctx context.Context, userCred mcclient.TokenCredential, input *api.SSecgroupCreateInput) (*api.SSecgroupCreateInput, error) {
  38. for i := range input.Rules {
  39. rule := input.Rules[i]
  40. if len(rule.Ports) > 0 && strings.Contains(rule.Ports, ",") {
  41. return nil, httperrors.NewInputParameterError("invalid ports %s", rule.Ports)
  42. }
  43. }
  44. return self.SManagedVirtualizationRegionDriver.ValidateCreateSecurityGroupInput(ctx, userCred, input)
  45. }
  46. func (self *SBingoCloudRegionDriver) ValidateUpdateSecurityGroupRuleInput(ctx context.Context, userCred mcclient.TokenCredential, input *api.SSecgroupRuleUpdateInput) (*api.SSecgroupRuleUpdateInput, error) {
  47. if input.Ports != nil && strings.Contains(*input.Ports, ",") {
  48. return nil, httperrors.NewInputParameterError("invalid ports %s", *input.Ports)
  49. }
  50. return self.SManagedVirtualizationRegionDriver.ValidateUpdateSecurityGroupRuleInput(ctx, userCred, input)
  51. }
  52. func (self *SBingoCloudRegionDriver) GetSecurityGroupFilter(vpc *models.SVpc) (func(q *sqlchemy.SQuery) *sqlchemy.SQuery, error) {
  53. return func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
  54. return q.Equals("cloudregion_id", vpc.CloudregionId).Equals("manager_id", vpc.ManagerId)
  55. }, nil
  56. }