Replace occurrences of registry.notify

This change replaces remaining occurences of the notify method with
calls to the publish method.
As NSX admin utilities heavily rely on callbacks, this change also
ensures that all callbacks are now accepting event payloads rather
thank kwargs.

Change-Id: I0450fff486898d6ab74086b7952dc27134cb77e2
This commit is contained in:
Salvatore Orlando 2021-10-15 06:01:34 -07:00
parent 8031a85420
commit 819c74ef30
38 changed files with 234 additions and 42 deletions

View File

@ -85,11 +85,6 @@ class ExtendedSecurityGroupPropertiesMixin(object):
enable egress traffic which normal neutron security groups do.
"""
s = security_group['security_group']
kwargs = {
'context': context,
'security_group': s,
'is_default': default_sg,
}
self._registry_publish(resources.SECURITY_GROUP, events.BEFORE_CREATE,
exc_cls=ext_sg.SecurityGroupConflict,
@ -119,9 +114,12 @@ class ExtendedSecurityGroupPropertiesMixin(object):
secgroup_dict = self._make_security_group_dict(sg)
secgroup_dict[sg_policy.POLICY] = s.get(sg_policy.POLICY)
secgroup_dict[provider_sg.PROVIDER] = is_provider
kwargs['security_group'] = secgroup_dict
registry.notify(resources.SECURITY_GROUP, events.AFTER_CREATE, self,
**kwargs)
registry.publish(resources.SECURITY_GROUP, events.AFTER_CREATE, self,
payload=events.DBEventPayload(
context,
request_body=security_group,
metadata={'is_default': default_sg},
states=(s, secgroup_dict,)))
return secgroup_dict
def _process_security_group_properties_create(self, context,

View File

@ -2278,8 +2278,12 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
LOG.exception(msg)
raise nsx_exc.NsxPluginException(err_msg=msg)
kwargs = {'context': context, 'port': neutron_db}
registry.notify(resources.PORT, events.AFTER_CREATE, self, **kwargs)
registry.publish(
resources.PORT, events.AFTER_CREATE, self,
payload=events.DBEventPayload(
context, resource_id=port_data['id'],
states=(neutron_db,)))
return port_data
def _delete_port_on_backend(self, context, net_id, port_id):
@ -2486,13 +2490,14 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
updated_port['revision_number'] = port_model.revision_number
# Notifications must be sent after the above transaction is complete
kwargs = {
'context': context,
'port': updated_port,
'mac_address_updated': False,
'original_port': original_port,
}
registry.notify(resources.PORT, events.AFTER_UPDATE, self, **kwargs)
registry.publish(
resources.PORT, events.AFTER_UPDATE, self,
payload=events.DBEventPayload(
context,
resource_id=port_id,
metadata={'mac_address_updated': False},
states=(original_port, updated_port,)))
return updated_port
def get_port(self, context, id, fields=None):

View File

@ -2217,8 +2217,11 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
self._remove_provider_security_groups_from_list(port_data)
self._extend_nsx_port_dict_binding(context, port_data)
kwargs = {'context': context, 'port': neutron_db}
registry.notify(resources.PORT, events.AFTER_CREATE, self, **kwargs)
payload = events.DBEventPayload(
context,
states=(neutron_db,))
registry.publish(resources.PORT, events.AFTER_CREATE, self,
payload=payload)
return port_data
def _make_port_dict(self, port, fields=None,
@ -2676,13 +2679,14 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
LOG.error("Unable to update mac learning for port %s, "
"reason: %s", id, e)
kwargs = {
'context': context,
'port': ret_port,
'mac_address_updated': False,
'original_port': original_port,
}
registry.notify(resources.PORT, events.AFTER_UPDATE, self, **kwargs)
registry.publish(
resources.PORT, events.AFTER_UPDATE, self,
payload=events.DBEventPayload(
context,
resource_id=id,
metadata={'mac_address_updated': False},
states=(original_port, ret_port,)))
return ret_port
def _extend_get_port_dict_qos_and_binding(self, context, port):

View File

@ -1575,8 +1575,13 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
if not cfg.CONF.nsx_v3.native_dhcp_metadata:
with db_api.CONTEXT_WRITER.using(context):
nsx_rpc.handle_port_metadata_access(self, context, neutron_db)
kwargs = {'context': context, 'port': neutron_db}
registry.notify(resources.PORT, events.AFTER_CREATE, self, **kwargs)
registry.publish(
resources.PORT, events.AFTER_CREATE, self,
payload=events.DBEventPayload(
context, resource_id=port_data['id'],
states=(neutron_db,)))
return port_data
def _pre_delete_port_check(self, context, port_id, l2gw_port_check):
@ -1886,14 +1891,14 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
updated_port['revision_number'] = port_model.revision_number
# Notifications must be sent after the above transaction is complete
kwargs = {
'context': context,
'port': updated_port,
'mac_address_updated': False,
'original_port': original_port,
}
registry.publish(
resources.PORT, events.AFTER_UPDATE, self,
payload=events.DBEventPayload(
context,
resource_id=id,
metadata={'mac_address_updated': False},
states=(original_port, updated_port,)))
registry.notify(resources.PORT, events.AFTER_UPDATE, self, **kwargs)
return updated_port
def _extend_get_port_dict_qos_and_binding(self, context, port):

View File

@ -24,6 +24,7 @@ LOG = logging.getLogger(__name__)
@admin_utils.output_header
@admin_utils.unpack_payload
def set_loadbalancer_status_error(resource, event, trigger, **kwargs):
usage_msg = ("Loadbalancer id should be specified with "
"--property loadbalancer-id=<id>")

View File

@ -21,12 +21,42 @@ from vmware_nsx.db import db
from vmware_nsx.shell import resources as nsxadmin
from neutron.common import profiler # noqa
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
class MetadataEventPayload(events.EventPayload):
"""An event type where only metadata metters.
Event metadata will be accessed like a dictionary.
"""
def __init__(self, metadata):
super().__init__(None, metadata=metadata)
def __getitem__(self, key):
return self.metadata[key]
def unpack_payload(func):
"""Decorator to run admin shell functions.
Unpacks payload metadata and passess them as kwargs to the
actual callback
"""
def wrapper(resource, event, trigger, payload):
# Use only with MetadataEventPayload
if payload:
func(resource, event, trigger, **payload.metadata)
else:
func(resource, event, trigger)
return wrapper
def output_header(func):
"""Decorator to demarcate the output of various hooks.

View File

@ -22,6 +22,7 @@ from oslo_config import cfg
@admin_utils.output_header
@admin_utils.unpack_payload
def generate_cert(resource, event, trigger, **kwargs):
"""Generate self signed client certificate and private key
"""
@ -29,24 +30,28 @@ def generate_cert(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def delete_cert(resource, event, trigger, **kwargs):
"""Delete client certificate and private key """
return v3_common_cert.delete_cert(cfg.CONF.nsx_p, **kwargs)
@admin_utils.output_header
@admin_utils.unpack_payload
def show_cert(resource, event, trigger, **kwargs):
"""Show client certificate details """
return v3_common_cert.show_cert(cfg.CONF.nsx_p, **kwargs)
@admin_utils.output_header
@admin_utils.unpack_payload
def import_cert(resource, event, trigger, **kwargs):
"""Import client certificate that was generated externally"""
return v3_common_cert.import_cert(cfg.CONF.nsx_p, **kwargs)
@admin_utils.output_header
@admin_utils.unpack_payload
def show_nsx_certs(resource, event, trigger, **kwargs):
"""Show client certificates associated with openstack identity in NSX"""
return v3_common_cert.show_nsx_certs(cfg.CONF.nsx_p, **kwargs)

View File

@ -26,6 +26,7 @@ LOG = logging.getLogger(__name__)
@admin_utils.output_header
@admin_utils.unpack_payload
def update_lb_service_tags(resource, event, trigger, **kwargs):
"""Update the LB id tag on existing LB services"""
nsxpolicy = p_utils.get_connected_nsxpolicy()

View File

@ -34,11 +34,14 @@ LOG = logging.getLogger(__name__)
@admin_utils.output_header
def cleanup_db_mappings(resource, event, trigger, **kwargs):
"""Delete all entries from nsx-t mapping tables in DB"""
return migration. MP2Policy_cleanup_db_mappings(
# Don't annotate with unpack_payload because this is just a wrapper for
# another callback!
return migration.MP2Policy_cleanup_db_mappings(
resource, event, trigger, **kwargs)
@admin_utils.output_header
@admin_utils.unpack_payload
def post_v2t_migration_cleanups(resource, event, trigger, **kwargs):
"""Cleanup unneeded migrated resources after v2t migration is done"""
nsxpolicy = p_utils.get_connected_nsxpolicy()
@ -68,6 +71,7 @@ def post_v2t_migration_cleanups(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def migration_tier0_redistribute(resource, event, trigger, **kwargs):
"""Disable/Restore tier0s route redistribution during V2T migration"""
errmsg = ("Need to specify --property action=disable/restore and a comma "
@ -166,6 +170,7 @@ def _cidrs_overlap(cidr0, cidr1):
@admin_utils.output_header
@admin_utils.unpack_payload
def migration_validate_external_cidrs(resource, event, trigger, **kwargs):
"""Before V2T migration, validate that the external subnets cidrs
do not overlap the tier0 uplinks

View File

@ -27,6 +27,7 @@ LOG = logging.getLogger(__name__)
@admin_utils.list_handler(constants.NETWORKS)
@admin_utils.output_header
@admin_utils.unpack_payload
def list_networks(resource, event, trigger, **kwargs):
"""List neutron networks
@ -55,6 +56,7 @@ def list_networks(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def migrate_dhcp_to_policy(resource, event, trigger, **kwargs):
errmsg = ("Need to specify policy dhcp config id. Add "
"--property dhcp-config=<id>")
@ -116,6 +118,7 @@ def migrate_dhcp_to_policy(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_admin_state(resource, event, trigger, **kwargs):
"""Upon upgrade to NSX3 update policy segments & ports
So that the neutron admin state will match the policy one
@ -144,6 +147,7 @@ def update_admin_state(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_metadata(resource, event, trigger, **kwargs):
"""
Update the metadata proxy configuration of segments
@ -191,6 +195,7 @@ def update_metadata(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_dhcp_profile_edge(resource, event, trigger, **kwargs):
"""
Bind the specified dhcp profile to the edge clusters of tier0 GW

View File

@ -39,6 +39,7 @@ class RoutersPlugin(db_base_plugin_v2.NeutronDbPluginV2,
@admin_utils.list_handler(constants.ROUTERS)
@admin_utils.output_header
@admin_utils.unpack_payload
def list_routers(resource, event, trigger, **kwargs):
"""List neutron routers
@ -63,6 +64,7 @@ def list_routers(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_tier0(resource, event, trigger, **kwargs):
"""Replace old tier0 with a new one on the neutron DB and NSX backend"""
errmsg = ("Need to specify old and new tier0 ID. Add --property "
@ -120,6 +122,7 @@ def update_tier0(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def recover_tier0(resource, event, trigger, **kwargs):
"""
Reconfigure the tier1 routers with tier0 GW at NSX backend and update the
@ -208,6 +211,7 @@ def recover_tier0(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_nat_firewall_match(resource, event, trigger, **kwargs):
"""Update the firewall_match value in neutron nat rules with a new value"""
errmsg = ("Need to specify internal/external firewall_match value. "

View File

@ -26,6 +26,7 @@ neutron_client = securitygroups_db.SecurityGroupDbMixin()
@admin_utils.list_handler(constants.SECURITY_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def list_security_groups(resource, event, trigger, **kwargs):
"""List neutron security groups

View File

@ -28,6 +28,7 @@ MIN_REALIZATION_INTERVAL = 1
MAX_REALIZATION_INTERVAL = 10
@admin_utils.unpack_payload
def set_system_parameters(resource, event, trigger, **kwargs):
"""Set interval that controls realization and purge frequency

View File

@ -73,6 +73,7 @@ def extend_edge_info(edge):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_backup_edges(resource, event, trigger, **kwargs):
"""List backup edges"""
backup_edges = get_nsxv_backup_edges()
@ -123,6 +124,7 @@ def _nsx_delete_backup_edge(edge_id, all_backup_edges):
return _delete_edge_from_nsx_and_neutron(edge_id, edge['name'])
@admin_utils.unpack_payload
def nsx_clean_backup_edge(resource, event, trigger, **kwargs):
"""Delete backup edge"""
errmsg = ("Need to specify edge-id property. Add --property "
@ -146,6 +148,7 @@ def nsx_clean_backup_edge(resource, event, trigger, **kwargs):
_nsx_delete_backup_edge(edge_id, get_nsxv_backup_edges())
@admin_utils.unpack_payload
def nsx_clean_all_backup_edges(resource, event, trigger, **kwargs):
"""Delete all backup edges"""
scope = "all"
@ -177,6 +180,7 @@ def nsx_clean_all_backup_edges(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def neutron_clean_backup_edge(resource, event, trigger, **kwargs):
"""Delete a backup edge from the neutron, and backend by it's name
@ -212,6 +216,7 @@ def neutron_clean_backup_edge(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_name_mismatches(resource, event, trigger, **kwargs):
edges = utils.get_nsxv_backend_edges()
plugin_nsx_mismatch = []
@ -255,6 +260,7 @@ def nsx_list_name_mismatches(resource, event, trigger, **kwargs):
['edge_id', 'router_id', 'db_status']))
@admin_utils.unpack_payload
def nsx_fix_name_mismatch(resource, event, trigger, **kwargs):
errmsg = ("Need to specify edge-id property. Add --property "
"edge-id=<edge-id>")

View File

@ -30,6 +30,7 @@ LOG = logging.getLogger(__name__)
@admin_utils.output_header
@admin_utils.unpack_payload
def validate_configuration(resource, event, trigger, **kwargs):
"""Validate the nsxv configuration"""
try:
@ -43,6 +44,7 @@ def validate_configuration(resource, event, trigger, **kwargs):
LOG.info("Configuration validation succeeded")
@admin_utils.unpack_payload
def check_clusters(resource, event, trigger, **kwargs):
clusters_str = ""
if kwargs.get('property'):

View File

@ -74,6 +74,7 @@ def neutron_get_static_bindings_by_edge(edge_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_dhcp_bindings(resource, event, trigger, **kwargs):
"""List missing DHCP bindings from NSXv backend.
@ -103,6 +104,7 @@ def list_missing_dhcp_bindings(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_update_dhcp_edge_binding(resource, event, trigger, **kwargs):
"""Resync DHCP bindings on NSXv Edge"""
if not kwargs.get('property'):
@ -199,6 +201,7 @@ def recreate_network_dhcp(context, plugin, edge_manager, old_edge_id, net_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_recreate_dhcp_edge(resource, event, trigger, **kwargs):
"""Recreate a dhcp edge with all the networks on a new NSXv edge"""
usage_msg = ("Need to specify edge-id or net-id parameter")
@ -301,6 +304,7 @@ def nsx_recreate_dhcp_edge_by_net_id(net_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_redistribute_dhcp_edges(resource, event, trigger, **kwargs):
"""If any of the DHCP networks are on a conflicting edge move them"""
context = n_context.get_admin_context()

View File

@ -47,6 +47,7 @@ INTERNAL_SUBNET = "169.254"
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_edges(resource, event, trigger, **kwargs):
"""List edges from NSXv backend"""
@ -70,6 +71,7 @@ def extend_edge_info(edges):
@admin_utils.output_header
@admin_utils.unpack_payload
def neutron_list_router_edge_bindings(resource, event, trigger, **kwargs):
"""List NSXv edges from Neutron DB"""
edges = utils.get_router_edge_bindings()
@ -79,6 +81,7 @@ def neutron_list_router_edge_bindings(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def clean_orphaned_router_bindings(resource, event, trigger, **kwargs):
"""Delete nsx router bindings entries without real objects behind them"""
orphaned_list = get_orphaned_router_bindings()
@ -110,6 +113,7 @@ def clean_orphaned_router_bindings(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_orphaned_router_bindings(resource, event, trigger, **kwargs):
"""List nsx router bindings entries without real objects behind them"""
orphaned_list = get_orphaned_router_bindings()
@ -210,6 +214,7 @@ def router_binding_obj_exist(context, binding, net_ids, rtr_ids, plr_tlr_ids):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_orphaned_edges(resource, event, trigger, **kwargs):
"""List orphaned Edges on NSXv.
@ -231,6 +236,7 @@ def nsx_list_orphaned_edges(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_delete_orphaned_edges(resource, event, trigger, **kwargs):
"""Delete orphaned edges from NSXv backend"""
orphaned_edges = utils.get_orphaned_edges()
@ -273,6 +279,7 @@ def get_router_edge_vnic_bindings(edge_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_missing_edges(resource, event, trigger, **kwargs):
"""List missing edges and networks serviced by those edges.
@ -544,6 +551,7 @@ def change_edge_hostgroup(properties):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_update_edge(resource, event, trigger, **kwargs):
"""Update edge properties"""
usage_msg = ("Need to specify edge-id parameter and "
@ -601,6 +609,7 @@ def nsx_update_edge(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_update_edges(resource, event, trigger, **kwargs):
"""Update all edges with the given property"""
if not kwargs.get('property'):
@ -772,11 +781,13 @@ def _update_edges_connectivity(disconnect=True):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_disconnect_edges(resource, event, trigger, **kwargs):
return _update_edges_connectivity(disconnect=True)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_reconnect_edges(resource, event, trigger, **kwargs):
return _update_edges_connectivity(disconnect=False)

View File

@ -135,6 +135,7 @@ def _assemble_gw_edge(name, size, external_iface_info, internal_iface_info,
@admin_utils.output_header
@admin_utils.unpack_payload
def create_bgp_gw(resource, event, trigger, **kwargs):
"""Creates a new BGP GW edge"""
usage = ("nsxadmin -r bgp-gw-edge -o create "
@ -203,6 +204,7 @@ def create_bgp_gw(resource, event, trigger, **kwargs):
LOG.info(formatters.output_formatter('BGP GW Edge', [res], headers))
@admin_utils.unpack_payload
def delete_bgp_gw(resource, event, trigger, **kwargs):
usage = ("nsxadmin -r bgp-gw-edge -o delete "
"--property gw-edge-id=<EDGE_ID>")
@ -219,6 +221,7 @@ def delete_bgp_gw(resource, event, trigger, **kwargs):
return
@admin_utils.unpack_payload
def list_bgp_edges(resource, event, trigger, **kwargs):
bgp_edges = []
edges = v_utils.get_nsxv_backend_edges()
@ -237,6 +240,7 @@ def list_bgp_edges(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def create_redis_rule(resource, event, trigger, **kwargs):
usage = ("nsxadmin -r routing-redistribution-rule -o create "
"--property gw-edge-ids=<GW_EDGE_ID>[,...] "
@ -293,6 +297,7 @@ def create_redis_rule(resource, event, trigger, **kwargs):
'Routing redistribution rule', res, headers))
@admin_utils.unpack_payload
def delete_redis_rule(resource, event, trigger, **kwargs):
usage = ("nsxadmin -r routing-redistribution-rule -o delete "
"--property gw-edge-ids=<GW_EDGE_ID>[,...]"
@ -316,6 +321,7 @@ def delete_redis_rule(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def add_bgp_neighbour(resource, event, trigger, **kwargs):
usage = ("nsxadmin -r bgp-neighbour -o create "
"--property gw-edge-ids=<GW_EDGE_ID>[,...] "
@ -356,6 +362,7 @@ def add_bgp_neighbour(resource, event, trigger, **kwargs):
res, headers))
@admin_utils.unpack_payload
def remove_bgp_neighbour(resource, event, trigger, **kwargs):
usage = ("nsxadmin -r bgp-neighbour -o delete "
"--property gw-edge-ids=<GW_EDGE_ID>[,...] "

View File

@ -217,6 +217,7 @@ def _handle_edge(context, plugin, az_name, edge_id, edge_internal_ips):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_redo_metadata_cfg(resource, event, trigger, **kwargs):
properties = admin_utils.parse_multi_keyval_opt(kwargs.get('property'))
edgeapi = utils.NeutronDbClient()
@ -337,6 +338,7 @@ def nsx_redo_metadata_cfg_for_az(context, plugin, az_name, check_az=True):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_shared_secret(resource, event, trigger, **kwargs):
edgeapi = utils.NeutronDbClient()
edge_list = nsxv_db.get_nsxv_internal_edges_by_purpose(
@ -392,6 +394,7 @@ def _md_member_status(title, edge_ids):
@admin_utils.output_header
@admin_utils.unpack_payload
def get_metadata_status(resource, event, trigger, **kwargs):
if kwargs.get('property'):
properties = admin_utils.parse_multi_keyval_opt(kwargs['property'])

View File

@ -520,6 +520,7 @@ def _validate_config():
@admin_utils.output_header
@admin_utils.unpack_payload
def validate_config_for_migration(resource, event, trigger, **kwargs):
"""Validate the nsxv configuration before migration to nsx-t"""
# Read the command line parameters
@ -612,6 +613,7 @@ def validate_config_for_migration(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_ports_vif_ids(resource, event, trigger, **kwargs):
filename = None
if kwargs.get('property'):
@ -649,6 +651,7 @@ def list_ports_vif_ids(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def build_edge_mapping_file(resource, event, trigger, **kwargs):
filename = None
if kwargs.get('property'):

View File

@ -56,6 +56,7 @@ def get_networks_name_map():
@admin_utils.output_header
@admin_utils.unpack_payload
def neutron_list_networks(resource, event, trigger,
**kwargs):
LOG.info(formatters.output_formatter(constants.NETWORKS,
@ -64,6 +65,7 @@ def neutron_list_networks(resource, event, trigger,
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_update_switch(resource, event, trigger, **kwargs):
nsxv_c = utils.get_nsxv_client()
if not kwargs.get('property'):
@ -114,6 +116,7 @@ def nsx_update_switch(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_networks(resource, event, trigger, **kwargs):
"""List the neutron networks which are missing the backend moref
"""
@ -145,6 +148,7 @@ def list_missing_networks(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_orphaned_networks(resource, event, trigger, **kwargs):
"""List the NSX networks which are missing the neutron DB
"""
@ -174,6 +178,7 @@ def _get_nsx_portgroups(dvs_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_nsx_portgroups(resource, event, trigger, **kwargs):
if not cfg.CONF.dvs.host_ip:
LOG.info("Please configure the dvs section in the nsx configuration "
@ -188,6 +193,7 @@ def list_nsx_portgroups(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def delete_nsx_portgroups(resource, event, trigger, **kwargs):
if not cfg.CONF.dvs.host_ip:
LOG.info("Please configure the dvs section in the nsx configuration "
@ -273,6 +279,7 @@ def list_neutron_virtual_wires(vws):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_nsx_virtual_wires(resource, event, trigger, **kwargs):
filename = None
internal = False
@ -298,6 +305,7 @@ def list_nsx_virtual_wires(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def delete_backend_network(resource, event, trigger, **kwargs):
"""Delete a backend network by its moref
"""

View File

@ -166,6 +166,7 @@ def nsx_recreate_router(router_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_recreate_router_or_edge(resource, event, trigger, **kwargs):
"""Recreate a router edge with all the data on a new NSXv edge"""
if not kwargs.get('property'):
@ -188,6 +189,7 @@ def nsx_recreate_router_or_edge(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def migrate_distributed_routers_dhcp(resource, event, trigger, **kwargs):
context = n_context.get_admin_context()
nsxv = utils.get_nsxv_client()
@ -224,6 +226,7 @@ def migrate_distributed_routers_dhcp(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_edge_firewalls(resource, event, trigger, **kwargs):
context = n_context.get_admin_context()
updated_routers = []
@ -292,6 +295,7 @@ def is_router_conflicting_on_edge(context, driver, router_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def redistribute_routers(resource, event, trigger, **kwargs):
"""If any of the shared routers are on a conflicting edge move them"""
context = n_context.get_admin_context()
@ -309,6 +313,7 @@ def redistribute_routers(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_orphaned_vnics(resource, event, trigger, **kwargs):
"""List router orphaned router vnics where the port was deleted"""
orphaned_vnics = get_orphaned_vnics()
@ -359,6 +364,7 @@ def get_orphaned_vnics():
@admin_utils.output_header
@admin_utils.unpack_payload
def clean_orphaned_vnics(resource, event, trigger, **kwargs):
"""List router orphaned router vnics where the port was deleted"""
orphaned_vnics = get_orphaned_vnics()

View File

@ -239,6 +239,7 @@ def _log_info(resource, data, attrs=['name', 'id']):
@admin_utils.list_handler(constants.SECURITY_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def neutron_list_security_groups_mappings(resource, event, trigger, **kwargs):
sg_mappings = neutron_sg.get_security_groups_mappings()
_log_info(constants.SECURITY_GROUPS,
@ -249,6 +250,7 @@ def neutron_list_security_groups_mappings(resource, event, trigger, **kwargs):
@admin_utils.list_handler(constants.FIREWALL_SECTIONS)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_dfw_sections(resource, event, trigger, **kwargs):
fw_sections = nsxv_firewall.list_fw_sections()
_log_info(constants.FIREWALL_SECTIONS, fw_sections)
@ -257,6 +259,7 @@ def nsx_list_dfw_sections(resource, event, trigger, **kwargs):
@admin_utils.list_handler(constants.FIREWALL_NSX_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_security_groups(resource, event, trigger, **kwargs):
nsx_secgroups = nsxv_firewall.list_security_groups()
_log_info(constants.FIREWALL_NSX_GROUPS, nsx_secgroups)
@ -278,6 +281,7 @@ def _find_missing_security_groups():
@admin_utils.list_mismatches_handler(constants.FIREWALL_NSX_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_security_groups(resource, event, trigger, **kwargs):
sgs_with_missing_nsx_group = _find_missing_security_groups()
missing_securitgroups_info = [
@ -307,6 +311,7 @@ def _find_missing_sections():
@admin_utils.list_mismatches_handler(constants.FIREWALL_SECTIONS)
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_firewall_sections(resource, event, trigger, **kwargs):
sgs_with_missing_section = _find_missing_sections()
missing_sections_info = [{'securitygroup-name': sg['name'],
@ -334,6 +339,7 @@ def _get_unused_firewall_sections():
@admin_utils.output_header
@admin_utils.unpack_payload
def list_unused_firewall_sections(resource, event, trigger, **kwargs):
unused_sections = _get_unused_firewall_sections()
_log_info(constants.FIREWALL_SECTIONS, unused_sections,
@ -342,6 +348,7 @@ def list_unused_firewall_sections(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def clean_unused_firewall_sections(resource, event, trigger, **kwargs):
unused_sections = _get_unused_firewall_sections()
for fw_section in unused_sections:
@ -376,6 +383,7 @@ def _find_orphaned_section_rules():
@admin_utils.output_header
@admin_utils.unpack_payload
def list_orphaned_firewall_section_rules(resource, event, trigger, **kwargs):
orphaned_rules = _find_orphaned_section_rules()
_log_info(constants.FIREWALL_SECTIONS, orphaned_rules,
@ -385,6 +393,7 @@ def list_orphaned_firewall_section_rules(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def clean_orphaned_firewall_section_rules(resource, event, trigger, **kwargs):
orphaned_rules = _find_orphaned_section_rules()
for rule in orphaned_rules:
@ -400,12 +409,14 @@ def clean_orphaned_firewall_section_rules(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def reorder_firewall_sections(resource, event, trigger, **kwargs):
nsxv_firewall.reorder_fw_sections()
@admin_utils.fix_mismatches_handler(constants.SECURITY_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def fix_security_groups(resource, event, trigger, **kwargs):
context_ = n_context.get_admin_context()
sgs_with_missing_section = _find_missing_sections()
@ -444,6 +455,7 @@ def fix_security_groups(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_policies(resource, event, trigger, **kwargs):
"""List nsx service composer policies"""
context = n_context.get_admin_context()
@ -456,6 +468,7 @@ def list_policies(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def migrate_sg_to_policy(resource, event, trigger, **kwargs):
"""Change the mode of a security group from rules to NSX policy"""
if not kwargs.get('property'):
@ -537,6 +550,7 @@ def migrate_sg_to_policy(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def firewall_update_cluster_default_fw_section(resource, event, trigger,
**kwargs):
with utils.NsxVPluginWrapper() as plugin:
@ -545,6 +559,7 @@ def firewall_update_cluster_default_fw_section(resource, event, trigger,
@admin_utils.output_header
@admin_utils.unpack_payload
def update_security_groups_logging(resource, event, trigger, **kwargs):
"""Update allowed traffic logging for all neutron security group rules"""
errmsg = ("Need to specify log-allowed-traffic property. Add --property "

View File

@ -45,6 +45,7 @@ def get_spoofguard_policy_data(policy_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_spoofguard_policies(resource, event, trigger, **kwargs):
"""List spoofguard policies from NSXv backend"""
policies = get_spoofguard_policies()
@ -59,6 +60,7 @@ def get_spoofguard_policy_network_mappings():
@admin_utils.output_header
@admin_utils.unpack_payload
def neutron_list_spoofguard_policy_mappings(resource, event, trigger,
**kwargs):
mappings = get_spoofguard_policy_network_mappings()
@ -81,6 +83,7 @@ def get_missing_spoofguard_policy_mappings(reverse=None):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_missing_spoofguard_policies(resource, event, trigger,
**kwargs):
"""List missing spoofguard policies on NSXv.
@ -167,6 +170,7 @@ def nsx_list_mismatch_addresses_for_net(context, plugin, network_id,
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_mismatch_addresses(resource, event, trigger, **kwargs):
"""List missing spoofguard policies approved addresses on NSXv.
@ -209,6 +213,7 @@ def nsx_list_mismatch_addresses(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_fix_mismatch_addresses(resource, event, trigger, **kwargs):
"""Fix missing spoofguard policies approved addresses for a port."""
@ -235,6 +240,7 @@ def nsx_fix_mismatch_addresses(resource, event, trigger, **kwargs):
LOG.info("Done.")
@admin_utils.unpack_payload
def nsx_clean_spoofguard_policy(resource, event, trigger, **kwargs):
"""Delete spoofguard policy"""
errmsg = ("Need to specify policy-id. Add --property "

View File

@ -23,6 +23,7 @@ from oslo_config import cfg
@admin_utils.output_header
@admin_utils.unpack_payload
def generate_cert(resource, event, trigger, **kwargs):
"""Generate self signed client certificate and private key
"""
@ -30,24 +31,28 @@ def generate_cert(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def delete_cert(resource, event, trigger, **kwargs):
"""Delete client certificate and private key """
return v3_common_cert.delete_cert(cfg.CONF.nsx_v3, **kwargs)
@admin_utils.output_header
@admin_utils.unpack_payload
def show_cert(resource, event, trigger, **kwargs):
"""Show client certificate details """
return v3_common_cert.show_cert(cfg.CONF.nsx_v3, **kwargs)
@admin_utils.output_header
@admin_utils.unpack_payload
def import_cert(resource, event, trigger, **kwargs):
"""Import client certificate that was generated externally"""
return v3_common_cert.import_cert(cfg.CONF.nsx_v3, **kwargs)
@admin_utils.output_header
@admin_utils.unpack_payload
def show_nsx_certs(resource, event, trigger, **kwargs):
"""Show client certificates associated with openstack identity in NSX"""
return v3_common_cert.show_nsx_certs(cfg.CONF.nsx_v3, **kwargs)

View File

@ -24,6 +24,7 @@ LOG = logging.getLogger(__name__)
@admin_utils.output_header
@admin_utils.unpack_payload
def find_cluster_managers_ips(resource, event, trigger, **kwargs):
"""Show the current NSX rate limit."""

View File

@ -24,6 +24,7 @@ LOG = logging.getLogger(__name__)
@admin_utils.output_header
@admin_utils.unpack_payload
def validate_configuration(resource, event, trigger, **kwargs):
"""Validate the nsxv3 configuration"""
try:

View File

@ -29,6 +29,7 @@ neutron_client = utils.NeutronDbClient()
@admin_utils.output_header
@admin_utils.unpack_payload
def list_dhcp_bindings(resource, event, trigger, **kwargs):
"""List DHCP bindings in Neutron."""
@ -39,6 +40,7 @@ def list_dhcp_bindings(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_recreate_dhcp_server(resource, event, trigger, **kwargs):
"""Recreate DHCP server & binding for a neutron network"""
if not cfg.CONF.nsx_v3.native_dhcp_metadata:

View File

@ -43,6 +43,7 @@ def _get_dhcp_profile_uuid(**kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_orphaned_dhcp_servers(resource, event, trigger, **kwargs):
"""List logical DHCP servers without associated DHCP-enabled subnet."""
@ -68,6 +69,7 @@ def nsx_list_orphaned_dhcp_servers(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_clean_orphaned_dhcp_servers(resource, event, trigger, **kwargs):
"""Remove logical DHCP servers without associated DHCP-enabled subnet."""

View File

@ -25,6 +25,7 @@ neutron_client = utils.NeutronDbClient()
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_rate_limit_show(resource, event, trigger, **kwargs):
"""Show the current NSX rate limit."""
@ -34,6 +35,7 @@ def nsx_rate_limit_show(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_rate_limit_update(resource, event, trigger, **kwargs):
"""Set the NSX rate limit

View File

@ -30,6 +30,7 @@ LOG = logging.getLogger(__name__)
@admin_utils.list_handler(constants.LB_SERVICES)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_lb_services(resource, event, trigger, **kwargs):
"""List LB services on NSX backend"""
@ -43,6 +44,7 @@ def nsx_list_lb_services(resource, event, trigger, **kwargs):
@admin_utils.list_handler(constants.LB_VIRTUAL_SERVERS)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_lb_virtual_servers(resource, event, trigger, **kwargs):
"""List LB virtual servers on NSX backend"""
@ -56,6 +58,7 @@ def nsx_list_lb_virtual_servers(resource, event, trigger, **kwargs):
@admin_utils.list_handler(constants.LB_POOLS)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_lb_pools(resource, event, trigger, **kwargs):
nsxlib = utils.get_connected_nsxlib()
@ -68,6 +71,7 @@ def nsx_list_lb_pools(resource, event, trigger, **kwargs):
@admin_utils.list_handler(constants.LB_MONITORS)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_lb_monitors(resource, event, trigger, **kwargs):
nsxlib = utils.get_connected_nsxlib()
@ -79,6 +83,7 @@ def nsx_list_lb_monitors(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_update_router_lb_advertisement(resource, event, trigger, **kwargs):
"""The implementation of the VIP advertisement changed.

View File

@ -1625,6 +1625,7 @@ def pre_migration_checks(nsxlib, plugin):
@admin_utils.output_header
@admin_utils.unpack_payload
def MP2Policy_pre_migration_check(resource, event, trigger, **kwargs):
"""Verify if the current configuration can be migrated to Policy"""
nsxlib = utils.get_connected_nsxlib()
@ -1699,6 +1700,7 @@ def _get_nsxlib_from_config(verbose, for_end_api=False):
@admin_utils.output_header
@admin_utils.unpack_payload
def MP2Policy_migration(resource, event, trigger, **kwargs):
"""Migrate NSX resources and neutron DB from NSX-T (MP) to Policy"""
@ -1776,6 +1778,7 @@ def MP2Policy_migration(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def MP2Policy_cleanup_db_mappings(resource, event, trigger, **kwargs):
"""Delete all entries from nsx-t mapping tables in DB.
This cleanup does not have to run, as all those tables have delete-cascade

View File

@ -38,6 +38,7 @@ def get_network_nsx_id(context, neutron_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_networks(resource, event, trigger, **kwargs):
"""List neutron networks that are missing the NSX backend network
"""
@ -72,6 +73,7 @@ def list_missing_networks(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_orphaned_networks(resource, event, trigger, **kwargs):
nsxlib = utils.get_connected_nsxlib()
admin_cxt = neutron_context.get_admin_context()
@ -82,6 +84,7 @@ def list_orphaned_networks(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def delete_backend_network(resource, event, trigger, **kwargs):
errmsg = ("Need to specify nsx-id property. Add --property nsx-id=<id>")
if not kwargs.get('property'):

View File

@ -67,6 +67,7 @@ def get_network_nsx_id(session, neutron_id):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_ports(resource, event, trigger, **kwargs):
"""List neutron ports that are missing the NSX backend port
And ports with wrong switch profiles or bindings
@ -102,6 +103,7 @@ def get_vm_network_device(vm_mng, vm_moref, mac_address):
return device
@admin_utils.unpack_payload
def migrate_compute_ports_vms(resource, event, trigger, **kwargs):
"""Update the VMs ports on the backend after migrating nsx-v -> nsx-v3
@ -192,6 +194,7 @@ def migrate_compute_ports_vms(resource, event, trigger, **kwargs):
LOG.info("Instance %s successfully migrated!", device_id)
@admin_utils.unpack_payload
def migrate_exclude_ports(resource, event, trigger, **kwargs):
_nsx_client = v3_utils.get_nsxv3_client()
@ -241,6 +244,7 @@ def migrate_exclude_ports(resource, event, trigger, **kwargs):
LOG.info("Port %s successfully updated", port_id)
@admin_utils.unpack_payload
def tag_default_ports(resource, event, trigger, **kwargs):
nsxlib = v3_utils.get_connected_nsxlib()
admin_cxt = neutron_context.get_admin_context()

View File

@ -40,6 +40,7 @@ class RoutersPlugin(db_base_plugin_v2.NeutronDbPluginV2,
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_routers(resource, event, trigger, **kwargs):
"""List neutron routers that are missing the NSX backend router
"""
@ -76,6 +77,7 @@ def list_missing_routers(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_nat_rules(resource, event, trigger, **kwargs):
"""Update all routers NAT rules to not bypass the firewall"""
# This feature is supported only since nsx version 2
@ -113,6 +115,7 @@ def update_nat_rules(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_enable_standby_relocation(resource, event, trigger, **kwargs):
"""Enable standby relocation on all routers """
# This feature is supported only since nsx version 2.4
@ -148,6 +151,7 @@ def update_enable_standby_relocation(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def list_orphaned_routers(resource, event, trigger, **kwargs):
nsxlib = utils.get_connected_nsxlib()
admin_cxt = neutron_context.get_admin_context()
@ -158,6 +162,7 @@ def list_orphaned_routers(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def delete_backend_router(resource, event, trigger, **kwargs):
nsxlib = utils.get_connected_nsxlib()
errmsg = ("Need to specify nsx-id property. Add --property nsx-id=<id>")
@ -195,6 +200,7 @@ def delete_backend_router(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_dhcp_relay(resource, event, trigger, **kwargs):
"""Update all routers dhcp relay service by the current configuration"""
nsxlib = utils.get_connected_nsxlib()
@ -243,6 +249,7 @@ def update_dhcp_relay(resource, event, trigger, **kwargs):
@admin_utils.output_header
@admin_utils.unpack_payload
def update_tier0(resource, event, trigger, **kwargs):
"""Replace old tier0 with a new one on the neutron DB and NSX backend"""
errmsg = ("Need to specify old and new tier0 ID. Add --property "

View File

@ -110,6 +110,7 @@ def _log_info(resource, data, attrs=['display_name', 'id']):
@admin_utils.list_handler(constants.SECURITY_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def list_security_groups_mappings(resource, event, trigger, **kwargs):
"""List neutron security groups"""
sg_mappings = plugin_utils.get_security_groups_mappings(neutron_sg.context)
@ -121,6 +122,7 @@ def list_security_groups_mappings(resource, event, trigger, **kwargs):
@admin_utils.list_handler(constants.FIREWALL_SECTIONS)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_dfw_sections(resource, event, trigger, **kwargs):
"""List NSX backend firewall sections"""
nsxlib = v3_utils.get_connected_nsxlib()
@ -131,6 +133,7 @@ def nsx_list_dfw_sections(resource, event, trigger, **kwargs):
@admin_utils.list_handler(constants.FIREWALL_NSX_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def nsx_list_security_groups(resource, event, trigger, **kwargs):
"""List NSX backend security groups"""
nsxlib = v3_utils.get_connected_nsxlib()
@ -155,6 +158,7 @@ def _find_missing_security_groups():
@admin_utils.list_mismatches_handler(constants.FIREWALL_NSX_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_security_groups(resource, event, trigger, **kwargs):
"""List security groups with sections missing on the NSX backend"""
sgs_with_missing_nsx_group = _find_missing_security_groups()
@ -186,6 +190,7 @@ def _find_missing_sections():
@admin_utils.list_mismatches_handler(constants.FIREWALL_SECTIONS)
@admin_utils.output_header
@admin_utils.unpack_payload
def list_missing_firewall_sections(resource, event, trigger, **kwargs):
"""List security groups with missing sections on the NSX backend"""
sgs_with_missing_section = _find_missing_sections()
@ -200,6 +205,7 @@ def list_missing_firewall_sections(resource, event, trigger, **kwargs):
@admin_utils.fix_mismatches_handler(constants.SECURITY_GROUPS)
@admin_utils.output_header
@admin_utils.unpack_payload
def fix_security_groups(resource, event, trigger, **kwargs):
"""Fix mismatch security groups by recreating missing sections & NS groups
on the NSX backend
@ -259,6 +265,7 @@ def fix_security_groups(resource, event, trigger, **kwargs):
plugin.save_security_group_rule_mappings(context_, rules['rules'])
@admin_utils.unpack_payload
def list_orphaned_sections(resource, event, trigger, **kwargs):
"""List orphaned firewall sections"""
nsxlib = v3_utils.get_connected_nsxlib()
@ -268,6 +275,7 @@ def list_orphaned_sections(resource, event, trigger, **kwargs):
attrs=['id', 'display_name'])
@admin_utils.unpack_payload
def list_orphaned_section_rules(resource, event, trigger, **kwargs):
"""List orphaned firewall section rules"""
nsxlib = v3_utils.get_connected_nsxlib()
@ -278,6 +286,7 @@ def list_orphaned_section_rules(resource, event, trigger, **kwargs):
'section-id', 'rule-id'])
@admin_utils.unpack_payload
def clean_orphaned_sections(resource, event, trigger, **kwargs):
"""Delete orphaned firewall sections from the NSX backend"""
nsxlib = v3_utils.get_connected_nsxlib()
@ -295,6 +304,7 @@ def clean_orphaned_sections(resource, event, trigger, **kwargs):
LOG.info("Backend firewall section %s was deleted.", sec['id'])
@admin_utils.unpack_payload
def clean_orphaned_section_rules(resource, event, trigger, **kwargs):
"""Delete orphaned firewall section rules from the NSX backend"""
nsxlib = v3_utils.get_connected_nsxlib()
@ -315,6 +325,7 @@ def clean_orphaned_section_rules(resource, event, trigger, **kwargs):
LOG.info("Backend firewall rule %s was deleted.", rule['rule-id'])
@admin_utils.unpack_payload
def update_security_groups_logging(resource, event, trigger, **kwargs):
"""Update allowed traffic logging for all neutron security group rules"""
errmsg = ("Need to specify log-allowed-traffic property. Add --property "
@ -351,6 +362,7 @@ def update_security_groups_logging(resource, event, trigger, **kwargs):
"for rule in section %s", section_id)
@admin_utils.unpack_payload
def reuse_default_section(resource, event, trigger, **kwargs):
"""Reuse existing NSX default section & NS group that might already exist
on the NSX from a previous installation.

View File

@ -35,6 +35,7 @@ import requests
from vmware_nsx.common import config # noqa
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 import version
from vmware_nsx.shell import resources
@ -162,9 +163,14 @@ def main(argv=sys.argv[1:]):
_validate_resource_choice(cfg.CONF.resource, selected_plugin)
_validate_op_choice(cfg.CONF.operation, selected_plugin)
registry.notify(cfg.CONF.resource, cfg.CONF.operation, 'nsxadmin',
force=cfg.CONF.force, property=cfg.CONF.property,
verbose=cfg.CONF.verbose)
# build event payload - no context
payload = admin_utils.MetadataEventPayload(
None,
{'force': cfg.CONF.force,
'property': cfg.CONF.property,
'verbose': cfg.CONF.verbose})
registry.publish(cfg.CONF.resource, cfg.CONF.operation,
'nsxadmin', payload=payload)
if __name__ == "__main__":

View File

@ -33,6 +33,7 @@ from vmware_nsx._i18n import _
from vmware_nsx.common import config # noqa
from vmware_nsx.db import nsxv_db
from vmware_nsx.dvs import dvs_utils
from vmware_nsx.shell.admin.plugins.common import utils as admin_utils
from vmware_nsx.shell.admin.plugins.nsxp.resources import utils as nsxp_utils
from vmware_nsx.shell.admin.plugins.nsxv.resources import migration
from vmware_nsx.shell.admin.plugins.nsxv.resources import utils as nsxv_utils
@ -96,9 +97,10 @@ class AbstractTestAdminUtils(base.BaseTestCase, metaclass=abc.ABCMeta):
self.fail(msg=msg)
def _test_resource_with_errors(self, res_name, op, **kwargs):
payload = admin_utils.MetadataEventPayload(kwargs)
# Must call the internal notify_loop in order to get the errors
return registry._get_callback_manager()._notify_loop(
res_name, op, 'nsxadmin', **kwargs)
res_name, op, 'nsxadmin', payload=payload)
def _test_resources(self, res_dict):
for res in res_dict.keys():
@ -281,10 +283,11 @@ class TestNsxvAdminUtils(AbstractTestAdminUtils,
def test_migration_validation(self):
# check that validation fails
args = {'property': ["transit-network=1.1.1.0/24"]}
payload = admin_utils.MetadataEventPayload(
{'property': ["transit-network=1.1.1.0/24"]})
try:
migration.validate_config_for_migration(
'nsx-migrate-v2t', 'validate', None, **args)
'nsx-migrate-v2t', 'validate', None, payload)
except SystemExit:
return
else: