diff --git a/pkg/multicloud/aws/bucket.go b/pkg/multicloud/aws/bucket.go index fc699957c..17cdbd9d7 100644 --- a/pkg/multicloud/aws/bucket.go +++ b/pkg/multicloud/aws/bucket.go @@ -24,6 +24,7 @@ import ( "strings" "time" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/service/s3" @@ -31,6 +32,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/fileutils" + "yunion.io/x/pkg/util/httputils" "yunion.io/x/pkg/utils" "yunion.io/x/s3cli" @@ -159,6 +161,15 @@ func (b *SBucket) GetStats() cloudprovider.SBucketStats { return stats } +func standardizeAwsError(err error) error { + switch ne := err.(type) { + case awserr.RequestFailure: + return httputils.NewJsonClientError(ne.StatusCode(), ne.Code(), ne.Message()) + default: + return err + } +} + func (b *SBucket) ListObjects(prefix string, marker string, delimiter string, maxCount int) (cloudprovider.SListObjectResult, error) { result := cloudprovider.SListObjectResult{} s3cli, err := b.region.GetS3Client() @@ -181,7 +192,9 @@ func (b *SBucket) ListObjects(prefix string, marker string, delimiter string, ma } oResult, err := s3cli.ListObjects(input) if err != nil { - return result, errors.Wrap(err, "ListObjects") + + log.Debugf("%#v", err) + return result, errors.Wrap(standardizeAwsError(err), "ListObjects") } result.Objects = make([]cloudprovider.ICloudObject, 0) for _, object := range oResult.Contents { diff --git a/pkg/multicloud/azure/storageaccount.go b/pkg/multicloud/azure/storageaccount.go index 88e3907e8..f828f49ca 100644 --- a/pkg/multicloud/azure/storageaccount.go +++ b/pkg/multicloud/azure/storageaccount.go @@ -868,6 +868,7 @@ func (b *SStorageAccount) ListObjects(prefix string, marker string, delimiter st result := cloudprovider.SListObjectResult{} containers, err := b.GetContainers() if err != nil { + log.Debugf("%#v", err) return result, errors.Wrap(err, "GetContainers") } result.Objects = make([]cloudprovider.ICloudObject, 0) diff --git a/pkg/multicloud/google/eip.go b/pkg/multicloud/google/eip.go index 14249afc7..8d7da4073 100644 --- a/pkg/multicloud/google/eip.go +++ b/pkg/multicloud/google/eip.go @@ -204,9 +204,8 @@ func (region *SRegion) AssociateInstanceEip(instanceId string, eip string) error return fmt.Errorf("no valid networkinterface to associate") } -func (self *SRegion) DissociateInstanceEip(instanceId string, eip string) error { - instance := SInstance{} - err := self.GetBySelfId(instanceId, &instance) +func (region *SRegion) DissociateInstanceEip(instanceId string, eip string) error { + instance, err := region.GetInstance(instanceId) if err != nil { return errors.Wrap(err, "region.GetInstance") } @@ -218,7 +217,7 @@ func (self *SRegion) DissociateInstanceEip(instanceId string, eip string) error "networkInterface": networkInterface.Name, "accessConfig": accessConfig.Name, } - return self.Do(instance.SelfLink, "deleteAccessConfig", params, jsonutils.Marshal(body)) + return region.Do(instance.SelfLink, "deleteAccessConfig", params, jsonutils.Marshal(body)) } } } diff --git a/pkg/multicloud/google/shell/eip.go b/pkg/multicloud/google/shell/eip.go index f1cd85bf1..64734da47 100644 --- a/pkg/multicloud/google/shell/eip.go +++ b/pkg/multicloud/google/shell/eip.go @@ -45,7 +45,7 @@ func init() { }) type EipIdOptions struct { - ID string + ID string `help:"numeric id of eip"` } shellutils.R(&EipIdOptions{}, "eip-show", "Show eip", func(cli *google.SRegion, args *EipIdOptions) error { eip, err := cli.GetEip(args.ID) @@ -56,15 +56,17 @@ func init() { return nil }) - shellutils.R(&EipIdOptions{}, "eip-delete", "Delete eip", func(cli *google.SRegion, args *EipIdOptions) error { - return cli.Delete(args.ID) + type EipIdOptions2 struct { + LINK string `help:"self link of eip"` + } + shellutils.R(&EipIdOptions2{}, "eip-delete", "Delete eip", func(cli *google.SRegion, args *EipIdOptions2) error { + return cli.Delete(args.LINK) }) type EipCreateOptions struct { NAME string Desc string } - shellutils.R(&EipCreateOptions{}, "eip-create", "Create eip", func(cli *google.SRegion, args *EipCreateOptions) error { eip, err := cli.CreateEip(args.NAME, args.Desc) if err != nil {