| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
import abc |
| 14 |
from oslo_config import cfg |
| 15 |
|
| 16 |
|
| 17 |
CONF = cfg.CONF |
| 18 |
|
| 19 |
|
| 20 |
class PluginBase(metaclass=abc.ABCMeta): |
| 21 |
"""Base class for all VIF plugins.""" |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
CONFIG_OPTS = () |
| 26 |
|
| 27 |
def __init__(self, config): |
| 28 |
""" |
| 29 |
Initialize the plugin object with the provided config |
| 30 |
|
| 31 |
:param config: ``oslo_config.ConfigOpts.GroupAttr`` instance: |
| 32 |
""" |
| 33 |
self.config = config |
| 34 |
|
| 35 |
@abc.abstractmethod |
| 36 |
def describe(self): |
| 37 |
""" |
| 38 |
Return an object that describes the plugin's supported vif types and |
| 39 |
the earliest/latest known VIF object versions. |
| 40 |
|
| 41 |
:returns: A ``os_vif.objects.host_info.HostPluginInfo`` instance |
| 42 |
""" |
| 43 |
|
| 44 |
@abc.abstractmethod |
| 45 |
def plug(self, vif, instance_info): |
| 46 |
""" |
| 47 |
Given a model of a VIF, perform operations to plug the VIF properly. |
| 48 |
|
| 49 |
:param vif: ``os_vif.objects.vif.VIFBase`` object. |
| 50 |
:param instance_info: ``os_vif.objects.instance_info.InstanceInfo`` |
| 51 |
object. |
| 52 |
:raises ``processutils.ProcessExecutionError``. Plugins implementing |
| 53 |
this method should let `processutils.ProcessExecutionError` |
| 54 |
bubble up. |
| 55 |
""" |
| 56 |
|
| 57 |
@abc.abstractmethod |
| 58 |
def unplug(self, vif, instance_info): |
| 59 |
""" |
| 60 |
Given a model of a VIF, perform operations to unplug the VIF properly. |
| 61 |
|
| 62 |
:param vif: ``os_vif.objects.vif.VIFBase`` object. |
| 63 |
:param instance_info: ``os_vif.objects.instance_info.InstanceInfo`` |
| 64 |
object. |
| 65 |
:raises ``processutils.ProcessExecutionError``. Plugins implementing |
| 66 |
this method should let ``processutils.ProcessExecutionError`` |
| 67 |
bubble up. |
| 68 |
""" |
| 69 |
|
| 70 |
@classmethod |
| 71 |
def load(cls, plugin_name): |
| 72 |
""" |
| 73 |
Load a plugin, registering its configuration options |
| 74 |
|
| 75 |
:param plugin_name: the name of the plugin extension |
| 76 |
|
| 77 |
:returns: an initialized instance of the class |
| 78 |
""" |
| 79 |
cfg_group_name = "os_vif_" + plugin_name |
| 80 |
cfg_opts = getattr(cls, "CONFIG_OPTS") |
| 81 |
cfg_vals = None |
| 82 |
if cfg_opts and len(cfg_opts) > 0: |
| 83 |
cfg_group = cfg.OptGroup( |
| 84 |
cfg_group_name, |
| 85 |
"os-vif plugin %s options" % plugin_name) |
| 86 |
CONF.register_opts(cfg_opts, group=cfg_group) |
| 87 |
|
| 88 |
cfg_vals = getattr(CONF, cfg_group_name) |
| 89 |
return cls(cfg_vals) |