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
This commit is contained in:
Akash Gangil 2015-12-02 03:45:21 -08:00
parent 06cd0d5bf0
commit f88a8cfb7b
23 changed files with 52 additions and 45 deletions

View File

@ -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 = {}

View File

@ -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)

View File

@ -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=<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=<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)

View File

@ -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)

View File

@ -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():