-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: adds initial neutron plugin
- Loading branch information
Showing
12 changed files
with
236 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ components/01-secrets/kustomization.yaml | |
# python virtualenv | ||
.venv/ | ||
venv/ | ||
.python-version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Nicholas Kuechler <[email protected]> | ||
Micah Culpepper <[email protected]> <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
ARG OPENSTACK_VERSION | ||
FROM docker.io/openstackhelm/neutron:${OPENSTACK_VERSION}-ubuntu_jammy | ||
|
||
COPY python/neutron-understack /tmp/neutron-understack | ||
RUN /var/lib/openstack/bin/python -m pip install --no-input --no-index /tmp/neutron-understack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Understack neutron plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.1" |
146 changes: 146 additions & 0 deletions
146
python/neutron-understack/neutron_understack/neutron_understack_mech.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import json | ||
import logging | ||
import typing | ||
import uuid | ||
|
||
from neutron_lib.plugins.ml2.api import MechanismDriver, NetworkContext, PortContext, SubnetContext | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def dump_context(context: typing.Union[NetworkContext, SubnetContext, PortContext]) -> dict: | ||
# RESOURCE_ATTRIBUTE_MAP | ||
# from neutron_lib.api.definitions import network, subnet, port, portbindings | ||
# The properties of a NetworkContext.current are defined in network.RESOURCE_ATTRIBUTE_MAP | ||
# The properties of a SubnetContext.current are defined in subnet.RESOURCE_ATTRIBUTE_MAP | ||
# The properties of a PortContext.current are defined in port.RESOURCE_ATTRIBUTE_MAP | ||
attr_map = { | ||
NetworkContext: ("current", "original", "network_segments"), | ||
SubnetContext: ("current", "original"), | ||
PortContext: ( | ||
"current", | ||
"original", | ||
"status", | ||
"original_status", | ||
"network", | ||
"binding_levels", | ||
"original_binding_levels", | ||
"top_bound_segment", | ||
"original_top_bound_segment", | ||
"bottom_bound_segment", | ||
"original_bottom_bound_segment", | ||
"host", | ||
"original_host", | ||
"vif_type", | ||
"original_vif_type", | ||
"vif_details", | ||
"original_vif_details", | ||
"segments_to_bind", | ||
), | ||
} | ||
retval = {"errors": [], "other_attrs": []} | ||
if isinstance(context, NetworkContext): | ||
attrs_to_dump = attr_map[NetworkContext] | ||
elif isinstance(context, SubnetContext): | ||
attrs_to_dump = attr_map[SubnetContext] | ||
elif isinstance(context, PortContext): | ||
attrs_to_dump = attr_map[PortContext] | ||
else: | ||
retval["errors"].append(f"Error: unknown object type {type(context)}") | ||
return retval | ||
|
||
attrs = vars(context) | ||
for attr in attrs: | ||
if attr in attrs_to_dump: | ||
try: | ||
val = getattr(context, attr) | ||
retval.update({attr: val}) | ||
except Exception as e: | ||
retval["errors"].append(f"Error dumping {attr}: {str(e)}") | ||
else: | ||
retval["other_attrs"].append(attr) | ||
return retval | ||
|
||
|
||
def log_call(method: str, context: typing.Union[NetworkContext, SubnetContext, PortContext]) -> None: | ||
data = dump_context(context) | ||
data.update({"method": method}) | ||
try: | ||
jsondata = json.dumps(data) | ||
except Exception as e: | ||
LOG.error( | ||
"failed to dump %s object to JSON on %s call: %s", | ||
str(context), | ||
method, | ||
str(e), | ||
) | ||
return | ||
LOG.info("%s method called with data: %s", method, jsondata) | ||
|
||
|
||
class UnderstackDriver(MechanismDriver): | ||
# See MechanismDriver docs for resource_provider_uuid5_namespace | ||
resource_provider_uuid5_namespace = uuid.UUID("6eae3046-4072-11ef-9bcf-d6be6370a162") | ||
|
||
def initialize(self): | ||
pass | ||
|
||
def create_network_precommit(self, context): | ||
log_call("create_network_precommit", context) | ||
|
||
def create_network_postcommit(self, context): | ||
log_call("create_network_postcommit", context) | ||
|
||
def update_network_precommit(self, context): | ||
log_call("update_network_precommit", context) | ||
|
||
def update_network_postcommit(self, context): | ||
log_call("update_network_postcommit", context) | ||
|
||
def delete_network_precommit(self, context): | ||
log_call("delete_network_precommit", context) | ||
|
||
def delete_network_postcommit(self, context): | ||
log_call("delete_network_postcommit", context) | ||
|
||
def create_subnet_precommit(self, context): | ||
log_call("create_subnet_precommit", context) | ||
|
||
def create_subnet_postcommit(self, context): | ||
log_call("create_subnet_postcommit", context) | ||
|
||
def update_subnet_precommit(self, context): | ||
log_call("update_subnet_precommit", context) | ||
|
||
def update_subnet_postcommit(self, context): | ||
log_call("update_subnet_postcommit", context) | ||
|
||
def delete_subnet_precommit(self, context): | ||
log_call("delete_subnet_precommit", context) | ||
|
||
def delete_subnet_postcommit(self, context): | ||
log_call("delete_subnet_postcommit", context) | ||
|
||
def create_port_precommit(self, context): | ||
log_call("create_port_precommit", context) | ||
|
||
def create_port_postcommit(self, context): | ||
log_call("create_port_postcommit", context) | ||
|
||
def update_port_precommit(self, context): | ||
log_call("update_port_precommit", context) | ||
|
||
def update_port_postcommit(self, context): | ||
log_call("update_port_postcommit", context) | ||
|
||
def delete_port_precommit(self, context): | ||
log_call("delete_port_precommit", context) | ||
|
||
def delete_port_postcommit(self, context): | ||
log_call("delete_port_postcommit", context) | ||
|
||
def bind_port(self, context): | ||
log_call("bind_port", context) | ||
|
||
def check_vlan_transparency(self, context): | ||
log_call("check_vlan_transparency", context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[metadata] | ||
name = neutron-understack | ||
author = Rackspace Technology | ||
author_email = [email protected] | ||
home_page = https://github.com/rackerlabs/understack | ||
summary = Understack ML2 Neutron Driver | ||
python_requires = >=3.10 | ||
classifier = | ||
Development Status :: 3 - Alpha | ||
Environment :: OpenStack | ||
Intended Audience :: System Administrators | ||
Intended Audience :: Information Technology | ||
License :: OSI Approved :: Apache Software License | ||
Operating System :: OS Independent | ||
Programming Language :: Python | ||
Programming Language :: Python :: Implementation :: CPython | ||
Programming Language :: Python :: 3 :: Only | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3.10 | ||
|
||
|
||
description_file = | ||
README.rst | ||
|
||
[options] | ||
install_requires = | ||
neutron-lib==3.* | ||
|
||
packages = find: | ||
|
||
|
||
[options.entry_points] | ||
neutron.ml2.mechanism_drivers = | ||
understack = neutron_understack.neutron_understack_mech:UnderstackDriver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from setuptools import setup | ||
import codecs | ||
import os.path | ||
|
||
# Obtaining version number using recommended approach from | ||
# https://packaging.python.org/guides/single-sourcing-package-version/ | ||
# This avoids problems that may arise from trying to import neutron_understack while it is not installed. | ||
|
||
|
||
def read(rel_path): | ||
here = os.path.abspath(os.path.dirname(__file__)) | ||
with codecs.open(os.path.join(here, rel_path), "r") as fp: | ||
return fp.read() | ||
|
||
|
||
def get_version(rel_path): | ||
for line in read(rel_path).splitlines(): | ||
if line.startswith("__version__"): | ||
delim = '"' if '"' in line else "'" | ||
return line.split(delim)[1] | ||
else: | ||
raise RuntimeError("Unable to find version string.") | ||
|
||
|
||
setup( | ||
name="neutron_understack", | ||
version=get_version("neutron_understack/__init__.py"), | ||
) |