fix: backport network avaialble addresses (#19112)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2023-12-26 20:43:37 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 8e6d5a16e3
commit f6c23817a6
3 changed files with 31 additions and 0 deletions
+1
View File
@@ -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"`
+8
View File
@@ -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
+22
View File
@@ -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) {