
This patch refactors the current codebase to be more modular and testable. The main changes are: - pull out all of the profile setup logic from the __init__ method to it's own method _init_nsx_profiles method to make testing the code easier. - refactors the nsxlib.v3 code to break out all neutron related exceptions and cleans up the interface so we can make nsxlib.v3 it's own standalone library eventually. To improve: - Currently we have nsxlib.v3.dfw_api and nsxlib.v3.firewall, we should refactor this code and merge them into one file. - refactor nsxlib to section of each api component to it's own subclass. For example, nsxlib().port.create() rather than nsxlib().create_port(). I think this would be most useful for the security group/firewall integration as there are many methods there that are needed to interface with nsx as the security group feature is requires the most orchestration with nsx. Breaking them into a sub class will make things more easy to understand. Change-Id: If2fe1e014b78703ff0a9cdff1e4e8d45f3a4a16d
60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
# Copyright 2016 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.
|
|
|
|
import logging
|
|
|
|
from neutron.callbacks import registry
|
|
from oslo_config import cfg
|
|
|
|
from vmware_nsx._i18n import _LI, _LE
|
|
from vmware_nsx.common import nsx_constants
|
|
from vmware_nsx.common import utils as nsx_utils
|
|
from vmware_nsx.nsxlib.v3 import resources
|
|
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.admin.plugins.nsxv3.resources import utils
|
|
import vmware_nsx.shell.resources as shell
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
neutron_client = utils.NeutronDbClient()
|
|
|
|
|
|
@admin_utils.output_header
|
|
def nsx_update_metadata_proxy(resource, event, trigger, **kwargs):
|
|
"""Update Metadata proxy for NSXv3 CrossHairs."""
|
|
|
|
nsx_client = utils.get_nsxv3_client()
|
|
port_resource = resources.LogicalPort(nsx_client)
|
|
|
|
for network in neutron_client.get_networks():
|
|
# For each Neutron network, create a logical switch port with
|
|
# MD-Proxy attachment.
|
|
lswitch_id = neutron_client.net_id_to_lswitch_id(network['id'])
|
|
if lswitch_id:
|
|
tags = nsx_utils.build_v3_tags_payload(
|
|
network, resource_type='os-neutron-net-id',
|
|
project_name='NSX Neutron plugin upgrade')
|
|
port_resource.create(
|
|
lswitch_id, cfg.CONF.nsx_v3.metadata_proxy_uuid, tags=tags,
|
|
attachment_type=nsx_constants.ATTACHMENT_MDPROXY)
|
|
LOG.info(_LI("Enabled native metadata proxy for network %s"),
|
|
network['id'])
|
|
else:
|
|
LOG.error(_LE("Unable to find logical switch for network %s"),
|
|
network['id'])
|
|
|
|
registry.subscribe(nsx_update_metadata_proxy,
|
|
constants.METADATA_PROXY,
|
|
shell.Operations.NSX_UPDATE.value)
|