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:
parent
06cd0d5bf0
commit
f88a8cfb7b
@ -14,11 +14,11 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from tabulate import tabulate
|
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
|
import prettytable
|
||||||
|
|
||||||
from vmware_nsx._i18n import _LI
|
from vmware_nsx._i18n import _LI
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -37,13 +37,15 @@ def output_formatter(resource_name, resources_list, attrs):
|
|||||||
|
|
||||||
fmt = cfg.CONF.fmt
|
fmt = cfg.CONF.fmt
|
||||||
if fmt == 'psql':
|
if fmt == 'psql':
|
||||||
resource_attr_values = []
|
tableout = prettytable.PrettyTable(attrs)
|
||||||
|
tableout.padding_width = 1
|
||||||
|
tableout.align = "l"
|
||||||
for resource in resources_list:
|
for resource in resources_list:
|
||||||
resource_list = []
|
resource_list = []
|
||||||
for attr in attrs:
|
for attr in attrs:
|
||||||
resource_list.append(resource.get(attr))
|
resource_list.append(resource.get(attr))
|
||||||
resource_attr_values.append(resource_list)
|
tableout.add_row(resource_list)
|
||||||
return tabulate(resource_attr_values, attrs, tablefmt=fmt)
|
return tableout
|
||||||
|
|
||||||
elif fmt == 'json':
|
elif fmt == 'json':
|
||||||
js_output = {}
|
js_output = {}
|
@ -15,10 +15,12 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from admin.plugins.common import constants
|
from tools.python_nsxadmin.admin.plugins.common import constants
|
||||||
from admin.plugins.common.utils import output_header
|
|
||||||
import admin.plugins.nsxv.resources.utils as utils
|
import tools.python_nsxadmin.admin.plugins.common.utils as admin_utils
|
||||||
from admin.shell import Operations
|
import tools.python_nsxadmin.admin.plugins.nsxv.resources.utils as utils
|
||||||
|
|
||||||
|
import tools.python_nsxadmin.admin.shell as shell
|
||||||
|
|
||||||
from neutron.callbacks import registry
|
from neutron.callbacks import registry
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ def neutron_get_static_bindings_by_edge(edge_id):
|
|||||||
return neutron_db_dhcp_bindings
|
return neutron_db_dhcp_bindings
|
||||||
|
|
||||||
|
|
||||||
@output_header
|
@admin_utils.output_header
|
||||||
def list_missing_dhcp_bindings(resource, event, trigger, **kwargs):
|
def list_missing_dhcp_bindings(resource, event, trigger, **kwargs):
|
||||||
"""List missing DHCP bindings from NSXv backend.
|
"""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,
|
registry.subscribe(list_missing_dhcp_bindings,
|
||||||
constants.DHCP_BINDING,
|
constants.DHCP_BINDING,
|
||||||
Operations.LIST.value)
|
shell.Operations.LIST.value)
|
@ -15,13 +15,12 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from admin.plugins.common import constants
|
from tools.python_nsxadmin.admin.plugins.common import constants
|
||||||
from admin.plugins.common import formatters
|
from tools.python_nsxadmin.admin.plugins.common import formatters
|
||||||
from admin.plugins.common.utils import output_header
|
|
||||||
from admin.plugins.common.utils import parse_multi_keyval_opt
|
import tools.python_nsxadmin.admin.plugins.common.utils as admin_utils
|
||||||
from admin.plugins.common.utils import query_yes_no
|
import tools.python_nsxadmin.admin.plugins.nsxv.resources.utils as utils
|
||||||
import admin.plugins.nsxv.resources.utils as utils
|
import tools.python_nsxadmin.admin.shell as shell
|
||||||
from admin.shell import Operations
|
|
||||||
|
|
||||||
from neutron.callbacks import registry
|
from neutron.callbacks import registry
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ def get_nsxv_edges():
|
|||||||
return edges['edgePage'].get('data', [])
|
return edges['edgePage'].get('data', [])
|
||||||
|
|
||||||
|
|
||||||
@output_header
|
@admin_utils.output_header
|
||||||
def nsx_list_edges(resource, event, trigger, **kwargs):
|
def nsx_list_edges(resource, event, trigger, **kwargs):
|
||||||
"""List edges from NSXv backend"""
|
"""List edges from NSXv backend"""
|
||||||
edges = get_nsxv_edges()
|
edges = get_nsxv_edges()
|
||||||
@ -50,7 +49,7 @@ def get_router_edge_bindings():
|
|||||||
return nsxv_db.get_nsxv_router_bindings(edgeapi.context)
|
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):
|
def neutron_list_router_edge_bindings(resource, event, trigger, **kwargs):
|
||||||
"""List NSXv edges from Neutron DB"""
|
"""List NSXv edges from Neutron DB"""
|
||||||
edges = get_router_edge_bindings()
|
edges = get_router_edge_bindings()
|
||||||
@ -70,7 +69,7 @@ def get_orphaned_edges():
|
|||||||
return nsxv_edge_ids - neutron_edge_bindings
|
return nsxv_edge_ids - neutron_edge_bindings
|
||||||
|
|
||||||
|
|
||||||
@output_header
|
@admin_utils.output_header
|
||||||
def nsx_list_orphaned_edges(resource, event, trigger, **kwargs):
|
def nsx_list_orphaned_edges(resource, event, trigger, **kwargs):
|
||||||
"""List orphaned Edges on NSXv.
|
"""List orphaned Edges on NSXv.
|
||||||
|
|
||||||
@ -81,7 +80,7 @@ def nsx_list_orphaned_edges(resource, event, trigger, **kwargs):
|
|||||||
LOG.info(orphaned_edges)
|
LOG.info(orphaned_edges)
|
||||||
|
|
||||||
|
|
||||||
@output_header
|
@admin_utils.output_header
|
||||||
def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs):
|
def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs):
|
||||||
"""Delete orphaned edges from NSXv backend"""
|
"""Delete orphaned edges from NSXv backend"""
|
||||||
orphaned_edges = get_orphaned_edges()
|
orphaned_edges = get_orphaned_edges()
|
||||||
@ -89,8 +88,9 @@ def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs):
|
|||||||
|
|
||||||
if not kwargs['force']:
|
if not kwargs['force']:
|
||||||
if len(orphaned_edges):
|
if len(orphaned_edges):
|
||||||
user_confirm = query_yes_no("Do you want to delete "
|
user_confirm = admin_utils.query_yes_no("Do you want to delete "
|
||||||
"orphaned edges", default="no")
|
"orphaned edges",
|
||||||
|
default="no")
|
||||||
if not user_confirm:
|
if not user_confirm:
|
||||||
LOG.info(_LI("NSXv Edge deletion aborted by user"))
|
LOG.info(_LI("NSXv Edge deletion aborted by user"))
|
||||||
return
|
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())
|
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):
|
def nsx_update_edge(resource, event, trigger, **kwargs):
|
||||||
"""Update edge properties"""
|
"""Update edge properties"""
|
||||||
if not kwargs.get('property'):
|
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> "
|
"attribute to update. Add --property edge-id=<edge-id> "
|
||||||
"--property highavailability=True"))
|
"--property highavailability=True"))
|
||||||
return
|
return
|
||||||
properties = parse_multi_keyval_opt(kwargs['property'])
|
properties = admin_utils.parse_multi_keyval_opt(kwargs['property'])
|
||||||
if not properties.get('edge-id'):
|
if not properties.get('edge-id'):
|
||||||
LOG.error(_LE("Need to specify edge-id. "
|
LOG.error(_LE("Need to specify edge-id. "
|
||||||
"Add --property edge-id=<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,
|
registry.subscribe(nsx_list_edges,
|
||||||
constants.EDGES,
|
constants.EDGES,
|
||||||
Operations.LIST.value)
|
shell.Operations.LIST.value)
|
||||||
registry.subscribe(neutron_list_router_edge_bindings,
|
registry.subscribe(neutron_list_router_edge_bindings,
|
||||||
constants.EDGES,
|
constants.EDGES,
|
||||||
Operations.LIST.value)
|
shell.Operations.LIST.value)
|
||||||
registry.subscribe(nsx_list_orphaned_edges,
|
registry.subscribe(nsx_list_orphaned_edges,
|
||||||
constants.EDGES,
|
constants.EDGES,
|
||||||
Operations.LIST.value)
|
shell.Operations.LIST.value)
|
||||||
registry.subscribe(nsx_delete_orphaned_edges,
|
registry.subscribe(nsx_delete_orphaned_edges,
|
||||||
constants.EDGES,
|
constants.EDGES,
|
||||||
Operations.CLEAN.value)
|
shell.Operations.CLEAN.value)
|
||||||
registry.subscribe(nsx_update_edge,
|
registry.subscribe(nsx_update_edge,
|
||||||
constants.EDGES,
|
constants.EDGES,
|
||||||
Operations.NSX_UPDATE.value)
|
shell.Operations.NSX_UPDATE.value)
|
@ -15,11 +15,13 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from admin.plugins.common import constants
|
from tools.python_nsxadmin.admin.plugins.common import constants
|
||||||
from admin.plugins.common import formatters
|
from tools.python_nsxadmin.admin.plugins.common import formatters
|
||||||
from admin.plugins.common.utils import output_header
|
|
||||||
import admin.plugins.nsxv.resources.utils as utils
|
import tools.python_nsxadmin.admin.plugins.common.utils as admin_utils
|
||||||
from admin.shell import Operations
|
import tools.python_nsxadmin.admin.plugins.nsxv.resources.utils as utils
|
||||||
|
|
||||||
|
import tools.python_nsxadmin.admin.shell as shell
|
||||||
|
|
||||||
from neutron.callbacks import registry
|
from neutron.callbacks import registry
|
||||||
|
|
||||||
@ -34,7 +36,7 @@ def get_spoofguard_policies():
|
|||||||
return nsxv.get_spoofguard_policies()[1].get("policies")
|
return nsxv.get_spoofguard_policies()[1].get("policies")
|
||||||
|
|
||||||
|
|
||||||
@output_header
|
@admin_utils.output_header
|
||||||
def nsx_list_spoofguard_policies(resource, event, trigger, **kwargs):
|
def nsx_list_spoofguard_policies(resource, event, trigger, **kwargs):
|
||||||
"""List spoofguard policies from NSXv backend"""
|
"""List spoofguard policies from NSXv backend"""
|
||||||
policies = get_spoofguard_policies()
|
policies = get_spoofguard_policies()
|
||||||
@ -48,7 +50,7 @@ def get_spoofguard_policy_network_mappings():
|
|||||||
spgapi.context)
|
spgapi.context)
|
||||||
|
|
||||||
|
|
||||||
@output_header
|
@admin_utils.output_header
|
||||||
def neutron_list_spoofguard_policy_mappings(resource, event, trigger,
|
def neutron_list_spoofguard_policy_mappings(resource, event, trigger,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
mappings = get_spoofguard_policy_network_mappings()
|
mappings = get_spoofguard_policy_network_mappings()
|
||||||
@ -68,7 +70,7 @@ def get_missing_spoofguard_policy_mappings():
|
|||||||
return neutron_spoofguard_policy_mappings - nsxv_spoofguard_policies
|
return neutron_spoofguard_policy_mappings - nsxv_spoofguard_policies
|
||||||
|
|
||||||
|
|
||||||
@output_header
|
@admin_utils.output_header
|
||||||
def nsx_list_missing_spoofguard_policies(resource, event, trigger,
|
def nsx_list_missing_spoofguard_policies(resource, event, trigger,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""List missing spoofguard policies on NSXv.
|
"""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,
|
registry.subscribe(neutron_list_spoofguard_policy_mappings,
|
||||||
constants.SPOOFGUARD_POLICY,
|
constants.SPOOFGUARD_POLICY,
|
||||||
Operations.LIST.value)
|
shell.Operations.LIST.value)
|
||||||
registry.subscribe(nsx_list_spoofguard_policies,
|
registry.subscribe(nsx_list_spoofguard_policies,
|
||||||
constants.SPOOFGUARD_POLICY,
|
constants.SPOOFGUARD_POLICY,
|
||||||
Operations.LIST.value)
|
shell.Operations.LIST.value)
|
||||||
registry.subscribe(nsx_list_missing_spoofguard_policies,
|
registry.subscribe(nsx_list_missing_spoofguard_policies,
|
||||||
constants.SPOOFGUARD_POLICY,
|
constants.SPOOFGUARD_POLICY,
|
||||||
Operations.LIST.value)
|
shell.Operations.LIST.value)
|
@ -41,8 +41,8 @@ from vmware_nsx.common import config # noqa
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import _options
|
from oslo_log import _options
|
||||||
|
|
||||||
from admin.plugins.common import constants
|
from tools.python_nsxadmin.admin.plugins.common import constants
|
||||||
from admin import version
|
from tools.python_nsxadmin.admin import version
|
||||||
|
|
||||||
# Suppress the Insecure request warning
|
# Suppress the Insecure request warning
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
@ -104,7 +104,8 @@ def _get_plugin():
|
|||||||
|
|
||||||
|
|
||||||
def _get_plugin_dir():
|
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():
|
def _get_resources():
|
Loading…
Reference in New Issue
Block a user