Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify events #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/dynect_rest/gslb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def initialize(init_hash={})

@region_code = init_hash[:region_code] || 'global'
@monitor = init_hash[:monitor] || {}
@notify_events = init_hash[:notify_events] || {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syskill this has to be a hash? looking at the usage, an array will work as well

@serve_count = init_hash[:serve_count] || 1
@min_healthy = init_hash[:min_healthy] || 1
end
Expand Down Expand Up @@ -74,6 +75,11 @@ def monitor(value=nil)
value ? (@monitor = value; self) : @monitor
end

def notify_events(value=nil)
# :ip => true, :svc => true, :nosrv => true
value ? (@notify_events = value; self) : @notify_events
end

def add_host(value)
# :address => 'x.x.x.x', :label => 'friendly-name', :weight => 10, :serve_mode => 'obey'
@host_list[value[:address]] = value
Expand Down Expand Up @@ -108,6 +114,10 @@ def get(fqdn=nil, region_code='global')
:serve_mode => h["serve_mode"]
}
end

notify_events = {}
results["notify_events"].split(/,/).each {|s| notify_events[s] = true}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syskill do we need a regex for split? split(',') should do right?


DynectRest::GSLB.new(:dynect => @dynect,
:zone => results["zone"],
:fqdn => results["fqdn"],
Expand All @@ -116,6 +126,7 @@ def get(fqdn=nil, region_code='global')
:contact_nick => results["contact_nickname"],
:region_code => region["region_code"],
:monitor => results["monitor"],
:notify_events => notify_events,
:serve_count => region["serve_count"],
:min_healthy => region["min_healthy"]
)
Expand Down Expand Up @@ -157,6 +168,7 @@ def to_json
{
"ttl" => @ttl,
"monitor" => @monitor.sort,
"notify_events" => @notify_events.reject {|k,v| !v}.keys.join(','),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syskill Array#compact removes nil values, if thats what you want

"region" => {
"region_code" => @region_code,
"serve_count" => @serve_count,
Expand Down
33 changes: 30 additions & 3 deletions spec/dynect_rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,36 @@
expect(dynect.ds.resource_path).to eq('DSRecord/zone')
end

describe "gslb" do
subject { dynect.gslb }
its(:resource_path) { should == 'GSLB/zone' }
describe "GSLB" do

let(:gslb) do
dynect.gslb.
add_host(:address => '1.1.1.1', :label => 'one', :weight => 1, :serve_mode => 'obey').
monitor(:protocol => 'HTTPS', :path => '/_test.gif', :interval => 1, :retries => 3).
notify_events(:ip => true, :nosrv => false)
end

it "Resource Path" do
expect(gslb.resource_path).to eq('GSLB/zone')
end

describe "Host List" do
subject { gslb.host_list }
its(['1.1.1.1']) { should satisfy { |h| h[:label] == 'one' } }
it { should_not include('1.1.2.2') }
end

it "Monitoring" do
expect(gslb.monitor[:protocol]).to eq('HTTPS')
end

describe "Notify Events" do
subject { JSON.parse(gslb.to_json)['notify_events'] }
it { should match(/\bip\b/) }
it { should_not match(/\bsvc\b/) }
it { should_not match(/\bnosrv\b/) }
end

end

describe "key" do
Expand Down