简体   繁体   English

如何将用户元数据添加到IBM Cloud虚拟设备订单?

[英]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. 我通过发布以下所示的JSON成功使用NodeJS(JavaScript)在IBM Cloud(ex SoftLayer)上订购了新设备。 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): 这是我的工作顺序(在一个API调用中请求3个Ubuntu框):

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 : 此代码使用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: 用户元数据是一个字符串数组,大概应该是virtualGuests数组元素的一部分(每个“虚拟来宾”都有其自己的单个user_metadata数组),但是当我尝试指定“ UserMetadata”时,出现错误:

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: 我找到了这些SoftLayer API参考页:
1) Reference » Data Types » SoftLayer_Container_Product_Order_Virtual_Guest 1)参考»数据类型» SoftLayer_Container_Product_Order_Virtual_Guest
2) Reference » Services » SoftLayer_Virtual_Guest 2)参考»服务» 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!) 但是它们并不是100%相关的(他们建议使用setUserMetadata方法,但我所拥有的只是一个低级的“预烘焙” JSON!)

Or may be there're other more elegant ways to order new devices from IBM Cloud (ex SoftLayer) from NodeJS? 还是有其他更优雅的方法可以从NodeJS订购IBM Cloud(ex SoftLayer)的新设备?

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 . 没错,但是错误是由于发送的属性“ UserMetaData”造成的,这不是virtualGuests的有效属性,您要查找的特定属性称为“ userData”,而是在数据类型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 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 检索有关已配置的SoftLayer服务器的用户元数据返回null

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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