2014-04-04 20:21:34 +04:00
|
|
|
# Copyright 2014 Mirantis, Inc.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2015-03-09 23:48:47 +01:00
|
|
|
from oslo_log import log
|
|
|
|
|
2014-04-04 20:21:34 +04:00
|
|
|
from ironic_python_agent import errors
|
2014-04-11 16:46:36 -07:00
|
|
|
from ironic_python_agent.extensions import base
|
2014-04-04 20:21:34 +04:00
|
|
|
|
|
|
|
LOG = log.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def _validate_exts(ext, flow=None):
|
|
|
|
for task in flow:
|
|
|
|
for method in task:
|
|
|
|
ext_name, cmd = ext.split_command(method)
|
|
|
|
if ext_name not in ext.ext_mgr.names():
|
|
|
|
raise errors.RequestedObjectNotFoundError('Extension',
|
|
|
|
ext_name)
|
|
|
|
ext_obj = ext.ext_mgr[ext_name].obj
|
|
|
|
ext.check_cmd_presence(ext_obj, ext_name, cmd)
|
|
|
|
|
|
|
|
|
|
|
|
class FlowExtension(base.BaseAgentExtension, base.ExecuteCommandMixin):
|
2014-09-11 10:49:33 +02:00
|
|
|
@base.async_command('start_flow', _validate_exts)
|
2014-04-13 17:45:18 -07:00
|
|
|
def start_flow(self, flow=None):
|
2014-04-04 20:21:34 +04:00
|
|
|
for task in flow:
|
|
|
|
for method, params in task.items():
|
2016-11-08 11:08:21 -08:00
|
|
|
LOG.info("Executing method %s for now", method)
|
2014-04-04 20:21:34 +04:00
|
|
|
result = self.execute_command(method, **params)
|
|
|
|
result.join()
|
2016-11-08 11:08:21 -08:00
|
|
|
LOG.info("%s method's execution is done", method)
|
2014-04-04 20:21:34 +04:00
|
|
|
if result.command_status == base.AgentCommandStatus.FAILED:
|
|
|
|
raise errors.CommandExecutionError(
|
|
|
|
"%s was failed" % method
|
|
|
|
)
|