Revision 60a7335b
b/lib/cmdlib.py | ||
---|---|---|
16423 | 16423 |
|
16424 | 16424 |
def ExpandNames(self, lu): |
16425 | 16425 |
lu.needed_locks = {} |
16426 |
lu.share_locks = _ShareAll() |
|
16426 | 16427 |
|
16427 |
self._all_networks = lu.cfg.GetAllNetworksInfo() |
|
16428 |
name_to_uuid = dict((n.name, n.uuid) for n in self._all_networks.values()) |
|
16428 |
self.do_locking = self.use_locking |
|
16429 | 16429 |
|
16430 |
if not self.names: |
|
16431 |
self.wanted = [name_to_uuid[name] |
|
16432 |
for name in utils.NiceSort(name_to_uuid.keys())] |
|
16433 |
else: |
|
16434 |
# Accept names to be either names or UUIDs. |
|
16430 |
all_networks = lu.cfg.GetAllNetworksInfo() |
|
16431 |
name_to_uuid = dict((n.name, n.uuid) for n in all_networks.values()) |
|
16432 |
|
|
16433 |
if self.names: |
|
16435 | 16434 |
missing = [] |
16436 | 16435 |
self.wanted = [] |
16437 |
all_uuid = frozenset(self._all_networks.keys()) |
|
16438 | 16436 |
|
16439 | 16437 |
for name in self.names: |
16440 |
if name in all_uuid: |
|
16441 |
self.wanted.append(name) |
|
16442 |
elif name in name_to_uuid: |
|
16438 |
if name in name_to_uuid: |
|
16443 | 16439 |
self.wanted.append(name_to_uuid[name]) |
16444 | 16440 |
else: |
16445 | 16441 |
missing.append(name) |
... | ... | |
16447 | 16443 |
if missing: |
16448 | 16444 |
raise errors.OpPrereqError("Some networks do not exist: %s" % missing, |
16449 | 16445 |
errors.ECODE_NOENT) |
16446 |
else: |
|
16447 |
self.wanted = locking.ALL_SET |
|
16448 |
|
|
16449 |
if self.do_locking: |
|
16450 |
lu.needed_locks[locking.LEVEL_NETWORK] = self.wanted |
|
16451 |
if query.NETQ_INST in self.requested_data: |
|
16452 |
lu.needed_locks[locking.LEVEL_INSTANCE] = locking.ALL_SET |
|
16453 |
if query.NETQ_GROUP in self.requested_data: |
|
16454 |
lu.needed_locks[locking.LEVEL_NODEGROUP] = locking.ALL_SET |
|
16450 | 16455 |
|
16451 | 16456 |
def DeclareLocks(self, lu, level): |
16452 | 16457 |
pass |
... | ... | |
16455 | 16460 |
"""Computes the list of networks and their attributes. |
16456 | 16461 |
|
16457 | 16462 |
""" |
16463 |
all_networks = lu.cfg.GetAllNetworksInfo() |
|
16464 |
|
|
16465 |
network_uuids = self._GetNames(lu, all_networks.keys(), |
|
16466 |
locking.LEVEL_NETWORK) |
|
16467 |
|
|
16468 |
name_to_uuid = dict((n.name, n.uuid) for n in all_networks.values()) |
|
16469 |
|
|
16458 | 16470 |
do_instances = query.NETQ_INST in self.requested_data |
16459 |
do_groups = do_instances or (query.NETQ_GROUP in self.requested_data)
|
|
16471 |
do_groups = query.NETQ_GROUP in self.requested_data
|
|
16460 | 16472 |
|
16461 | 16473 |
network_to_instances = None |
16474 |
network_to_groups = None |
|
16462 | 16475 |
|
16463 | 16476 |
# For NETQ_GROUP, we need to map network->[groups] |
16464 | 16477 |
if do_groups: |
16465 | 16478 |
all_groups = lu.cfg.GetAllNodeGroupsInfo() |
16466 |
network_to_groups = dict((uuid, []) for uuid in self.wanted) |
|
16467 |
|
|
16468 |
if do_instances: |
|
16469 |
all_instances = lu.cfg.GetAllInstancesInfo() |
|
16470 |
all_nodes = lu.cfg.GetAllNodesInfo() |
|
16471 |
network_to_instances = dict((uuid, []) for uuid in self.wanted) |
|
16472 |
|
|
16473 |
for group in all_groups.values(): |
|
16474 |
if do_instances: |
|
16475 |
group_nodes = [node.name for node in all_nodes.values() if |
|
16476 |
node.group == group.uuid] |
|
16477 |
group_instances = [instance for instance in all_instances.values() |
|
16478 |
if instance.primary_node in group_nodes] |
|
16479 |
|
|
16480 |
for net_uuid in self.wanted: |
|
16479 |
network_to_groups = dict((uuid, []) for uuid in network_uuids) |
|
16480 |
for _, group in all_groups.iteritems(): |
|
16481 |
for net_uuid in network_uuids: |
|
16481 | 16482 |
netparams = group.networks.get(net_uuid, None) |
16482 | 16483 |
if netparams: |
16483 | 16484 |
info = (group.name, netparams[constants.NIC_MODE], |
... | ... | |
16485 | 16486 |
|
16486 | 16487 |
network_to_groups[net_uuid].append(info) |
16487 | 16488 |
|
16488 |
if do_instances: |
|
16489 |
for instance in group_instances: |
|
16490 |
for nic in instance.nics: |
|
16491 |
if nic.network == self._all_networks[net_uuid].name: |
|
16492 |
network_to_instances[net_uuid].append(instance.name) |
|
16493 |
break |
|
16494 |
else: |
|
16495 |
network_to_groups = None |
|
16489 |
if do_instances: |
|
16490 |
all_instances = lu.cfg.GetAllInstancesInfo() |
|
16491 |
network_to_instances = dict((uuid, []) for uuid in network_uuids) |
|
16492 |
for instance in all_instances.values(): |
|
16493 |
for nic in instance.nics: |
|
16494 |
if nic.network: |
|
16495 |
net_uuid = name_to_uuid[nic.network] |
|
16496 |
if net_uuid in network_uuids: |
|
16497 |
network_to_instances[net_uuid].append(instance.name) |
|
16498 |
break |
|
16496 | 16499 |
|
16497 | 16500 |
if query.NETQ_STATS in self.requested_data: |
16498 | 16501 |
stats = \ |
16499 | 16502 |
dict((uuid, |
16500 |
self._GetStats(network.AddressPool(self._all_networks[uuid])))
|
|
16501 |
for uuid in self.wanted)
|
|
16503 |
self._GetStats(network.AddressPool(all_networks[uuid]))) |
|
16504 |
for uuid in network_uuids)
|
|
16502 | 16505 |
else: |
16503 | 16506 |
stats = None |
16504 | 16507 |
|
16505 |
return query.NetworkQueryData([self._all_networks[uuid]
|
|
16506 |
for uuid in self.wanted],
|
|
16508 |
return query.NetworkQueryData([all_networks[uuid] |
|
16509 |
for uuid in network_uuids],
|
|
16507 | 16510 |
network_to_groups, |
16508 | 16511 |
network_to_instances, |
16509 | 16512 |
stats) |
Also available in: Unified diff