raw plugin injection

Change-Id: I97eaa055cac2821077923c575b601369f21bfb84
This commit is contained in:
Fabio Verboso 2017-02-22 11:46:38 +01:00
parent 7f717e995b
commit f5a222f2e0
3 changed files with 40 additions and 0 deletions

View File

@ -166,3 +166,16 @@ class PluginsController(rest.RestController):
rpc_plugin = api_utils.get_rpc_plugin(plugin_ident) rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)
pecan.request.rpcapi.destroy_plugin(pecan.request.context, pecan.request.rpcapi.destroy_plugin(pecan.request.context,
rpc_plugin.uuid) rpc_plugin.uuid)
@expose.expose(None, types.uuid_or_name, types.uuid_or_name,
status_code=200)
def put(self, plugin_ident, node_ident):
"""inject a plugin into a node.
:param plugin_ident: UUID or logical name of a plugin.
:param node_ident: UUID or logical name of a node.
"""
rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)
rpc_node = api_utils.get_rpc_node(node_ident)
pecan.request.rpcapi.inject_plugin(pecan.request.context,
rpc_plugin.uuid, rpc_node.uuid)

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import cPickle as cpickle
from iotronic.common import exception from iotronic.common import exception
from iotronic.common import states from iotronic.common import states
from iotronic.conductor.provisioner import Provisioner from iotronic.conductor.provisioner import Provisioner
@ -183,5 +184,19 @@ class ConductorEndpoint(object):
new_plugin = serializer.deserialize_entity(ctx, plugin_obj) new_plugin = serializer.deserialize_entity(ctx, plugin_obj)
LOG.debug('Creating plugin %s', LOG.debug('Creating plugin %s',
new_plugin.name) new_plugin.name)
new_plugin.config = cpickle.dumps(new_plugin.config, 0)
new_plugin.create() new_plugin.create()
return serializer.serialize_entity(ctx, new_plugin) return serializer.serialize_entity(ctx, new_plugin)
def inject_plugin(self, ctx, plugin_uuid, node_uuid):
LOG.info('Injecting plugin with id %s into the node %s',
plugin_uuid, node_uuid)
plugin = objects.Plugin.get_by_uuid(ctx, plugin_uuid)
try:
self.execute_on_node(ctx, node_uuid, 'PluginInject',
(plugin.name, plugin.config))
except Exception:
LOG.error('cannot execute remote injection on %s. '
'Maybe it is OFFLINE', node_uuid)
return

View File

@ -168,3 +168,15 @@ class ConductorAPI(object):
""" """
cctxt = self.client.prepare(topic=topic or self.topic, version='1.0') cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
return cctxt.call(context, 'destroy_plugin', plugin_id=plugin_id) return cctxt.call(context, 'destroy_plugin', plugin_id=plugin_id)
def inject_plugin(self, context, plugin_uuid, node_uuid, topic=None):
"""inject a plugin into a node.
:param context: request context.
:param plugin_uuid: plugin id or uuid.
:param ndoe_uuid: node id or uuid.
"""
cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
return cctxt.call(context, 'inject_plugin', plugin_uuid=plugin_uuid,
node_uuid=node_uuid)