简体   繁体   中英

How to add user metadata to IBM Cloud virtual device order?

I'm successfully ordering new devices on IBM Cloud (ex SoftLayer) using NodeJS (JavaScript) by posting JSON shown below. Now I'm trying to modify my orders and add user metadata to each ordered device, but can not find the way to easily add it.

Here's my working order (requesting 3 Ubuntu boxes in one API call):

var ibm_order = {
  imageTemplateGlobalIdentifier: 'a1237539-c54d-46dd-bece-c17c2329c607',
  imageTemplateId: '',
  location: 138124,
  packageId: 46,
  presetId: '',
  quantity: 3,
  sourceVirtualGuestId: '',
  useHourlyPricing: true,
  complexType: 'SoftLayer_Container_Product_Order_Virtual_Guest',
  prices: 
  [{id: 1641},        // description: 2 x 2.0 GHz Cores
    {id: 1647},       // description: 8 GB
    {id: 13899},      // description: 25 GB (LOCAL)
    {id: 905},        // description: Reboot / Remote Console
    {id: 274},        // description: 1 Gbps Public & Private Network Uplinks
    {id: 1800},       // description: 0 GB Bandwidth
    {id: 21},         // description: 1 IP Address
    {id: 55},         // description: Host Ping
    {id: 57},         // description: Email and Ticket
    {id: 58},         // description: Automated Notification
    {id: 420},        // description: Unlimited SSL VPN Users & 1 PPTP VPN User per account
    {id: 418}],       // description: Nessus Vulnerability Assessment & Reporting
    sshKeys: [{sshKeyIds: [4512]}],
    virtualGuests: [
      {domain: 'mydomain.com', hostname: 'rw-ff-dal05-1a'},
      {domain: 'mydomain.com', hostname: 'rw-ff-dal05-1b'},
      {domain: 'mydomain.com', hostname: 'rw-ff-dal05-1c'}
    ]
  }

And this code posts the above order using softlayer-node npm :

  var SoftLayer = require('softlayer-node');
  var softlayer_client = new SoftLayer();

  // actual SL API call
  softlayer_client
  .auth(softlayer_username, softlayer_api_key)
  .path('Product_Order', 'placeOrder')
  .parameters(ibm_order)
  .post()
  .then(function(result:any) {
    console.log('success! result: ' + JSON.stringify(result, null, 4) );
  }, function(error:any) {
    console.log('error: details: ' + JSON.stringify(error, null, 4) );
  });

Question: how to add user metadata to each of requested devices? User metadata is an array of strings, which presumably should be part of virtualGuests array elements (each "virtual guest" has it's own individual user_metadata array), but when I'm trying to specify "UserMetadata" I get an error:

error: details: {
    "message": {
        "error": "The property 'UserMetadata' is not valid for 'SoftLayer_Virtual_Guest'.",
        "code": "SoftLayer_Exception_Public"
    },
    "statusCode": 500
}

I found these SoftLayer API reference pages:
1) Reference » Data Types » SoftLayer_Container_Product_Order_Virtual_Guest
2) Reference » Services » SoftLayer_Virtual_Guest
but those aren't 100% relevant (they suggest to use setUserMetadata method, but all I have is a low level "pre-baked" JSON!)

Or may be there're other more elegant ways to order new devices from IBM Cloud (ex SoftLayer) from NodeJS?

You were right, but the error was due to the property "UserMetaData" you sent, this is not a valid property for virtualGuests , the specific property you are looking for is called "userData" instead, it is inside the datatype Virtual_Guest .

Try the following:

var ibm_order = {
imageTemplateGlobalIdentifier: 'a1237539-c54d-46dd-bece-c17c2329c607',
imageTemplateId: '',
location: 138124,
packageId: 46,
presetId: '',
quantity: 3,
sourceVirtualGuestId: '',
useHourlyPricing: true,
complexType: 'SoftLayer_Container_Product_Order_Virtual_Guest',
prices: 
[{id: 1641},        // description: 2 x 2.0 GHz Cores
  {id: 1647},       // description: 8 GB
  {id: 13899},      // description: 25 GB (LOCAL)
  {id: 905},        // description: Reboot / Remote Console
  {id: 274},        // description: 1 Gbps Public & Private Network Uplinks
  {id: 1800},       // description: 0 GB Bandwidth
  {id: 21},         // description: 1 IP Address
  {id: 55},         // description: Host Ping
  {id: 57},         // description: Email and Ticket
  {id: 58},         // description: Automated Notification
  {id: 420},        // description: Unlimited SSL VPN Users & 1 PPTP VPN User per account
  {id: 418}],       // description: Nessus Vulnerability Assessment & Reporting
  sshKeys: [{sshKeyIds: [4512]}],
  virtualGuests: [
  {domain: 'mydomain.com', hostname: 'rw-ff-dal05-1a', userData: [{value: 'someValue1'}]},
  {domain: 'mydomain.com', hostname: 'rw-ff-dal05-1b', userData: [{value: 'someValue2'}]},
  {domain: 'mydomain.com', hostname: 'rw-ff-dal05-1c', userData: [{value: 'someValue3'}]}
  ]
}

For more information you may see below:

http://sldn.softlayer.com/blog/jarteche/getting-started-user-data-and-post-provisioning-scripts

Retrieving user metadata about a provisioned SoftLayer server comes back null

https://sldn.softlayer.com/article/softlayer-api-overview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM