From 5efa4d29e3e5dc69757a38519e5aa48e45fbf7cc Mon Sep 17 00:00:00 2001 From: soarpenguin Date: Fri, 9 Oct 2015 11:19:24 +0800 Subject: [PATCH] fix some warning of undefined name. --- lib/ansible/module_utils/gce.py | 1 + lib/ansible/module_utils/vca.py | 7 ++++--- lib/ansible/new_inventory/__init__.py | 5 ++++- lib/ansible/plugins/inventory/directory.py | 4 ++-- lib/ansible/plugins/inventory/ini.py | 4 ++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/ansible/module_utils/gce.py b/lib/ansible/module_utils/gce.py index 37a4bf1deaf..d3ed90c68b2 100644 --- a/lib/ansible/module_utils/gce.py +++ b/lib/ansible/module_utils/gce.py @@ -28,6 +28,7 @@ # import pprint +from libcloud.compute.providers import get_driver USER_AGENT_PRODUCT="Ansible-gce" USER_AGENT_VERSION="v1" diff --git a/lib/ansible/module_utils/vca.py b/lib/ansible/module_utils/vca.py index 2d4cd39d5bc..b6085354e68 100644 --- a/lib/ansible/module_utils/vca.py +++ b/lib/ansible/module_utils/vca.py @@ -76,7 +76,7 @@ class VcaAnsibleModule(AnsibleModule): gateway_name = self.params['gateway_name'] _gateway = self.vca.get_gateway(vdc_name, gateway_name) if not _gateway: - raise VcaError('vca instance has no gateway named %s' % name) + raise VcaError('vca instance has no gateway named %s' % gateway_name) self._gateway = _gateway return _gateway @@ -84,9 +84,10 @@ class VcaAnsibleModule(AnsibleModule): def vdc(self): if self._vdc is not None: return self._vdc - _vdc = self.vca.get_vdc(self.params['vdc_name']) + vdc_name = self.params['vdc_name'] + _vdc = self.vca.get_vdc(vdc_name) if not _vdc: - raise VcaError('vca instance has no vdc named %s' % name) + raise VcaError('vca instance has no vdc named %s' % vdc_name) self._vdc = _vdc return _vdc diff --git a/lib/ansible/new_inventory/__init__.py b/lib/ansible/new_inventory/__init__.py index b91d9f05a28..4c57edc1613 100644 --- a/lib/ansible/new_inventory/__init__.py +++ b/lib/ansible/new_inventory/__init__.py @@ -21,10 +21,13 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import re +import sys from ansible import constants as C from ansible.inventory.group import Group from .host import Host from ansible.plugins.inventory.aggregate import InventoryAggregateParser +from ansible import errors class Inventory: ''' @@ -98,7 +101,7 @@ class Inventory: ''' for group in self._groups: - if group.name == group_name: + if group.name == groupname: return group return None diff --git a/lib/ansible/plugins/inventory/directory.py b/lib/ansible/plugins/inventory/directory.py index 2a2a3c31933..93ef7378b10 100644 --- a/lib/ansible/plugins/inventory/directory.py +++ b/lib/ansible/plugins/inventory/directory.py @@ -47,9 +47,9 @@ class InventoryDirectoryParser(InventoryAggregateParser): if filename in ("host_vars", "group_vars", "vars_plugins"): continue fullpath = os.path.join(directory, filename) - new_names.append(fullpath) + filtered_names.append(fullpath) - super(InventoryDirectoryParser, self).__init__(new_names) + super(InventoryDirectoryParser, self).__init__(filtered_names) def parse(self): return super(InventoryDirectoryParser, self).parse() diff --git a/lib/ansible/plugins/inventory/ini.py b/lib/ansible/plugins/inventory/ini.py index bc6a2bc4894..81601e5606c 100644 --- a/lib/ansible/plugins/inventory/ini.py +++ b/lib/ansible/plugins/inventory/ini.py @@ -47,9 +47,9 @@ class InventoryIniParser(InventoryAggregateParser): if filename in ("host_vars", "group_vars", "vars_plugins"): continue fullpath = os.path.join(directory, filename) - new_names.append(fullpath) + filtered_names.append(fullpath) - super(InventoryDirectoryParser, self).__init__(new_names) + super(InventoryDirectoryParser, self).__init__(filtered_names) def parse(self): return super(InventoryDirectoryParser, self).parse()