class Fog::Network::SakuraCloud::Real
Public Class Methods
new(options = {})
click to toggle source
# File lib/fog/sakuracloud/network.rb, line 27 def initialize(options = {}) @auth_encord = 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' @connection = Fog::Core::Connection.new(@sakuracloud_api_url) end
Public Instance Methods
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_encord}" }, :expects => 202, :method => 'POST', :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/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_encord}" }, :expects => 201, :method => 'POST', :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/switch", :body => Fog::JSON.encode(body) ) 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_encord}" }, :expects => [200], :method => 'DELETE', :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/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_encord}" }, :expects => [200], :method => 'DELETE', :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/switch/#{id}" ) 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_encord}" }, :method => 'GET', :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/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_encord}" }, :method => 'GET', :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/switch" ) end
request(params)
click to toggle source
# File lib/fog/sakuracloud/network.rb, line 40 def request(params) response = parse @connection.request(params) response end
Private Instance Methods
parse(response)
click to toggle source
# File lib/fog/sakuracloud/network.rb, line 46 def parse(response) return response if response.body.empty? response.body = Fog::JSON.decode(response.body) response end