From 7a447d31dbf91164507cc023dc02cc3a14e7d2ff Mon Sep 17 00:00:00 2001 From: TangBin Date: Wed, 13 Feb 2019 12:14:16 +0800 Subject: [PATCH] server delete etc fix --- pkg/util/huawei/consts.go | 32 ++++++++++++++++++++++++++++++++ pkg/util/huawei/region.go | 6 ++++-- pkg/util/huawei/securitygroup.go | 2 +- pkg/util/huawei/utils.go | 12 +++++++++++- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/pkg/util/huawei/consts.go b/pkg/util/huawei/consts.go index ae0cc1ca0e..3b5b1a14c7 100644 --- a/pkg/util/huawei/consts.go +++ b/pkg/util/huawei/consts.go @@ -20,3 +20,35 @@ const ( RESOURCE_TYPE_IP = "hws.resource.type.ip" // VPC公网IP RESOURCE_TYPE_IMAGE = "hws.resource.type.marketplace" // 市场镜像 ) + +// Not Found Error code +// 网络等资源直接通过http code 404即可判断资源不存在。另外有些资源可能不是返回404这里单独列出来 +const ( + VM_NOT_FOUND = "Ecs.0114" // 云服务器不存在 + ECS_NOT_FOUND = "Ecs.0614" // 弹性云服务器不存在 + IMG_ID_NOT_FOUND = "IMG.0027" // 请求的镜像ID不存在 + IMG_NOT_FOUND = "IMG.0027" // 镜像不存在 + IMG_ERR_NOT_FOUND = "IMG.0057" // 镜像文件不存在或者为空或者不是允许格式的文件 + IMG_BACKUP_NOT_FOUND = "IMG.0020" // 备份不存在 + IMG_VM_BACKUP_NOT_FOUND = "IMG.0127" // 云服务器备份不存在 + IMG_VM_NOT_FOUND = "IMG.0005" // 云主机不存在 + JOB_NOT_FOUND = "Common.0011" // jobId为空 + EVS_NOT_FOUND = "EVS.5404" // 磁盘、快照和备份等资源未找到。 + FIP_NOT_FOUND = "VPC.0504" // 未找到弹性公网IP。 + VPC_NOT_FOUND = "VPC.0012" // 未找到弹性公网VPC。 +) + +var NOT_FOUND_CODES = []string{ + VM_NOT_FOUND, + ECS_NOT_FOUND, + IMG_ID_NOT_FOUND, + IMG_NOT_FOUND, + IMG_ERR_NOT_FOUND, + IMG_BACKUP_NOT_FOUND, + IMG_VM_BACKUP_NOT_FOUND, + IMG_VM_NOT_FOUND, + JOB_NOT_FOUND, + EVS_NOT_FOUND, + FIP_NOT_FOUND, + VPC_NOT_FOUND, +} diff --git a/pkg/util/huawei/region.go b/pkg/util/huawei/region.go index a09ee15cfd..1d1e9294b5 100644 --- a/pkg/util/huawei/region.go +++ b/pkg/util/huawei/region.go @@ -640,6 +640,7 @@ func (self *SRegion) addSecurityGroupRules(secGrpId string, rule *secrules.Secur return nil } +// todo: icmp协议目前存在差异,华为云能指定icmp code,onecloud不支持 func (self *SRegion) addSecurityGroupRule(secGrpId, direction, portStart, portEnd, protocol, ipNet string) error { params := jsonutils.NewDict() secgroupObj := jsonutils.NewDict() @@ -647,10 +648,11 @@ func (self *SRegion) addSecurityGroupRule(secGrpId, direction, portStart, portEn secgroupObj.Add(jsonutils.NewString(direction), "direction") secgroupObj.Add(jsonutils.NewString(ipNet), "remote_ip_prefix") secgroupObj.Add(jsonutils.NewString("IPV4"), "ethertype") - if len(portStart) > 0 && portStart != "0" { + // 端口为空或者1-65535 + if len(portStart) > 0 && portStart != "0" && portStart != "-1" { secgroupObj.Add(jsonutils.NewString(portStart), "port_range_min") } - if len(portEnd) > 0 && portEnd != "0" { + if len(portEnd) > 0 && portEnd != "0" && portEnd != "-1" { secgroupObj.Add(jsonutils.NewString(portEnd), "port_range_max") } if len(protocol) > 0 { diff --git a/pkg/util/huawei/securitygroup.go b/pkg/util/huawei/securitygroup.go index ead715c452..007d769072 100644 --- a/pkg/util/huawei/securitygroup.go +++ b/pkg/util/huawei/securitygroup.go @@ -194,7 +194,7 @@ func (self *SSecurityGroup) GetSecurityRule(ruleId string, withRuleId bool) (sec } else { desc = remoteRule.Description } - // todo: icmp 可能不兼容 + // todo: icmp 可能不兼容。华为云能指定icmp code,onecloud不支持 rule := secrules.SecurityRule{ Priority: 1, Action: secrules.SecurityRuleAllow, diff --git a/pkg/util/huawei/utils.go b/pkg/util/huawei/utils.go index 63a6e80036..c57febde2e 100644 --- a/pkg/util/huawei/utils.go +++ b/pkg/util/huawei/utils.go @@ -22,11 +22,21 @@ type deleteFunc2 func(ctx manager.IManagerContext, id string, spec string, param type listInCtxFunc func(ctx manager.IManagerContext, querys map[string]string) (*responses.ListResult, error) type listInCtxWithSpecFunc func(ctx manager.IManagerContext, spec string, querys map[string]string, responseKey string) (*responses.ListResult, error) +func notFound(code string) bool { + for _, c := range NOT_FOUND_CODES { + if code == c { + return true + } + } + + return false +} + func unmarshalResult(resp jsonutils.JSONObject, respErr error, result interface{}) error { if respErr != nil { switch e := respErr.(type) { case *httputils.JSONClientError: - if e.Code == 404 { + if e.Code == 404 || notFound(e.Class) { return cloudprovider.ErrNotFound } return e