class Fog::Compute::Brightbox::Real

Public Class Methods

new(options) click to toggle source
# File lib/fog/brightbox/compute.rb, line 165
def initialize(options)
  # Currently authentication and api endpoints are the same but may change
  @auth_url             = options[:brightbox_auth_url] || Fog.credentials[:brightbox_auth_url] || API_URL
  @api_url              = options[:brightbox_api_url] || Fog.credentials[:brightbox_api_url] || API_URL
  @connection_options   = options[:connection_options] || {}
  @brightbox_client_id  = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id]
  @brightbox_secret     = options[:brightbox_secret] || Fog.credentials[:brightbox_secret]
  @brightbox_username   = options[:brightbox_username] || Fog.credentials[:brightbox_username]
  @brightbox_password   = options[:brightbox_password] || Fog.credentials[:brightbox_password]
  @brightbox_account    = options[:brightbox_account] || Fog.credentials[:brightbox_account]
  @persistent           = options[:persistent] || false
  @connection = Fog::Connection.new(@api_url, @persistent, @connection_options)
end

Public Instance Methods

account() click to toggle source

Returns the scoped account being used for requests

API Clients

This is the owning account

User Apps

This is the account specified by either account_id option on a connection or the brightbox_account setting in your configuration

Returns:

Fog::Compute::Brightbox::Account

# File lib/fog/brightbox/compute.rb, line 201
def account
  Fog::Compute::Brightbox::Account.new(get_scoped_account)
end
activate_console_server(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/activate_console_server.rb, line 6
def activate_console_server(identifier)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/servers/#{identifier}/activate_console", [202])
end
add_listeners_load_balancer(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/add_listeners_load_balancer.rb, line 6
def add_listeners_load_balancer(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/load_balancers/#{identifier}/add_listeners", [202], options)
end
add_nodes_load_balancer(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/add_nodes_load_balancer.rb, line 6
def add_nodes_load_balancer(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/load_balancers/#{identifier}/add_nodes", [202], options)
end
add_servers_server_group(identifier, options) click to toggle source

Add a number of servers to a server group

>> Compute[:brightbox].add_servers_server_group "grp-12345", :servers => [{:server => "srv-abcde"}]

Parameters:

  • identifier (String) - The identifier of the server group to add to

  • options

    • servers (Array) - An Array of Hashes containing {“server” => server_id} for each server to add

    [{“server” => “srv-abcde”}, {“server” => “srv-fghij”}]

Returns:

A Ruby hash of the server response

# File lib/fog/brightbox/requests/compute/add_servers_server_group.rb, line 20
def add_servers_server_group(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/server_groups/#{identifier}/add_servers", [202], options)
end
apply_to_firewall_policy(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/apply_to_firewall_policy.rb, line 6
def apply_to_firewall_policy(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/firewall_policies/#{identifier}/apply_to", [202], options)
end
create_api_client(options) click to toggle source
# File lib/fog/brightbox/requests/compute/create_api_client.rb, line 6
def create_api_client(options)
  request("post", "/1.0/api_clients", [201], options)
end
create_application(options) click to toggle source
# File lib/fog/brightbox/requests/compute/create_application.rb, line 6
def create_application(options)
  request("post", "/1.0/applications", [201], options)
end
create_cloud_ip(options = {}) click to toggle source
# File lib/fog/brightbox/requests/compute/create_cloud_ip.rb, line 6
def create_cloud_ip(options = {})
  request("post", "/1.0/cloud_ips", [201], options)
end
create_firewall_policy(options) click to toggle source
# File lib/fog/brightbox/requests/compute/create_firewall_policy.rb, line 6
def create_firewall_policy(options)
  request("post", "/1.0/firewall_policies", [201], options)
end
create_firewall_rule(options) click to toggle source
# File lib/fog/brightbox/requests/compute/create_firewall_rule.rb, line 6
def create_firewall_rule(options)
  request("post", "/1.0/firewall_rules", [202], options)
end
create_image(options) click to toggle source
# File lib/fog/brightbox/requests/compute/create_image.rb, line 6
def create_image(options)
  request("post", "/1.0/images", [201], options)
end
create_load_balancer(options) click to toggle source
# File lib/fog/brightbox/requests/compute/create_load_balancer.rb, line 6
def create_load_balancer(options)
  request("post", "/1.0/load_balancers", [202], options)
end
create_server(options) click to toggle source
# File lib/fog/brightbox/requests/compute/create_server.rb, line 6
def create_server(options)
  request("post", "/1.0/servers", [202], options)
end
create_server_group(options) click to toggle source
# File lib/fog/brightbox/requests/compute/create_server_group.rb, line 6
def create_server_group(options)
  request("post", "/1.0/server_groups", [202], options)
end
destroy_api_client(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_api_client.rb, line 6
def destroy_api_client(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/api_clients/#{identifier}", [200])
end
destroy_application(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_application.rb, line 6
def destroy_application(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/applications/#{identifier}", [200])
end
destroy_cloud_ip(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_cloud_ip.rb, line 6
def destroy_cloud_ip(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/cloud_ips/#{identifier}", [200])
end
destroy_firewall_policy(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_firewall_policy.rb, line 6
def destroy_firewall_policy(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/firewall_policies/#{identifier}", [202])
end
destroy_firewall_rule(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_firewall_rule.rb, line 6
def destroy_firewall_rule(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/firewall_rules/#{identifier}", [202])
end
destroy_image(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_image.rb, line 6
def destroy_image(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/images/#{identifier}", [202])
end
destroy_load_balancer(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_load_balancer.rb, line 6
def destroy_load_balancer(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/load_balancers/#{identifier}", [202])
end
destroy_server(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_server.rb, line 6
def destroy_server(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/servers/#{identifier}", [202])
end
destroy_server_group(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/destroy_server_group.rb, line 6
def destroy_server_group(identifier)
  return nil if identifier.nil? || identifier == ""
  request("delete", "/1.0/server_groups/#{identifier}", [202])
end
get_account(identifier = nil) click to toggle source

Requests details about an account from the API

Parameters:

identifier <String>

The identifier to request (Default is nil)

Returns:

Hash

The JSON response parsed to a Hash

Notes:

This also supports a deprecated form where if an identifier is not passed then the scoping account is returned instead. This should not be used in new code. Use get_scoped_account instead.

Reference:

api.gb1.brightbox.com/1.0/#account_get_account

# File lib/fog/brightbox/requests/compute/get_account.rb, line 25
def get_account(identifier = nil)
  if identifier.nil? || identifier.empty?
    Fog::Logger.deprecation("get_account() without a parameter is deprecated, use get_scoped_account instead [light_black](#{caller.first})[/]")
    get_scoped_account
  else
    request("get", "/1.0/accounts/#{identifier}", [200])
  end
end
get_api_client(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_api_client.rb, line 6
def get_api_client(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/api_clients/#{identifier}", [200])
end
get_application(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_application.rb, line 6
def get_application(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/applications/#{identifier}", [200])
end
get_authenticated_user() click to toggle source

Requests details about authenticated user from the API

Returns:

Hash

The JSON response parsed to a Hash

# File lib/fog/brightbox/requests/compute/get_authenticated_user.rb, line 11
def get_authenticated_user
  request("get", "/1.0/user", [200])
end
get_cloud_ip(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_cloud_ip.rb, line 6
def get_cloud_ip(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/cloud_ips/#{identifier}", [200])
end
get_firewall_policy(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_firewall_policy.rb, line 6
def get_firewall_policy(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/firewall_policies/#{identifier}", [200])
end
get_firewall_rule(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_firewall_rule.rb, line 6
def get_firewall_rule(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/firewall_rules/#{identifier}", [200])
end
get_image(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_image.rb, line 6
def get_image(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/images/#{identifier}", [200])
end
get_interface(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_interface.rb, line 6
def get_interface(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/interfaces/#{identifier}", [200])
end
get_load_balancer(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_load_balancer.rb, line 6
def get_load_balancer(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/load_balancers/#{identifier}", [200])
end
get_scoped_account() click to toggle source

Requests details about currently scoped account

Returns:

Hash

The JSON response parsed to a Hash

# File lib/fog/brightbox/requests/compute/get_scoped_account.rb, line 12
def get_scoped_account
  request("get", "/1.0/account", [200])
end
get_server(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_server.rb, line 6
def get_server(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/servers/#{identifier}", [200])
end
get_server_group(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_server_group.rb, line 6
def get_server_group(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/server_groups/#{identifier}", [200])
end
get_server_type(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_server_type.rb, line 6
def get_server_type(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/server_types/#{identifier}", [200])
end
get_user(identifier = nil) click to toggle source

Requests details about a user from the API

Parameters:

identifier <String>

The identifier to request (Default is nil)

Returns:

Hash

The JSON response parsed to a Hash

Notes:

This also supports a deprecated form where if an identifier is not passed then the requesting user is returned instead. This should not be used in new code. Use get_authenticated_user instead.

Reference:

api.gb1.brightbox.com/1.0/#user_get_user

# File lib/fog/brightbox/requests/compute/get_user.rb, line 25
def get_user(identifier = nil)
  if identifier.nil? || identifier == ""
    Fog::Logger.deprecation("get_user() without a parameter is deprecated, use get_authenticated_user instead [light_black](#{caller.first})[/]")
    get_authenticated_user
  else
    request("get", "/1.0/users/#{identifier}", [200])
  end
end
get_zone(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/get_zone.rb, line 6
def get_zone(identifier)
  return nil if identifier.nil? || identifier == ""
  request("get", "/1.0/zones/#{identifier}", [200])
end
list_accounts() click to toggle source
# File lib/fog/brightbox/requests/compute/list_accounts.rb, line 6
def list_accounts
  request("get", "/1.0/accounts", [200])
end
list_api_clients() click to toggle source
# File lib/fog/brightbox/requests/compute/list_api_clients.rb, line 6
def list_api_clients
  request("get", "/1.0/api_clients", [200])
end
list_applications() click to toggle source
# File lib/fog/brightbox/requests/compute/list_applications.rb, line 6
def list_applications
  request("get", "/1.0/applications", [200])
end
list_cloud_ips() click to toggle source
# File lib/fog/brightbox/requests/compute/list_cloud_ips.rb, line 6
def list_cloud_ips
  request("get", "/1.0/cloud_ips", [200])
end
list_firewall_policies() click to toggle source
# File lib/fog/brightbox/requests/compute/list_firewall_policies.rb, line 6
def list_firewall_policies
  request("get", "/1.0/firewall_policies", [200])
end
list_images() click to toggle source
# File lib/fog/brightbox/requests/compute/list_images.rb, line 6
def list_images
  request("get", "/1.0/images", [200])
end
list_load_balancers() click to toggle source
# File lib/fog/brightbox/requests/compute/list_load_balancers.rb, line 6
def list_load_balancers
  request("get", "/1.0/load_balancers", [200])
end
list_server_groups() click to toggle source
# File lib/fog/brightbox/requests/compute/list_server_groups.rb, line 6
def list_server_groups
  request("get", "/1.0/server_groups", [200])
end
list_server_types() click to toggle source
# File lib/fog/brightbox/requests/compute/list_server_types.rb, line 6
def list_server_types
  request("get", "/1.0/server_types", [200])
end
list_servers() click to toggle source
# File lib/fog/brightbox/requests/compute/list_servers.rb, line 6
def list_servers
  request("get", "/1.0/servers", [200])
end
list_users() click to toggle source
# File lib/fog/brightbox/requests/compute/list_users.rb, line 6
def list_users
  request("get", "/1.0/users", [200])
end
list_zones() click to toggle source
# File lib/fog/brightbox/requests/compute/list_zones.rb, line 6
def list_zones
  request("get", "/1.0/zones", [200])
end
map_cloud_ip(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/map_cloud_ip.rb, line 6
def map_cloud_ip(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/cloud_ips/#{identifier}/map", [202], options)
end
move_servers_server_group(identifier, options) click to toggle source

Moves a number of servers between two server groups

>> Compute[:brightbox].remove_servers_server_group "grp-12345", :destination => "grp-67890", :servers => [{:server => "srv-abcde"}]

Parameters:

  • identifier - The identifier (String) of the server group to remove from

  • options (Hash)

    • destination (String)- The identifier of the server group to move to

    • servers (Array) - Array of Hashes containing {“server” => server_id} for each server to remove

    [{“server” => “srv-abcde”}, {“server” => “srv-fghij”}]

Returns:

A Ruby hash of the server response

# File lib/fog/brightbox/requests/compute/move_servers_server_group.rb, line 21
def move_servers_server_group(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/server_groups/#{identifier}/move_servers", [202], options)
end
remove_firewall_policy(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/remove_firewall_policy.rb, line 6
def remove_firewall_policy(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/firewall_policies/#{identifier}/remove", [202], options)
end
remove_listeners_load_balancer(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/remove_listeners_load_balancer.rb, line 6
def remove_listeners_load_balancer(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/load_balancers/#{identifier}/remove_listeners", [202], options)
end
remove_nodes_load_balancer(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/remove_nodes_load_balancer.rb, line 6
def remove_nodes_load_balancer(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/load_balancers/#{identifier}/remove_nodes", [202], options)
end
remove_servers_server_group(identifier, options) click to toggle source

Remove a number of servers from a server group

>> Compute[:brightbox].remove_servers_server_group "grp-12345", :servers => [{:server => "srv-abcde"}]

Parameters:

  • identifier (String) - The identifier of the server group to remove from

  • options (Array) - An Array of Hashes containing {“server” => server_id} for each server to remove

    [{“server” => “srv-abcde”}, {“server” => “srv-fghij”}]

Returns:

A Ruby hash of the server response

# File lib/fog/brightbox/requests/compute/remove_servers_server_group.rb, line 19
def remove_servers_server_group(identifier, options)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/server_groups/#{identifier}/remove_servers", [202], options)
end
request(method, url, expected_responses, options = {}) click to toggle source
# File lib/fog/brightbox/compute.rb, line 179
def request(method, url, expected_responses, options = {})
  request_options = {
    :method   => method.to_s.upcase,
    :path     => url,
    :expects  => expected_responses
  }
  options[:account_id] = @brightbox_account if options[:account_id].nil? && @brightbox_account
  request_options[:body] = Fog::JSON.encode(options) unless options.empty?
  make_request(request_options)
end
reset_ftp_password_account() click to toggle source
# File lib/fog/brightbox/requests/compute/reset_ftp_password_account.rb, line 6
def reset_ftp_password_account
  request("post", "/1.0/account/reset_ftp_password", [200])
end
reset_secret_api_client(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/reset_secret_api_client.rb, line 6
def reset_secret_api_client(identifier)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/api_clients/#{identifier}/reset_secret", [200])
end
reset_secret_application(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/reset_secret_application.rb, line 6
def reset_secret_application(identifier)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/applications/#{identifier}/reset_secret", [200])
end
shutdown_server(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/shutdown_server.rb, line 6
def shutdown_server(identifier)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/servers/#{identifier}/shutdown", [202])
end
snapshot_server(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/snapshot_server.rb, line 6
def snapshot_server(identifier)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/servers/#{identifier}/snapshot", [202])
end
start_server(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/start_server.rb, line 6
def start_server(identifier)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/servers/#{identifier}/start", [202])
end
stop_server(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/stop_server.rb, line 6
def stop_server(identifier)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/servers/#{identifier}/stop", [202])
end
unmap_cloud_ip(identifier) click to toggle source
# File lib/fog/brightbox/requests/compute/unmap_cloud_ip.rb, line 6
def unmap_cloud_ip(identifier)
  return nil if identifier.nil? || identifier == ""
  request("post", "/1.0/cloud_ips/#{identifier}/unmap", [202])
end
update_api_client(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_api_client.rb, line 6
def update_api_client(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/api_clients/#{identifier}", [200], options)
end
update_application(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_application.rb, line 6
def update_application(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/applications/#{identifier}", [200], options)
end
update_cloud_ip(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_cloud_ip.rb, line 6
def update_cloud_ip(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/cloud_ips/#{identifier}", [200], options)
end
update_firewall_rule(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_firewall_rule.rb, line 6
def update_firewall_rule(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/firewall_rules/#{identifier}", [202], options)
end
update_image(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_image.rb, line 6
def update_image(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/images/#{identifier}", [200], options)
end
update_load_balancer(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_load_balancer.rb, line 6
def update_load_balancer(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/load_balancers/#{identifier}", [202], options)
end
update_server(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_server.rb, line 6
def update_server(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/servers/#{identifier}", [200], options)
end
update_server_group(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_server_group.rb, line 6
def update_server_group(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/server_groups/#{identifier}", [202], options)
end
update_user(identifier, options) click to toggle source
# File lib/fog/brightbox/requests/compute/update_user.rb, line 6
def update_user(identifier, options)
  return nil if identifier.nil? || identifier == ""
  return nil if options.empty? || options.nil?
  request("put", "/1.0/users/#{identifier}", [200], options)
end

Private Instance Methods

authenticated_request(options) click to toggle source
# File lib/fog/brightbox/compute.rb, line 249
def authenticated_request(options)
  headers = options[:headers] || {}
  headers.merge!("Authorization" => "OAuth #{@oauth_token}", "Content-Type" => "application/json")
  options[:headers] = headers
  @connection.request(options)
end
get_oauth_token(options = {}) click to toggle source
# File lib/fog/brightbox/compute.rb, line 206
def get_oauth_token(options = {})
  auth_url = options[:brightbox_auth_url] || @auth_url

  connection = Fog::Connection.new(auth_url)
  authentication_body_hash = if @brightbox_username && @brightbox_password
    {
      'client_id' => @brightbox_client_id,
      'grant_type' => 'password',
      'username' => @brightbox_username,
      'password' => @brightbox_password
    }
  else
    {'client_id' => @brightbox_client_id, 'grant_type' => 'none'}
  end
  @authentication_body = Fog::JSON.encode(authentication_body_hash)

  response = connection.request({
    :path => "/token",
    :expects  => 200,
    :headers  => {
      'Authorization' => "Basic " + Base64.encode64("#{@brightbox_client_id}:#{@brightbox_secret}").chomp,
      'Content-Type' => 'application/json'
    },
    :method   => 'POST',
    :body     => @authentication_body
  })
  @oauth_token = Fog::JSON.decode(response.body)["access_token"]
  return @oauth_token
end
make_request(params) click to toggle source
# File lib/fog/brightbox/compute.rb, line 236
def make_request(params)
  begin
    get_oauth_token if @oauth_token.nil?
    response = authenticated_request(params)
  rescue Excon::Errors::Unauthorized
    get_oauth_token
    response = authenticated_request(params)
  end
  unless response.body.empty?
    response = Fog::JSON.decode(response.body)
  end
end
select_default_image() click to toggle source

Queries the API and tries to select the most suitable official Image to use if the user chooses not to select their own.

# File lib/fog/brightbox/compute.rb, line 258
def select_default_image
  return @default_image_id unless @default_image_id.nil?

  all_images = list_images
  official_images = all_images.select {|img| img["official"] == true}
  ubuntu_lts_images = official_images.select {|img| img["name"] =~ /Ubuntu.*LTS/}
  ubuntu_lts_i686_images = ubuntu_lts_images.select {|img| img["arch"] == "i686"}

  if ubuntu_lts_i686_images.empty?
    # Accept other architectures
    if ubuntu_lts_images.empty?
      # Accept non-LTS versions of Ubuntu
      unsorted_images = official_images.select {|img| img["name"] =~ /Ubuntu/}
    else
      unsorted_images = ubuntu_lts_images
    end
  else
    unsorted_images = ubuntu_lts_i686_images
  end

  # Get the latest and use it's ID for the default image
  @default_image_id = unsorted_images.sort {|a,b| a["created_at"] <=> b["created_at"]}.first["id"]
rescue
  nil
end