如何使用Cloudify REST插件发送八位字节流内容类型

时间:2019-04-03 13:27:03

标签: cloudify

使用Cloudify最新的REST插件,我正在尝试发送具有八位字节流内容类型的请求。

尝试了几种发送数据的方法,但没有成功

我的REST模板如下:

rest_calls:
  - path: /v2/projects/{{ PROJECT_ID }}/import?name={{ PROJECT_NAME }}
    method: POST
    headers:
        Content-type: application/octet-stream
        Content-Length: 28022
    payload:
        {{ PROJECT_BINARY }}
    response_format: json
    recoverable_codes: [400]
    response_translation: [project_info]
    response_expectation:
        - [ 'name', '{{ PROJECT_NAME }}' ]

这是设置参数的方式: 执行

 params {u'PROJECT_ID': u'8c76f840-fb1f-401f-b348-22b432caeef2', u'PROJECT_NAME': u'isis', u'PROJECT_BINARY': u'504b03041400080000003757814e'} 
 template 
 templates/create_and_import.yaml

我使用get_input函数初始化PROJECT_BINARY参数(和其他变量)。我可以在Cloudify日志中看到变量已设置为正确的值。

但是,运行安装工作流程时出现以下错误:

'install' workflow execution failed: RuntimeError: Workflow failed: Task failed 'cloudify_rest.tasks.execute' -> while constructing a mapping
  in "<string>", line 8, column 9:
            {{ PROJECT_BINARY }}
            ^
found unacceptable key (unhashable type: 'dict')
  in "<string>", line 8, column 10:
            {{ PROJECT_BINARY }}
             ^

1 个答案:

答案 0 :(得分:0)

可以使用一种可能的解决方案“ prerender == true”。参见here。在这种情况下,我们呈现{{PLACEHOLDERS}},然后解析YAML。在某些情况下,这可能是一个很好的解决方案。它将适用于除破损的JSON(未封闭的引号和字典)和带有新行的内容以外的任何内容。

如果您可以使用预先创建的文件-您可以尝试使用raw_payload。参见here

或作为可以测试的解决方案:

====
rest_calls:
 - path: /v2/projects/{{ PROJECT_ID }}/import?name={{ PROJECT_NAME }}
   method: POST
   headers:
       Content-type: application/octet-stream
       Content-Length: 28022
   payload: "{{ PROJECT_BINARY }}"
   response_format: json
   recoverable_codes: [400]
   response_translation: [project_info]
   response_expectation:
       - [ 'name', '{{ PROJECT_NAME }}' ]
====
相关问题