vagrant-powerdns 0.1.1 → 0.1.2

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: acb0cb8a88a2a042926f73b8413195f26f54296b
4
- data.tar.gz: a9884828fe4222180e4e60bc4d85ab499a2ef8b6
3
+ metadata.gz: 72d6438d5052854280b1685c92c883236e22a28c
4
+ data.tar.gz: 135fdbd6e654a8e405f23ab8afc21e1092589676
5
5
  SHA512:
6
- metadata.gz: e85525301d3762ae8eeb431a70d567e7e49363c14a942820db88cbad19339c7212609cc24c0e158ec3113e3377bfbce2fbf5fe5dea33321ddc4ce3b9c6b183f7
7
- data.tar.gz: 7fe9fc614097755d8af7b5e9243bcf0531ce7f5b820e658b2ea89da832f0082e9022af301bd823f2f1fff2ec2b25efa64da4a3e34a05ad38be107d83f695966d
6
+ metadata.gz: 9f6f74dec4825318bbee4c43d67ee7aca986ce0492e65066644544cdbaa28fc0ed355e4b53f4e70e533ce9d678636b70341447d06e7614dd5a4128878bed4bb0
7
+ data.tar.gz: 3abc1137238395a9f5a81ec2a727ec89be1b88e64d2dbda5948716e36d4700aa98ad2592a6eb9df0b5930ad4d2e06072ec7a35766c608253e3498fc599709a62
@@ -5,13 +5,12 @@ 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
8
9
  @host = env[:machine].config.vm.hostname.nil? ?
9
10
  env[:machine].name.to_s : env[:machine].config.vm.hostname.to_s
10
- @domain = @host + env[:machine].config.powerdns.default_zone.to_s
11
- @zone = env[:machine].config.powerdns.default_zone.name
11
+ @domain = @host.include?(@zone.name)? @host : @host + @zone.dotted
12
12
 
13
13
  # Identify who i am
14
- @myname = Etc.getpwuid[:gecos]
15
14
  @myuser = Etc.getlogin.gsub(/\s+/, '')
16
15
  @myhost = Socket.gethostname
17
16
  end
@@ -24,27 +23,28 @@ module Vagrant
24
23
  if !stdout.empty?
25
24
  re = /src ([0-9\.]+)/
26
25
  ip = stdout.match(re)[1]
26
+ zone = @zone.name
27
27
 
28
28
  p = PdnsRestApiClient.new(env[:machine].config.powerdns.api_url,
29
29
  env[:machine].config.powerdns.api_key)
30
30
 
31
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?
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?
34
34
 
35
35
  if record_not_found or record_disabled
36
36
  env[:ui].info "PowerDNS action..."
37
37
  # Append new comment
38
38
  new_comment = {
39
- content: "#{@myname} (#{@myuser}) added this record from #{@myhost}",
40
- account: @myname,
39
+ content: "#{@myuser} added this record from #{@myhost}",
40
+ account: @myuser,
41
41
  name: @domain,
42
42
  type: "A"
43
43
  }
44
- comments = p.zone(@zone)["comments"].delete_if { |v| v["name"] != @domain }
44
+ comments = p.zone(zone)["comments"].delete_if { |v| v["name"] != @domain }
45
45
  comments << new_comment
46
46
 
47
- ret = p.modify_domain(domain: @domain, ip: ip, zone_id: @zone,
47
+ ret = p.modify_domain(domain: @domain, ip: ip, zone_id: zone,
48
48
  comments: comments)
49
49
 
50
50
  # Check return
@@ -61,9 +61,9 @@ module Vagrant
61
61
 
62
62
  # Display ui
63
63
  if error.nil?
64
- env[:ui].detail "=> record #{@domain}(#{ip}) in zone #{@zone} added !"
64
+ env[:ui].detail "=> record #{@domain}(#{ip}) in zone #{zone} added !"
65
65
  else
66
- env[:ui].detail "=> failed to add record #{@domain}(#{ip}) in zone #{@zone}. Error was: #{error}"
66
+ env[:ui].detail "=> failed to add record #{@domain}(#{ip}) in zone #{zone}. Error was: #{error}"
67
67
  end
68
68
  end
69
69
  end
@@ -79,13 +79,12 @@ module Vagrant
79
79
  def initialize(app, env)
80
80
  @app = app
81
81
  @machine = env[:machine]
82
+ @zone = env[:machine].config.powerdns.default_zone
82
83
  @host = env[:machine].config.vm.hostname.nil? ?
83
84
  env[:machine].name.to_s : env[:machine].config.vm.hostname.to_s
84
- @domain = @host + env[:machine].config.powerdns.default_zone.to_s
85
- @zone = env[:machine].config.powerdns.default_zone.name
85
+ @domain = @host.include?(@zone.name)? @host : @host + @zone.dotted
86
86
 
87
87
  # Identify who i am
88
- @myname = Etc.getpwuid[:gecos]
89
88
  @myuser = Etc.getlogin.gsub(/\s+/, '')
90
89
  @myhost = Socket.gethostname
91
90
  end
@@ -95,17 +94,18 @@ module Vagrant
95
94
  p = PdnsRestApiClient.new(env[:machine].config.powerdns.api_url,
96
95
  env[:machine].config.powerdns.api_key)
97
96
 
97
+ zone = @zone.name
98
98
  # Get A record
99
- record = p.zone(@zone)
99
+ record = p.zone(zone)["records"].find {|v| v["name"] == @domain}
100
100
 
101
101
  # only disable if active
102
- if not record["records"].find {|v| v["name"] == @domain}["disabled"]
102
+ if !record.nil? and not record["disabled"]
103
103
  env[:ui].info "PowerDNS action..."
104
104
 
105
105
  # Prepare comment to be appended
106
106
  new_comment = {
107
- content: "#{@myname} (#{@myuser}) disabled this record from #{@myhost}",
108
- account: @myname,
107
+ content: "#{@myuser} disabled this record from #{@myhost}",
108
+ account: @myuser,
109
109
  name: @domain,
110
110
  type: "A"
111
111
  }
@@ -115,7 +115,7 @@ module Vagrant
115
115
  # Get the old IP
116
116
  ip = record["records"].find {|v| v["name"] == @domain}["content"]
117
117
 
118
- ret = p.disable_domain(domain: @domain, ip: ip, zone_id: @zone,
118
+ ret = p.disable_domain(domain: @domain, ip: ip, zone_id: zone,
119
119
  comments: comments)
120
120
 
121
121
  # Check return
@@ -132,9 +132,9 @@ module Vagrant
132
132
 
133
133
  # Display ui
134
134
  if error.nil?
135
- env[:ui].detail "=> record #{@domain}(#{ip}) in zone #{@zone} disabled !"
135
+ env[:ui].detail "=> record #{@domain}(#{ip}) in zone #{zone} disabled !"
136
136
  else
137
- env[:ui].detail "=> failed to disab;e record #{@domain} in zone #{@zone}. Error was: #{error}"
137
+ env[:ui].detail "=> failed to disab;e record #{@domain} in zone #{zone}. Error was: #{error}"
138
138
  end
139
139
  end
140
140
 
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module PowerDNS
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-21 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,8 +83,6 @@ files:
83
83
  - bin/setup
84
84
  - lib/vagrant-powerdns.rb
85
85
  - lib/vagrant-powerdns/action.rb
86
- - lib/vagrant-powerdns/action/add_record.rb
87
- - lib/vagrant-powerdns/action/del_record.rb
88
86
  - lib/vagrant-powerdns/config.rb
89
87
  - lib/vagrant-powerdns/errors.rb
90
88
  - lib/vagrant-powerdns/includes/Ip.class.rb
File without changes
File without changes