Browse Source

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
changes/61/252561/4
Akash Gangil 6 years ago
parent
commit
f88a8cfb7b
  1. 0
      tools/__init__.py
  2. 0
      tools/python_nsxadmin/README.rst
  3. 0
      tools/python_nsxadmin/__init__.py
  4. 0
      tools/python_nsxadmin/admin/__init__.py
  5. 0
      tools/python_nsxadmin/admin/plugins/__init__.py
  6. 0
      tools/python_nsxadmin/admin/plugins/common/__init__.py
  7. 0
      tools/python_nsxadmin/admin/plugins/common/constants.py
  8. 12
      tools/python_nsxadmin/admin/plugins/common/formatters.py
  9. 0
      tools/python_nsxadmin/admin/plugins/common/utils.py
  10. 0
      tools/python_nsxadmin/admin/plugins/nsxv/__init__.py
  11. 0
      tools/python_nsxadmin/admin/plugins/nsxv/resources/__init__.py
  12. 14
      tools/python_nsxadmin/admin/plugins/nsxv/resources/dhcp_binding.py
  13. 40
      tools/python_nsxadmin/admin/plugins/nsxv/resources/edges.py
  14. 24
      tools/python_nsxadmin/admin/plugins/nsxv/resources/spoofguard_policy.py
  15. 0
      tools/python_nsxadmin/admin/plugins/nsxv/resources/utils.py
  16. 0
      tools/python_nsxadmin/admin/plugins/nsxv3/__init__.py
  17. 0
      tools/python_nsxadmin/admin/plugins/nsxv3/resources/__init__.py
  18. 0
      tools/python_nsxadmin/admin/plugins/nsxv3/resources/securitygroups.py
  19. 7
      tools/python_nsxadmin/admin/shell.py
  20. 0
      tools/python_nsxadmin/admin/version.py
  21. 0
      tools/python_nsxadmin/requirements.txt
  22. 0
      tools/python_nsxadmin/setup.cfg
  23. 0
      tools/python_nsxadmin/setup.py

0
tools/python-nsxadmin/admin/plugins/__init__.py → tools/__init__.py

0
tools/python-nsxadmin/README.rst → tools/python_nsxadmin/README.rst

0
tools/python-nsxadmin/admin/plugins/common/__init__.py → tools/python_nsxadmin/__init__.py

0
tools/python-nsxadmin/admin/__init__.py → tools/python_nsxadmin/admin/__init__.py

0
tools/python-nsxadmin/admin/plugins/nsxv/__init__.py → tools/python_nsxadmin/admin/plugins/__init__.py

0
tools/python-nsxadmin/admin/plugins/nsxv/resources/__init__.py → tools/python_nsxadmin/admin/plugins/common/__init__.py

0
tools/python-nsxadmin/admin/plugins/common/constants.py → tools/python_nsxadmin/admin/plugins/common/constants.py

12
tools/python-nsxadmin/admin/plugins/common/formatters.py → 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 = {}

0
tools/python-nsxadmin/admin/plugins/common/utils.py → tools/python_nsxadmin/admin/plugins/common/utils.py

0
tools/python-nsxadmin/admin/plugins/nsxv3/__init__.py → tools/python_nsxadmin/admin/plugins/nsxv/__init__.py

0
tools/python-nsxadmin/admin/plugins/nsxv3/resources/__init__.py → tools/python_nsxadmin/admin/plugins/nsxv/resources/__init__.py

14
tools/python-nsxadmin/admin/plugins/nsxv/resources/dhcp_binding.py → 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)

40
tools/python-nsxadmin/admin/plugins/nsxv/resources/edges.py → 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=<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)

24
tools/python-nsxadmin/admin/plugins/nsxv/resources/spoofguard_policy.py → 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)

0
tools/python-nsxadmin/admin/plugins/nsxv/resources/utils.py → tools/python_nsxadmin/admin/plugins/nsxv/resources/utils.py

0
tools/python_nsxadmin/admin/plugins/nsxv3/__init__.py

0
tools/python_nsxadmin/admin/plugins/nsxv3/resources/__init__.py

0
tools/python-nsxadmin/admin/plugins/nsxv3/resources/securitygroups.py → tools/python_nsxadmin/admin/plugins/nsxv3/resources/securitygroups.py

7
tools/python-nsxadmin/admin/shell.py → 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():

0
tools/python-nsxadmin/admin/version.py → tools/python_nsxadmin/admin/version.py

0
tools/python-nsxadmin/requirements.txt → tools/python_nsxadmin/requirements.txt

0
tools/python-nsxadmin/setup.cfg → tools/python_nsxadmin/setup.cfg

0
tools/python-nsxadmin/setup.py → tools/python_nsxadmin/setup.py

Loading…
Cancel
Save