0

Using Cloudify latest REST plugin I'm trying to send request with octet-stream content type.

Tried several ways to send the data but with no success

My REST template looks like this:

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 }}' ]

And this is how the parameters were set: execute

 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

I initialize the PROJECT_BINARY parameter (and the other variables) using get_input function. I can see in Cloudify log that the variables are set to the correct value.

However, I get the following error when running install workflow:

'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 }}
             ^
user21696
  • 1
  • 1

1 Answers1

0

One of possible solutions can be used "prerender==true". See here. n such case we render {{PLACEHOLDERS}} and then parse YAML. It could be good solution for some cases. It will work for any content except broken JSON (unclosed quotes and dicts) and content with new lines.

If you can use pre-created files - you can try to use raw_payload. See here.

Or as solution that can be tested:

====
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 }}' ]
====
earthmant
  • 259
  • 1
  • 4
  • Thank you for the answer. Both "prerender==true" and payload: "{{ PROJECT_BINARY }}" didn't work. I didn't understand how to use raw_payload. Here is what I tried, however it didn't work. Seems the file is not being transferred. raw_payload: my-file The below 'curl' command works for me from any Linux command line. What is the equivalent for Cloudify REST Plugin? curl -X POST -H 'Content-Type: application/octet-stream' --data-binary @my-file http://:3080/v2/projects/8c76f840-fb1f-401f-b348-22b432caeef2/import?name=isis – user21696 Apr 04 '19 at 11:48