Merge pull request #623 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-secgroup-rule to release/2.1.0

* commit '0f78dd1ffcb8c4fef3fd42324e5adf22eb8e911e':
  大部分公有云不需要将安全组拆分为单个单个的规则
This commit is contained in:
邱剑
2018-11-30 23:04:03 +08:00
2 changed files with 8 additions and 2 deletions
+4
View File
@@ -273,6 +273,10 @@ func (self *SSecurityGroupRule) String() string {
return fields[0] + strings.Join(fields[1:], " ")
}
func (self *SSecurityGroupRule) toRule() (*secrules.SecurityRule, error) {
return secrules.ParseSecurityRule(self.String())
}
func (self *SSecurityGroupRule) SingleRules() ([]secrules.SecurityRule, error) {
rules := make([]secrules.SecurityRule, 0)
ruleStr := self.String()
+4 -2
View File
@@ -116,11 +116,13 @@ func (self *SSecurityGroup) getSecurityRules(direction string) (rules []SSecurit
func (self *SSecurityGroup) getSecRules(direction string) []secrules.SecurityRule {
rules := make([]secrules.SecurityRule, 0)
for _, _rule := range self.getSecurityRules(direction) {
singleRules, err := _rule.SingleRules()
//这里没必要拆分为单个单个的端口,到公有云那边适配
rule, err := _rule.toRule()
if err != nil {
log.Errorf(err.Error())
continue
}
rules = append(rules, singleRules...)
rules = append(rules, *rule)
}
return rules
}