diff --git a/doc/source/admin_util.rst b/doc/source/admin_util.rst index b93caf3c4d..8bb60b7c00 100644 --- a/doc/source/admin_util.rst +++ b/doc/source/admin_util.rst @@ -454,7 +454,7 @@ BGP GW edges LBaaS -~~~~~~~~~~~~ +~~~~~ - List NSX LB services:: nsxadmin -r lb-services -o list @@ -472,6 +472,12 @@ LBaaS nsxadmin -r lb-monitors -o list +NSXtvd +------ + +- Add mapping between projects and plugin before starting to use the tvd plugin: + nsxadmin -r projects -o import --property plugin=nsx-v --property project=<> + Config ~~~~~~ diff --git a/vmware_nsx/shell/admin/plugins/common/constants.py b/vmware_nsx/shell/admin/plugins/common/constants.py index 0f199b538d..76cc56460a 100644 --- a/vmware_nsx/shell/admin/plugins/common/constants.py +++ b/vmware_nsx/shell/admin/plugins/common/constants.py @@ -19,8 +19,10 @@ NSX_INI = '/etc/neutron/plugins/vmware/nsx.ini' # NSX Plugin Constants NSXV3_PLUGIN = 'vmware_nsx.plugin.NsxV3Plugin' NSXV_PLUGIN = 'vmware_nsx.plugin.NsxVPlugin' +NSXTVD_PLUGIN = 'vmware_nsx.plugin.NsxTVDPlugin' VMWARE_NSXV = 'vmware_nsxv' VMWARE_NSXV3 = 'vmware_nsxv3' +VMWARE_NSXTVD = 'vmware_nsxtvd' # Common Resource Constants NETWORKS = 'networks' @@ -57,3 +59,6 @@ LBAAS = 'lbaas' BGP_GW_EDGE = 'bgp-gw-edge' ROUTING_REDIS_RULE = 'routing-redistribution-rule' BGP_NEIGHBOUR = 'bgp-neighbour' + +# NSXTV only Resource Constants +PROJECTS = 'projects' diff --git a/vmware_nsx/shell/admin/plugins/nsxtvd/__init__.py b/vmware_nsx/shell/admin/plugins/nsxtvd/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vmware_nsx/shell/admin/plugins/nsxtvd/resources/__init__.py b/vmware_nsx/shell/admin/plugins/nsxtvd/resources/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vmware_nsx/shell/admin/plugins/nsxtvd/resources/migrate.py b/vmware_nsx/shell/admin/plugins/nsxtvd/resources/migrate.py new file mode 100644 index 0000000000..fcfba684f3 --- /dev/null +++ b/vmware_nsx/shell/admin/plugins/nsxtvd/resources/migrate.py @@ -0,0 +1,56 @@ +# Copyright 2017 VMware, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_log import log as logging + +from neutron_lib.callbacks import registry +from neutron_lib import context + +from vmware_nsx.db import db +from vmware_nsx.extensions import projectpluginmap +from vmware_nsx.shell.admin.plugins.common import constants +from vmware_nsx.shell.admin.plugins.common import utils as admin_utils +from vmware_nsx.shell import resources as shell + +LOG = logging.getLogger(__name__) + + +@admin_utils.output_header +def migrate_projects(resource, event, trigger, **kwargs): + """Import existing openstack projects to the current plugin""" + # TODO(asarfaty): get the projects list from keystone + + # get the plugin name from the user + if not kwargs.get('property'): + LOG.error("Need to specify plugin and project parameters") + return + else: + properties = admin_utils.parse_multi_keyval_opt(kwargs['property']) + plugin = properties.get('plugin') + project = properties.get('project') + if not plugin or not project: + LOG.error("Need to specify plugin and project parameters") + return + if plugin not in projectpluginmap.VALID_TYPES: + LOG.error("The supported plugins are %s", projectpluginmap.VALID_TYPES) + return + + ctx = context.get_admin_context() + if not db.get_project_plugin_mapping(ctx.session, project): + db.add_project_plugin_mapping(ctx.session, project, plugin) + + +registry.subscribe(migrate_projects, + constants.PROJECTS, + shell.Operations.IMPORT.value) diff --git a/vmware_nsx/shell/nsxadmin.py b/vmware_nsx/shell/nsxadmin.py index 6c518aa877..461a3d616b 100644 --- a/vmware_nsx/shell/nsxadmin.py +++ b/vmware_nsx/shell/nsxadmin.py @@ -78,6 +78,10 @@ def _validate_resource_choice(resource, nsx_plugin): LOG.error('Supported list of NSX-V3 resources: %s', resources.nsxv3_resources_names) sys.exit(1) + elif nsx_plugin == 'nsxtvd'and resource not in resources.nsxtvd_resources: + LOG.error('Supported list of NSX-TVD resources: %s', + resources.nsxtvd_resources_names) + sys.exit(1) def _validate_op_choice(choice, nsx_plugin): @@ -97,6 +101,14 @@ def _validate_op_choice(choice, nsx_plugin): 'resource %s', supported_resource_ops) sys.exit(1) + elif nsx_plugin == 'nsxtvd': + supported_resource_ops = \ + resources.nsxtvd_resources[cfg.CONF.resource].supported_ops + if choice not in supported_resource_ops: + LOG.error('Supported list of operations for the NSX-TVD ' + 'resource %s', supported_resource_ops) + sys.exit(1) + def main(argv=sys.argv[1:]): _init_cfg() diff --git a/vmware_nsx/shell/resources.py b/vmware_nsx/shell/resources.py index aca743e211..8e71d77a90 100644 --- a/vmware_nsx/shell/resources.py +++ b/vmware_nsx/shell/resources.py @@ -207,8 +207,17 @@ nsxv_resources = { Operations.DELETE.value]) } + +# Add supported NSX-TVD resources in this dictionary +# TODO(asarfaty): add v+v3 resources here too +nsxtvd_resources = { + constants.PROJECTS: Resource(constants.PROJECTS, + [Operations.IMPORT.value]), +} + nsxv3_resources_names = list(nsxv3_resources.keys()) nsxv_resources_names = list(nsxv_resources.keys()) +nsxtvd_resources_names = list(nsxtvd_resources.keys()) def get_resources(plugin_dir): @@ -224,6 +233,8 @@ def get_plugin(): plugin_name = 'nsxv3' elif plugin in (constants.NSXV_PLUGIN, constants.VMWARE_NSXV): plugin_name = 'nsxv' + elif plugin in (constants.NSXTVD_PLUGIN, constants.VMWARE_NSXTVD): + plugin_name = 'nsxtvd' return plugin_name @@ -233,6 +244,8 @@ def _get_choices(): return nsxv3_resources_names elif plugin == 'nsxv': return nsxv_resources_names + elif plugin == 'nsxtvd': + return nsxtvd_resources_names def _get_resources(): @@ -241,6 +254,8 @@ def _get_resources(): return 'NSX-V3 resources: %s' % (', '.join(nsxv3_resources_names)) elif plugin == 'nsxv': return 'NSX-V resources: %s' % (', '.join(nsxv_resources_names)) + elif plugin == 'nsxtvd': + return 'NSX-TVD resources: %s' % (', '.join(nsxtvd_resources_names)) cli_opts = [cfg.StrOpt('fmt', diff --git a/vmware_nsx/tests/unit/shell/test_admin_utils.py b/vmware_nsx/tests/unit/shell/test_admin_utils.py index e83bae2ffa..f0e9ed7f79 100644 --- a/vmware_nsx/tests/unit/shell/test_admin_utils.py +++ b/vmware_nsx/tests/unit/shell/test_admin_utils.py @@ -286,3 +286,12 @@ class TestNsxv3AdminUtils(AbstractTestAdminUtils, # Run all utilities with backend objects self._test_resources_with_args( resources.nsxv3_resources, args) + + +class TestNsxtvdAdminUtils(AbstractTestAdminUtils): + + def _get_plugin_name(self): + return 'nsxtvd' + + def test_nsxtv_resources(self): + self._test_resources(resources.nsxtvd_resources)