November 23, 2017


# Edit a server's basic information
# Change the notes property for a single server record to the sentence "This
# is my fastest server!" using the editObject() method in the
# SoftLayer_Hardware_Server API service. See below for more details.
# Important manual pages
# License:
# Author: SoftLayer Technologies, Inc.<>
require 'softlayer_api'

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'

# The name of the server we wish to edit.
server_name = 'set me'

# Define the new local properties to set.
# A SoftLayer_Hardware_Server record has a few local properties that you can
# change via the API. Every service's editObject() method takes a single
# parameter, a skeleton object that only defines the properties we wish to
# change. While we're only editing a server's notes in this example you can
# also use editObject() to edit the server's hostname and domain record.
edit_template = {
  'notes' => 'This is my fastest server!'

hardware_id = '12321'

# Declare the API client
client = USERNAME, api_key: API_KEY)
account_service = client['SoftLayer_Account']
hardware_server_service = client['SoftLayer_Hardware_Server']

  # Make the call to retrieve our hardware records.
  hardware_list = account_service.getHardware
rescue StandardError => exception
  # If there was an error returned from the SoftLayer API then bomb out with the
  # error message.
  puts "Unable to list the servers: #{exception}"

# Looking for the server name to get its id
hardware_list.each do |hardware|
  hardware_id = hardware['id'] if hardware['hostname'] == server_name

  # Edit our server record.
  result = hardware_server_service.object_with_id(hardware_id).editObject(edit_template)
  puts 'Server edited'
  print result
rescue StandardError => exception
  puts "Unable to edit the server: #{exception}"


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue