Rest API v3 for creating vm with cloud-init config

Badge +3
  • Trailblazer
  • 11 replies
Hello, I am trying to create VM using Rest API v3, i get response code 202, but VM isn't created.
I get the follow message in the Prism:
Create VM intentful - error.
I tried to use yaml/python but the result is the same.
If I use these settings in cloud-init settings:
hostname: client
I don't see any errors in the log of CVM connecting with creating VM.
however if use this config:
hostname: ansible-client
i get the following message in the log:
2017-09-11 11:39:34 ERROR 6c70031e-34e0-48b2-a037-ce97d1b95308 Error: {'reason': 'INTERNAL_ERROR', 'message': "'rZ.v)\xe2\xb6\x1a,\xb6v\xa6y\xa9\xec\x89\xb9^rX\x9e\x9e\xddt' has type bytes, but isn't in 7-bit ASCII encoding. Non-ASCII strings must be converted to unicode objects before being added."}
Stack: Traceback (most recent call last):

What I am doing wrong ? How to use cloud-init config with rest api ?

P.S. everything looks fine, but doesn't work
2017-09-11 11:56:06 INFO f6427b91-ce21-476c-9687-c1974b041972 vm,{u'status': {u'state': u'PENDING'}, u'uuid': u'58a64198-3d55-4aa1-9952-f255a262326e', u'intent_spec_uuid': u'5ce93840-49b2-4a08-8b55-fbd4732d78c0', u'permission_metadata': {u'trace': u'', u'session_log_uuid': u'f6427b91-ce21-476c-9687-c1974b041972', u'category_id_list': [], u'tenant_uuid': u'46a8a769-cca1-4915-8957-bc11cf98214e', u'owner_uuid': u'dfbde6f3-1702-4e84-a863-3007de36efac'}, u'method': u'post', u'task_uuid': u'8c681431-3afb-4296-a911-19ae15f411cb', u'domain_metadata': {u'username': u'admin', u'ds_domain': None}, u'spec': {u'name': u'client10', u'resources': {u'nic_list': [{u'subnet_reference': {u'kind': u'subnet', u'uuid': u'88ba1a7c-5989-43a8-831f-e6355bb2b6d9'}}], u'num_vcpus_per_socket': 1, u'num_sockets': 1, u'memory_size_mib': 1024, u'power_state': u'ON', u'guest_customization': {u'cloud_init': {u'user_data': u'#cloud-inithostname: "client10"'}}, u'disk_list': [{u'data_source_reference': {u'kind': u'image', u'uuid': u'c625aab3-3785-4aa7-b6b8-96d3841c2225', u'name': u'Centos7-cloudInit'}, u'device_properties': {u'device_type': u'DISK', u'disk_address': {u'device_index': 0, u'adapter_type': u'SCSI'}}}]}, u'cluster_reference': {u'kind': u'cluster', u'uuid': u'0005558c-536f-7adc-2348-001fc69c242b'}}, u'api_version': u'3.0', u'metadata': {u'kind': u'vm', u'uuid': u'58a64198-3d55-4aa1-9952-f255a262326e', u'categories': {}}}

Best answer by ckousoulis 11 September 2017, 22:42

I believe the first line of the config file needs to be #cloud-config instead of #cloud-init:

View original

4 replies

Badge +5
The contents for the attributes under guest_customization must be base64-encoded. Try encoding the object you're providing in user-data and see if that resolves the issue.
Badge +3
Thanks, VM was created but cloud-init config didn't applied.
in the cloud-init log:[warning]: Unhandled non-multipart (text/x-not-multipart) userdata: '#cloud-inithostname: c...'
I have the same message in the log if I create VM using prism gui and type script in the gui according to this article:

Badge +5
I believe the first line of the config file needs to be #cloud-config instead of #cloud-init:
Badge +3
You are totally right, I made too many files of cloud-init, and some of them was with that misprint.
Thank you for your help.