VMware Cloud Community
tobyj12
Contributor
Contributor

How can we add a second disk to a machine via the Rest API?

We're using vRealize Automation Version: 7.5.0 (Build: 10053500).

I'm able to obtain the Reconfigure template from the following URL: /catalog-service/api/consumer/resources/<machine-id>/actions/<reconfigure-action-id>/requests

The template looks like this:

{'actionId': 'e57ef020-677d-47fe-a9da-4afa2f16a1c7',

'data': {'allowForceShutdown': 'false',

          'cpu': 4,

          'customProperties': [],

          'description': 'Test machine 1',

          'disks': [{'classId': 'Infrastructure.Compute.Machine.MachineDisk',

                     'componentId': None,

                     'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                     'data': {'customProperties': [{'classId': 'Infrastructure.CustomProperty',

                                                    'componentId': None,

                                                    'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                                                    'data': {'id': 'IsClone',

                                                             'is_encrypted': False,

                                                             'is_hidden': False,

                                                             'prompt_user': False,

                                                             'value': 'true'},

                                                    'typeFilter': None},

                                                   {'classId': 'Infrastructure.CustomProperty',

                                                    'componentId': None,

                                                    'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                                                    'data': {'id': 'Name',

                                                             'is_encrypted': False,

                                                             'is_hidden': False,

                                                             'prompt_user': False,

                                                             'value': 'Hard '

                                                                      'disk 1'},

                                                    'typeFilter': None}],

                              'driveLetter': None,

                              'externalId': '6000C29f-0a27-4188-c9cd-37b967436e90',

                              'label': 'Hard disk 1',

                              'reservationPolicy': None,

                              'reservationPolicyMode': None,

                              'size': 24,

                              'storagePath': 'san_01'},

                     'typeFilter': None}],

          'executionSelector': '1',

          'memory': 8192,

          'name': 'test-machine-1',

          'nics': [{'classId': 'Infrastructure.Compute.Machine.Nic',

                    'componentId': None,

                    'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                    'data': {'macAddress': '00:50:56:9d:8e:ca',

                             'name': 'Development'},

                    'typeFilter': None}],

          'powerActionSelector': '0',

          'requestor': 'APIUser',

          'storage': 24},

'description': None,

'reasons': None,

'resourceId': '299e5023-7f85-4920-b51a-21837b22df99',

'type': 'com.vmware.vcac.catalog.domain.request.CatalogResourceRequest'}

I wish to add a second disk. I figured what I could do is to add another entry to the 'disks' array in this object. Having done so, the template then resembles the following:

{'actionId': 'e57ef020-677d-47fe-a9da-4afa2f16a1c7',

'data': {'allowForceShutdown': 'false',

          'cpu': 4,

          'customProperties': [],

          'description': 'Test machine 1',

          'disks': [{'classId': 'Infrastructure.Compute.Machine.MachineDisk',

                     'componentId': None,

                     'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                     'data': {'customProperties': [{'classId': 'Infrastructure.CustomProperty',

                                                    'componentId': None,

                                                    'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                                                    'data': {'id': 'IsClone',

                                                             'is_encrypted': False,

                                                             'is_hidden': False,

                                                             'prompt_user': False,

                                                             'value': 'true'},

                                                    'typeFilter': None},

                                                   {'classId': 'Infrastructure.CustomProperty',

                                                    'componentId': None,

                                                    'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                                                    'data': {'id': 'Name',

                                                             'is_encrypted': False,

                                                             'is_hidden': False,

                                                             'prompt_user': False,

                                                             'value': 'Hard '

                                                                      'disk 1'},

                                                    'typeFilter': None}],

                              'driveLetter': None,

                              'externalId': '6000C29f-0a27-4188-c9cd-37b967436e90',

                              'label': 'Hard disk 1',

                              'reservationPolicy': None,

                              'reservationPolicyMode': None,

                              'size': 24,

                              'storagePath': 'san_01'},

                     'typeFilter': None},

                    {'classId': 'Infrastructure.Compute.Machine.MachineDisk',

                     'componentId': None,

                     'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                     'data': {'driveLetter': None,

                              'externalId': '',

                              'label': 'Hard disk 2',

                              'reservationPolicy': None,

                              'reservationPolicyMode': None,

                              'size': 32,

                              'storagePath': ''},

                     'typeFilter': None}],

          'executionSelector': '1',

          'memory': 8192,

          'name': 'test-machine-1',

          'nics': [{'classId': 'Infrastructure.Compute.Machine.Nic',

                    'componentId': None,

                    'componentTypeId': 'com.vmware.csp.component.iaas.proxy.provider',

                    'data': {'macAddress': '00:50:56:9d:8e:ca',

                             'name': 'Development'},

                    'typeFilter': None}],

          'powerActionSelector': '0',

          'requestor': 'APIUser',

          'storage': 56},

'description': None,

'reasons': None,

'resourceId': '299e5023-7f85-4920-b51a-21837b22df99',

'type': 'com.vmware.vcac.catalog.domain.request.CatalogResourceRequest'}

As you can see, I copied the disk entry for the first disk and appended it. I read that when doing so, 'externalId' must be set to an empty string, so I did so. When I submit this request, I get an HTTP 201 response. I can see the request spinning up in the vRealize GUI.

However, the request fails at the Reconfigure state with the following:

Machine test-machine-1: Machine reconfigure request failed - Could not validate storages. To prevent data loss, this reconfigure request has been cancelled. Please try again.

I've read that this error can be returned if multiple tabs are open, but I purposefully connected to the Rest API with a different user to guard against this.

I cannot find any good documentation anywhere on what format these requests are supposed to take, or anything of the sort.

Has anyone done something similar?

0 Kudos
1 Reply
lnairn
VMware Employee
VMware Employee

Hi,

Did you see this blog Executing Day 2 Actions with the vRA 7 REST API | | VMtoCloud.com I've used similar approach time ago.

In the comments, there is an example for the same use case you mentioned.

Regards

0 Kudos