From 5efa4d29e3e5dc69757a38519e5aa48e45fbf7cc Mon Sep 17 00:00:00 2001 From: soarpenguin Date: Fri, 9 Oct 2015 11:19:24 +0800 Subject: [PATCH 1/2] 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 37a4bf1dea..d3ed90c68b 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 2d4cd39d5b..b6085354e6 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 b91d9f05a2..4c57edc161 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 2a2a3c3193..93ef7378b1 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 bc6a2bc489..81601e5606 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() From b11ea1738557638f845032855850b71461168e04 Mon Sep 17 00:00:00 2001 From: soarpenguin Date: Fri, 9 Oct 2015 12:46:31 +0800 Subject: [PATCH 2/2] fix classmethod syntax error. --- lib/ansible/cli/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index bf5e33e6be..cffdccb3a9 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -473,13 +473,13 @@ class CLI(object): pass @classmethod - def tty_ify(self, text): + def tty_ify(cls, text): - t = self._ITALIC.sub("`" + r"\1" + "'", text) # I(word) => `word' - t = self._BOLD.sub("*" + r"\1" + "*", t) # B(word) => *word* - t = self._MODULE.sub("[" + r"\1" + "]", t) # M(word) => [word] - t = self._URL.sub(r"\1", t) # U(word) => word - t = self._CONST.sub("`" + r"\1" + "'", t) # C(word) => `word' + t = cls._ITALIC.sub("`" + r"\1" + "'", text) # I(word) => `word' + t = cls._BOLD.sub("*" + r"\1" + "*", t) # B(word) => *word* + t = cls._MODULE.sub("[" + r"\1" + "]", t) # M(word) => [word] + t = cls._URL.sub(r"\1", t) # U(word) => word + t = cls._CONST.sub("`" + r"\1" + "'", t) # C(word) => `word' return t