mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #419 from ioito/hotfix/qx-openstack-secgroup-error
避免OpenStack不支持安全组部署失败
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user