class Fog::Compute::DigitalOceanV2::Real
noinspection RubyStringKeysInHashInspection
noinspection RubyStringKeysInHashInspection
noinspection RubyStringKeysInHashInspection
noinspection RubyStringKeysInHashInspection
noinspection RubyStringKeysInHashInspection
Public Class Methods
new(options={})
click to toggle source
# File lib/fog/digitalocean/compute_v2.rb, line 78 def initialize(options={}) digitalocean_token = options[:digitalocean_token] persistent = false options = { headers: { 'Authorization' => "Bearer #{digitalocean_token}", } } @connection = Fog::Core::Connection.new 'https://api.digitalocean.com', persistent, options end
Public Instance Methods
change_kernel(id, kernel)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/change_kernel.rb, line 5 def change_kernel(id, kernel) body = { :type => "change_kernel", :kernel => kernel } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
convert_to_snapshot(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/convert_to_snapshot.rb, line 5 def convert_to_snapshot(id) body = { :type => 'convert',} encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/images/#{id}/actions", :body => encoded_body, ) end
create_server(name, size, image, region, options = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/create_server.rb, line 7 def create_server(name, size, image, region, options = {}) create_options = { :name => name, :region => region, :size => size, :image => image, } [:backups, :ipv6, :private_networking].each do |opt| create_options[opt] = !!options[opt] if options[opt] end [:user_data, :ssh_keys].each do |opt| create_options[opt] = options[opt] if options[opt] end encoded_body = Fog::JSON.encode(create_options) request( :expects => [202], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => '/v2/droplets', :body => encoded_body, ) end
create_ssh_key(name, public_key)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/create_ssh_key.rb, line 7 def create_ssh_key(name, public_key) create_options = { :name => name, :public_key => public_key, } encoded_body = Fog::JSON.encode(create_options) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => '/v2/account/keys', :body => encoded_body, ) end
delete_server(server_id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/destroy_server.rb, line 6 def delete_server(server_id) Fog::Logger.warning("delete_server method has been deprecated, use destroy_server instead") destroy_server(server_id) end
delete_ssh_key(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/delete_ssh_key.rb, line 6 def delete_ssh_key(id) request( :expects => [204], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'DELETE', :path => "/v2/account/keys/#{id}", ) end
destroy_server(server_id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/destroy_server.rb, line 10 def destroy_server(server_id) request( :expects => [204], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'DELETE', :path => "/v2/droplets/#{server_id}", ) end
disable_backups(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/disable_backups.rb, line 5 def disable_backups(id) body = { :type => "disable_backups" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
enable_ipv6(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/enable_ipv6.rb, line 5 def enable_ipv6(id) body = { :type => "enable_ipv6" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
enable_private_networking(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/enable_private_networking.rb, line 5 def enable_private_networking(id) body = { :type => "enable_private_networking" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
get_droplet_action(droplet_id, action_id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/get_droplet_action.rb, line 5 def get_droplet_action(droplet_id, action_id) request( :expects => [200], :method => 'GET', :path => "v2/droplets/#{droplet_id}/actions/#{action_id}", ) end
get_image_details(image_id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/get_image_details.rb, line 5 def get_image_details(image_id) request( :expects => [200], :method => 'GET', :path => "/v2/images/#{image_id}" ) end
get_server_details(server_id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/get_server_details.rb, line 5 def get_server_details(server_id) request( :expects => [200], :method => 'GET', :path => "/v2/droplets/#{server_id}" ) end
get_ssh_key(key_id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/get_ssh_key.rb, line 5 def get_ssh_key(key_id) request( :expects => [200], :method => 'GET', :path => "/v2/account/keys/#{key_id}" ) end
list_droplet_actions(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/list_droplet_actions.rb, line 5 def list_droplet_actions(id) request( :expects => [200], :method => 'GET', :path => "v2/droplets/#{id}/actions", ) end
list_flavors()
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/list_flavors.rb, line 5 def list_flavors request( :expects => [200], :method => 'GET', :path => '/v2/sizes' ) end
list_images(filters = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/list_images.rb, line 5 def list_images(filters = {}) request( :expects => [200], :method => 'GET', :path => "/v2/images?#{filters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")}" ) end
list_regions(filters = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/list_regions.rb, line 5 def list_regions(filters = {}) request( :expects => [200], :method => 'GET', :path => "/v2/regions?#{filters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")}" ) end
list_servers(filters = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/list_servers.rb, line 5 def list_servers(filters = {}) request( :expects => [200], :method => 'GET', :path => "/v2/droplets?#{filters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")}" ) end
list_ssh_keys()
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/list_ssh_keys.rb, line 5 def list_ssh_keys request( :expects => [200], :method => 'GET', :path => 'v2/account/keys', ) end
password_reset(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/password_reset.rb, line 5 def password_reset(id) body = { :type => "password_reset" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
power_cycle(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/power_cycle.rb, line 5 def power_cycle(id) body = { :type => "power_cycle" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
power_off(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/power_off.rb, line 5 def power_off(id) body = { :type => "power_off" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
power_on(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/power_on.rb, line 5 def power_on(id) body = { :type => "power_on" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
reboot_server(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/reboot_server.rb, line 5 def reboot_server(id) body = { :type => "reboot" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
rebuild(id, image)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/rebuild.rb, line 5 def rebuild(id, image) body = { :type => "rebuild", :image => image } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
rename(id, name)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/rename.rb, line 5 def rename(id, name) body = { :type => "rename", :name => name } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
request(params)
click to toggle source
# File lib/fog/digitalocean/compute_v2.rb, line 89 def request(params) params[:headers] ||= {} begin response = @connection.request(params) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound NotFound.slurp(error) else error end end unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end
resize(id, resize_disk, size)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/resize.rb, line 5 def resize(id, resize_disk, size) body = { :type => "resize", :disk => resize_disk, :size => size } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
restore(id, image)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/restore.rb, line 5 def restore(id, image) body = { :type => "restore", :image => image } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
shutdown(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/shutdown.rb, line 5 def shutdown(id) body = { :type => "shutdown" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
snapshot(id, name)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/snapshot.rb, line 5 def snapshot(id, name) body = { :type => "snapshot", :name => name } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end
transfer_image(id, region)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/transfer_image.rb, line 5 def transfer_image(id, region) body = { :type => 'transfer', :region => region } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/images/#{id}/actions", :body => encoded_body, ) end
update_ssh_key(key_id, name)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/update_ssh_key.rb, line 7 def update_ssh_key(key_id, name) update_options = { :name => name, } encoded_body = Fog::JSON.encode(update_options) request( :expects => [200], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'PUT', :path => "/v2/account/keys/#{key_id}", :body => encoded_body, ) end
upgrade(id)
click to toggle source
# File lib/fog/digitalocean/requests/compute_v2/upgrade.rb, line 5 def upgrade(id) body = { :type => "upgrade" } encoded_body = Fog::JSON.encode(body) request( :expects => [201], :headers => { 'Content-Type' => "application/json; charset=UTF-8", }, :method => 'POST', :path => "v2/droplets/#{id}/actions", :body => encoded_body, ) end