无法使用脚本插件执行生命周期操作

时间:2019-04-13 13:36:11

标签: cloudify

我正在尝试学习如何使用脚本插件。我正在关注脚本插件文档here,但无法使其正常工作。

我尝试过两种方式使用插件。首先,将cloudify.interface.lifecycle.start操作直接映射到脚本:

tosca_definitions_version: cloudify_dsl_1_3
imports:
  - 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
  Import_Project:
    type: cloudify.nodes.WebServer
    capabilities:
      scalable:
        properties:
          default_instances: 1
    interfaces:
      cloudify.interfaces.lifecycle:
        start:
          implementation: scripts/create_project.sh
          inputs: {}

第二个具有直接映射:

tosca_definitions_version: cloudify_dsl_1_3
imports:
  - 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
  Import_Project:
    type: cloudify.nodes.WebServer
    capabilities:
      scalable:
        properties:
          default_instances: 1
    interfaces:
      cloudify.interfaces.lifecycle:
        start:
          implementation: script.script_runner.tasks.run
          inputs:
            script_path: scripts/create_project.sh

我已经创建了一个名为scripts的目录,并将以下create_project.sh脚本放置在该目录中:

#! /bin/bash -e

ctx logger info "Hello to this world"
hostname

验证蓝图时出现错误。 将操作直接映射到脚本时出错:

[2019-04-13 13:29:40.594] [DEBUG] DslParserExecClient - got output from dsl parser Could not extract plugin from operation mapping 'scripts/create_project.sh', which is declared for operation 'start'. In interface 'cloudify.interfaces.lifecycle' in node 'Import_Project' of type 'cloudify.nodes.WebServer'
  in: /opt/cloudify-composer/backend/dev/workspace/2/tmp-27O0e1t813N6as
  in line: 3, column: 2
  path: node_templates.Import_Project
  value: {'interfaces': {'cloudify.interfaces.lifecycle': {'start': {'implementation': 'scripts/create_project.sh', 'inputs': {}}}}, 'type': 'cloudify.nodes.WebServer', 'capabilities': {'scalable': {'properties': {'default_instances': 1}}}}

使用直接映射时出错:

[2019-04-13 13:25:21.015] [DEBUG] DslParserExecClient - got output from dsl parser node 'Import_Project' has no relationship which makes it contained within a host and it has a plugin 'script' with 'host_agent' as an executor. These types of plugins must be installed on a host
  in: /opt/cloudify-composer/backend/dev/workspace/2/tmp-279QCz2CV3Y81L
  in line: 2, column: 0
  path: node_templates
  value: {'Import_Project': {'interfaces': {'cloudify.interfaces.lifecycle': {'start': {'implementation': 'script.script_runner.tasks.run', 'inputs': {'script_path': 'scripts/create_project.sh'}}}}, 'type': 'cloudify.nodes.WebServer', 'capabilities': {'scalable': {'properties': {'default_instances': 1}}}}}

这项工作缺少什么?

1 个答案:

答案 0 :(得分:1)

我还发现其文档中的Cloudify脚本插件示例不起作用:https://docs.cloudify.co/4.6/working_with/official_plugins/configuration/script/

但是,我发现我可以通过在实现行的旁边添加 executor 行来使示例工作,以覆盖host_agent执行程序,如下所示:

tosca_definitions_version: cloudify_dsl_1_3
imports:
  - 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
  Import_Project:
    type: cloudify.nodes.WebServer
    capabilities:
      scalable:
        properties:
          default_instances: 1
    interfaces:
      cloudify.interfaces.lifecycle:
        start:
          implementation: scripts/create_project.sh
          executor: central_deployment_agent
          inputs: {}