Files
python-group-based-policy-c…/gbpclient/gbp/v2_0/port.py
Thomas Bachman 2745ef3bbd Add support for ERSPAN
Add support for ERSPAN extension on the openstack port resource.

Change-Id: Ie9c5b429dfab774faef92d514be9110f6795991b
2021-01-26 20:37:12 +00:00

112 lines
3.2 KiB
Python

# 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.
#
"""
Port extension implementations
"""
from cliff import hooks
from osc_lib.cli import parseractions
from openstack.network.v2 import port as port_sdk
from openstack import resource
from openstackclient.i18n import _
from openstackclient.network.v2 import port
_get_attrs_port_new = port._get_attrs
def _convert_erspan_config(parsed_args):
ops = []
for opt in parsed_args.apic_erspan_config:
addr = {}
addr['dest_ip'] = opt['dest-ip']
addr['flow_id'] = opt['flow-id']
if 'direction' in opt:
addr['direction'] = opt['direction']
ops.append(addr)
return ops
def _get_attrs_port_extension(client_manager, parsed_args):
attrs = _get_attrs_port_new(client_manager, parsed_args)
if parsed_args.apic_synchronization_state:
attrs['apic:synchronization_state'
] = parsed_args.apic_synchronization_state
if parsed_args.apic_erspan_config:
attrs['apic:erspan_config'
] = _convert_erspan_config(parsed_args)
if parsed_args.no_apic_erspan_config:
attrs['apic:erspan_config'] = []
return attrs
port._get_attrs = _get_attrs_port_extension
port_sdk.Port.apic_synchronization_state = resource.Body(
'apic:synchronization_state')
port_sdk.Port.apic_erspan_config = resource.Body('apic:erspan_config')
class CreateAndSetPortExtension(hooks.CommandHook):
def get_parser(self, parser):
parser.add_argument(
'--apic-synchronization-state',
metavar="<apic_synchronization_state>",
dest='apic_synchronization_state',
help=_("Apic synchronization state")
)
parser.add_argument(
'--apic-erspan-config',
metavar="<apic_erspan_config>",
dest='apic_erspan_config',
action=parseractions.MultiKeyValueAction,
required_keys=['flow-id', 'dest-ip'],
optional_keys=['direction'],
help=_("Apic ERSPAN configuration")
)
parser.add_argument(
'--no-apic-erspan-config',
dest='no_apic_erspan_config',
action='store_true',
help=_("Apic ERSPAN configuration")
)
return parser
def get_epilog(self):
return ''
def before(self, parsed_args):
return parsed_args
def after(self, parsed_args, return_code):
return return_code
class ShowPortExtension(hooks.CommandHook):
def get_parser(self, parser):
return parser
def get_epilog(self):
return ''
def before(self, parsed_args):
return parsed_args
def after(self, parsed_args, return_code):
return return_code