Cloudify 脚本插件:将输入作为环境变量传递给脚本

Cloudify Script Plugin : Passing inputs as Environment Variables to scripts

我正在尝试将蓝图输入作为环境变量传递给 python 脚本(在节点的生命周期操作之一期间由 script_plugin 执行)。

我们正在使用 Cloudify 3.1。 我的蓝图如下所示(修剪它以显示所需的部分):

inputs:
  sql_server_username:
    type: string
    default: ''
    description: >
      Enter SQL Server User Name

node_templates:  
  my_install:
      type: my.nodes.Root
      relationships:
        - target: win2012r2
          type: cloudify.relationships. contained_in
      interfaces:
        cloudify.interfaces.lifecycle:
          start:
            implementation: scripts/my/installer.py
            inputs:
                process:
                    env:
                        SQL_USERNAME: { get_input: sql_server_username }

并且在我的 python 脚本 (installer.py) 中,我正在尝试使用 os.environ.get("SQL_USERNAME", "DEFAULT") 访问 SQL_USERNAME。但是即使我在部署期间通过输入传递自定义值,我也总是得到默认值,

我应该更改什么才能在脚本中访问输入参数作为环境变量(从蓝图的输入部分)?

花了将近24小时后,发现如果脚本是python脚本,并且Process配置选项中eval_script没有设置为false,则不会注入环境变量(至少对于 3.1 版)。

感谢丹·基尔曼。 下面的代码片段来自 Ref# https://groups.google.com/d/msg/cloudify-users/mEAI9x9ivXQ/39Rg6KgKP4cJ

They are indeed not exposed as environment variables but are readily available as inputs by placing them in the top level inputs instead of the nested env.process and then doing something like

from cloudify.state import ctx_parameters as inputs

afterward, you can access these like this

# inputs in this case is just a sugared dict that allows top level key attribute-like access to the operation inputs # you could just as well do inputs['LOAD_BALANCER_IP'] ``ctx.logger.info(inputs.LOAD_BALANCER_IP)

希望文档中明确说明这一点..