mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: backport network avaialble addresses (#19112)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -43,6 +43,7 @@ func init() {
|
||||
cmd.Get("change-owner-candidate-domains", &compute_options.NetworkIdOptions{})
|
||||
cmd.Perform("set-class-metadata", &options.ResourceMetadataOptions{})
|
||||
cmd.Perform("switch-wire", &compute_options.NetworkSwitchWireOptions{})
|
||||
cmd.Get("available-addresses", &compute_options.NetworkIdOptions{})
|
||||
|
||||
type NetworkShareOptions struct {
|
||||
ID string `help:"ID or Name of the zone to show"`
|
||||
|
||||
@@ -425,6 +425,14 @@ type GetNetworkAddressesOutput struct {
|
||||
Addresses []SNetworkUsedAddress `json:"addresses"`
|
||||
}
|
||||
|
||||
type GetNetworkAvailableAddressesInput struct {
|
||||
}
|
||||
|
||||
type GetNetworkAvailableAddressesOutput struct {
|
||||
// IP子网地址记录
|
||||
Addresses []string `json:"addresses"`
|
||||
}
|
||||
|
||||
type NetworkSetBgpTypeInput struct {
|
||||
apis.Meta
|
||||
|
||||
|
||||
@@ -2886,6 +2886,28 @@ func (network *SNetwork) GetDetailsAddresses(ctx context.Context, userCred mccli
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func (network *SNetwork) GetDetailsAvailableAddresses(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
input api.GetNetworkAvailableAddressesInput,
|
||||
) (api.GetNetworkAvailableAddressesOutput, error) {
|
||||
var availables []string
|
||||
addrTable := network.GetUsedAddresses()
|
||||
recentUsedAddrTable := GuestnetworkManager.getRecentlyReleasedIPAddresses(network.Id, network.getAllocTimoutDuration())
|
||||
addrRange := network.getIPRange()
|
||||
for addr := addrRange.StartIp(); addr <= addrRange.EndIp(); addr = addr.StepUp() {
|
||||
addrStr := addr.String()
|
||||
if _, ok := addrTable[addrStr]; !ok {
|
||||
if _, ok := recentUsedAddrTable[addrStr]; !ok {
|
||||
availables = append(availables, addrStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
return api.GetNetworkAvailableAddressesOutput{
|
||||
Addresses: availables,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 同步接入云IP子网状态
|
||||
// 本地IDC不支持此操作
|
||||
func (net *SNetwork) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.NetworkSyncInput) (jsonutils.JSONObject, error) {
|
||||
|
||||
Reference in New Issue
Block a user