
Adds extension support with emphasis on ease of extension creation. Extensions strongly conform to preexisting neutron commands (/neutron/v2_0/*). A sample extension has been included (/neutron/v2_0/contrib/_fox_sockets.py). As it is assumed that the sample extension will be packaged with the client, small changes were required to include it with the unit tests. It is also possible to install a module with a 'neutronclient.extension' entry- point defined. More information on this can be found in the stevedore docs under the section "Loading the Plugins". Extension discovery is modeled after nova's module discovery but deviates strongly beyond that. A conforming module, at a minimum: * Will have a class that subclasses NeutronClientExtension to provide the requisite version support, paths, and variable names for the client. Example: neutronclient.neutron.v2_0.contrib._fox_sockets.FoxInSocket * Will have at least one class that subclasses from the ClientExtension* classes to provide the new functionality to the client Example: neutronclient.neutron.v2_0.contrib._fox_sockets.FoxInSocketsList * ClientExtension* subclasses must have a shell_command class variable if the command is to be available to the CLI (shell.py) Example: neutronclient.neutron.v2_0.contrib._fox_sockets.FoxInSocketsList Provides client command extensions through new classes: NeutronClientExtension, and ClientExtension<Action>. The precedence of command loading are as follows: * hard coded commands are loaded first * contribued commands (those in /contrib) * external commands (installed in the environment) are loaded last Commands that have the same name will be overwritten by commands that are loaded later. To greatly change the execution of a command for your particular extension you only need to override the execute method. Currently this extension support is limited to top-level resources. Parent/ child relationships may be added if desired. Change-Id: I5b2fe530c90b5ce1243fc10341d6d434a1ecea7a Implements: blueprint extensible-neutronclient
87 lines
3.3 KiB
Python
87 lines
3.3 KiB
Python
# Copyright 2015 Rackspace Hosting Inc.
|
|
# All Rights Reserved
|
|
#
|
|
# 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 stevedore import extension
|
|
|
|
from neutronclient.neutron import v2_0 as neutronV20
|
|
|
|
|
|
def _discover_via_entry_points():
|
|
emgr = extension.ExtensionManager('neutronclient.extension',
|
|
invoke_on_load=False)
|
|
return ((ext.name, ext.plugin) for ext in emgr)
|
|
|
|
|
|
class NeutronClientExtension(neutronV20.NeutronCommand):
|
|
pagination_support = False
|
|
_formatters = {}
|
|
sorting_support = False
|
|
|
|
|
|
class ClientExtensionShow(NeutronClientExtension, neutronV20.ShowCommand):
|
|
def get_data(self, parsed_args):
|
|
# NOTE(mdietz): Calls 'execute' to provide a consistent pattern
|
|
# for any implementers adding extensions with
|
|
# regard to any other extension verb.
|
|
return self.execute(parsed_args)
|
|
|
|
def execute(self, parsed_args):
|
|
return super(ClientExtensionShow, self).get_data(parsed_args)
|
|
|
|
|
|
class ClientExtensionList(NeutronClientExtension, neutronV20.ListCommand):
|
|
|
|
def get_data(self, parsed_args):
|
|
# NOTE(mdietz): Calls 'execute' to provide a consistent pattern
|
|
# for any implementers adding extensions with
|
|
# regard to any other extension verb.
|
|
return self.execute(parsed_args)
|
|
|
|
def execute(self, parsed_args):
|
|
return super(ClientExtensionList, self).get_data(parsed_args)
|
|
|
|
|
|
class ClientExtensionDelete(NeutronClientExtension, neutronV20.DeleteCommand):
|
|
def run(self, parsed_args):
|
|
# NOTE(mdietz): Calls 'execute' to provide a consistent pattern
|
|
# for any implementers adding extensions with
|
|
# regard to any other extension verb.
|
|
return self.execute(parsed_args)
|
|
|
|
def execute(self, parsed_args):
|
|
return super(ClientExtensionDelete, self).run(parsed_args)
|
|
|
|
|
|
class ClientExtensionCreate(NeutronClientExtension, neutronV20.CreateCommand):
|
|
def get_data(self, parsed_args):
|
|
# NOTE(mdietz): Calls 'execute' to provide a consistent pattern
|
|
# for any implementers adding extensions with
|
|
# regard to any other extension verb.
|
|
return self.execute(parsed_args)
|
|
|
|
def execute(self, parsed_args):
|
|
return super(ClientExtensionCreate, self).get_data(parsed_args)
|
|
|
|
|
|
class ClientExtensionUpdate(NeutronClientExtension, neutronV20.UpdateCommand):
|
|
def run(self, parsed_args):
|
|
# NOTE(mdietz): Calls 'execute' to provide a consistent pattern
|
|
# for any implementers adding extensions with
|
|
# regard to any other extension verb.
|
|
return self.execute(parsed_args)
|
|
|
|
def execute(self, parsed_args):
|
|
return super(ClientExtensionUpdate, self).run(parsed_args)
|