Merge pull request #419 from ioito/hotfix/qx-openstack-secgroup-error

避免OpenStack不支持安全组部署失败
This commit is contained in:
yunion-ci-robot
2019-04-16 18:54:10 +08:00
committed by GitHub
3 changed files with 19 additions and 1 deletions
+3 -1
View File
@@ -157,7 +157,9 @@ func (host *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudpr
secgroups := []map[string]string{}
for _, secgroupId := range desc.ExternalSecgroupIds {
secgroups = append(secgroups, map[string]string{"name": secgroupId})
if secgroupId != SECGROUP_NOT_SUPPORT {
secgroups = append(secgroups, map[string]string{"name": secgroupId})
}
}
image, err := host.zone.region.GetImage(desc.ExternalImageId)
+7
View File
@@ -606,6 +606,9 @@ func (region *SRegion) AttachDisk(instanceId string, diskId string) error {
}
func (instance *SInstance) AssignSecurityGroup(secgroupId string) error {
if secgroupId == SECGROUP_NOT_SUPPORT {
return fmt.Errorf("Security groups are not supported. Security group components are not installed")
}
secgroup, err := instance.host.zone.region.GetSecurityGroup(secgroupId)
if err != nil {
return err
@@ -620,6 +623,10 @@ func (instance *SInstance) AssignSecurityGroup(secgroupId string) error {
}
func (instance *SInstance) RevokeSecurityGroup(secgroupId string) error {
// 若OpenStack不支持安全组,则忽略解绑安全组
if secgroupId == SECGROUP_NOT_SUPPORT {
return nil
}
secgroup, err := instance.host.zone.region.GetSecurityGroup(secgroupId)
if err != nil {
return err
+9
View File
@@ -30,6 +30,10 @@ import (
"yunion.io/x/onecloud/pkg/util/httputils"
)
const (
SECGROUP_NOT_SUPPORT = "openstack_skip_security_group"
)
type SSecurityGroupRule struct {
Direction string
Ethertype string
@@ -218,6 +222,11 @@ func (region *SRegion) SyncSecurityGroup(secgroupId string, vpcId string, name s
if len(secgroupId) == 0 {
secgroups, err := region.GetSecurityGroups()
if err != nil {
// 若返回 cloudprovider.ErrNotFound, 表明不支持安全组或者未安装安全组相关组件
if err == cloudprovider.ErrNotFound {
return SECGROUP_NOT_SUPPORT, nil
}
log.Errorf("failed to get secgroups: %v", err)
return "", err
}