Hello Sandro Bonazzola,
I'd like you to do a code review. Please visit
http://gerrit.ovirt.org/13475
to review the following change.
Change subject: Fixed set_hosts for handling correctly -H option
......................................................................
Fixed set_hosts for handling correctly -H option
As stated in the method documentation each option set together
is treated as an intersection.
Previously -H caused an error when a host list was supplied due
to a parameter passed with the wrong type to get_hypervisor_data.
Change-Id: Ib9a99fc1e9bd49fbdcfcbdcb18dfddf6cd7e80e6
Bug-Url: https://bugzilla.redhat.com/918020
Signed-off-by: Sandro Bonazzola <[email protected]>
---
M src/__main__.py
1 file changed, 27 insertions(+), 31 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector
refs/changes/75/13475/1
diff --git a/src/__main__.py b/src/__main__.py
index d7cae54..4d57485 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -869,61 +869,57 @@
])
def set_hosts(self):
- """Fetches the hostnames for the supplied cluster or datacenter.
- Filtering is applied if patterns are found in the --hosts, --cluster
- or --datacenters options. There can be multiple patterns in each
- option. Patterns found within the same option are inclusive and
- each each option set together is treated as an intersection.
+ """
+ Fetches the hostnames for the supplied cluster or datacenter.
+ Filtering is applied if patterns are found in the --hosts, --cluster
+ or --datacenters options. There can be multiple patterns in each
+ option. Patterns found within the same option are inclusive and
+ each option set together is treated as an intersection.
"""
- self.conf["hosts"] = set()
+ self.conf['hosts'] = set()
host_patterns, host_others = self._sift_patterns(
- self.conf.get("hosts_list")
+ self.conf.get('hosts_list')
)
- datacenter_patterns = self.conf.get("datacenter", [])
- cluster_patterns = self.conf.get("cluster", [])
+ datacenter_patterns = self.conf.get('datacenter', [])
+ cluster_patterns = self.conf.get('cluster', [])
if host_patterns:
self.conf['host_pattern'] = host_patterns
- if any((
- host_patterns,
- datacenter_patterns,
- cluster_patterns
- )) or not host_others:
- self.conf["hosts"] = self._get_hypervisors_from_api()
-
+ self.conf['hosts'] = self._get_hypervisors_from_api()
+ #Filter all host specified with -H
host_filtered = set()
- cluster_filtered = set()
- datacenter_filtered = set()
-
+ if host_others:
+ host_filtered = set([
+ (dc, cl, h) for dc, cl, h in self.conf['hosts']
+ if h in host_others
+ ])
if host_patterns:
for pattern in host_patterns:
- host_filtered |= self._filter_hosts("host", pattern)
+ host_filtered |= self._filter_hosts('host', pattern)
+ if host_patterns or host_others:
self.conf['hosts'] &= host_filtered
+ #Intersect with hosts belonging to the data centers specified with -d
if datacenter_patterns:
+ datacenter_filtered = set()
for pattern in datacenter_patterns:
datacenter_filtered |= self._filter_hosts(
- "datacenter", pattern
+ 'datacenter', pattern
)
self.conf['hosts'] &= datacenter_filtered
+ #Intersect with hosts belonging to the clusters specified with -c
if cluster_patterns:
+ #remove all hosts that don't match the patterns
+ cluster_filtered = set()
for pattern in cluster_patterns:
- cluster_filtered |= self._filter_hosts("cluster", pattern)
+ cluster_filtered |= self._filter_hosts('cluster', pattern)
self.conf['hosts'] &= cluster_filtered
- # build a set of hostnames that are already in the target host list.
- # So that we can prevent duplication in the next step
- hostnames = set((t[2] for t in self.conf['hosts']))
-
- for hostname in host_others:
- if hostname not in hostnames:
- self.conf['hosts'].add(("", "", hostname))
-
- return bool(self.conf.get("hosts"))
+ return bool(self.conf.get('hosts'))
def list_hosts(self):
--
To view, visit http://gerrit.ovirt.org/13475
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib9a99fc1e9bd49fbdcfcbdcb18dfddf6cd7e80e6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-log-collector
Gerrit-Branch: ovirt-log-collector-3.2
Gerrit-Owner: Kiril Nesenko <[email protected]>
Gerrit-Reviewer: Sandro Bonazzola <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches