From 0ec77fc5a56bc14b89823033db702728897ac561 Mon Sep 17 00:00:00 2001 From: Paul Thornthwaite Date: Mon, 8 Nov 2010 12:21:31 +0000 Subject: [PATCH] [brightbox] Added support for Brightbox cloud API beta (http://beta.brightbox.com) --- README.rdoc | 1 + lib/fog.rb | 1 + lib/fog/brightbox.rb | 7 + lib/fog/brightbox/bin.rb | 23 ++++ lib/fog/brightbox/compute.rb | 129 ++++++++++++++++++ lib/fog/brightbox/models/compute/account.rb | 52 +++++++ lib/fog/brightbox/models/compute/cloud_ip.rb | 43 ++++++ lib/fog/brightbox/models/compute/cloud_ips.rb | 34 +++++ lib/fog/brightbox/models/compute/flavor.rb | 33 +++++ lib/fog/brightbox/models/compute/flavors.rb | 28 ++++ lib/fog/brightbox/models/compute/image.rb | 53 +++++++ lib/fog/brightbox/models/compute/images.rb | 28 ++++ lib/fog/brightbox/models/compute/server.rb | 98 +++++++++++++ lib/fog/brightbox/models/compute/servers.rb | 29 ++++ lib/fog/brightbox/models/compute/user.rb | 40 ++++++ lib/fog/brightbox/models/compute/users.rb | 29 ++++ lib/fog/brightbox/models/compute/zone.rb | 21 +++ lib/fog/brightbox/models/compute/zones.rb | 29 ++++ .../requests/compute/create_api_client.rb | 27 ++++ .../requests/compute/create_cloud_ip.rb | 27 ++++ .../requests/compute/create_image.rb | 27 ++++ .../requests/compute/create_server.rb | 27 ++++ .../requests/compute/destroy_api_client.rb | 27 ++++ .../requests/compute/destroy_cloud_ip.rb | 27 ++++ .../requests/compute/destroy_image.rb | 27 ++++ .../requests/compute/destroy_server.rb | 27 ++++ .../brightbox/requests/compute/get_account.rb | 27 ++++ .../requests/compute/get_api_client.rb | 27 ++++ .../requests/compute/get_cloud_ip.rb | 27 ++++ .../brightbox/requests/compute/get_image.rb | 27 ++++ .../requests/compute/get_interface.rb | 27 ++++ .../brightbox/requests/compute/get_server.rb | 27 ++++ .../requests/compute/get_server_type.rb | 27 ++++ .../brightbox/requests/compute/get_user.rb | 27 ++++ .../brightbox/requests/compute/get_zone.rb | 27 ++++ .../requests/compute/list_api_clients.rb | 27 ++++ .../requests/compute/list_cloud_ips.rb | 27 ++++ .../brightbox/requests/compute/list_images.rb | 27 ++++ .../requests/compute/list_server_types.rb | 27 ++++ .../requests/compute/list_servers.rb | 27 ++++ .../brightbox/requests/compute/list_users.rb | 27 ++++ .../brightbox/requests/compute/list_zones.rb | 27 ++++ .../requests/compute/map_cloud_ip.rb | 27 ++++ .../requests/compute/rebuild_server.rb | 27 ++++ .../compute/reset_ftp_password_account.rb | 27 ++++ .../requests/compute/resize_server.rb | 27 ++++ .../requests/compute/restart_server.rb | 27 ++++ .../requests/compute/shutdown_server.rb | 27 ++++ .../requests/compute/snapshot_server.rb | 27 ++++ .../requests/compute/start_server.rb | 27 ++++ .../brightbox/requests/compute/stop_server.rb | 27 ++++ .../requests/compute/unmap_cloud_ip.rb | 27 ++++ .../requests/compute/update_account.rb | 27 ++++ .../requests/compute/update_api_client.rb | 27 ++++ .../requests/compute/update_image.rb | 27 ++++ .../requests/compute/update_server.rb | 27 ++++ .../brightbox/requests/compute/update_user.rb | 27 ++++ lib/fog/core/bin.rb | 2 + lib/fog/core/compute.rb | 3 + lib/fog/core/credentials.rb | 2 + spec/brightbox/models/flavors_spec.rb | 18 +++ spec/brightbox/models/server_spec.rb | 28 ++++ spec/brightbox/models/servers_spec.rb | 29 ++++ 63 files changed, 1813 insertions(+) create mode 100644 lib/fog/brightbox.rb create mode 100644 lib/fog/brightbox/bin.rb create mode 100644 lib/fog/brightbox/compute.rb create mode 100644 lib/fog/brightbox/models/compute/account.rb create mode 100644 lib/fog/brightbox/models/compute/cloud_ip.rb create mode 100644 lib/fog/brightbox/models/compute/cloud_ips.rb create mode 100644 lib/fog/brightbox/models/compute/flavor.rb create mode 100644 lib/fog/brightbox/models/compute/flavors.rb create mode 100644 lib/fog/brightbox/models/compute/image.rb create mode 100644 lib/fog/brightbox/models/compute/images.rb create mode 100644 lib/fog/brightbox/models/compute/server.rb create mode 100644 lib/fog/brightbox/models/compute/servers.rb create mode 100644 lib/fog/brightbox/models/compute/user.rb create mode 100644 lib/fog/brightbox/models/compute/users.rb create mode 100644 lib/fog/brightbox/models/compute/zone.rb create mode 100644 lib/fog/brightbox/models/compute/zones.rb create mode 100644 lib/fog/brightbox/requests/compute/create_api_client.rb create mode 100644 lib/fog/brightbox/requests/compute/create_cloud_ip.rb create mode 100644 lib/fog/brightbox/requests/compute/create_image.rb create mode 100644 lib/fog/brightbox/requests/compute/create_server.rb create mode 100644 lib/fog/brightbox/requests/compute/destroy_api_client.rb create mode 100644 lib/fog/brightbox/requests/compute/destroy_cloud_ip.rb create mode 100644 lib/fog/brightbox/requests/compute/destroy_image.rb create mode 100644 lib/fog/brightbox/requests/compute/destroy_server.rb create mode 100644 lib/fog/brightbox/requests/compute/get_account.rb create mode 100644 lib/fog/brightbox/requests/compute/get_api_client.rb create mode 100644 lib/fog/brightbox/requests/compute/get_cloud_ip.rb create mode 100644 lib/fog/brightbox/requests/compute/get_image.rb create mode 100644 lib/fog/brightbox/requests/compute/get_interface.rb create mode 100644 lib/fog/brightbox/requests/compute/get_server.rb create mode 100644 lib/fog/brightbox/requests/compute/get_server_type.rb create mode 100644 lib/fog/brightbox/requests/compute/get_user.rb create mode 100644 lib/fog/brightbox/requests/compute/get_zone.rb create mode 100644 lib/fog/brightbox/requests/compute/list_api_clients.rb create mode 100644 lib/fog/brightbox/requests/compute/list_cloud_ips.rb create mode 100644 lib/fog/brightbox/requests/compute/list_images.rb create mode 100644 lib/fog/brightbox/requests/compute/list_server_types.rb create mode 100644 lib/fog/brightbox/requests/compute/list_servers.rb create mode 100644 lib/fog/brightbox/requests/compute/list_users.rb create mode 100644 lib/fog/brightbox/requests/compute/list_zones.rb create mode 100644 lib/fog/brightbox/requests/compute/map_cloud_ip.rb create mode 100644 lib/fog/brightbox/requests/compute/rebuild_server.rb create mode 100644 lib/fog/brightbox/requests/compute/reset_ftp_password_account.rb create mode 100644 lib/fog/brightbox/requests/compute/resize_server.rb create mode 100644 lib/fog/brightbox/requests/compute/restart_server.rb create mode 100644 lib/fog/brightbox/requests/compute/shutdown_server.rb create mode 100644 lib/fog/brightbox/requests/compute/snapshot_server.rb create mode 100644 lib/fog/brightbox/requests/compute/start_server.rb create mode 100644 lib/fog/brightbox/requests/compute/stop_server.rb create mode 100644 lib/fog/brightbox/requests/compute/unmap_cloud_ip.rb create mode 100644 lib/fog/brightbox/requests/compute/update_account.rb create mode 100644 lib/fog/brightbox/requests/compute/update_api_client.rb create mode 100644 lib/fog/brightbox/requests/compute/update_image.rb create mode 100644 lib/fog/brightbox/requests/compute/update_server.rb create mode 100644 lib/fog/brightbox/requests/compute/update_user.rb create mode 100644 spec/brightbox/models/flavors_spec.rb create mode 100644 spec/brightbox/models/server_spec.rb create mode 100644 spec/brightbox/models/servers_spec.rb diff --git a/README.rdoc b/README.rdoc index ad41457ce..ed9e640e3 100644 --- a/README.rdoc +++ b/README.rdoc @@ -102,6 +102,7 @@ Play around and use the console to explore or check out the {getting started gui You should try out the (varying) support fog has for: * {AWS}[http://aws.amazon.com] [{Compute}[http://aws.amazon.com/ec2], {ELB}[http://aws.amazon.com/elasticloadbalancing], {Storage}[http://aws.amazon.com/s3], {SimpleDB}[http://aws.amazon.com/simpledb]] * {Blue Box Group}[http://www.blueboxgrp.com] [{Compute}[http://www.blueboxgrp.com/blocks]] +* {Brightbox}[http://www.brightbox.co.uk] [{Compute}[http://beta.brightbox.com/]] * {Google}[http://www.google.com] [{Storage}[http://code.google.com/apis/storage]] * {Rackspace}[http://www.rackspace.com] [{Compute}[http://www.rackspacecloud.com/cloud_hosting_products/servers], {Storage}[http://www.rackspacecloud.com/cloud_hosting_products/files]] * {Slicehost}[http://www.slicehost.com] [{Compute}[http://www.slicehost.com]] diff --git a/lib/fog.rb b/lib/fog.rb index 5154ac2b2..610cc9010 100644 --- a/lib/fog.rb +++ b/lib/fog.rb @@ -72,6 +72,7 @@ end require 'fog/aws' require 'fog/bluebox' +require 'fog/brightbox' require 'fog/go_grid' require 'fog/linode' require 'fog/local' diff --git a/lib/fog/brightbox.rb b/lib/fog/brightbox.rb new file mode 100644 index 000000000..ae5c945dd --- /dev/null +++ b/lib/fog/brightbox.rb @@ -0,0 +1,7 @@ +module Fog + module Brightbox + extend Fog::Provider + service_path 'fog/brightbox' + service 'compute' + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/bin.rb b/lib/fog/brightbox/bin.rb new file mode 100644 index 000000000..90dc99ba1 --- /dev/null +++ b/lib/fog/brightbox/bin.rb @@ -0,0 +1,23 @@ +class Brightbox < Fog::Bin + class << self + + def [](service) + @@connections ||= Hash.new do |hash, key| + hash[key] = case key + when :compute + Fog::Brightbox::Compute.new + end + end + @@connections[service] + end + + def services + [:compute] + end + + def account + @@connections[:compute].account + end + + end +end diff --git a/lib/fog/brightbox/compute.rb b/lib/fog/brightbox/compute.rb new file mode 100644 index 000000000..a7ed86ffe --- /dev/null +++ b/lib/fog/brightbox/compute.rb @@ -0,0 +1,129 @@ +module Fog + module Brightbox + class Compute < Fog::Service + + API_URL = "https://api.gb1.brightbox.com/" + + requires :brightbox_client_id, :brightbox_secret + + model_path 'fog/brightbox/models/compute' + model :account # Singular resource, no collection + collection :servers + model :server + collection :flavors + model :flavor + collection :images + model :image + collection :zones + model :zone + collection :cloud_ips + model :cloud_ip + collection :users + model :user + + request_path 'fog/brightbox/requests/compute' + request :create_api_client + request :create_cloud_ip + request :create_image + request :create_server + request :destroy_api_client + request :destroy_cloud_ip + request :destroy_image + request :destroy_server + request :get_account + request :get_api_client + request :get_cloud_ip + request :get_image + request :get_interface + request :get_server + request :get_server_type + request :get_user + request :get_zone + request :list_api_clients + request :list_cloud_ips + request :list_images + request :list_server_types + request :list_servers + request :list_users + request :list_zones + request :map_cloud_ip + request :rebuild_server + request :reset_ftp_password_account + request :resize_server + request :restart_server + request :shutdown_server + request :snapshot_server + request :start_server + request :stop_server + request :unmap_cloud_ip + request :update_account + request :update_api_client + request :update_image + request :update_server + request :update_user + + class Mock + + def request(options) + raise "Not implemented" + end + end + + class Real + + def initialize(options) + require "json" + # 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 + @brightbox_client_id = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id] || nil + @brightbox_secret = options[:brightbox_secret] || Fog.credentials[:brightbox_secret] || nil + @connection = Fog::Connection.new(@api_url) + end + + def request(params) + begin + get_oauth_token if @oauth_token.nil? + response = authenticated_request(params) + rescue Excon::Errors::Unauthorized => e + get_oauth_token + response = authenticated_request(params) + end + response + end + + def account + Fog::Brightbox::Compute::Account.new(JSON.parse(get_account.body)) + end + + private + def get_oauth_token(options = {}) + auth_url = options[:brightbox_auth_url] || @auth_url + + connection = Fog::Connection.new(auth_url) + @authentication_body = {'client_id' => @brightbox_client_id, 'grant_type' => 'none'}.to_json + + 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 = JSON.parse(response.body)["access_token"] + return @oauth_token + end + + def authenticated_request(options) + headers = options[:headers] || {} + headers.merge!("Authorization" => "OAuth #{@oauth_token}") + options[:headers] = headers + @connection.request(options) + end + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/models/compute/account.rb b/lib/fog/brightbox/models/compute/account.rb new file mode 100644 index 000000000..868dbd2a9 --- /dev/null +++ b/lib/fog/brightbox/models/compute/account.rb @@ -0,0 +1,52 @@ +require 'fog/core/model' + +module Fog + module Brightbox + class Compute + + class Account < Fog::Model + + identity :id + attribute :resource_type + attribute :url + attribute :name + attribute :status + attribute :address_1 + attribute :address_2 + attribute :city + attribute :county + attribute :postcode + attribute :country_code + attribute :country_name + attribute :vat_registration_number + attribute :telephone_number + attribute :telephone_verified + attribute :ram_limit + attribute :ram_used + attribute :limits_cloudips + attribute :library_ftp_host + attribute :library_ftp_user + # This is always returned as null/nil unless performing a reset_ftp_password request + attribute :library_ftp_password + attribute :created_at + + + + attribute :owner_id, :aliases => "owner", :squash => "id" + attribute :clients + attribute :images + attribute :servers + attribute :users + attribute :zones + + def reset_ftp_password + requires :identity + response = connection.reset_ftp_password_account(identity) + JSON.parse(response.body)["library_ftp_password"] + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/models/compute/cloud_ip.rb b/lib/fog/brightbox/models/compute/cloud_ip.rb new file mode 100644 index 000000000..e1b417481 --- /dev/null +++ b/lib/fog/brightbox/models/compute/cloud_ip.rb @@ -0,0 +1,43 @@ +require 'fog/core/model' + +module Fog + module Brightbox + class Compute + + class CloudIp < Fog::Model + + identity :id + + attribute :url + attribute :name + attribute :status + attribute :resource_type + attribute :description + + attribute :reverse_dns + attribute :public_ip + + attribute :account_id, :aliases => "account", :squash => "id" + attribute :interface_id, :aliases => "interface", :squash => "id" + attribute :server_id, :aliases => "server", :squash => "id" + + def map(interface_to_map) + requires :identity + connection.map_cloud_ip(identity, :interface => interface_to_map) + end + + def unmap + requires :identity + connection.unmap_cloud_ip(identity) + end + + def destroy + requires :identity + connection.destroy_cloud_ip(identity) + end + + end + + end + end +end diff --git a/lib/fog/brightbox/models/compute/cloud_ips.rb b/lib/fog/brightbox/models/compute/cloud_ips.rb new file mode 100644 index 000000000..c20a60387 --- /dev/null +++ b/lib/fog/brightbox/models/compute/cloud_ips.rb @@ -0,0 +1,34 @@ +require 'fog/core/collection' +require 'fog/brightbox/models/compute/cloud_ip' + +module Fog + module Brightbox + class Compute + + class CloudIps < Fog::Collection + + model Fog::Brightbox::Compute::CloudIp + + def all + data = JSON.parse(connection.list_cloud_ips.body) + load(data) + end + + def get(identifier) + return nil if identifier.nil? || identifier == "" + data = JSON.parse(connection.get_cloud_ip(identifier).body) + new(data) + rescue Excon::Errors::NotFound + nil + end + + def allocate + data = JSON.parse(connection.create_cloud_ip.body) + new(data) + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/models/compute/flavor.rb b/lib/fog/brightbox/models/compute/flavor.rb new file mode 100644 index 000000000..805b79b5b --- /dev/null +++ b/lib/fog/brightbox/models/compute/flavor.rb @@ -0,0 +1,33 @@ +require 'fog/core/model' + +module Fog + module Brightbox + class Compute + + class Flavor < Fog::Model + + identity :id + + attribute :url + attribute :name + attribute :status + + attribute :handle + + attribute :bits + attribute :cores + attribute :disk, :aliases => "disk_size" + attribute :ram + + attribute :resource_type + attribute :description + + def bits + 0 # This is actually based on the Image type used. 32bit or 64bit Images are supported + end + + end + + end + end +end diff --git a/lib/fog/brightbox/models/compute/flavors.rb b/lib/fog/brightbox/models/compute/flavors.rb new file mode 100644 index 000000000..bbab0165a --- /dev/null +++ b/lib/fog/brightbox/models/compute/flavors.rb @@ -0,0 +1,28 @@ +require 'fog/core/collection' +require 'fog/brightbox/models/compute/flavor' + +module Fog + module Brightbox + class Compute + + class Flavors < Fog::Collection + + model Fog::Brightbox::Compute::Flavor + + def all + data = connection.list_server_types.body + load(JSON.parse(data)) + end + + def get(identifier) + response = connection.get_server_type(identifier) + new(JSON.parse(response.body)) + rescue Excon::Errors::NotFound + nil + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/models/compute/image.rb b/lib/fog/brightbox/models/compute/image.rb new file mode 100644 index 000000000..f05a430c3 --- /dev/null +++ b/lib/fog/brightbox/models/compute/image.rb @@ -0,0 +1,53 @@ +require 'fog/core/model' + +module Fog + module Brightbox + class Compute + + class Image < Fog::Model + + identity :id + + attribute :url + attribute :name + attribute :status + attribute :source + attribute :source_type + + attribute :ancestor_id, :aliases => "ancestor", :squash => "id" + attribute :owner_id, :aliases => "owner", :squash => "id" + attribute :arch + + attribute :resource_type + attribute :description + attribute :public + attribute :official + attribute :virtual_size + attribute :disk_size + attribute :created_at + + def save + requires :source, :arch + options = { + :source => @source, + :arch => @arch, + :name => @name, + :description => @description + }.delete_if {|k,v| v.nil? || v == "" } + response = connection.create_image(options) + data = JSON.parse(response.body) + merge_attributes(data) + true + end + + def destroy + requires :identity + connection.destroy_image(identity) + true + end + + end + + end + end +end diff --git a/lib/fog/brightbox/models/compute/images.rb b/lib/fog/brightbox/models/compute/images.rb new file mode 100644 index 000000000..a8ce3c362 --- /dev/null +++ b/lib/fog/brightbox/models/compute/images.rb @@ -0,0 +1,28 @@ +require 'fog/core/collection' +require 'fog/brightbox/models/compute/image' + +module Fog + module Brightbox + class Compute + + class Images < Fog::Collection + + model Fog::Brightbox::Compute::Image + + def all + data = connection.list_images.body + load(JSON.parse(data)) + end + + def get(identifier) + response = connection.get_image(identifier) + new(JSON.parse(response.body)) + rescue Excon::Errors::NotFound + nil + end + + end + + end + end +end diff --git a/lib/fog/brightbox/models/compute/server.rb b/lib/fog/brightbox/models/compute/server.rb new file mode 100644 index 000000000..98d2bb288 --- /dev/null +++ b/lib/fog/brightbox/models/compute/server.rb @@ -0,0 +1,98 @@ +require 'fog/core/model' + +module Fog + module Brightbox + class Compute + + class Server < Fog::Model + + identity :id + + attribute :url + attribute :name + attribute :status + attribute :hostname + attribute :created_at, :type => :time + attribute :deleted_at, :type => :time + attribute :started_at, :type => :time + attribute :user_data + + attribute :resource_type + attribute :description + + attribute :account_id, :aliases => "account", :squash => "id" + attribute :image_id, :aliases => "image", :squash => "id" + attribute :flavor_id, :aliases => "server_type", :squash => "id" + attribute :zone_id, :aliases => "zone", :squash => "id" + + attribute :snapshots + attribute :cloud_ips + attribute :interfaces + + def snapshot + requires :identity + connection.snapshot_server(identity) + end + + def reboot(type = "soft") + requires :identity + connection.restart_server(identity, :type => type) + true + end + + def start + requires :identity + connection.start_server(identity) + true + end + + def stop + requires :identity + connection.stop_server(identity) + true + end + + def shutdown + requires :identity + connection.shutdown_server(identity) + true + end + + def destroy + requires :identity + connection.destroy_server(identity) + true + end + + def flavor + requires :flavor_id + connection.flavors.get(@flavor_id) + end + + def image + requires :image_id + connection.images.get(@image_id) + end + + def ready? + status == 'active' + end + + def save + requires :image_id + options = { + :image => @image_id, + :server_type => @flavor_id, + :name => @name, + :zone => @zone_id, + :user_data => @user_data + }.delete_if {|k,v| v.nil? || v == "" } + response = connection.create_server(options) + data = JSON.parse(response.body) + merge_attributes(data) + true + end + end + end + end +end diff --git a/lib/fog/brightbox/models/compute/servers.rb b/lib/fog/brightbox/models/compute/servers.rb new file mode 100644 index 000000000..9b99fb4a6 --- /dev/null +++ b/lib/fog/brightbox/models/compute/servers.rb @@ -0,0 +1,29 @@ +require 'fog/core/collection' +require 'fog/brightbox/models/compute/server' + +module Fog + module Brightbox + class Compute + + class Servers < Fog::Collection + + model Fog::Brightbox::Compute::Server + + def all + data = JSON.parse(connection.list_servers.body) + load(data) + end + + def get(identifier) + return nil if identifier.nil? || identifier == "" + data = JSON.parse(connection.get_server(identifier).body) + new(data) + rescue Excon::Errors::NotFound + nil + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/models/compute/user.rb b/lib/fog/brightbox/models/compute/user.rb new file mode 100644 index 000000000..fb49762f2 --- /dev/null +++ b/lib/fog/brightbox/models/compute/user.rb @@ -0,0 +1,40 @@ +require 'fog/core/model' + +module Fog + module Brightbox + class Compute + + class User < Fog::Model + + identity :id + + attribute :url + attribute :resource_type + attribute :name + attribute :email_address + attribute :email_verified + attribute :ssh_key + + attribute :account_id, :aliases => "default_account", :squash => "id" + attribute :accounts + + def save + requires :identity + + options = { + :email_address => @email_address, + :ssh_key => @ssh_key, + :name => @name + } + + response = connection.update_user(identity, options) + data = JSON.parse(response.body) + merge_attributes(data) + true + end + + end + + end + end +end diff --git a/lib/fog/brightbox/models/compute/users.rb b/lib/fog/brightbox/models/compute/users.rb new file mode 100644 index 000000000..28f352a75 --- /dev/null +++ b/lib/fog/brightbox/models/compute/users.rb @@ -0,0 +1,29 @@ +require 'fog/core/collection' +require 'fog/brightbox/models/compute/user' + +module Fog + module Brightbox + class Compute + + class Users < Fog::Collection + + model Fog::Brightbox::Compute::User + + def all + data = JSON.parse(connection.list_users.body) + load(data) + end + + def get(identifier) + return nil if identifier.nil? || identifier == "" + data = JSON.parse(connection.get_user(identifier).body) + new(data) + rescue Excon::Errors::NotFound + nil + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/models/compute/zone.rb b/lib/fog/brightbox/models/compute/zone.rb new file mode 100644 index 000000000..e04156163 --- /dev/null +++ b/lib/fog/brightbox/models/compute/zone.rb @@ -0,0 +1,21 @@ +require 'fog/core/model' + +module Fog + module Brightbox + class Compute + + class Zone < Fog::Model + + identity :id + + attribute :url + attribute :handle + attribute :status + attribute :resource_type + attribute :description + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/models/compute/zones.rb b/lib/fog/brightbox/models/compute/zones.rb new file mode 100644 index 000000000..3342469e8 --- /dev/null +++ b/lib/fog/brightbox/models/compute/zones.rb @@ -0,0 +1,29 @@ +require 'fog/core/collection' +require 'fog/brightbox/models/compute/zone' + +module Fog + module Brightbox + class Compute + + class Zones < Fog::Collection + + model Fog::Brightbox::Compute::Zone + + def all + data = JSON.parse(connection.list_zones.body) + load(data) + end + + def get(identifier) + return nil if identifier.nil? || identifier == "" + data = JSON.parse(connection.get_zone(identifier).body) + new(data) + rescue Excon::Errors::NotFound + nil + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/create_api_client.rb b/lib/fog/brightbox/requests/compute/create_api_client.rb new file mode 100644 index 000000000..70ca4e541 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/create_api_client.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def create_api_client(options = {}) + request( + :expects => [201], + :method => 'POST', + :path => "/1.0/api_clients", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def create_api_client(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/create_cloud_ip.rb b/lib/fog/brightbox/requests/compute/create_cloud_ip.rb new file mode 100644 index 000000000..e71f10575 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/create_cloud_ip.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def create_cloud_ip(options = {}) + request( + :expects => [201], + :method => 'POST', + :path => "/1.0/cloud_ips", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def create_cloud_ip(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/create_image.rb b/lib/fog/brightbox/requests/compute/create_image.rb new file mode 100644 index 000000000..d020b764e --- /dev/null +++ b/lib/fog/brightbox/requests/compute/create_image.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def create_image(options = {}) + request( + :expects => [201], + :method => 'POST', + :path => "/1.0/images", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def create_image(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/create_server.rb b/lib/fog/brightbox/requests/compute/create_server.rb new file mode 100644 index 000000000..fc70bc76f --- /dev/null +++ b/lib/fog/brightbox/requests/compute/create_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def create_server(options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/servers", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def create_server(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/destroy_api_client.rb b/lib/fog/brightbox/requests/compute/destroy_api_client.rb new file mode 100644 index 000000000..d2ca8a359 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/destroy_api_client.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def destroy_api_client(identifier, options = {}) + request( + :expects => [200], + :method => 'DELETE', + :path => "/1.0/api_clients/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def destroy_api_client(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/destroy_cloud_ip.rb b/lib/fog/brightbox/requests/compute/destroy_cloud_ip.rb new file mode 100644 index 000000000..38c8dbafb --- /dev/null +++ b/lib/fog/brightbox/requests/compute/destroy_cloud_ip.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def destroy_cloud_ip(identifier, options = {}) + request( + :expects => [200], + :method => 'DELETE', + :path => "/1.0/cloud_ips/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def destroy_cloud_ip(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/destroy_image.rb b/lib/fog/brightbox/requests/compute/destroy_image.rb new file mode 100644 index 000000000..2c48673da --- /dev/null +++ b/lib/fog/brightbox/requests/compute/destroy_image.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def destroy_image(identifier, options = {}) + request( + :expects => [202], + :method => 'DELETE', + :path => "/1.0/images/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def destroy_image(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/destroy_server.rb b/lib/fog/brightbox/requests/compute/destroy_server.rb new file mode 100644 index 000000000..083f7b4f5 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/destroy_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def destroy_server(identifier, options = {}) + request( + :expects => [202], + :method => 'DELETE', + :path => "/1.0/servers/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def destroy_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_account.rb b/lib/fog/brightbox/requests/compute/get_account.rb new file mode 100644 index 000000000..0d21a240e --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_account.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_account(options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/account", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_account(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_api_client.rb b/lib/fog/brightbox/requests/compute/get_api_client.rb new file mode 100644 index 000000000..fd3cd0a31 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_api_client.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_api_client(identifier, options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/api_clients/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_api_client(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_cloud_ip.rb b/lib/fog/brightbox/requests/compute/get_cloud_ip.rb new file mode 100644 index 000000000..a36839629 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_cloud_ip.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_cloud_ip(identifier, options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/cloud_ips/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_cloud_ip(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_image.rb b/lib/fog/brightbox/requests/compute/get_image.rb new file mode 100644 index 000000000..31d67ab7a --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_image.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_image(identifier, options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/images/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_image(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_interface.rb b/lib/fog/brightbox/requests/compute/get_interface.rb new file mode 100644 index 000000000..b6774bdd9 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_interface.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_interface(identifier, options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/interfaces/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_interface(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_server.rb b/lib/fog/brightbox/requests/compute/get_server.rb new file mode 100644 index 000000000..0c07f1044 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_server(identifier, options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/servers/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_server_type.rb b/lib/fog/brightbox/requests/compute/get_server_type.rb new file mode 100644 index 000000000..bb3926268 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_server_type.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_server_type(identifier, options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/server_types/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_server_type(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_user.rb b/lib/fog/brightbox/requests/compute/get_user.rb new file mode 100644 index 000000000..2703696b4 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_user.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_user(identifier, options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/users/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_user(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/get_zone.rb b/lib/fog/brightbox/requests/compute/get_zone.rb new file mode 100644 index 000000000..ad15416b3 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/get_zone.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def get_zone(identifier, options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/zones/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def get_zone(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/list_api_clients.rb b/lib/fog/brightbox/requests/compute/list_api_clients.rb new file mode 100644 index 000000000..c7bf4f730 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/list_api_clients.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def list_api_clients(options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/api_clients", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def list_api_clients(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/list_cloud_ips.rb b/lib/fog/brightbox/requests/compute/list_cloud_ips.rb new file mode 100644 index 000000000..e2a83889d --- /dev/null +++ b/lib/fog/brightbox/requests/compute/list_cloud_ips.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def list_cloud_ips(options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/cloud_ips", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def list_cloud_ips(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/list_images.rb b/lib/fog/brightbox/requests/compute/list_images.rb new file mode 100644 index 000000000..900d0583d --- /dev/null +++ b/lib/fog/brightbox/requests/compute/list_images.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def list_images(options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/images", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def list_images(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/list_server_types.rb b/lib/fog/brightbox/requests/compute/list_server_types.rb new file mode 100644 index 000000000..728c797d5 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/list_server_types.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def list_server_types(options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/server_types", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def list_server_types(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/list_servers.rb b/lib/fog/brightbox/requests/compute/list_servers.rb new file mode 100644 index 000000000..1806b5d69 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/list_servers.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def list_servers(options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/servers", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def list_servers(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/list_users.rb b/lib/fog/brightbox/requests/compute/list_users.rb new file mode 100644 index 000000000..bcd933c4b --- /dev/null +++ b/lib/fog/brightbox/requests/compute/list_users.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def list_users(options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/users", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def list_users(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/list_zones.rb b/lib/fog/brightbox/requests/compute/list_zones.rb new file mode 100644 index 000000000..a9e873877 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/list_zones.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def list_zones(options = {}) + request( + :expects => [200], + :method => 'GET', + :path => "/1.0/zones", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def list_zones(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/map_cloud_ip.rb b/lib/fog/brightbox/requests/compute/map_cloud_ip.rb new file mode 100644 index 000000000..6b5440e05 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/map_cloud_ip.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def map_cloud_ip(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/cloud_ips/#{identifier}/map", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def map_cloud_ip(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/rebuild_server.rb b/lib/fog/brightbox/requests/compute/rebuild_server.rb new file mode 100644 index 000000000..52d0fd5da --- /dev/null +++ b/lib/fog/brightbox/requests/compute/rebuild_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def rebuild_server(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/servers/#{identifier}/rebuild", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def rebuild_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/reset_ftp_password_account.rb b/lib/fog/brightbox/requests/compute/reset_ftp_password_account.rb new file mode 100644 index 000000000..007abcfc3 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/reset_ftp_password_account.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def reset_ftp_password_account(options = {}) + request( + :expects => [200], + :method => 'POST', + :path => "/1.0/account/reset_ftp_password", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def reset_ftp_password_account(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/resize_server.rb b/lib/fog/brightbox/requests/compute/resize_server.rb new file mode 100644 index 000000000..b22f36a42 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/resize_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def resize_server(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/servers/#{identifier}/resize", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def resize_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/restart_server.rb b/lib/fog/brightbox/requests/compute/restart_server.rb new file mode 100644 index 000000000..9010f1401 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/restart_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def restart_server(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/servers/#{identifier}/restart", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def restart_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/shutdown_server.rb b/lib/fog/brightbox/requests/compute/shutdown_server.rb new file mode 100644 index 000000000..082be4439 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/shutdown_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def shutdown_server(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/servers/#{identifier}/shutdown", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def shutdown_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/snapshot_server.rb b/lib/fog/brightbox/requests/compute/snapshot_server.rb new file mode 100644 index 000000000..d3fbbcbd4 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/snapshot_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def snapshot_server(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/servers/#{identifier}/snapshot", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def snapshot_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/start_server.rb b/lib/fog/brightbox/requests/compute/start_server.rb new file mode 100644 index 000000000..e39bb4653 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/start_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def start_server(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/servers/#{identifier}/start", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def start_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/stop_server.rb b/lib/fog/brightbox/requests/compute/stop_server.rb new file mode 100644 index 000000000..8a2c19d39 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/stop_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def stop_server(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/servers/#{identifier}/stop", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def stop_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/unmap_cloud_ip.rb b/lib/fog/brightbox/requests/compute/unmap_cloud_ip.rb new file mode 100644 index 000000000..c9e6dc85b --- /dev/null +++ b/lib/fog/brightbox/requests/compute/unmap_cloud_ip.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def unmap_cloud_ip(identifier, options = {}) + request( + :expects => [202], + :method => 'POST', + :path => "/1.0/cloud_ips/#{identifier}/unmap", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def unmap_cloud_ip(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/update_account.rb b/lib/fog/brightbox/requests/compute/update_account.rb new file mode 100644 index 000000000..24c5fc673 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/update_account.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def update_account(options = {}) + request( + :expects => [200], + :method => 'PUT', + :path => "/1.0/account", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def update_account(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/update_api_client.rb b/lib/fog/brightbox/requests/compute/update_api_client.rb new file mode 100644 index 000000000..1f198323d --- /dev/null +++ b/lib/fog/brightbox/requests/compute/update_api_client.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def update_api_client(identifier, options = {}) + request( + :expects => [200], + :method => 'PUT', + :path => "/1.0/api_clients/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def update_api_client(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/update_image.rb b/lib/fog/brightbox/requests/compute/update_image.rb new file mode 100644 index 000000000..f86e69808 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/update_image.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def update_image(identifier, options = {}) + request( + :expects => [200], + :method => 'PUT', + :path => "/1.0/images/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def update_image(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/update_server.rb b/lib/fog/brightbox/requests/compute/update_server.rb new file mode 100644 index 000000000..45a13adeb --- /dev/null +++ b/lib/fog/brightbox/requests/compute/update_server.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def update_server(identifier, options = {}) + request( + :expects => [200], + :method => 'PUT', + :path => "/1.0/servers/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def update_server(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/brightbox/requests/compute/update_user.rb b/lib/fog/brightbox/requests/compute/update_user.rb new file mode 100644 index 000000000..5c75b2e88 --- /dev/null +++ b/lib/fog/brightbox/requests/compute/update_user.rb @@ -0,0 +1,27 @@ +module Fog + module Brightbox + class Compute + class Real + + def update_user(identifier, options = {}) + request( + :expects => [200], + :method => 'PUT', + :path => "/1.0/users/#{identifier}", + :headers => {"Content-Type" => "application/json"}, + :body => options.to_json + ) + end + + end + + class Mock + + def update_user(identifier, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/core/bin.rb b/lib/fog/core/bin.rb index 4dd77bdd2..efcec9862 100644 --- a/lib/fog/core/bin.rb +++ b/lib/fog/core/bin.rb @@ -7,6 +7,7 @@ module Fog [ ::AWS, ::Bluebox, + ::Brightbox, ::GoGrid, ::Google, ::Linode, @@ -68,6 +69,7 @@ end require 'fog/aws/bin' require 'fog/bluebox/bin' +require 'fog/brightbox/bin' require 'fog/go_grid/bin' require 'fog/google/bin' require 'fog/linode/bin' diff --git a/lib/fog/core/compute.rb b/lib/fog/core/compute.rb index 9034c702f..e6aefff65 100644 --- a/lib/fog/core/compute.rb +++ b/lib/fog/core/compute.rb @@ -9,6 +9,9 @@ module Fog when 'Bluebox' require 'fog/bluebox' Fog::Bluebox::Compute.new(attributes) + when 'Brightbox' + require 'fog/brightbox' + Fog::Brightbox::Compute.new(attributes) when 'GoGrid' require 'fog/go_grid' Fog::GoGrid::Compute.new(attributes) diff --git a/lib/fog/core/credentials.rb b/lib/fog/core/credentials.rb index 214384a35..cc4d75917 100644 --- a/lib/fog/core/credentials.rb +++ b/lib/fog/core/credentials.rb @@ -34,6 +34,8 @@ module Fog :aws_secret_access_key: INTENTIONALLY_LEFT_BLANK :bluebox_api_key: INTENTIONALLY_LEFT_BLANK :bluebox_customer_id: INTENTIONALLY_LEFT_BLANK + :brightbox_client_id: INTENTIONALLY_LEFT_BLANK + :brightbox_secret: INTENTIONALLY_LEFT_BLANK :go_grid_api_key: INTENTIONALLY_LEFT_BLANK :go_grid_shared_secret: INTENTIONALLY_LEFT_BLANK :local_root: INTENTIONALLY_LEFT_BLANK diff --git a/spec/brightbox/models/flavors_spec.rb b/spec/brightbox/models/flavors_spec.rb new file mode 100644 index 000000000..f81344aae --- /dev/null +++ b/spec/brightbox/models/flavors_spec.rb @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require File.dirname(__FILE__) + '/../../shared_examples/flavors_examples' + +describe 'Fog::Brightbox::Compute::Flavors' do + + if Fog.mocking? + it "needs to have mocks implemented" + else + it_should_behave_like "Flavors" + end + + subject { @flavor = @flavors.all.first } + + before(:each) do + @flavors = Brightbox[:compute].flavors + end + +end diff --git a/spec/brightbox/models/server_spec.rb b/spec/brightbox/models/server_spec.rb new file mode 100644 index 000000000..a81f4b7f9 --- /dev/null +++ b/spec/brightbox/models/server_spec.rb @@ -0,0 +1,28 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require File.dirname(__FILE__) + '/../../shared_examples/server_examples' + +describe 'Fog::Brightbox::Compute::Server' do + + if Fog.mocking? + it "needs to have mocks implemented" + else + it_should_behave_like "Server" + end + + subject { + @image_id = "img-9vxqi" # Ubuntu Maverick 10.10 server + @server = @servers.new(:image_id => @image_id) + } + + before(:each) do + @servers = Brightbox[:compute].servers + end + + after(:each) do + if @server && !@server.new_record? + @server.wait_for { ready? } + @server.destroy.should be_true + end + end + +end diff --git a/spec/brightbox/models/servers_spec.rb b/spec/brightbox/models/servers_spec.rb new file mode 100644 index 000000000..8d71cedd6 --- /dev/null +++ b/spec/brightbox/models/servers_spec.rb @@ -0,0 +1,29 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require File.dirname(__FILE__) + '/../../shared_examples/servers_examples' + +describe 'Fog::Brightbox::Compute::Servers' do + + if Fog.mocking? + it "needs to have mocks implemented" + else + it_should_behave_like "Servers" + end + + subject { + @image_id = "img-9vxqi" # Ubuntu Maverick 10.10 server + @server = @servers.new(:image_id => @image_id) + @server + } + + before(:each) do + @servers = Brightbox[:compute].servers + end + + after(:each) do + if @server && !@server.new_record? + @server.wait_for { ready? } + @server.destroy.should be_true + end + end + +end \ No newline at end of file