secgrouprules.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 cloudpods
  15. import (
  16. "yunion.io/x/cloudmux/pkg/cloudprovider"
  17. "yunion.io/x/cloudmux/pkg/multicloud"
  18. "yunion.io/x/pkg/util/secrules"
  19. api "yunion.io/x/onecloud/pkg/apis/compute"
  20. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  21. )
  22. type SecurityGroupRule struct {
  23. multicloud.SResourceBase
  24. CloudpodsTags
  25. region *SRegion
  26. api.SecgroupRuleDetails
  27. }
  28. func (self *SecurityGroupRule) GetGlobalId() string {
  29. return self.Id
  30. }
  31. func (self *SecurityGroupRule) GetAction() secrules.TSecurityRuleAction {
  32. return secrules.TSecurityRuleAction(self.Action)
  33. }
  34. func (self *SecurityGroupRule) GetDescription() string {
  35. return self.Description
  36. }
  37. func (self *SecurityGroupRule) GetDirection() secrules.TSecurityRuleDirection {
  38. return secrules.TSecurityRuleDirection(self.Direction)
  39. }
  40. func (self *SecurityGroupRule) GetCIDRs() []string {
  41. return []string{self.CIDR}
  42. }
  43. func (self *SecurityGroupRule) GetProtocol() string {
  44. return self.Protocol
  45. }
  46. func (self *SecurityGroupRule) GetPorts() string {
  47. return self.Ports
  48. }
  49. func (self *SecurityGroupRule) GetPriority() int {
  50. return int(self.Priority)
  51. }
  52. func (self *SecurityGroupRule) Delete() error {
  53. return self.region.cli.delete(&modules.SecGroupRules, self.Id)
  54. }
  55. func (self *SecurityGroupRule) Update(opts *cloudprovider.SecurityGroupRuleUpdateOptions) error {
  56. input := api.SSecgroupRuleUpdateInput{}
  57. input.Priority = &opts.Priority
  58. action := string(opts.Action)
  59. input.Action = &action
  60. protocol := string(opts.Protocol)
  61. input.Protocol = &protocol
  62. input.Description = opts.Desc
  63. input.CIDR = &opts.CIDR
  64. input.Ports = &opts.Ports
  65. return self.region.cli.update(&modules.SecGroupRules, self.Id, input)
  66. }