@@ -240,15 +240,10 @@ func (self *SEipAddress) ChangeBandwidth(bw int) error {
240240 return self .region .UpdateEipBandwidth (self .AllocationId , bw )
241241}
242242
243- func (region * SRegion ) GetEips (eipId string , associatedId , addr string , offset int , limit int ) ([]SEipAddress , int , error ) {
244- if limit > 50 || limit <= 0 {
245- limit = 50
246- }
247-
243+ func (region * SRegion ) GetEips (eipId string , associatedId , addr string ) ([]SEipAddress , error ) {
248244 params := make (map [string ]string )
249245 params ["RegionId" ] = region .RegionId
250- params ["PageSize" ] = fmt .Sprintf ("%d" , limit )
251- params ["PageNumber" ] = fmt .Sprintf ("%d" , (offset / limit )+ 1 )
246+ params ["PageSize" ] = "100"
252247 if len (addr ) > 0 {
253248 params ["EipAddress" ] = addr
254249 }
@@ -266,27 +261,36 @@ func (region *SRegion) GetEips(eipId string, associatedId, addr string, offset i
266261 }
267262 }
268263
269- body , err := region .vpcRequest ("DescribeEipAddresses" , params )
270- if err != nil {
271- log .Errorf ("DescribeEipAddresses fail %s" , err )
272- return nil , 0 , err
273- }
274-
275- eips := make ([]SEipAddress , 0 )
276- err = body .Unmarshal (& eips , "EipAddresses" , "EipAddress" )
277- if err != nil {
278- log .Errorf ("Unmarshal EipAddress details fail %s" , err )
279- return nil , 0 , err
280- }
281- total , _ := body .Int ("TotalCount" )
282- for i := 0 ; i < len (eips ); i += 1 {
283- eips [i ].region = region
264+ pageNumber := 1
265+ ret := []SEipAddress {}
266+ for {
267+ params ["PageNumber" ] = fmt .Sprintf ("%d" , pageNumber )
268+ body , err := region .vpcRequest ("DescribeEipAddresses" , params )
269+ if err != nil {
270+ log .Errorf ("DescribeEipAddresses fail %s" , err )
271+ return nil , err
272+ }
273+ part := struct {
274+ EipAddresses struct {
275+ EipAddress []SEipAddress
276+ } `json:"EipAddresses"`
277+ TotalCount int `json:"TotalCount"`
278+ }{}
279+ err = body .Unmarshal (& part )
280+ if err != nil {
281+ return nil , errors .Wrapf (err , "Unmarshal EipAddress details" )
282+ }
283+ ret = append (ret , part .EipAddresses .EipAddress ... )
284+ if len (ret ) >= part .TotalCount {
285+ break
286+ }
287+ pageNumber ++
284288 }
285- return eips , int ( total ) , nil
289+ return ret , nil
286290}
287291
288292func (region * SRegion ) GetEip (eipId string ) (* SEipAddress , error ) {
289- eips , _ , err := region .GetEips (eipId , "" , "" , 0 , 1 )
293+ eips , err := region .GetEips (eipId , "" , "" )
290294 if err != nil {
291295 return nil , err
292296 }
0 commit comments