aws not found error fix

This commit is contained in:
TangBin
2019-03-27 17:08:26 +08:00
committed by Yousong Zhou
parent 4856ece09c
commit 892f96dc91
9 changed files with 25 additions and 9 deletions
-1
View File
@@ -201,7 +201,6 @@ type SAccountBalance struct {
}
func (self *SAwsClient) QueryAccountBalance() (*SAccountBalance, error) {
// todo: aws 貌似没有余额?
return nil, cloudprovider.ErrNotSupported
}
+2
View File
@@ -155,6 +155,7 @@ func (self *SRegion) GetEips(eipId string, eipAddress string, offset int, limit
}
res, err := self.ec2Client.DescribeAddresses(&params)
err = parseNotFoundError(err)
if err != nil {
log.Errorf("DescribeEipAddresses fail %s", err)
return nil, 0, err
@@ -215,6 +216,7 @@ func (self *SRegion) GetEipByIpAddress(eipAddress string) (*SEipAddress, error)
if err != nil {
return nil, err
}
if total != 1 {
return nil, cloudprovider.ErrNotFound
}
+1 -4
View File
@@ -3,7 +3,6 @@ package aws
import (
"context"
"fmt"
"strings"
"time"
"github.com/aws/aws-sdk-go/service/ec2"
@@ -368,10 +367,8 @@ func (self *SRegion) getImages(status ImageStatusType, owners []TImageOwnerType,
}
ret, err := self.ec2Client.DescribeImages(params)
err = parseNotFoundError(err)
if err != nil {
if strings.Contains(err.Error(), ".NotFound") {
return nil, cloudprovider.ErrNotFound
}
return nil, err
}
+1 -1
View File
@@ -375,7 +375,7 @@ func (self *SInstance) ChangeConfig2(ctx context.Context, instanceType string) e
}
func (self *SInstance) GetVNCInfo() (jsonutils.JSONObject, error) {
panic("implement me")
return nil, cloudprovider.ErrNotSupported
}
func (self *SInstance) AttachDisk(ctx context.Context, diskId string) error {
+1
View File
@@ -181,6 +181,7 @@ func (self *SRegion) GetNetwroks(ids []string, vpcId string, limit int, offset i
}
ret, err := self.ec2Client.DescribeSubnets(params)
err = parseNotFoundError(err)
if err != nil {
return nil, 0, err
}
+3
View File
@@ -267,9 +267,11 @@ func (self *SRegion) GetSecurityGroupDetails(secGroupId string) (*SSecurityGroup
params.SetGroupIds([]*string{&secGroupId})
ret, err := self.ec2Client.DescribeSecurityGroups(params)
err = parseNotFoundError(err)
if err != nil {
return nil, err
}
if len(ret.SecurityGroups) == 1 {
s := ret.SecurityGroups[0]
vpc, err := self.getVpc(*s.VpcId)
@@ -433,6 +435,7 @@ func (self *SRegion) GetSecurityGroups(vpcId string, secgroupId string, offset i
}
ret, err := self.ec2Client.DescribeSecurityGroups(params)
err = parseNotFoundError(err)
if err != nil {
return nil, 0, err
}
+1
View File
@@ -128,6 +128,7 @@ func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName
}
ret, err := self.ec2Client.DescribeSnapshots(params)
err = parseNotFoundError(err)
if err != nil {
if strings.Contains(err.Error(), "InvalidSnapshot.NotFound") {
return nil, 0, cloudprovider.ErrNotFound
+14
View File
@@ -12,6 +12,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/pkg/util/secrules"
)
@@ -468,3 +469,16 @@ func FetchTags(client *ec2.EC2, resourceId string) (*jsonutils.JSONDict, error)
return result, nil
}
// error
func parseNotFoundError(err error) error {
if err == nil {
return nil
}
if strings.Contains(err.Error(), ".NotFound") {
return cloudprovider.ErrNotFound
} else {
return err
}
}
+2 -3
View File
@@ -296,11 +296,10 @@ func (self *SRegion) GetVpcs(vpcId []string, offset int, limit int) ([]SVpc, int
if len(vpcId) > 0 {
params.SetVpcIds(ConvertedList(vpcId))
}
ret, err := self.ec2Client.DescribeVpcs(params)
err = parseNotFoundError(err)
if err != nil {
if strings.Contains(err.Error(), "InvalidVpcID.NotFound") {
return nil, 0, cloudprovider.ErrNotFound
}
return nil, 0, err
}