LIBCLOUD-820 fixed lint errors Closes #788
Signed-off-by: Tomaz Muraus <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/13e3b6e2 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/13e3b6e2 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/13e3b6e2 Branch: refs/heads/trunk Commit: 13e3b6e2c0e134350f6a50ac0af7a8e4cd819d36 Parents: bff3f29 Author: René Kjellerup <[email protected]> Authored: Fri May 27 17:27:16 2016 -0700 Committer: Tomaz Muraus <[email protected]> Committed: Sat May 28 19:26:14 2016 +0200 ---------------------------------------------------------------------- libcloud/compute/drivers/libvirt_driver.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/13e3b6e2/libcloud/compute/drivers/libvirt_driver.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/libvirt_driver.py b/libcloud/compute/drivers/libvirt_driver.py index d586d82..006a13b 100644 --- a/libcloud/compute/drivers/libvirt_driver.py +++ b/libcloud/compute/drivers/libvirt_driver.py @@ -267,16 +267,17 @@ class LibvirtNodeDriver(NodeDriver): try: cmd = ['arp', '-an'] child = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.PIPE) stdout, _ = child.communicate() arp_table = self._parse_arp_table(arp_output=stdout) except OSError as e: if e.errno == 2: cmd = ['ip', 'neigh'] child = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.PIPE) stdout, _ = child.communicate() - arp_table = self._parse_arp_table(arp_output=stdout,re_match='(.*?)\s+.*lladdr\s+(.*?)\s+') + arp_table = self._parse_arp_table(arp_output=stdout, + arp_cmd='ip') for mac_address in mac_addresses: if mac_address in arp_table: @@ -323,7 +324,7 @@ class LibvirtNodeDriver(NodeDriver): return result - def _parse_arp_table(self, arp_output, re_match='.*?\((.*?)\) at (.*?)\s+'): + def _parse_arp_table(self, arp_output, arp_cmd='arp'): """ Parse arp command output and return a dictionary which maps mac address to an IP address. @@ -331,7 +332,10 @@ class LibvirtNodeDriver(NodeDriver): :return: Dictionary which maps mac address to IP address. :rtype: ``dict`` """ - ip_mac = re.compile(re_match) + re_match = {} + re_match['arp'] = '.*?\((.*?)\) at (.*?)\s+' + re_match['ip'] = '(.*?)\s+.*lladdr\s+(.*?)\s+' + ip_mac = re.compile(re_match[arp_cmd]) lines = arp_output.split('\n') arp_table = defaultdict(list)
