Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pkg/multicloud/aws/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ 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"

"yunion.io/x/jsonutils"
"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"

Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/multicloud/azure/storageaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions pkg/multicloud/google/eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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))
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/multicloud/google/shell/eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Loading