Retrieving user metadata about a provisioned SoftLayer server comes back null

余生长醉 提交于 2019-12-25 18:25:47

问题


I'm trying to retrieve the user meta information for each machine consistently but what I'm finding is most of my machines are missing this data. I'd like to understand better what is required for this user data to be there. I'm curious if a server can be requested and provisioned without requiring user information (e.g. an API call to order a server and no user data is given). Or whether I am missing something in how I retrieve this information. Here is the basic ruby program I'm running:

user = ###
api_key = ###

client = SoftLayer::Client.new(:username => user, :api_key => api_key, :timeout => 999999)

list_of_virtual_machines = client['Account'].result_limit(i*50,50).object_mask("mask[id, billingItem[recurringFee, associatedChildren[recurringFee], orderItem[description, order[userRecord[username], id]]], userData]").getVirtualGuests
for x in 0..list_of_virtual_machines.length - 1
  pp list_of_virtual_machines[i]['userData']
  if list_of_virtual_machines[i]['billingItem'] && list_of_virtual_machines[i]['billingItem']['orderItem'] && list_of_virtual_machines[i]['billingItem']['orderItem']['order'] && list_of_virtual_machines[i]['billingItem']['orderItem']['order']['userRecord']
    pp list_of_virtual_machines[i]['billingItem']['orderItem']['order']['userRecord']
  end
end

My prints are consistently showing null. This question is related to a similar question I asked not too long ago (but the focus of that question moved towards the provisionDate): How to get order username and provisionDate for all SoftLayer machines using Ruby?


回答1:


They are missing that data because you did not added.

you can create the user data at moment to order a new server or VSI, you just have to send the data in your order request either using the createObject method or the placeOrder method. see http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/createObject

e.g.

{ 
    "userData": [ 
        { 
            "value": "someValue" 
        } 
    ] 
}

or you can set it after the server has been provisioned using these methods

http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/setUserMetadata http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/setUserMetadata

Basically the usermetadata are useful if you are going to use a post install script. The usermetadata value is not required to order a new server

take a look this article for examples: http://sldn.softlayer.com/blog/jarteche/getting-started-user-data-and-post-provisioning-scripts



来源:https://stackoverflow.com/questions/36873435/retrieving-user-metadata-about-a-provisioned-softlayer-server-comes-back-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!