From f88a8cfb7b71a54c3d792f52d9123c4907752372 Mon Sep 17 00:00:00 2001 From: Akash Gangil Date: Wed, 2 Dec 2015 03:45:21 -0800 Subject: [PATCH] Use prettytable and rename python-nsxadmin - to _ This patch dumps the tabulate package in favor of prettytable since its a global requirement and is used by all openstack clients. So users won't have to install a package separately. We also refactor python-nsxadmin to python_nsxadmin. Since setup.cfg does not like names with '-' Change-Id: Ib510c7b40673b747e0712a656d19e18e4ff4accb --- .../admin/plugins => }/__init__.py | 0 .../README.rst | 0 .../common => python_nsxadmin}/__init__.py | 0 .../admin/__init__.py | 0 .../admin/plugins}/__init__.py | 0 .../admin/plugins/common}/__init__.py | 0 .../admin/plugins/common/constants.py | 0 .../admin/plugins/common/formatters.py | 12 +++--- .../admin/plugins/common/utils.py | 0 .../admin/plugins/nsxv}/__init__.py | 0 .../admin/plugins/nsxv}/resources/__init__.py | 0 .../plugins/nsxv/resources/dhcp_binding.py | 14 ++++--- .../admin/plugins/nsxv/resources/edges.py | 40 +++++++++---------- .../nsxv/resources/spoofguard_policy.py | 24 ++++++----- .../admin/plugins/nsxv/resources/utils.py | 0 .../admin/plugins/nsxv3/__init__.py | 0 .../admin/plugins/nsxv3/resources/__init__.py | 0 .../plugins/nsxv3/resources/securitygroups.py | 0 .../admin/shell.py | 7 ++-- .../admin/version.py | 0 .../requirements.txt | 0 .../setup.cfg | 0 .../setup.py | 0 23 files changed, 52 insertions(+), 45 deletions(-) rename tools/{python-nsxadmin/admin/plugins => }/__init__.py (100%) rename tools/{python-nsxadmin => python_nsxadmin}/README.rst (100%) rename tools/{python-nsxadmin/admin/plugins/common => python_nsxadmin}/__init__.py (100%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/__init__.py (100%) rename tools/{python-nsxadmin/admin/plugins/nsxv => python_nsxadmin/admin/plugins}/__init__.py (100%) rename tools/{python-nsxadmin/admin/plugins/nsxv/resources => python_nsxadmin/admin/plugins/common}/__init__.py (100%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/plugins/common/constants.py (100%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/plugins/common/formatters.py (89%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/plugins/common/utils.py (100%) rename tools/{python-nsxadmin/admin/plugins/nsxv3 => python_nsxadmin/admin/plugins/nsxv}/__init__.py (100%) rename tools/{python-nsxadmin/admin/plugins/nsxv3 => python_nsxadmin/admin/plugins/nsxv}/resources/__init__.py (100%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/plugins/nsxv/resources/dhcp_binding.py (89%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/plugins/nsxv/resources/edges.py (80%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/plugins/nsxv/resources/spoofguard_policy.py (84%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/plugins/nsxv/resources/utils.py (100%) create mode 100644 tools/python_nsxadmin/admin/plugins/nsxv3/__init__.py create mode 100644 tools/python_nsxadmin/admin/plugins/nsxv3/resources/__init__.py rename tools/{python-nsxadmin => python_nsxadmin}/admin/plugins/nsxv3/resources/securitygroups.py (100%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/shell.py (97%) rename tools/{python-nsxadmin => python_nsxadmin}/admin/version.py (100%) rename tools/{python-nsxadmin => python_nsxadmin}/requirements.txt (100%) rename tools/{python-nsxadmin => python_nsxadmin}/setup.cfg (100%) rename tools/{python-nsxadmin => python_nsxadmin}/setup.py (100%) diff --git a/tools/python-nsxadmin/admin/plugins/__init__.py b/tools/__init__.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/__init__.py rename to tools/__init__.py diff --git a/tools/python-nsxadmin/README.rst b/tools/python_nsxadmin/README.rst similarity index 100% rename from tools/python-nsxadmin/README.rst rename to tools/python_nsxadmin/README.rst diff --git a/tools/python-nsxadmin/admin/plugins/common/__init__.py b/tools/python_nsxadmin/__init__.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/common/__init__.py rename to tools/python_nsxadmin/__init__.py diff --git a/tools/python-nsxadmin/admin/__init__.py b/tools/python_nsxadmin/admin/__init__.py similarity index 100% rename from tools/python-nsxadmin/admin/__init__.py rename to tools/python_nsxadmin/admin/__init__.py diff --git a/tools/python-nsxadmin/admin/plugins/nsxv/__init__.py b/tools/python_nsxadmin/admin/plugins/__init__.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/nsxv/__init__.py rename to tools/python_nsxadmin/admin/plugins/__init__.py diff --git a/tools/python-nsxadmin/admin/plugins/nsxv/resources/__init__.py b/tools/python_nsxadmin/admin/plugins/common/__init__.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/nsxv/resources/__init__.py rename to tools/python_nsxadmin/admin/plugins/common/__init__.py diff --git a/tools/python-nsxadmin/admin/plugins/common/constants.py b/tools/python_nsxadmin/admin/plugins/common/constants.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/common/constants.py rename to tools/python_nsxadmin/admin/plugins/common/constants.py diff --git a/tools/python-nsxadmin/admin/plugins/common/formatters.py b/tools/python_nsxadmin/admin/plugins/common/formatters.py similarity index 89% rename from tools/python-nsxadmin/admin/plugins/common/formatters.py rename to tools/python_nsxadmin/admin/plugins/common/formatters.py index c3f8c3c0b6..0975b0436c 100644 --- a/tools/python-nsxadmin/admin/plugins/common/formatters.py +++ b/tools/python_nsxadmin/admin/plugins/common/formatters.py @@ -14,11 +14,11 @@ import logging -from tabulate import tabulate - from oslo_config import cfg from oslo_serialization import jsonutils +import prettytable + from vmware_nsx._i18n import _LI LOG = logging.getLogger(__name__) @@ -37,13 +37,15 @@ def output_formatter(resource_name, resources_list, attrs): fmt = cfg.CONF.fmt if fmt == 'psql': - resource_attr_values = [] + tableout = prettytable.PrettyTable(attrs) + tableout.padding_width = 1 + tableout.align = "l" for resource in resources_list: resource_list = [] for attr in attrs: resource_list.append(resource.get(attr)) - resource_attr_values.append(resource_list) - return tabulate(resource_attr_values, attrs, tablefmt=fmt) + tableout.add_row(resource_list) + return tableout elif fmt == 'json': js_output = {} diff --git a/tools/python-nsxadmin/admin/plugins/common/utils.py b/tools/python_nsxadmin/admin/plugins/common/utils.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/common/utils.py rename to tools/python_nsxadmin/admin/plugins/common/utils.py diff --git a/tools/python-nsxadmin/admin/plugins/nsxv3/__init__.py b/tools/python_nsxadmin/admin/plugins/nsxv/__init__.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/nsxv3/__init__.py rename to tools/python_nsxadmin/admin/plugins/nsxv/__init__.py diff --git a/tools/python-nsxadmin/admin/plugins/nsxv3/resources/__init__.py b/tools/python_nsxadmin/admin/plugins/nsxv/resources/__init__.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/nsxv3/resources/__init__.py rename to tools/python_nsxadmin/admin/plugins/nsxv/resources/__init__.py diff --git a/tools/python-nsxadmin/admin/plugins/nsxv/resources/dhcp_binding.py b/tools/python_nsxadmin/admin/plugins/nsxv/resources/dhcp_binding.py similarity index 89% rename from tools/python-nsxadmin/admin/plugins/nsxv/resources/dhcp_binding.py rename to tools/python_nsxadmin/admin/plugins/nsxv/resources/dhcp_binding.py index de626f3ba1..a651ae191b 100644 --- a/tools/python-nsxadmin/admin/plugins/nsxv/resources/dhcp_binding.py +++ b/tools/python_nsxadmin/admin/plugins/nsxv/resources/dhcp_binding.py @@ -15,10 +15,12 @@ import logging -from admin.plugins.common import constants -from admin.plugins.common.utils import output_header -import admin.plugins.nsxv.resources.utils as utils -from admin.shell import Operations +from tools.python_nsxadmin.admin.plugins.common import constants + +import tools.python_nsxadmin.admin.plugins.common.utils as admin_utils +import tools.python_nsxadmin.admin.plugins.nsxv.resources.utils as utils + +import tools.python_nsxadmin.admin.shell as shell from neutron.callbacks import registry @@ -57,7 +59,7 @@ def neutron_get_static_bindings_by_edge(edge_id): return neutron_db_dhcp_bindings -@output_header +@admin_utils.output_header def list_missing_dhcp_bindings(resource, event, trigger, **kwargs): """List missing DHCP bindings from NSXv backend. @@ -82,4 +84,4 @@ def list_missing_dhcp_bindings(resource, event, trigger, **kwargs): registry.subscribe(list_missing_dhcp_bindings, constants.DHCP_BINDING, - Operations.LIST.value) + shell.Operations.LIST.value) diff --git a/tools/python-nsxadmin/admin/plugins/nsxv/resources/edges.py b/tools/python_nsxadmin/admin/plugins/nsxv/resources/edges.py similarity index 80% rename from tools/python-nsxadmin/admin/plugins/nsxv/resources/edges.py rename to tools/python_nsxadmin/admin/plugins/nsxv/resources/edges.py index 131541f375..ae2db77822 100644 --- a/tools/python-nsxadmin/admin/plugins/nsxv/resources/edges.py +++ b/tools/python_nsxadmin/admin/plugins/nsxv/resources/edges.py @@ -15,13 +15,12 @@ import logging -from admin.plugins.common import constants -from admin.plugins.common import formatters -from admin.plugins.common.utils import output_header -from admin.plugins.common.utils import parse_multi_keyval_opt -from admin.plugins.common.utils import query_yes_no -import admin.plugins.nsxv.resources.utils as utils -from admin.shell import Operations +from tools.python_nsxadmin.admin.plugins.common import constants +from tools.python_nsxadmin.admin.plugins.common import formatters + +import tools.python_nsxadmin.admin.plugins.common.utils as admin_utils +import tools.python_nsxadmin.admin.plugins.nsxv.resources.utils as utils +import tools.python_nsxadmin.admin.shell as shell from neutron.callbacks import registry @@ -37,7 +36,7 @@ def get_nsxv_edges(): return edges['edgePage'].get('data', []) -@output_header +@admin_utils.output_header def nsx_list_edges(resource, event, trigger, **kwargs): """List edges from NSXv backend""" edges = get_nsxv_edges() @@ -50,7 +49,7 @@ def get_router_edge_bindings(): return nsxv_db.get_nsxv_router_bindings(edgeapi.context) -@output_header +@admin_utils.output_header def neutron_list_router_edge_bindings(resource, event, trigger, **kwargs): """List NSXv edges from Neutron DB""" edges = get_router_edge_bindings() @@ -70,7 +69,7 @@ def get_orphaned_edges(): return nsxv_edge_ids - neutron_edge_bindings -@output_header +@admin_utils.output_header def nsx_list_orphaned_edges(resource, event, trigger, **kwargs): """List orphaned Edges on NSXv. @@ -81,7 +80,7 @@ def nsx_list_orphaned_edges(resource, event, trigger, **kwargs): LOG.info(orphaned_edges) -@output_header +@admin_utils.output_header def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs): """Delete orphaned edges from NSXv backend""" orphaned_edges = get_orphaned_edges() @@ -89,8 +88,9 @@ def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs): if not kwargs['force']: if len(orphaned_edges): - user_confirm = query_yes_no("Do you want to delete " - "orphaned edges", default="no") + user_confirm = admin_utils.query_yes_no("Do you want to delete " + "orphaned edges", + default="no") if not user_confirm: LOG.info(_LI("NSXv Edge deletion aborted by user")) return @@ -103,7 +103,7 @@ def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs): LOG.info(_LI("After delete; Orphaned Edges: %s"), get_orphaned_edges()) -@output_header +@admin_utils.output_header def nsx_update_edge(resource, event, trigger, **kwargs): """Update edge properties""" if not kwargs.get('property'): @@ -111,7 +111,7 @@ def nsx_update_edge(resource, event, trigger, **kwargs): "attribute to update. Add --property edge-id= " "--property highavailability=True")) return - properties = parse_multi_keyval_opt(kwargs['property']) + properties = admin_utils.parse_multi_keyval_opt(kwargs['property']) if not properties.get('edge-id'): LOG.error(_LE("Need to specify edge-id. " "Add --property edge-id=")) @@ -128,16 +128,16 @@ def nsx_update_edge(resource, event, trigger, **kwargs): registry.subscribe(nsx_list_edges, constants.EDGES, - Operations.LIST.value) + shell.Operations.LIST.value) registry.subscribe(neutron_list_router_edge_bindings, constants.EDGES, - Operations.LIST.value) + shell.Operations.LIST.value) registry.subscribe(nsx_list_orphaned_edges, constants.EDGES, - Operations.LIST.value) + shell.Operations.LIST.value) registry.subscribe(nsx_delete_orphaned_edges, constants.EDGES, - Operations.CLEAN.value) + shell.Operations.CLEAN.value) registry.subscribe(nsx_update_edge, constants.EDGES, - Operations.NSX_UPDATE.value) + shell.Operations.NSX_UPDATE.value) diff --git a/tools/python-nsxadmin/admin/plugins/nsxv/resources/spoofguard_policy.py b/tools/python_nsxadmin/admin/plugins/nsxv/resources/spoofguard_policy.py similarity index 84% rename from tools/python-nsxadmin/admin/plugins/nsxv/resources/spoofguard_policy.py rename to tools/python_nsxadmin/admin/plugins/nsxv/resources/spoofguard_policy.py index fd0611feb3..c70f642d5a 100644 --- a/tools/python-nsxadmin/admin/plugins/nsxv/resources/spoofguard_policy.py +++ b/tools/python_nsxadmin/admin/plugins/nsxv/resources/spoofguard_policy.py @@ -15,11 +15,13 @@ import logging -from admin.plugins.common import constants -from admin.plugins.common import formatters -from admin.plugins.common.utils import output_header -import admin.plugins.nsxv.resources.utils as utils -from admin.shell import Operations +from tools.python_nsxadmin.admin.plugins.common import constants +from tools.python_nsxadmin.admin.plugins.common import formatters + +import tools.python_nsxadmin.admin.plugins.common.utils as admin_utils +import tools.python_nsxadmin.admin.plugins.nsxv.resources.utils as utils + +import tools.python_nsxadmin.admin.shell as shell from neutron.callbacks import registry @@ -34,7 +36,7 @@ def get_spoofguard_policies(): return nsxv.get_spoofguard_policies()[1].get("policies") -@output_header +@admin_utils.output_header def nsx_list_spoofguard_policies(resource, event, trigger, **kwargs): """List spoofguard policies from NSXv backend""" policies = get_spoofguard_policies() @@ -48,7 +50,7 @@ def get_spoofguard_policy_network_mappings(): spgapi.context) -@output_header +@admin_utils.output_header def neutron_list_spoofguard_policy_mappings(resource, event, trigger, **kwargs): mappings = get_spoofguard_policy_network_mappings() @@ -68,7 +70,7 @@ def get_missing_spoofguard_policy_mappings(): return neutron_spoofguard_policy_mappings - nsxv_spoofguard_policies -@output_header +@admin_utils.output_header def nsx_list_missing_spoofguard_policies(resource, event, trigger, **kwargs): """List missing spoofguard policies on NSXv. @@ -83,10 +85,10 @@ def nsx_list_missing_spoofguard_policies(resource, event, trigger, registry.subscribe(neutron_list_spoofguard_policy_mappings, constants.SPOOFGUARD_POLICY, - Operations.LIST.value) + shell.Operations.LIST.value) registry.subscribe(nsx_list_spoofguard_policies, constants.SPOOFGUARD_POLICY, - Operations.LIST.value) + shell.Operations.LIST.value) registry.subscribe(nsx_list_missing_spoofguard_policies, constants.SPOOFGUARD_POLICY, - Operations.LIST.value) + shell.Operations.LIST.value) diff --git a/tools/python-nsxadmin/admin/plugins/nsxv/resources/utils.py b/tools/python_nsxadmin/admin/plugins/nsxv/resources/utils.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/nsxv/resources/utils.py rename to tools/python_nsxadmin/admin/plugins/nsxv/resources/utils.py diff --git a/tools/python_nsxadmin/admin/plugins/nsxv3/__init__.py b/tools/python_nsxadmin/admin/plugins/nsxv3/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/python_nsxadmin/admin/plugins/nsxv3/resources/__init__.py b/tools/python_nsxadmin/admin/plugins/nsxv3/resources/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/python-nsxadmin/admin/plugins/nsxv3/resources/securitygroups.py b/tools/python_nsxadmin/admin/plugins/nsxv3/resources/securitygroups.py similarity index 100% rename from tools/python-nsxadmin/admin/plugins/nsxv3/resources/securitygroups.py rename to tools/python_nsxadmin/admin/plugins/nsxv3/resources/securitygroups.py diff --git a/tools/python-nsxadmin/admin/shell.py b/tools/python_nsxadmin/admin/shell.py similarity index 97% rename from tools/python-nsxadmin/admin/shell.py rename to tools/python_nsxadmin/admin/shell.py index 9c9711aa51..4cafef3631 100644 --- a/tools/python-nsxadmin/admin/shell.py +++ b/tools/python_nsxadmin/admin/shell.py @@ -41,8 +41,8 @@ from vmware_nsx.common import config # noqa from oslo_config import cfg from oslo_log import _options -from admin.plugins.common import constants -from admin import version +from tools.python_nsxadmin.admin.plugins.common import constants +from tools.python_nsxadmin.admin import version # Suppress the Insecure request warning requests.packages.urllib3.disable_warnings() @@ -104,7 +104,8 @@ def _get_plugin(): def _get_plugin_dir(): - return 'admin/plugins/{}/resources'.format(_get_plugin()) + plugin_dir = 'tools/python_nsxadmin/admin/plugins' + return '{}/{}/resources'.format(plugin_dir, _get_plugin()) def _get_resources(): diff --git a/tools/python-nsxadmin/admin/version.py b/tools/python_nsxadmin/admin/version.py similarity index 100% rename from tools/python-nsxadmin/admin/version.py rename to tools/python_nsxadmin/admin/version.py diff --git a/tools/python-nsxadmin/requirements.txt b/tools/python_nsxadmin/requirements.txt similarity index 100% rename from tools/python-nsxadmin/requirements.txt rename to tools/python_nsxadmin/requirements.txt diff --git a/tools/python-nsxadmin/setup.cfg b/tools/python_nsxadmin/setup.cfg similarity index 100% rename from tools/python-nsxadmin/setup.cfg rename to tools/python_nsxadmin/setup.cfg diff --git a/tools/python-nsxadmin/setup.py b/tools/python_nsxadmin/setup.py similarity index 100% rename from tools/python-nsxadmin/setup.py rename to tools/python_nsxadmin/setup.py