mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-30 18:23:35 +08:00
fix: openstack eip dissociate optimized
This commit is contained in:
@@ -875,6 +875,18 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient.
|
||||
return nil, httperrors.NewInvalidStatusError("cannot associate server in status %s", server.Status)
|
||||
}
|
||||
|
||||
if len(self.NetworkId) > 0 {
|
||||
gns, err := server.GetNetworks("")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(errors.Wrap(err, "GetNetworks"))
|
||||
}
|
||||
for _, gn := range gns {
|
||||
if gn.NetworkId == self.NetworkId {
|
||||
return nil, httperrors.NewInputParameterError("cannot associate eip with same network")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
serverRegion := server.getRegion()
|
||||
if serverRegion == nil {
|
||||
return nil, httperrors.NewInputParameterError("server region is not found???")
|
||||
|
||||
@@ -2808,6 +2808,18 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T
|
||||
return nil, httperrors.NewInputParameterError("cannot associate eip and instance in different region")
|
||||
}
|
||||
|
||||
if len(eip.NetworkId) > 0 {
|
||||
gns, err := self.GetNetworks("")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(errors.Wrap(err, "GetNetworks"))
|
||||
}
|
||||
for _, gn := range gns {
|
||||
if gn.NetworkId == eip.NetworkId {
|
||||
return nil, httperrors.NewInputParameterError("cannot associate eip with same network")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eipZone := eip.GetZone()
|
||||
if eipZone != nil {
|
||||
insZone := self.getZone()
|
||||
|
||||
@@ -179,7 +179,18 @@ func (eip *SEipAddress) GetAssociationType() string {
|
||||
}
|
||||
|
||||
func (eip *SEipAddress) GetAssociationExternalId() string {
|
||||
return eip.PortDetails.DeviceId
|
||||
if len(eip.PortDetails.DeviceId) > 0 {
|
||||
return eip.PortDetails.DeviceId
|
||||
}
|
||||
if len(eip.PortId) > 0 {
|
||||
port, err := eip.region.GetPort(eip.PortId)
|
||||
if err != nil {
|
||||
log.Errorf("failed to get eip port %s info", port.DeviceID)
|
||||
return ""
|
||||
}
|
||||
return port.DeviceID
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (eip *SEipAddress) GetBillingType() string {
|
||||
|
||||
@@ -161,6 +161,15 @@ func (region *SRegion) GetINetworkInterfaces() ([]cloudprovider.ICloudNetworkInt
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetPort(portId string) (*SPort, error) {
|
||||
_, resp, err := region.Get("network", "/v2.0/ports/"+portId, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
port := &SPort{}
|
||||
return port, resp.Unmarshal(port, "port")
|
||||
}
|
||||
|
||||
func (region *SRegion) GetPorts(macAddress string) ([]SPort, error) {
|
||||
base := fmt.Sprintf("/v2.0/ports")
|
||||
params := url.Values{}
|
||||
|
||||
@@ -32,4 +32,17 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type PortIdOptions struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
shellutils.R(&PortIdOptions{}, "port-show", "Show port", func(cli *openstack.SRegion, args *PortIdOptions) error {
|
||||
port, err := cli.GetPort(args.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(port)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user