class Fog::Network::SakuraCloud::Real

Public Class Methods

new(options = {}) click to toggle source
# File lib/fog/sakuracloud/network.rb, line 34
def initialize(options = {})
  @auth_encode = Base64.strict_encode64([
    options[:sakuracloud_api_token],
    options[:sakuracloud_api_token_secret]
  ].join(':'))
  Fog.credentials[:sakuracloud_api_token]        = options[:sakuracloud_api_token]
  Fog.credentials[:sakuracloud_api_token_secret] = options[:sakuracloud_api_token_secret]

  @sakuracloud_api_url = options[:sakuracloud_api_url] || 'https://secure.sakura.ad.jp'
  @api_zone            = options[:api_zone] || Fog.credentials[:sakuracloud_api_zone] || 'is1b'
  Fog::SakuraCloud.validate_api_zone!(@api_zone)

  @connection = Fog::Core::Connection.new(@sakuracloud_api_url)
end

Public Instance Methods

change_router_bandwidth( id, bandwidthmbps ) click to toggle source
# File lib/fog/sakuracloud/requests/network/change_router_bandwidth.rb, line 6
def change_router_bandwidth( id, bandwidthmbps )
  body = {
    "Internet" => {
      "BandWidthMbps" => bandwidthmbps
    }
  }

  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [200],
    :method => 'PUT',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/internet/#{id}/bandwidth",
    :body => Fog::JSON.encode(body)
  )
end
collect_monitor_router( id ,start_time = nil, end_time = nil) click to toggle source
# File lib/fog/sakuracloud/requests/network/collect_monitor_router.rb, line 6
def collect_monitor_router( id ,start_time = nil, end_time = nil)
  filter = {}
  filter['Start'] = start_time if start_time
  filter['End']   = end_time if end_time
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [200],
    :method => 'GET',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/internet/#{id}/monitor",
    :query => URI.encode(Fog::JSON.encode(filter))
  )
end
connect_interface_to_switch( id, switch_id ) click to toggle source
# File lib/fog/sakuracloud/requests/network/connect_interface_to_switch.rb, line 6
def connect_interface_to_switch( id, switch_id )
  response = request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [200],
    :method => 'PUT',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/interface/#{id}/to/switch/#{switch_id}"
  )
  response.body['Interface']['ID']
end
create_router(options) click to toggle source
# File lib/fog/sakuracloud/requests/network/create_router.rb, line 6
def create_router(options)
  bandwidthmbps = options[:bandwidthmbps] ? options[:bandwidthmbps].to_i : 100

  body = {
    "Internet" => {
      "Name" => options[:name],
      "NetworkMaskLen"=> options[:networkmasklen].to_i,
      "BandWidthMbps"=> bandwidthmbps
    }
  }

  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => 202,
    :method => 'POST',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/internet",
    :body => Fog::JSON.encode(body)
  )
end
create_switch(options) click to toggle source
# File lib/fog/sakuracloud/requests/network/create_switch.rb, line 6
def create_switch(options)
  body = {
    "Switch" => {
      "Name" => options[:name]
    }
  }

  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => 201,
    :method => 'POST',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/switch",
    :body => Fog::JSON.encode(body)
  )
end
delete_interface( id ) click to toggle source
# File lib/fog/sakuracloud/requests/network/delete_interface.rb, line 6
def delete_interface( id )
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [200],
    :method => 'DELETE',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/interface/#{id}"
  )
end
delete_router( id ) click to toggle source
# File lib/fog/sakuracloud/requests/network/delete_router.rb, line 6
def delete_router( id )
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [200],
    :method => 'DELETE',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/internet/#{id}"
  )
end
delete_switch( id ) click to toggle source
# File lib/fog/sakuracloud/requests/network/delete_switch.rb, line 6
def delete_switch( id )
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [200],
    :method => 'DELETE',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/switch/#{id}"
  )
end
list_interfaces(options = {}) click to toggle source
# File lib/fog/sakuracloud/requests/network/list_interfaces.rb, line 6
def list_interfaces(options = {})
  filter = {
    "Include" => [
      "ID",
      "MACAddress",
      "IPAddress",
      "UserIPAddress",
      "Switch.ID",
      "Server.ID"]
  }
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :method => 'GET',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/interface",
    :query => URI.encode(Fog::JSON.encode(filter))
  )
end
list_routers(options = {}) click to toggle source
# File lib/fog/sakuracloud/requests/network/list_routers.rb, line 6
def list_routers(options = {})
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :method => 'GET',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/internet"
  )
end
list_switches(options = {}) click to toggle source
# File lib/fog/sakuracloud/requests/network/list_switches.rb, line 6
def list_switches(options = {})
  request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :method => 'GET',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/switch"
  )
end
regist_interface_to_server( server_id ) click to toggle source
# File lib/fog/sakuracloud/requests/network/regist_interface_to_server.rb, line 6
def regist_interface_to_server( server_id )
  body = {
    "Interface" => {
      "Server" => {
        "ID" => server_id
      }
    }
  }

  response = request(
    :headers => {
      'Authorization' => "Basic #{@auth_encode}"
    },
    :expects  => [201],
    :method => 'POST',
    :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/interface",
    :body => Fog::JSON.encode(body)
  )
  response.body['Interface']['ID']
end