From 246f300d04c6f11d1541337683b9caed119ed2fa Mon Sep 17 00:00:00 2001 From: Apollon Oikonomopoulos <apollon@noc.grnet.gr> Date: Thu, 9 Jun 2011 13:26:01 +0300 Subject: [PATCH] gnt-network info: include external reservations Also include the list of externally reserved IP addresses in an address pool in the output of gnt-network info <network_name>. Signed-off-by: Apollon Oikonomopoulos <apollon@noc.grnet.gr> --- lib/client/gnt_network.py | 10 ++++++++-- lib/cmdlib.py | 1 + lib/network.py | 5 +++++ lib/query.py | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/client/gnt_network.py b/lib/client/gnt_network.py index 318e9441a..a1d3dfdaa 100644 --- a/lib/client/gnt_network.py +++ b/lib/client/gnt_network.py @@ -140,11 +140,12 @@ def ShowNetworkConfig(opts, args): cl = GetClient() result = cl.QueryNetworks(fields=["name", "network", "gateway", "free_count", "reserved_count", - "map", "group_links", "inst_list"], + "map", "group_links", "inst_list", + "external_reservations"], names=args, use_locking=False) for (name, network, gateway, free_count, reserved_count, - map, group_links, instances) in result: + map, group_links, instances, ext_res) in result: size = free_count + reserved_count ToStdout("Network name: %s", name) ToStdout(" subnet: %s", network) @@ -159,6 +160,11 @@ def ShowNetworkConfig(opts, args): idx += 64 ToStdout(" (X) used (.) free") + if ext_res: + ToStdout(" externally reserved IPs:") + for line in wrap(ext_res, width=64): + ToStdout(" %s" % line) + if group_links: ToStdout(" connected to node groups:") for conn in group_links: diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 88b1f6f50..3a8a2c166 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -12146,6 +12146,7 @@ class _NetworkQuery(_QueryBase): "free_count": pool.GetFreeCount(), "reserved_count": pool.GetReservedCount(), "map": pool.GetMap(), + "external_reservations": ", ".join(pool.GetExternalReservations()), } return query.NetworkQueryData([self._all_networks[uuid] diff --git a/lib/network.py b/lib/network.py index 062bcb60d..ee9c7bf6a 100644 --- a/lib/network.py +++ b/lib/network.py @@ -162,6 +162,11 @@ class AddressPool(object): return _iter_free().next + def GetExternalReservations(self): + """Returns a list of all externally reserved addresses""" + idxs = self.ext_reservations.search("1") + return [str(self.network[idx]) for idx in idxs] + @classmethod def InitializeNetwork(cls, net): """Initialize an L{objects.Network} object diff --git a/lib/query.py b/lib/query.py index 688a851d2..6c23396c2 100644 --- a/lib/query.py +++ b/lib/query.py @@ -1343,6 +1343,7 @@ _NETWORK_STATS_FIELDS = { "free_count": ("FreeCount", QFT_NUMBER), "reserved_count": ("ReservedCount", QFT_NUMBER), "map": ("Map", QFT_TEXT), + "external_reservations": ("ExternalReservations", QFT_TEXT), } -- GitLab