Skip to content

Commit

Permalink
Test plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Matus Jenca <matus.jenca@dnation.cloud>
  • Loading branch information
MatusJenca2 committed Mar 19, 2024
1 parent 9d19f3b commit 19b83d3
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 14 deletions.
13 changes: 2 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
neutron-encryption
===============================

OpenStack Boilerplate contains all the boilerplate you need to create an OpenStack package.

Please fill here a long description which must be at least 3 lines wrapped on
80 cols, so that distribution package maintainers can use it in their packages.
Note that this is a hard requirement.

* Free software: Apache license
* Documentation: https://docs.openstack.org/neutron-encryption/latest
* Source: https://opendev.org/openstack/neutron-encryption
* Bugs: https://bugs.launchpad.net/replace with the name of the project on Launchpad or the ID from Storyboard
Test plugin for encryption in Neutron

Features
--------

* TODO
* None yet
23 changes: 23 additions & 0 deletions devstack/plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
NEUTRON_ENCRYPTION_XTRACE=$(set +o | grep xtrace)
set -o xtrace
function neutron_encryption_install {
setup_develop /opt/stack/neutron-encryption
echo "Installing Neutron encryption plugin" >> encryption-test.log
}

function neutron_encryption_configure {
neutron_service_plugin_class_add encryption
configure_l3_agent
echo "Configuring Neutron encryption plugin" >> encryption-test.log
}


if [[ "$1" == "stack" && "$2" == "install" ]]; then
neutron_encryption_install

elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
neutron_encryption_configure
fi


$NEUTRON_ENCRYPTION_XTRACE
6 changes: 6 additions & 0 deletions devstack/settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Config files
NEUTRON_CONF_DIR=${NEUTRON_CONF_DIR:-"/etc/neutron"}
NEUTRON_ENCRYPTION_DIR=$DEST/neutron-encryption

NEUTRON_ENCRYPTION_CONF_FILE=neutron_encryption.conf
NEUTRON_ENCRYPTION_CONF=$NEUTRON_CONF_DIR/$NEUTRON_ENCRYPTION_CONF_FILE
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions neutron_encryption/db/encryption_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from neutron_encryption.extensions import encryption
from oslo_log import log
_LOG = log.getLogger(__name__)

class EncryptionPluginDb(encryption.EncryptionPluginBase):
pass


class EncryptionPluginRpcDbMixin(object):
pass
Empty file.
82 changes: 82 additions & 0 deletions neutron_encryption/extensions/encryption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

import abc
from neutron_lib.plugins import constants as nconstants
from neutron_lib.services import base as service_base
from neutron_lib.api import extensions as api_extensions
from neutron_lib.plugins import directory
from neutron.api.v2 import base
from neutron.quota import resource_registry
from neutron_lib.db import constants as db_const
from neutron.extensions import standardattrdescription as stdattr_ext
from neutron.api import extensions
from oslo_log import log
_LOG = log.getLogger(__name__)

_LOG.info("TEST: Encryption extension loaded")

RESOURCE_ATTRIBUTE_MAP = {
'encryptions' : {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True,
'is_filter': True,
'is_sort_key': True,
'primary_key': True},
'name': {'allow_post': True, 'allow_put': True,
'is_visible': True, 'default': '', 'is_filter': True,
'is_sort_key': True,
'validate': {
'type:name_not_default': db_const.NAME_FIELD_SIZE}},
}

}

class Encryption(api_extensions.ExtensionDescriptor):
def get_plugin_interface(self):
_LOG.info(f"TEST PLUGIN BASE")
return EncryptionPluginBase

def get_name(self):
return "encryption"
def get_alias(self):
return "encryption"
def get_description(self):
return "The encryption extension."
def get_updated(self):
return "2022-03-14T15:00:00-00:00"
def get_resources(self):
"""Returns Ext Resources."""
exts = []
plugin = directory.get_plugin()
resource_name = 'encryption'
collection_name = "encryption"
params = RESOURCE_ATTRIBUTE_MAP.get("encryptions", dict())
resource_registry.register_resource_by_name(resource_name)
controller = base.create_resource(collection_name,
resource_name,
plugin, params, allow_bulk=True,
allow_pagination=True,
allow_sorting=True)

ex = extensions.ResourceExtension(collection_name,
controller,
attr_map=params)
exts.append(ex)
_LOG.info("TEST: get API resources ")
return exts

def update_attributes_map(self, attributes):
_LOG.info("TEST3: updating attributes map")
super(Encryption, self).update_attributes_map(
attributes, extension_attrs_map=RESOURCE_ATTRIBUTE_MAP)
def get_extended_resources(self, version):
return {}
def get_required_extensions(self):
return [stdattr_ext.Standardattrdescription.get_alias()]


class EncryptionPluginBase:
def get_plugin_type(self):
return 'ENCRYPTION'
def get_plugin_description(self):
return 'Encryption service plugin'
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions neutron_encryption/services/encryption/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from neutron_encryption.db import encryption_db
import inspect
from oslo_log import log
_LOG = log.getLogger(__name__)
class EncryptionPlugin(encryption_db.EncryptionPluginDb):
supported_extension_aliases = ["encryption"]
path_prefix = "/encryption"


class EncryptionDriverPlugin(EncryptionPlugin):
def __init__(self):
super(EncryptionDriverPlugin,self).__init__()
_LOG.info(f"EncryptionDriverPlugin inheritance tree:\n {inspect.getmro(EncryptionDriverPlugin)}")
def get_plugin_type(self):
return 'ENCRYPTION'
def get_plugin_description(self):
return 'Encryption service plugin'
Empty file.
File renamed without changes.
10 changes: 7 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ classifier =
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11


[files]
packages =
neutron-encryption
[entry_points]
neutron.service_plugins =
encryption = neutron_encryption.services.encryption.plugin:EncryptionDriverPlugin
neutron.services.encryption.plugin.EncryptionDriverPlugin = neutron_encryption.services.encryption.plugin:EncryptionDriverPlugin

0 comments on commit 19b83d3

Please sign in to comment.