haunm haunm - 9 months ago 60
Ruby Question

Retrieving user metadata about a provisioned SoftLayer server comes back null

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']

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?


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


    "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