diff --git a/lib/fog/bin/rackspace.rb b/lib/fog/bin/rackspace.rb index 68f85ddce..73a34d783 100644 --- a/lib/fog/bin/rackspace.rb +++ b/lib/fog/bin/rackspace.rb @@ -21,6 +21,8 @@ class Rackspace < Fog::Bin Fog::Rackspace::Identity when :databases Fog::Rackspace::Databases + when :monitoring + Fog::Rackspace::Monitoring else raise ArgumentError, "Unrecognized service: #{key}" end @@ -52,6 +54,8 @@ class Rackspace < Fog::Bin Fog::Rackspace::Databases.new when :block_storage Fog::Rackspace::BlockStorage.new + when :monitoring + Fog::Rackspace::Monitoring.new else raise ArgumentError, "Unrecognized service: #{key.inspect}" end diff --git a/lib/fog/rackspace.rb b/lib/fog/rackspace.rb index 7c996369d..74b527fcb 100644 --- a/lib/fog/rackspace.rb +++ b/lib/fog/rackspace.rb @@ -71,6 +71,7 @@ module Fog service(:load_balancers, 'rackspace/load_balancers', 'LoadBalancers') service(:identity, 'rackspace/identity', 'Identity') service(:databases, 'rackspace/databases', 'Databases') + service(:monitoring, 'rackspace/monitoring', 'Monitoring') def self.authenticate(options, connection_options = {}) rackspace_auth_url = options[:rackspace_auth_url] diff --git a/lib/fog/rackspace/monitoring.rb b/lib/fog/rackspace/monitoring.rb index 78c8f9762..7156f9d38 100644 --- a/lib/fog/rackspace/monitoring.rb +++ b/lib/fog/rackspace/monitoring.rb @@ -4,6 +4,12 @@ require 'fog/core' module Fog module Rackspace class Monitoring < Fog::Service + include Fog::Rackspace::Errors + + class IdentifierTaken < Fog::Errors::Error; end + class ServiceError < Fog::Rackspace::Errors::ServiceError; end + class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end + class BadRequest < Fog::Rackspace::Errors::BadRequest; end ENDPOINT = 'https://monitoring.api.rackspacecloud.com/v1.0' @@ -11,7 +17,7 @@ module Fog recognizes :rackspace_auth_url, :persistent, :raise_errors recognizes :rackspace_auth_token, :rackspace_service_url, :rackspace_account_id - model_path 'fog/rackspace/models/monitoring/models' + model_path 'fog/rackspace/models/monitoring' model :entity collection :entities model :check @@ -29,7 +35,7 @@ module Fog model :check_type collection :check_types - request_path 'fog/rackspace/models/monitoring/requests' + request_path 'fog/rackspace/requests/monitoring' request :list_agent_tokens request :list_alarms request :list_alarm_examples @@ -61,11 +67,13 @@ module Fog request :evaluate_alarm_example - class Mock - + class Mock < Fog::Rackspace::Service + def request(params) + Fog::Mock.not_implemented + end end - class Real + class Real < Fog::Rackspace::Service def initialize(options={}) @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] diff --git a/tests/rackspace/requests/monitoring/entity_tests.rb b/tests/rackspace/requests/monitoring/entity_tests.rb new file mode 100644 index 000000000..076cabdb9 --- /dev/null +++ b/tests/rackspace/requests/monitoring/entity_tests.rb @@ -0,0 +1,45 @@ +Shindo.tests('Fog::Rackspace::Monitoring | entity_tests', ['rackspace','rackspacemonitoring']) do + + pending if Fog.mocking? + require 'pp' + account = Fog::Rackspace::Monitoring.new + entity_id = nil + tests('success') do + tests('#create new entity').formats(DATA_FORMAT) do + response = account.create_entity(:label => "Foo").data + entity_id = response[:headers]["X-Object-ID"] + response[:status] == 201 ? response : false + end + tests('#update entity').formats(DATA_FORMAT) do + options = { :testing => "Bar"} + response = account.update_entity(entity_id,options).data + response[:status] == 204 ? response : false + end + tests('#delete entity').formats(DELETE_DATA_FORMAT) do + response = account.delete_entity(entity_id).data + response[:status] == 204 ? response : false + end + end +end +__END__ + tests('failure') do + tests('#create new entity(-1)').raises(Fog::Rackspace::Monitoring::BadRequest) do + response = account.create_entity(:label => "").data + puts "I made it this far" + pp response + puts "All done now" + end + tests('#update entity(-1)').raises(Fog::Rackspace::Monitoring::Notfound) do + entity_id = account.create_entity(:label => "Foo").data[:headers]["X-Object-ID"] #setup + options = { :testing => "Bar" } + response = account.update_entity(entity_id,options) + puts "" + pp response + account.delete_entity(entity_id) #cleanup + response + end + tests('#delete entity(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do + account.delete_entity(-1) + end + end +end diff --git a/tests/rackspace/requests/monitoring/helper.rb b/tests/rackspace/requests/monitoring/helper.rb new file mode 100644 index 000000000..2fd7a3789 --- /dev/null +++ b/tests/rackspace/requests/monitoring/helper.rb @@ -0,0 +1,27 @@ +DELETE_HEADERS_FORMAT = { + 'X-LB' => String, + 'X-Response-Id' => String, + 'X-RateLimit-Remaining' => String, + 'X-RateLimit-Window' => String, + 'X-RateLimit-Type' => String, + 'Content-Type' => String, + 'Date' => String, + 'X-RateLimit-Limit' => String, + 'Content-Length' => String +} +HEADERS_FORMAT = DELETE_HEADERS_FORMAT.merge({ + 'X-Object-ID' => String, + 'Location' => String, +}) +DATA_FORMAT = { + :status => Integer, + :body => String, + :headers => HEADERS_FORMAT, + :remote_ip => String +} +DELETE_DATA_FORMAT = { + :status => Integer, + :body => String, + :headers => DELETE_HEADERS_FORMAT, + :remote_ip => String +}