mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|monitoring] updating to use fog conventions
This commit is contained in:
parent
ff5a5bbabd
commit
b359376da0
10 changed files with 52 additions and 81 deletions
|
@ -11,21 +11,19 @@ module Fog
|
|||
attribute :label
|
||||
attribute :token
|
||||
|
||||
def prep
|
||||
def params
|
||||
options = {
|
||||
'label' => label,
|
||||
'token' => token
|
||||
}
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
options
|
||||
options.reject {|key, value| value.nil?}
|
||||
end
|
||||
|
||||
def save
|
||||
options = prep
|
||||
if identity then
|
||||
data = service.update_agent_token(identity, options)
|
||||
if identity
|
||||
raise NotImplementedError.new "Updating Agent Tokens is not currently implemented"
|
||||
else
|
||||
data = service.create_agent_token(options)
|
||||
data = service.create_agent_token(params)
|
||||
end
|
||||
true
|
||||
end
|
||||
|
|
|
@ -8,16 +8,11 @@ module Fog
|
|||
|
||||
model Fog::Rackspace::Monitoring::AgentToken
|
||||
|
||||
def all
|
||||
data = []
|
||||
opts = {}
|
||||
begin
|
||||
new_tokens = service.list_agent_tokens(opts)
|
||||
data.concat(new_tokens.body['values'])
|
||||
opts = {:marker => new_tokens.body['metadata']['next_marker']}
|
||||
end until opts[:marker].nil?
|
||||
def all(options={})
|
||||
clear
|
||||
body = service.list_agent_tokens(options).body
|
||||
|
||||
load(data)
|
||||
load(body['values'])
|
||||
end
|
||||
|
||||
def get(id)
|
||||
|
|
|
@ -16,24 +16,22 @@ module Fog
|
|||
attribute :check_id
|
||||
attribute :notification_plan_id
|
||||
|
||||
def prep
|
||||
options = {
|
||||
def params(options={})
|
||||
h = {
|
||||
'label' => label,
|
||||
'criteria' => criteria,
|
||||
'notification_plan_id' => notification_plan_id,
|
||||
}
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
options
|
||||
}.merge(options)
|
||||
h.reject {|key, value| value.nil?}
|
||||
end
|
||||
|
||||
def save
|
||||
requires :notification_plan_id
|
||||
options = prep
|
||||
if identity then
|
||||
data = service.update_alarm(get_entity_id, identity, options)
|
||||
|
||||
if identity
|
||||
data = service.update_alarm(get_entity_id, identity, params)
|
||||
else
|
||||
options['check_type'] = check_type if check_type
|
||||
options['check_id'] = check_id if check_id
|
||||
options = params('check_type' => check_type, 'check_id' => check_id)
|
||||
data = service.create_alarm(get_entity_id, options)
|
||||
end
|
||||
true
|
||||
|
|
|
@ -25,15 +25,9 @@ module Fog
|
|||
remain.empty?
|
||||
end
|
||||
|
||||
def get_entity_id
|
||||
requires :entity
|
||||
begin
|
||||
requires :entity
|
||||
entity_id = entity.identity
|
||||
rescue
|
||||
requires :entity_id
|
||||
end
|
||||
entity_id
|
||||
def entity_id
|
||||
raise(ArgumentError, "entity with id is required for this operation") unless entity && entity.identity
|
||||
entity.identity
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -22,8 +22,8 @@ module Fog
|
|||
attribute :disabled
|
||||
attribute :monitoring_zones_poll
|
||||
|
||||
def prep
|
||||
options = {
|
||||
def params(options={})
|
||||
h = {
|
||||
'label' => label,
|
||||
'metadata' => metadata,
|
||||
'target_alias'=> target_alias,
|
||||
|
@ -34,24 +34,17 @@ module Fog
|
|||
'details'=> details,
|
||||
'monitoring_zones_poll'=> monitoring_zones_poll,
|
||||
'disabled'=> disabled
|
||||
}
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
options
|
||||
}.merge(options)
|
||||
|
||||
h.reject {|key, value| value.nil?}
|
||||
end
|
||||
|
||||
def save
|
||||
begin
|
||||
requires :entity
|
||||
entity_id = entity.identity
|
||||
rescue
|
||||
requires :entity_id
|
||||
end
|
||||
options = prep
|
||||
if identity then
|
||||
data = service.update_check(entity_id, identity, options)
|
||||
if identity
|
||||
data = service.update_check(entity_id, identity, params)
|
||||
else
|
||||
requires :type
|
||||
options['type'] = type
|
||||
options = params('type' => type)
|
||||
data = service.create_check(entity_id, options)
|
||||
end
|
||||
true
|
||||
|
|
|
@ -9,9 +9,13 @@ module Fog
|
|||
|
||||
model Fog::Rackspace::Monitoring::Entity
|
||||
|
||||
def all
|
||||
data = service.list_entities.body['values']
|
||||
load(data)
|
||||
attribute :marker
|
||||
|
||||
def all(options={})
|
||||
data = service.list_entities(options).body
|
||||
marker = data['metadata']['next_marker']
|
||||
|
||||
load(data['values'])
|
||||
end
|
||||
|
||||
def get(entity_id)
|
||||
|
@ -21,18 +25,14 @@ module Fog
|
|||
nil
|
||||
end
|
||||
|
||||
def overview
|
||||
entities = []
|
||||
opts = {}
|
||||
begin
|
||||
new_entities = service.list_overview(opts)
|
||||
entities.concat(new_entities.body['values'])
|
||||
opts = {:marker => new_entities.body['metadata']['next_marker']}
|
||||
end while(!opts[:marker].nil?)
|
||||
loadAll(entities)
|
||||
def overview(options={})
|
||||
body = service.list_overview(options).body
|
||||
marker = body['metadata']['next_marker']
|
||||
|
||||
load_all(body['values'])
|
||||
end
|
||||
|
||||
def loadAll(objects)
|
||||
def load_all(objects)
|
||||
clear
|
||||
for object in objects
|
||||
en = new(object['entity'])
|
||||
|
|
|
@ -15,23 +15,21 @@ module Fog
|
|||
attribute :managed, :default => false
|
||||
attribute :uri
|
||||
|
||||
def prep
|
||||
def params
|
||||
options = {
|
||||
'label' => label,
|
||||
'metadata' => metadata,
|
||||
'ip_addresses'=> ip_addresses,
|
||||
'agent_id' => agent_id
|
||||
}
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
options
|
||||
options.reject {|key, value| value.nil?}
|
||||
end
|
||||
|
||||
def save
|
||||
options = prep
|
||||
if identity then
|
||||
data = service.update_entity(identity, options)
|
||||
if identity
|
||||
data = service.update_entity(identity, params)
|
||||
else
|
||||
data = service.create_entity(options)
|
||||
data = service.create_entity(params)
|
||||
end
|
||||
true
|
||||
end
|
||||
|
|
|
@ -3,11 +3,12 @@ module Fog
|
|||
class Monitoring
|
||||
class Real
|
||||
|
||||
def list_entities
|
||||
def list_entities(options={})
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => 'entities'
|
||||
:path => 'entities',
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -3,15 +3,12 @@ module Fog
|
|||
class Monitoring
|
||||
class Real
|
||||
|
||||
def list_overview(opts={})
|
||||
path = "views/overview"
|
||||
opts.keys.each do |key|
|
||||
path = path + "?#{key}=#{opts[key]}"
|
||||
end
|
||||
def list_overview(options={})
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => path
|
||||
:path => "views/overview",
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -38,9 +38,6 @@ Shindo.tests('Fog::Rackspace::Monitoring | list_tests', ['rackspace','rackspace_
|
|||
#tests('#fail to list metrics').raises(Fog::Rackspace::Monitoring::NotFound) do
|
||||
#account.list_metrics(-1,-1)
|
||||
#end
|
||||
tests('#fail to list overview').raises(NoMethodError) do
|
||||
account.list_overview(-1)
|
||||
end
|
||||
tests('#fail: 1 argument instead of 0 for list_notification_plans').raises(ArgumentError) do
|
||||
account.list_notification_plans('fail')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue