class Fog::Compute::SakuraCloud::Real
Public Class Methods
new(options = {})
click to toggle source
# File lib/fog/sakuracloud/compute.rb, line 32 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
boot_server( id )
click to toggle source
# File lib/fog/sakuracloud/requests/compute/boot_server.rb, line 6 def boot_server( id ) request( :headers => { 'Authorization' => "Basic #{@auth_encode}" }, :expects => [200], :method => 'PUT', :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/server/#{id}/power" ) true end
create_server(options)
click to toggle source
# File lib/fog/sakuracloud/requests/compute/create_server.rb, line 6 def create_server(options) if options[:switch] switchs = options[:switch].split(',') connectedswitches = switchs.map do |sw_id| { "ID" => sw_id } end else connectedswitches = [{"Scope"=>"shared", "BandWidthMbps"=>100}] end body = { "Server" => { "Name" => options[:name], "ServerPlan" => { "ID" => options[:serverplan].to_i }, "ConnectedSwitches" => connectedswitches } } request( :headers => { 'Authorization' => "Basic #{@auth_encode}" }, :expects => [201], :method => 'POST', :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/server", :body => Fog::JSON.encode(body) ) end
delete_server( id, force = false, disks = [] )
click to toggle source
# File lib/fog/sakuracloud/requests/compute/delete_server.rb, line 6 def delete_server( id, force = false, disks = [] ) body = { "Force" => force, 'WithDisk' => disks } request( :headers => { 'Authorization' => "Basic #{@auth_encode}" }, :expects => [200], :method => 'DELETE', :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/server/#{id}", :body => Fog::JSON.encode(body) ) end
list_plans(options = {})
click to toggle source
# File lib/fog/sakuracloud/requests/compute/list_plans.rb, line 6 def list_plans(options = {}) request( :headers => { 'Authorization' => "Basic #{@auth_encode}" }, :method => 'GET', :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/product/server" ) end
list_servers(options = {})
click to toggle source
# File lib/fog/sakuracloud/requests/compute/list_servers.rb, line 6 def list_servers(options = {}) request( :headers => { 'Authorization' => "Basic #{@auth_encode}" }, :method => 'GET', :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/server" ) end
list_ssh_keys(options = {})
click to toggle source
# File lib/fog/sakuracloud/requests/compute/list_ssh_keys.rb, line 6 def list_ssh_keys(options = {}) request( :headers => { 'Authorization' => "Basic #{@auth_encode}" }, :method => 'GET', :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/sshkey" ) end
list_zones(options = {})
click to toggle source
# File lib/fog/sakuracloud/requests/compute/list_zones.rb, line 6 def list_zones(options = {}) request( :headers => { 'Authorization' => "Basic #{@auth_encode}" }, :method => 'GET', :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/zone" ) end
stop_server( id, force = false )
click to toggle source
# File lib/fog/sakuracloud/requests/compute/stop_server.rb, line 6 def stop_server( id, force = false ) if force body = { "Force" => true } else body = {} end request( :headers => { 'Authorization' => "Basic #{@auth_encode}" }, :expects => [200,202], :method => 'DELETE', :path => "#{Fog::SakuraCloud.build_endpoint(@api_zone)}/server/#{id}/power", :body => Fog::JSON.encode(body) ) true end