class Fog::Network::Softlayer::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/softlayer/network.rb, line 114
def initialize(options={})
  @softlayer_api_key = options[:softlayer_api_key]
  @softlayer_username = options[:softlayer_username]
end

Public Instance Methods

create_network(order) click to toggle source
# File lib/fog/softlayer/requests/network/create_network.rb, line 481
def create_network(order)
  raise ArgumentError, "Order argument for #{self.class.name}##{__method__} must be Hash." unless order.is_a?(Hash)
  self.request(:product_order, :place_order, :body => order, :http_method => :post)
end
create_network_tags(id, tags = []) click to toggle source
# File lib/fog/softlayer/requests/network/create_network_tags.rb, line 43
def create_network_tags(id, tags = [])
  raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
  self.request(:network_vlan, "#{id}/set_tags", :body => tags.join(','), :http_method => :post)
end
create_new_global_ipv4() click to toggle source
# File lib/fog/softlayer/network.rb, line 124
def create_new_global_ipv4
  order = {
      "complexType" => 'SoftLayer_Container_Product_Order_Network_Subnet',
      "packageId" => 0, # everything that's not a Server is package 0 when using placeOrder
      "prices" => [{"id"=>global_ipv4_price_code}],
      "quantity" => 1
  }
  request(:product_order, :place_order, :body => order, :http_method => :POST).status == 200
end
create_new_global_ipv6() click to toggle source
# File lib/fog/softlayer/network.rb, line 134
def create_new_global_ipv6
  order = {
      "complexType" => 'SoftLayer_Container_Product_Order_Network_Subnet',
      "packageId" => 0, # everything that's not a Server is package 0 when using placeOrder
      "prices" => [{"id"=>global_ipv6_price_code}],
      "quantity" => 1
  }
  request(:product_order, :place_order, :body => order, :http_method => :POST).status == 200
end
create_subnet(order) click to toggle source
# File lib/fog/softlayer/requests/network/create_subnet.rb, line 20
def create_subnet(order)
  raise ArgumentError, "Order argument for #{self.class.name}##{__method__} must be Hash." unless order.is_a?(Hash)
  self.request(:product_order, :place_order, :body => order, :http_method => :post)
end
delete_global_ip_address(id) click to toggle source
# File lib/fog/softlayer/requests/network/delete_global_ip_address.rb, line 22
def delete_global_ip_address(id)
  billing = self.request(:network_subnet_ipaddress_global, "#{id}/get_billing_item").body
  billing.nil? and raise "Global IP Address with ID #{id} not found."
  request(:billing_item, "#{billing['id']}/cancel_service")
end
delete_network(id) click to toggle source
# File lib/fog/softlayer/requests/network/delete_network.rb, line 29
def delete_network(id)
  billing_id = request(:network_vlan, "#{id}/get_billing_item").body['id']
  billing_id.nil? and raise "SoftLayer VLAN with ID #{id} cannot be deleted." # will be automatically deleted when hardware using it is deleted.
  request(:billing_item, "#{billing_id}/cancel_service").body
end
delete_network_tags(id, tags = []) click to toggle source
# File lib/fog/softlayer/requests/network/delete_network_tags.rb, line 36
def delete_network_tags(id, tags = [])
  raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
  subset = self.get_network_tags(id).body['tagReferences'].map do |i|
    i['tag']['name'] unless tags.include?(i['tag']['name'])
  end.compact
  self.create_network_tags(id, subset)
end
get_datacenter_routers(id) click to toggle source
# File lib/fog/softlayer/requests/network/get_datacenter_routers.rb, line 35
def get_datacenter_routers(id)
  Excon.defaults[:read_timeout] *= 2 # this SLAPI method is incredibly slow to respond
  result = request(:location_datacenter, "#{id}/get_hardware_routers", :query => 'objectMask=id;hostname')
  Excon.defaults[:read_timeout] /= 2
  result
end
get_datacenters() click to toggle source
# File lib/fog/softlayer/requests/network/get_datacenters.rb, line 24
def get_datacenters
  request(:location_datacenter, :get_datacenters)
end
get_global_ip_address(id) click to toggle source
# File lib/fog/softlayer/requests/network/get_global_ip_address.rb, line 22
def get_global_ip_address(id)
  self.request(:network_subnet_ipaddress_global, id, :query => 'objectMask=mask[ipAddress,destinationIpAddress]')
end
get_global_ip_records() click to toggle source
# File lib/fog/softlayer/requests/network/get_global_ip_records.rb, line 22
def get_global_ip_records
  self.request(:account, :get_global_ip_records)
end
get_ip_address(id) click to toggle source
# File lib/fog/softlayer/requests/network/get_ip_address.rb, line 22
def get_ip_address(id)
  self.request(:network_subnet_IpAddress, id, :query => 'objectMask=mask[hardware.fullyQualifiedDomainName,hardware.id,virtualGuest.id,virtualGuest.fullyQualifiedDomainName,subnet.id]')
end
get_ip_addresses() click to toggle source
# File lib/fog/softlayer/requests/network/get_ip_addresses.rb, line 22
def get_ip_addresses
  self.request(:account, :get_ip_addresses, :query => 'objectMask=mask[hardware.fullyQualifiedDomainName,hardware.id,virtualGuest.id,virtualGuest.fullyQualifiedDomainName,subnet.id]')
end
get_maintenance_windows(location_id, begin_date, end_date, slots_number) click to toggle source
# File lib/fog/softlayer/requests/network/get_maintenance_windows.rb, line 23
def get_maintenance_windows(location_id, begin_date, end_date, slots_number)
  request(:provisioning_maintenance_window, :get_maintenance_windows, :body => [begin_date, end_date, location_id, slots_number], :http_method => :POST)
end
get_network(id) click to toggle source
# File lib/fog/softlayer/requests/network/get_network.rb, line 28
def get_network(id)
  self.request(:network_vlan, "#{id}/get_object", :query => 'objectMask=mask[subnets,tagReferences,type,primaryRouter.datacenter,networkSpace]')
end
get_network_tags(id) click to toggle source
# File lib/fog/softlayer/requests/network/get_network_tags.rb, line 41
def get_network_tags(id)
  self.request(:network_vlan, id, :query => 'objectMask=mask[tagReferences]')
end
get_portable_subnet_package_id(address_space) click to toggle source
# File lib/fog/softlayer/requests/network/get_portable_subnet_package_id.rb, line 23
def get_portable_subnet_package_id(address_space)
  address_space.downcase!; err_msg = "Argument for #{self.class.name}##{__method__} must be 'PRIVATE' or 'PUBLIC'."
  raise ArgumentError, err_msg unless %{private public}.include?(address_space)
  request(:product_package, '0/get_configuration', :query => 'objectMask=mask[isRequired,itemCategory]').body.map do |item|
    item['itemCategory']['id'] if item['itemCategory']['categoryCode'] == "sov_sec_ip_addresses_#{address_space == 'public' ? 'pub' : 'priv'}"
  end.compact.first
end
get_portable_subnet_price_code(address_count, public=true) click to toggle source
# File lib/fog/softlayer/requests/network/get_portable_subnet_price_code.rb, line 21
def get_portable_subnet_price_code(address_count, public=true)
  portable_subnet_package_id = get_portable_subnet_package_id(public ? 'PUBLIC' : 'PRIVATE')
  request(:product_package, '0/get_item_prices', :query => 'objectMask=mask[id,categories.id,item.description]').body.map do |item|
    catg = item['categories'][0]
    item['id'] if catg['id'] == portable_subnet_package_id && item['item']['description'] =~ /^#{address_count}/
  end.compact.first
end
get_private_vlan_price_code() click to toggle source
# File lib/fog/softlayer/requests/network/get_private_vlan_price_code.rb, line 21
def get_private_vlan_price_code
  request(:product_package, '0/get_items').body.map { |item| item['prices'][0]['id'] if item['description'] =~ /vlan/i and item['description'] =~ /private/i }.compact.first
end
get_public_vlan_price_code() click to toggle source
# File lib/fog/softlayer/requests/network/get_public_vlan_price_code.rb, line 21
def get_public_vlan_price_code
  request(:product_package, '0/get_items').body.map { |item| item['prices'][0]['id'] if item['description'] =~ /vlan/i and item['description'] =~ /public/i }.compact.first
end
get_references_by_tag_name(tag_list) click to toggle source
# File lib/fog/softlayer/requests/network/get_references_by_tag_name.rb, line 36
def get_references_by_tag_name(tag_list)
  self.request(:tag, "get_tag_by_tag_name/#{tag_list}", :query => 'objectMask=references')
end
get_subnet(id) click to toggle source
# File lib/fog/softlayer/requests/network/get_subnet.rb, line 22
def get_subnet(id)
  self.request(:network_subnet, "#{id}/get_object", :query => 'objectMask=mask[datacenter,ipAddresses.id,virtualGuests.fullyQualifiedDomainName,virtualGuests.id,hardware.fullyQualifiedDomainName,hardware.id,addressSpace]')
end
get_subnet_package_id(address_space) click to toggle source
# File lib/fog/softlayer/requests/network/get_subnet_package_id.rb, line 23
def get_subnet_package_id(address_space)
  address_space.downcase!; err_msg = "Argument for #{self.class.name}##{__method__} must be 'PRIVATE' or 'PUBLIC'."
  raise ArgumentError, err_msg unless %{private public}.include?(address_space)
  request(:product_package, '0/get_configuration', :query => 'objectMask=mask[isRequired,itemCategory]').body.map do |item|
    item['itemCategory']['id'] if item['itemCategory']['categoryCode'] == 'static_sec_ip_addresses'
  end.compact.first
end
get_subnet_price_code(address_count, public=true) click to toggle source
# File lib/fog/softlayer/requests/network/get_subnet_price_code.rb, line 21
def get_subnet_price_code(address_count, public=true)
  subnet_package_id = get_subnet_package_id(public ? 'PUBLIC' : 'PRIVATE')
  request(:product_package, '0/get_item_prices', :query => 'objectMask=mask[id,categories.id,item.description]').body.map do |item|
    item['id'] if catg['id'] == subnet_package_id && item['item']['description'] =~ /^#{address_count}/
  end.compact.first
end
list_networks() click to toggle source
# File lib/fog/softlayer/network.rb, line 144
def list_networks
  self.list_networks
end
list_subnets() click to toggle source
# File lib/fog/softlayer/requests/network/list_subnets.rb, line 22
def list_subnets
self.request(:account, :get_subnets, :query => 'objectMask=mask[networkVlan,ipAddresses.id,datacenter,hardware,virtualGuests.id,virtualGuests.fullyQualifiedDomainName]')
end
request(service, path, options = {}) click to toggle source
# File lib/fog/softlayer/network.rb, line 119
def request(service, path, options = {})
  options = {:username => @softlayer_username, :api_key => @softlayer_api_key}.merge(options)
  Fog::Softlayer::Slapi.slapi_request(service, path, options)
end
route_global_ip(global_ip_id, destination_ip_address) click to toggle source
# File lib/fog/softlayer/requests/network/route_global_ip.rb, line 22
def route_global_ip(global_ip_id, destination_ip_address)
  self.request(:network_subnet_ipaddress_global, "#{global_ip_id}/route", :body => destination_ip_address, :http_method => :post)
end
unroute_global_ip(global_ip_id) click to toggle source
# File lib/fog/softlayer/requests/network/unroute_global_ip.rb, line 22
def unroute_global_ip(global_ip_id)
  self.request(:network_subnet_ipaddress_global, "#{global_ip_id}/unroute")
end

Private Instance Methods

global_ipv4_cat_code() click to toggle source

Queries the SoftLayer API and returns the “category code” required for ordering a Global IPv4 address. @return [Integer]

# File lib/fog/softlayer/network.rb, line 153
def global_ipv4_cat_code
  request(:product_package, '0/get_configuration', :query => 'objectMask=mask[isRequired,itemCategory]').body.map do |item|
    item['itemCategory']['id'] if item['itemCategory']['categoryCode'] == 'global_ipv4'
  end.compact.first
end
global_ipv4_price_code() click to toggle source

Queries the SoftLayer API and returns the “price code” required for ordering a Global IPv4 address. @return [Integer]

# File lib/fog/softlayer/network.rb, line 171
def global_ipv4_price_code
  request(:product_package, '0/get_item_prices', :query => 'objectMask=mask[id,item.description,categories.id]').body.map do |item|
    item['id'] if item.has_key?('categories') && !item['categories'][0].nil? && item['categories'][0]['id'] == global_ipv4_cat_code
  end.compact.first
end
global_ipv6_cat_code() click to toggle source

Queries the SoftLayer API and returns the “category code” required for ordering a Global IPv4 address. @return [Integer]

# File lib/fog/softlayer/network.rb, line 162
def global_ipv6_cat_code
  request(:product_package, '0/get_configuration', :query => 'objectMask=mask[isRequired,itemCategory]').body.map do |item|
    item['itemCategory']['id'] if item['itemCategory']['categoryCode'] == 'global_ipv6'
  end.compact.first
end
global_ipv6_price_code() click to toggle source

Queries the SoftLayer API and returns the “price code” required for ordering a Global IPv4 address. @return [Integer]

# File lib/fog/softlayer/network.rb, line 180
def global_ipv6_price_code
  request(:product_package, '0/get_item_prices', :query => 'objectMask=mask[id,item.description,categories.id]').body.map do |item|
    item['id'] if item['categories'][0]['id'] == global_ipv6_cat_code
  end.compact.first
end