Created
July 12, 2019 21:46
-
-
Save kovyrin/9fe30be0143f6ca8bf4dacd8fdd20f88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'softlayer_api' | |
require 'pp' | |
require 'pry' | |
# Credentials to the API are read from a configuration file by default. | |
# See https://github.com/softlayer/softlayer-ruby/blob/master/lib/softlayer/Config.rb#L11-L44 | |
client = SoftLayer::Client.new(timeout: 120) | |
pool_id = 193291 | |
hardwareToAdd = [] | |
hardwareToRemove = [] | |
cloudsToAdd = [] | |
cloudsToRemove = [] | |
vdr_api = client['SoftLayer_Network_Bandwidth_Version1_Allotment'] | |
puts 'Getting all servers for the pool...' | |
vdr_servers = vdr_api.object_with_id(pool_id).getHardware.map { |s| s['id'] } | |
puts 'Getting all vms for the pool...' | |
vdr_vms = vdr_api.object_with_id(pool_id).getVirtualGuests.map { |s| s['id'] } | |
puts 'Creating an account client...' | |
account = SoftLayer::Account.account_for_client(client) | |
puts 'Finding servers to add...' | |
account.bare_metal_servers.each do |server| | |
next if server['hostname'] =~ /search-pocket\d+\.dal05/ # those are being cancelled | |
next unless server['hostname'] =~ /\.dal\d/ # only dallas for this pool | |
hardwareToAdd << { 'id' => server.id } unless vdr_servers.include?(server.id) | |
end | |
puts 'Finding VMs to add...' | |
account.virtual_servers.each do |server| | |
cloudsToAdd << { 'id' => server.id } unless vdr_vms.include?(server.id) | |
end | |
puts 'Modifying the pool:' | |
puts "Adding hardware (#{hardwareToAdd.count} servers): #{hardwareToAdd.inspect}" | |
puts "Adding VMs (#{cloudsToAdd.count} servers): #{cloudsToAdd.inspect}" | |
res = vdr_api.object_with_id(pool_id).requestVdrContentUpdates( | |
hardwareToAdd, | |
hardwareToRemove, | |
cloudsToAdd, | |
cloudsToRemove | |
) | |
puts "Done. Success = #{res}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment