sr-scripts 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/sr-update-dns CHANGED
@@ -5,17 +5,9 @@ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
5
5
  require 'fog'
6
6
  require 'sr-scripts'
7
7
 
8
- sdb = SrScripts::SimpleDB.get
9
8
 
10
- domain = "dns_info"
11
9
  dns_alias = ARGV[0]
12
10
  ip_address = ARGV[1]
13
11
 
12
+ SrScripts::HostsManager.new.update_dns(dns_alias, ip_address)
14
13
 
15
-
16
- if /^(\d{1,3}\.){3}\d{1,3}$/.match(ip_address) == nil
17
- p "Usage: sr-update-dns hostname ip_address"
18
- exit
19
- end
20
-
21
- sdb.put_attributes(domain, dns_alias, { "ip_address" => ip_address }, { :replace => "ip_address" })
@@ -5,16 +5,5 @@ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
5
5
  require 'fog'
6
6
  require 'sr-scripts'
7
7
 
8
- sdb = SrScripts::SimpleDB.get
9
-
10
- rows = sdb.select("SELECT * FROM dns_info").body["Items"]
11
-
12
- if rows.length > 0
13
- File.open('/etc/hosts', 'w') { |f|
14
- f.puts "# THIS FILE MANAGED BY sr-update-hosts SCRIPT"
15
- f.puts "127.0.0.1 localhost localhost.localdomain"
16
- rows.each_pair { |item_name, values|
17
- f.puts "#{values['ip_address']} #{item_name}"
18
- }
19
- }
20
- end
8
+ manager = SrScripts::HostsManager.new
9
+ manager.generate_file "/etc/hosts"
@@ -0,0 +1,32 @@
1
+ module SrScripts
2
+ class HostsManager
3
+ def generate_file(file_name)
4
+ sdb = SrScripts::SimpleDB.get
5
+
6
+ rows = sdb.select("SELECT * FROM dns_info").body["Items"]
7
+
8
+ if rows.length > 0
9
+ File.open(file_name, 'w') { |f|
10
+ f.puts "# THIS FILE MANAGED BY sr-update-hosts SCRIPT"
11
+ f.puts "127.0.0.1 localhost localhost.localdomain"
12
+ rows.each_pair { |item_name, values|
13
+ f.puts "#{values['ip_address']} #{item_name}"
14
+ }
15
+ }
16
+ end
17
+ end
18
+
19
+ def update_dns(host_name, ip_address)
20
+ sdb = SrScripts::SimpleDB.get
21
+ domain = "dns_info"
22
+
23
+ if /^(\d{1,3}\.){3}\d{1,3}$/.match(ip_address) == nil
24
+ p "Usage: sr-update-dns hostname ip_address"
25
+ exit
26
+ end
27
+
28
+ sdb.put_attributes(domain, host_name, { "ip_address" => ip_address }, { :replace => "ip_address" })
29
+
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module Sr
2
2
  module Scripts
3
- VERSION = "0.1.13"
3
+ VERSION = "0.1.14"
4
4
  end
5
5
  end
data/lib/sr-scripts.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'yaml'
2
2
  require 'logger'
3
+ require 'fog'
4
+
5
+ require 'sr-scripts/HostsManager'
3
6
 
4
7
  module SrScripts
5
8
  class ConfigFile
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 13
9
- version: 0.1.13
8
+ - 14
9
+ version: 0.1.14
10
10
  platform: ruby
11
11
  authors:
12
12
  - Davy Campano
@@ -62,6 +62,7 @@ files:
62
62
  - bin/sr-update-dns
63
63
  - bin/sr-update-hosts-file
64
64
  - lib/sr-scripts.rb
65
+ - lib/sr-scripts/HostsManager.rb
65
66
  - lib/sr-scripts/version.rb
66
67
  - sr-scripts.gemspec
67
68
  has_rdoc: true