November 23, 2017


# Power off a VSI.
# Important manual pages:
# @license <>
# @author SoftLayer Technologies, Inc. <>
require 'softlayer_api'
require 'pp'

USERNAME = 'set me'
API_KEY = 'set me'

client = USERNAME, api_key: API_KEY, timeout: 180)

# The VSI data
hostname = 'test' # Set this with the hostname of the machine you want
domain = 'softlayer.local' # Set this with the domain of the machine you want

account_service = client.service_named('SoftLayer_Account')
virtual_guest_service = client.service_named('SoftLayer_Virtual_Guest')

# Adding a filter to filter the VSI we want.
object_filter = do |filter|
  filter.accept('virtualGuests.hostname').when_it is(hostname)
  filter.accept('virtualGuests.domain').when_it is(domain)

  # It will return only the virtual machine which have the specified hostname and domain
  virtual_guest = account_service.object_filter(object_filter).getVirtualGuests
  result = virtual_guest_service.object_with_id(virtual_guest[0]['id']).powerOffSoft
  pp result
rescue StandardError => exception
  puts "Unable to power off the VSI: #{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