commit
0411743bb9
@ -0,0 +1,55 @@
|
||||
# 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 neutron_lib.api import converters
|
||||
from neutron_lib import context
|
||||
from neutron_lib.db import api as db_api
|
||||
from oslo_config import cfg
|
||||
from oslo_db import options as db_options
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron.db import models_v2
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup_conf():
|
||||
conf = cfg.CONF
|
||||
db_group, neutron_db_opts = db_options.list_opts()[0]
|
||||
cfg.CONF.register_cli_opts(neutron_db_opts, db_group)
|
||||
conf()
|
||||
|
||||
|
||||
def main():
|
||||
"""Main method for sanitizing the database ``port.mac_address`` column.
|
||||
|
||||
This script will sanitize all ``port.mac_address`` columns existing in the
|
||||
database. The output format will be xx:xx:xx:xx:xx:xx.
|
||||
"""
|
||||
setup_conf()
|
||||
admin_ctx = context.get_admin_context()
|
||||
with db_api.CONTEXT_WRITER.using(admin_ctx):
|
||||
for port in admin_ctx.session.query(models_v2.Port.id,
|
||||
models_v2.Port.mac_address).all():
|
||||
if port[1] == converters.convert_to_sanitized_mac_address(port[1]):
|
||||
continue
|
||||
|
||||
query = admin_ctx.session.query(models_v2.Port)
|
||||
port_db = query.filter(models_v2.Port.id == port[0]).first()
|
||||
if not port_db:
|
||||
continue
|
||||
|
||||
mac_address = converters.convert_to_sanitized_mac_address(port[1])
|
||||
port_db.update({'mac_address': mac_address})
|
||||
LOG.info('Port %s updated, MAC address: %s', port[0],
|
||||
mac_address)
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The ``port.mac_address`` field is sanitized to have a common format
|
||||
"xx:xx:xx:xx:xx:xx". The values stored in the database can be sanitized
|
||||
executing the new script provided ``neutron-sanitize-port-mac-addresses``.
|
||||
This script will read all ``port`` registers and fix, if needed, the
|
||||
stored MAC address format.
|
||||
The ``port`` API is also modified to sanitize the user input. This change
|
||||
was added to neutron-lib 2.12.0 in
|
||||
`788300 <https://review.opendev.org/c/openstack/neutron-lib/+/788300>`_.
|
Loading…
Reference in new issue