vagrant-powerdns 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a84f73045d0de48fadf6269e73e9bacf6cc4bc85
4
- data.tar.gz: f70af2316504e9829acd92d6cc4c6276e451a9f3
3
+ metadata.gz: cc8b1b7a3bec8ad99768ddd3b9a121c4c8e11d3f
4
+ data.tar.gz: 41e9ba6a0ef85ba5868e9004f88c4dc00ac24c25
5
5
  SHA512:
6
- metadata.gz: c2b3d2219acb1bc69d9ea58e13a1362e31882f726e67357360853eaa3ee4bbda0d174d281a670c4114afc363c563c00d30bd8275a7ac0ffe420cf1f55fd6272b
7
- data.tar.gz: 164724893991e6ef290a125a8a15e3f86e18c1b69b38045f8ba92f95ed63abb2f8c55941f88e3ddfdcf5cfd3795fc78c4e79d82dedbeea99747ff470793f89fd
6
+ metadata.gz: 78c6d01a68e63df6c00c1edb0b1b16705fd158fd923cc6176bdbaf5e5e34724f0e0c0479743b8454073bd48a1cc9cd90531abbd5fe994626bae009fc3ac91357
7
+ data.tar.gz: a61c70169d0ab2a0e2c3588fa8f62bac74597b520cdc0b2e1386b5fc285e34a58825e0f0fe6fffd8d0dcb1905cebc9060549d27858ceb71029ea6718e1f1b366
@@ -5,18 +5,19 @@ module Vagrant
5
5
  def initialize(app, env)
6
6
  @app = app
7
7
  @machine = env[:machine]
8
- @zone = env[:machine].config.powerdns.default_zone
9
- @host = env[:machine].config.vm.hostname.nil? ?
10
- env[:machine].name.to_s : env[:machine].config.vm.hostname.to_s
11
- @domain = @host.include?(@zone.name)? @host : @host + @zone.dotted
12
-
13
- # Identify who i am
14
- @myuser = Etc.getlogin.gsub(/\s+/, '')
15
- @myhost = Socket.gethostname
16
8
  end
17
9
 
18
10
  def call(env)
19
11
  if @machine.config.powerdns.enabled?
12
+ @zone = env[:machine].config.powerdns.default_zone
13
+ @host = env[:machine].config.vm.hostname.nil? ?
14
+ env[:machine].name.to_s : env[:machine].config.vm.hostname.to_s
15
+ @domain = @host.include?(@zone.name)? @host : @host + @zone.dotted
16
+
17
+ # Identify who i am
18
+ @myuser = Etc.getlogin.gsub(/\s+/, '')
19
+ @myhost = Socket.gethostname
20
+
20
21
  # assume default gateway address
21
22
  @machine.communicate.sudo "ip route get to 8.8.8.8 | head -n 1" do |type,data|
22
23
  stdout = data.chomp if type == :stdout
@@ -27,10 +28,14 @@ module Vagrant
27
28
 
28
29
  p = PdnsRestApiClient.new(env[:machine].config.powerdns.api_url,
29
30
  env[:machine].config.powerdns.api_key)
30
-
31
- # Only update if IP changed or inactive
32
- record_not_found = p.zone(zone)["records"].select {|v| v["type"] == "A" and v["name"] == @domain and v["content"] == ip}.empty?
33
- record_disabled = p.zone(zone)["records"].select { |v| v["type"] == "A" and v["name"] == @domain and v["disable"]}.empty?
31
+ begin
32
+ # Only update if IP changed or inactive
33
+ record_not_found = p.zone(zone)["records"].select {|v| v["type"] == "A" and v["name"] == @domain and v["content"] == ip}.empty?
34
+ record_disabled = p.zone(zone)["records"].select { |v| v["type"] == "A" and v["name"] == @domain and v["disable"]}.empty?
35
+ rescue
36
+ env[:ui].info "PowerDNS: Error while calling PowernDNS API. Skip DNS action..."
37
+ return
38
+ end
34
39
 
35
40
  if record_not_found or record_disabled
36
41
  env[:ui].info "PowerDNS action..."
@@ -79,26 +84,30 @@ module Vagrant
79
84
  def initialize(app, env)
80
85
  @app = app
81
86
  @machine = env[:machine]
82
- @zone = env[:machine].config.powerdns.default_zone
83
- @host = env[:machine].config.vm.hostname.nil? ?
84
- env[:machine].name.to_s : env[:machine].config.vm.hostname.to_s
85
- @domain = @host.include?(@zone.name)? @host : @host + @zone.dotted
86
-
87
- # Identify who i am
88
- @myuser = Etc.getlogin.gsub(/\s+/, '')
89
- @myhost = Socket.gethostname
90
87
  end
91
88
 
92
89
  def call(env)
93
90
  if @machine.config.powerdns.enabled?
91
+ @zone = env[:machine].config.powerdns.default_zone
92
+ @host = env[:machine].config.vm.hostname.nil? ?
93
+ env[:machine].name.to_s : env[:machine].config.vm.hostname.to_s
94
+ @domain = @host.include?(@zone.name)? @host : @host + @zone.dotted
95
+
96
+ # Identify who i am
97
+ @myuser = Etc.getlogin.gsub(/\s+/, '')
98
+ @myhost = Socket.gethostname
94
99
  p = PdnsRestApiClient.new(env[:machine].config.powerdns.api_url,
95
100
  env[:machine].config.powerdns.api_key)
96
101
 
97
102
  zone = @zone.name
98
- # Get A record
99
- record = p.zone(zone)["records"].find {|v| v["name"] == @domain}
100
- # Get comments for this domain
101
- comments = p.zone(zone)["comments"].select {|v| v["name"] == @domain}
103
+ begin
104
+ record = p.zone(zone)["records"].find {|v| v["name"] == @domain}
105
+ # Get comments for this domain
106
+ comments = p.zone(zone)["comments"].select {|v| v["name"] == @domain}
107
+ rescue
108
+ env[:ui].info "PowerDNS: Error while calling PowernDNS API. Skip DNS action..."
109
+ return
110
+ end # Get A record
102
111
 
103
112
  # only disable if active
104
113
  if !record.nil? and not record["disabled"]
@@ -15,9 +15,11 @@ module Vagrant
15
15
  end
16
16
 
17
17
  def finalize!
18
-
19
18
  if @default_zone == UNSET_VALUE
20
19
  @default_zone = nil
20
+ elsif @default_zone.nil?
21
+ # Completely disable if no default zone
22
+ @disable = true
21
23
  elsif !@default_zone.is_a?(Zone)
22
24
  @default_zone = Zone.new @default_zone;
23
25
  end
@@ -29,7 +31,7 @@ module Vagrant
29
31
  end
30
32
 
31
33
  def enabled?
32
- @api_url.is_a?(String) or @api_key.is_a?(String) or @default_zone.is_a?(String)
34
+ @api_url.is_a?(String) and @api_key.is_a?(String) and @default_zone.is_a?(Zone)
33
35
  end
34
36
 
35
37
  def validate(machine)
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module PowerDNS
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-powerdns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sayid Munawar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-28 00:00:00.000000000 Z
11
+ date: 2016-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler