Revision 53195377
b/lib/client/gnt_network.py | ||
---|---|---|
60 | 60 |
""" |
61 | 61 |
(network_name, ) = args |
62 | 62 |
|
63 |
if opts.network is None: |
|
64 |
raise errors.OpPrereqError("The --network option must be given", |
|
65 |
errors.ECODE_INVAL) |
|
66 |
|
|
67 | 63 |
if opts.tags is not None: |
68 | 64 |
tags = opts.tags.split(",") |
69 | 65 |
else: |
... | ... | |
214 | 210 |
for (name, network, gateway, network6, gateway6, |
215 | 211 |
mac_prefix, free_count, reserved_count, |
216 | 212 |
mapping, group_list, instances, ext_res, serial, uuid) in result: |
217 |
size = free_count + reserved_count
|
|
213 |
pool = free_count or reserved_count or mapping or reserved_count
|
|
218 | 214 |
ToStdout("Network name: %s", name) |
219 | 215 |
ToStdout("UUID: %s", uuid) |
220 | 216 |
ToStdout("Serial number: %d", serial) |
... | ... | |
223 | 219 |
ToStdout(" IPv6 Subnet: %s", network6) |
224 | 220 |
ToStdout(" IPv6 Gateway: %s", gateway6) |
225 | 221 |
ToStdout(" Mac Prefix: %s", mac_prefix) |
226 |
ToStdout(" Size: %d", size) |
|
227 |
ToStdout(" Free: %d (%.2f%%)", free_count, |
|
228 |
100 * float(free_count) / float(size)) |
|
229 |
ToStdout(" Usage map:") |
|
230 |
idx = 0 |
|
231 |
for line in textwrap.wrap(mapping, width=64): |
|
232 |
ToStdout(" %s %s %d", str(idx).rjust(3), line.ljust(64), idx + 63) |
|
233 |
idx += 64 |
|
234 |
ToStdout(" (X) used (.) free") |
|
235 |
|
|
236 |
if ext_res: |
|
237 |
ToStdout(" externally reserved IPs:") |
|
238 |
for line in textwrap.wrap(ext_res, width=64): |
|
239 |
ToStdout(" %s" % line) |
|
222 |
if pool: |
|
223 |
size = free_count + reserved_count |
|
224 |
ToStdout(" Size: %d", size) |
|
225 |
ToStdout(" Free: %d (%.2f%%)", free_count, |
|
226 |
100 * float(free_count) / float(size)) |
|
227 |
ToStdout(" Usage map:") |
|
228 |
idx = 0 |
|
229 |
for line in textwrap.wrap(mapping, width=64): |
|
230 |
ToStdout(" %s %s %d", str(idx).rjust(3), line.ljust(64), idx + 63) |
|
231 |
idx += 64 |
|
232 |
ToStdout(" (X) used (.) free") |
|
233 |
|
|
234 |
if ext_res: |
|
235 |
ToStdout(" externally reserved IPs:") |
|
236 |
for line in textwrap.wrap(ext_res, width=64): |
|
237 |
ToStdout(" %s" % line) |
|
240 | 238 |
|
241 | 239 |
if group_list: |
242 | 240 |
ToStdout(" connected to node groups:") |
b/lib/cmdlib/network.py | ||
---|---|---|
110 | 110 |
self.add_locks[locking.LEVEL_NETWORK] = self.network_uuid |
111 | 111 |
|
112 | 112 |
def CheckPrereq(self): |
113 |
if self.op.network is None: |
|
114 |
raise errors.OpPrereqError("Network must be given", |
|
115 |
errors.ECODE_INVAL) |
|
116 |
|
|
117 | 113 |
try: |
118 | 114 |
existing_uuid = self.cfg.LookupNetwork(self.op.network_name) |
119 | 115 |
except errors.OpPrereqError: |
... | ... | |
137 | 133 |
uuid=self.network_uuid) |
138 | 134 |
|
139 | 135 |
# Initialize the associated address pool |
140 |
try: |
|
141 |
self.pool = network.AddressPool.InitializeNetwork(self.nobj) |
|
142 |
except errors.AddressPoolError, err: |
|
143 |
raise errors.OpPrereqError("Cannot create IP address pool for network" |
|
144 |
" '%s': %s" % (self.op.network_name, err)) |
|
136 |
# This raises the appropriate OpPrereqError |
|
137 |
self.pool = network.Network(self.nobj) |
|
145 | 138 |
|
146 | 139 |
def BuildHooksEnv(self): |
147 | 140 |
"""Build hooks env. |
... | ... | |
278 | 271 |
"""Check prerequisites. |
279 | 272 |
|
280 | 273 |
""" |
281 |
self.network = self.cfg.GetNetwork(self.network_uuid)
|
|
274 |
self.nobj = self.cfg.GetNetwork(self.network_uuid)
|
|
282 | 275 |
self.gateway = self.network.gateway |
283 | 276 |
self.mac_prefix = self.network.mac_prefix |
284 | 277 |
self.network6 = self.network.network6 |
285 | 278 |
self.gateway6 = self.network.gateway6 |
286 | 279 |
self.tags = self.network.tags |
287 | 280 |
|
288 |
self.pool = network.AddressPool(self.network)
|
|
281 |
self.pool = network.Network(self.nobj)
|
|
289 | 282 |
|
290 | 283 |
if self.op.gateway: |
291 | 284 |
if self.op.gateway == constants.VALUE_NONE: |
... | ... | |
293 | 286 |
else: |
294 | 287 |
self.gateway = self.op.gateway |
295 | 288 |
|
289 |
network.Network.Check(self.gateway, self.network) |
|
290 |
|
|
296 | 291 |
if self.op.mac_prefix: |
297 | 292 |
if self.op.mac_prefix == constants.VALUE_NONE: |
298 | 293 |
self.mac_prefix = None |
... | ... | |
312 | 307 |
else: |
313 | 308 |
self.network6 = self.op.network6 |
314 | 309 |
|
310 |
network.Network.Check(self.gateway, self.network) |
|
311 |
|
|
315 | 312 |
def BuildHooksEnv(self): |
316 | 313 |
"""Build hooks env. |
317 | 314 |
|
... | ... | |
453 | 450 |
|
454 | 451 |
if query.NETQ_STATS in self.requested_data: |
455 | 452 |
stats = \ |
456 |
dict((uuid, |
|
457 |
self._GetStats(network.AddressPool(all_networks[uuid]))) |
|
453 |
dict((uuid, network.Network(all_networks[uuid]).GetStats()) |
|
458 | 454 |
for uuid in network_uuids) |
459 | 455 |
else: |
460 | 456 |
stats = None |
... | ... | |
615 | 611 |
|
616 | 612 |
# check only if not already connected |
617 | 613 |
elif self.op.conflicts_check: |
618 |
pool = network.AddressPool(self.cfg.GetNetwork(self.network_uuid))
|
|
614 |
pool = network.Network(self.cfg.GetNetwork(self.network_uuid))
|
|
619 | 615 |
|
620 | 616 |
_NetworkConflictCheck(self, lambda nic: pool.Contains(nic.ip), |
621 | 617 |
"connect to", owned_instances) |
b/lib/config.py | ||
---|---|---|
341 | 341 |
|
342 | 342 |
""" |
343 | 343 |
nobj = self._UnlockedGetNetwork(net_uuid) |
344 |
pool = network.AddressPool(nobj)
|
|
344 |
pool = network.Network(nobj)
|
|
345 | 345 |
if action == constants.RESERVE_ACTION: |
346 | 346 |
pool.Reserve(address, external) |
347 | 347 |
elif action == constants.RELEASE_ACTION: |
... | ... | |
374 | 374 |
|
375 | 375 |
""" |
376 | 376 |
nobj = self._UnlockedGetNetwork(net_uuid) |
377 |
pool = network.AddressPool(nobj)
|
|
377 |
pool = network.Network(nobj)
|
|
378 | 378 |
|
379 | 379 |
def gen_one(): |
380 | 380 |
try: |
... | ... | |
393 | 393 |
|
394 | 394 |
""" |
395 | 395 |
nobj = self._UnlockedGetNetwork(net_uuid) |
396 |
pool = network.AddressPool(nobj)
|
|
396 |
pool = network.Network(nobj)
|
|
397 | 397 |
if (address, net_uuid) in self._AllIPs(): |
398 | 398 |
raise errors.ConfigurationError("Address '%s' already exists in" |
399 | 399 |
" network '%s'" % (address, nobj.name)) |
... | ... | |
2651 | 2651 |
node_info = self._UnlockedGetNodeInfo(node) |
2652 | 2652 |
nodegroup_info = self._UnlockedGetNodeGroup(node_info.group) |
2653 | 2653 |
for net_uuid in nodegroup_info.networks.keys(): |
2654 |
net_info = self._UnlockedGetNetwork(net_uuid)
|
|
2655 |
pool = network.AddressPool(net_info)
|
|
2654 |
nobj = self._UnlockedGetNetwork(net_uuid)
|
|
2655 |
pool = network.Network(nobj)
|
|
2656 | 2656 |
if pool.Contains(ip): |
2657 |
return (net_info.name, nodegroup_info.networks[net_uuid])
|
|
2657 |
return (nobj.name, nodegroup_info.networks[net_uuid])
|
|
2658 | 2658 |
|
2659 | 2659 |
return (None, None) |
b/lib/opcodes.py | ||
---|---|---|
2100 | 2100 |
OP_DSC_FIELD = "network_name" |
2101 | 2101 |
OP_PARAMS = [ |
2102 | 2102 |
_PNetworkName, |
2103 |
("network", ht.NoDefault, _TIpNetwork4, "IPv4 subnet"),
|
|
2103 |
("network", None, ht.TMaybe(_TIpNetwork4), "IPv4 subnet"),
|
|
2104 | 2104 |
("gateway", None, ht.TMaybe(_TIpAddress4), "IPv4 gateway"), |
2105 | 2105 |
("network6", None, ht.TMaybe(_TIpNetwork6), "IPv6 subnet"), |
2106 | 2106 |
("gateway6", None, ht.TMaybe(_TIpAddress6), "IPv6 gateway"), |
b/lib/query.py | ||
---|---|---|
2658 | 2658 |
|
2659 | 2659 |
_NETWORK_SIMPLE_FIELDS = { |
2660 | 2660 |
"name": ("Network", QFT_TEXT, 0, "Name"), |
2661 |
"network": ("Subnet", QFT_TEXT, 0, "IPv4 subnet"),
|
|
2661 |
"network": ("Subnet", QFT_OTHER, 0, "IPv4 subnet"),
|
|
2662 | 2662 |
"gateway": ("Gateway", QFT_OTHER, 0, "IPv4 gateway"), |
2663 | 2663 |
"network6": ("IPv6Subnet", QFT_OTHER, 0, "IPv6 subnet"), |
2664 | 2664 |
"gateway6": ("IPv6Gateway", QFT_OTHER, 0, "IPv6 gateway"), |
Also available in: Unified diff