diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3059645 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.eggs +.tox +*.egg-info diff --git a/.zuul.yaml b/.zuul.yaml new file mode 100644 index 0000000..25c9e03 --- /dev/null +++ b/.zuul.yaml @@ -0,0 +1,47 @@ +--- +# Copyright 2020 VEXXHOST, Inc. +# +# 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. + +- job: + name: openstack-tools:image:build + parent: vexxhost-build-docker-image + provides: openstack-tools:image + vars: &id001 + docker_images: + - context: . + repository: vexxhost/openstack-tools + +- job: + name: openstack-tools:image:upload + parent: vexxhost-upload-docker-image + provides: openstack-tools:image + vars: *id001 + +- job: + name: openstack-tools:image:promote + parent: vexxhost-promote-docker-image + vars: *id001 + +- project: + check: + jobs: + - tox-linters + - openstack-tools:image:build + gate: + jobs: + - tox-linters + - openstack-tools:image:upload + promote: + jobs: + - openstack-tools:image:promote diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c164689 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# Copyright 2020 VEXXHOST, Inc. +# +# 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 docker.io/opendevorg/python-builder:3.7 as builder +COPY . /tmp/src +RUN assemble + +FROM docker.io/opendevorg/python-base:3.7 as zuul +COPY --from=builder /output/ /output +RUN /output/install-from-bindep +ADD https://raw.githubusercontent.com/openvswitch/ovs/master/vswitchd/vswitch.ovsschema /usr/share/openvswitch/vswitch.ovsschema diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..79d9ab5 --- /dev/null +++ b/README.rst @@ -0,0 +1,10 @@ +=============== +OpenStack Tools +=============== + +This repository includes useful utilties needed for operations of OpenStack, +however, it's important to note that the existance of some of these tools are +a bug. These are simple interim solutions (especially clean-up tools) which +should all be non-existant as they should be fixed in upstream. + +These tools are also published on DockerHub under ``vexxhost/openstack-tools``. diff --git a/openstack_tools/__init__.py b/openstack_tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstack_tools/cmd/__init__.py b/openstack_tools/cmd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstack_tools/cmd/cleanup/__init__.py b/openstack_tools/cmd/cleanup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstack_tools/cmd/cleanup/openvswitch.py b/openstack_tools/cmd/cleanup/openvswitch.py new file mode 100644 index 0000000..4e38035 --- /dev/null +++ b/openstack_tools/cmd/cleanup/openvswitch.py @@ -0,0 +1,79 @@ +# Copyright 2020 VEXXHOST, Inc. +# +# 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. + +"""Clean-up stale Open vSwitch ports + +It is possible that for some reason, when cleaning up system interfaces, that +Open vSwitch ends up with many ports inside it's configuration which don't +actually exist on the physical host anymore. This script removes them all to +reduce the size of the Open vSwitch database. + +NOTE(mnaser): This tool should simply not exist. Anything in here should + only be here because we're in the process of figuring out why + we need to clean it up. The fact that this file currently + exists is a bug. +""" + +import argparse + +import ovs.db.idl + + +def main(): + """Entry-point for script.""" + + parser = argparse.ArgumentParser(description='Open vSwitch Clean-up tool') + parser.add_argument('--remote', default='unix:/run/openvswitch/db.sock') + parser.add_argument('--schema', + default='/usr/share/openvswitch/vswitch.ovsschema') + parser.add_argument('--apply', action='store_true') + + args = parser.parse_args() + + schema_helper = ovs.db.idl.SchemaHelper(args.schema) + schema_helper.register_columns("Open_vSwitch", ["bridges"]) + schema_helper.register_columns("Bridge", ["name", "ports"]) + schema_helper.register_columns("Port", ["name", "interfaces"]) + schema_helper.register_columns("Interface", []) + + idl = ovs.db.idl.Idl(args.remote, schema_helper) + + seq_no = idl.change_seqno + while True: + idl.run() + + if seq_no == idl.change_seqno: + poller = ovs.poller.Poller() + idl.wait(poller) + poller.block() + continue + + seq_no = idl.change_seqno + break + + for _, bridge in idl.tables["Bridge"].rows.items(): + ports = [] + + for port in bridge.ports: + assert len(port.interfaces) == 1 + interface = port.interfaces[0] + + if interface.ofport == [-1]: + print("%s is invalid" % interface.name) + continue + ports.append(port) + + txn = ovs.db.idl.Transaction(idl) + bridge.ports = ports + txn.commit_block() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cfe5f30 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +ovs diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..128249f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,28 @@ +[metadata] +name = openstack-tools +summary = OpenStack system tools +description-file = + README.rst +author = VEXXHOST, Inc. +author-email = devops@vexxhost.com +home-page = https://opendev.org/vexxhost/openstack-tools +python-requires = >=3.6 +classifier = + Environment :: OpenStack + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + +[files] +packages = + openstack_tools + +[entry_points] +console_scripts = + openstack-cleanup-openvswitch = openstack_tools.cmd.cleanup.openvswitch:main diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fd3c007 --- /dev/null +++ b/setup.py @@ -0,0 +1,19 @@ +# Copyright 2020 VEXXHOST, Inc. +# +# 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 setuptools + +setuptools.setup( + setup_requires=['pbr'], + pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..897e59f --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +flake8 +pylint diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..bfa7c14 --- /dev/null +++ b/tox.ini @@ -0,0 +1,13 @@ +[tox] +envlist = linters + +[testenv] +usedevelop = True +deps = + -rtest-requirements.txt + -rrequirements.txt + +[testenv:linters] +commands = + pylint openstack_tools + flake8 openstack_tools