mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): convert eip with same project with vm
This commit is contained in:
@@ -239,7 +239,7 @@ func (self *SEipAddress) ChangeBandwidth(bw int) error {
|
||||
return self.region.UpdateEipBandwidth(self.AllocationId, bw)
|
||||
}
|
||||
|
||||
func (region *SRegion) GetEips(eipId string, associatedId string, offset int, limit int) ([]SEipAddress, int, error) {
|
||||
func (region *SRegion) GetEips(eipId string, associatedId, addr string, offset int, limit int) ([]SEipAddress, int, error) {
|
||||
if limit > 50 || limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
@@ -248,6 +248,9 @@ func (region *SRegion) GetEips(eipId string, associatedId string, offset int, li
|
||||
params["RegionId"] = region.RegionId
|
||||
params["PageSize"] = fmt.Sprintf("%d", limit)
|
||||
params["PageNumber"] = fmt.Sprintf("%d", (offset/limit)+1)
|
||||
if len(addr) > 0 {
|
||||
params["EipAddress"] = addr
|
||||
}
|
||||
|
||||
if len(eipId) > 0 {
|
||||
params["AllocationId"] = eipId
|
||||
@@ -282,7 +285,7 @@ func (region *SRegion) GetEips(eipId string, associatedId string, offset int, li
|
||||
}
|
||||
|
||||
func (region *SRegion) GetEip(eipId string) (*SEipAddress, error) {
|
||||
eips, total, err := region.GetEips(eipId, "", 0, 1)
|
||||
eips, total, err := region.GetEips(eipId, "", "", 0, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -977,6 +977,7 @@ func (self *SInstance) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
eip.AllocationId = self.InstanceId // fixed
|
||||
eip.AllocationTime = self.CreationTime
|
||||
eip.Bandwidth = self.InternetMaxBandwidthOut
|
||||
eip.ResourceGroupId = self.ResourceGroupId
|
||||
eip.InternetChargeType = self.InternetChargeType
|
||||
return &eip, nil
|
||||
}
|
||||
@@ -1061,7 +1062,35 @@ func (region *SRegion) ConvertPublicIpToEip(instanceId string) error {
|
||||
}
|
||||
|
||||
func (self *SInstance) ConvertPublicIpToEip() error {
|
||||
return self.host.zone.region.ConvertPublicIpToEip(self.InstanceId)
|
||||
err := self.host.zone.region.ConvertPublicIpToEip(self.InstanceId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "ConvertPublicIpToEip")
|
||||
}
|
||||
return cloudprovider.Wait(time.Second*5, time.Minute*5, func() (bool, error) {
|
||||
self.Refresh()
|
||||
iEip, err := self.GetIEIP()
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "GetIEIP")
|
||||
}
|
||||
if iEip == nil {
|
||||
return false, nil
|
||||
}
|
||||
if iEip.GetMode() == api.EIP_MODE_STANDALONE_EIP {
|
||||
return true, self.host.zone.region.VpcMoveResourceGroup("eip", self.ResourceGroupId, iEip.GetId())
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
}
|
||||
|
||||
func (self *SRegion) VpcMoveResourceGroup(resType, groupId, resId string) error {
|
||||
params := map[string]string{
|
||||
"RegionId": self.RegionId,
|
||||
"ResourceType": resType,
|
||||
"NewResourceGroupId": groupId,
|
||||
"ResourceId": resId,
|
||||
}
|
||||
_, err := self.vpcRequest("MoveResourceGroup", params)
|
||||
return errors.Wrapf(err, "MoveResourceGroup")
|
||||
}
|
||||
|
||||
func (region *SRegion) SetInstanceAutoRenew(instanceId string, autoRenew bool) error {
|
||||
|
||||
@@ -328,7 +328,7 @@ func (lb *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
}
|
||||
return &eip, nil
|
||||
}
|
||||
eips, total, err := lb.region.GetEips("", lb.LoadBalancerId, 0, 1)
|
||||
eips, total, err := lb.region.GetEips("", lb.LoadBalancerId, "", 0, 1)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "lb.region.GetEips(%s)", lb.LoadBalancerId)
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (nat *SNatGateway) GetExpiredAt() time.Time {
|
||||
func (nat *SNatGateway) GetIEips() ([]cloudprovider.ICloudEIP, error) {
|
||||
eips := []SEipAddress{}
|
||||
for {
|
||||
parts, total, err := nat.vpc.region.GetEips("", nat.NatGatewayId, len(eips), 50)
|
||||
parts, total, err := nat.vpc.region.GetEips("", nat.NatGatewayId, "", len(eips), 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -781,13 +781,13 @@ func (self *SRegion) UpdateInstancePassword(instId string, passwd string) error
|
||||
// }
|
||||
|
||||
func (self *SRegion) GetIEips() ([]cloudprovider.ICloudEIP, error) {
|
||||
eips, total, err := self.GetEips("", "", 0, 50)
|
||||
eips, total, err := self.GetEips("", "", "", 0, 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for len(eips) < total {
|
||||
var parts []SEipAddress
|
||||
parts, total, err = self.GetEips("", "", len(eips), 50)
|
||||
parts, total, err = self.GetEips("", "", "", len(eips), 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -801,7 +801,7 @@ func (self *SRegion) GetIEips() ([]cloudprovider.ICloudEIP, error) {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIEipById(eipId string) (cloudprovider.ICloudEIP, error) {
|
||||
eips, total, err := self.GetEips(eipId, "", 0, 1)
|
||||
eips, total, err := self.GetEips(eipId, "", "", 0, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -21,12 +21,14 @@ import (
|
||||
|
||||
func init() {
|
||||
type EipListOptions struct {
|
||||
Id string `help:"Eip id"`
|
||||
AssociateId string `help:"Id of associate resource"`
|
||||
Addr string `help:"Eip "`
|
||||
Offset int `help:"List offset"`
|
||||
Limit int `help:"List limit"`
|
||||
}
|
||||
shellutils.R(&EipListOptions{}, "eip-list", "List eips", func(cli *aliyun.SRegion, args *EipListOptions) error {
|
||||
eips, total, e := cli.GetEips("", args.AssociateId, args.Offset, args.Limit)
|
||||
eips, total, e := cli.GetEips(args.Id, args.AssociateId, args.Addr, args.Offset, args.Limit)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -41,4 +41,14 @@ func init() {
|
||||
return cli.DeleteVpc(args.ID)
|
||||
})
|
||||
|
||||
type VpcMoveResourceGroup struct {
|
||||
ResourceType string `choices:"vpc|eip|bandwidthpackage" default:"vpc"`
|
||||
ResourceGroupId string
|
||||
ResourceId string
|
||||
}
|
||||
|
||||
shellutils.R(&VpcMoveResourceGroup{}, "vpc-mv-resource-group", "Delete vpc", func(cli *aliyun.SRegion, args *VpcMoveResourceGroup) error {
|
||||
return cli.VpcMoveResourceGroup(args.ResourceType, args.ResourceGroupId, args.ResourceId)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user