ghost 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +7 -1
- data/bin/ghost +14 -0
- data/lib/ghost/linux-host.rb +9 -0
- data/lib/ghost/mac-host.rb +10 -0
- data/spec/ghost_spec.rb +13 -0
- metadata +2 -2
data/README
CHANGED
@@ -35,6 +35,10 @@ Command
|
|
35
35
|
$ ghost delete mydevsite.local
|
36
36
|
[Deleting] mydevsite.local
|
37
37
|
|
38
|
+
$ ghost delete_matching test
|
39
|
+
[Deleting] test2.local
|
40
|
+
[Deleting] test.local
|
41
|
+
|
38
42
|
$ ghost list
|
39
43
|
Listing 1 host(s):
|
40
44
|
staging-server.local -> 67.207.136.164
|
@@ -77,13 +81,15 @@ Contributors
|
|
77
81
|
============
|
78
82
|
|
79
83
|
* [Bodaniel Jeanes](http://github.com/bjeanes)
|
84
|
+
* [Ben Hoskings](http://github.com/benhoskings)
|
80
85
|
* [Mitchell V Riley](http://github.com/mitchellvriley)
|
81
86
|
* [Courtois Simon](http://github.com/simonc)
|
87
|
+
* [Justin Mazzi](http://github.com/jmazzi)
|
82
88
|
|
83
89
|
Legal Stuff
|
84
90
|
===========
|
85
91
|
|
86
|
-
Copyright (c) 2008 Bodaniel Jeanes
|
92
|
+
Copyright (c) 2008-2010 Bodaniel Jeanes
|
87
93
|
|
88
94
|
Permission is hereby granted, free of charge, to any person obtaining
|
89
95
|
a copy of this software and associated documentation files (the
|
data/bin/ghost
CHANGED
@@ -15,6 +15,7 @@ def help_text(exit_code = 0)
|
|
15
15
|
puts """USAGE: #{script_name} add <hostname> [<ip=127.0.1.1>]
|
16
16
|
#{script_name} modify <hostname> <ip>
|
17
17
|
#{script_name} delete <hostname>
|
18
|
+
#{script_name} delete_matching <pattern>
|
18
19
|
#{script_name} list
|
19
20
|
#{script_name} empty
|
20
21
|
#{script_name} export
|
@@ -62,6 +63,19 @@ else
|
|
62
63
|
$stderr.puts "The delete subcommand requires a hostname.\n\n"
|
63
64
|
help_text 2
|
64
65
|
end
|
66
|
+
when 'delete_matching'
|
67
|
+
if ARGV.size == 2
|
68
|
+
matched = Host.delete_matching(ARGV[1])
|
69
|
+
if matched.empty?
|
70
|
+
puts " No matching entries found"
|
71
|
+
else
|
72
|
+
matched.each { |h| puts " [Deleting] #{h}" }
|
73
|
+
end
|
74
|
+
exit 0
|
75
|
+
else
|
76
|
+
$stderr.puts "The delete_matching subcommand requires a hostname pattern.\n\n"
|
77
|
+
help_text 2
|
78
|
+
end
|
65
79
|
when 'list'
|
66
80
|
hosts = Host.list
|
67
81
|
pad = hosts.max{|a,b| a.to_s.length <=> b.to_s.length }.to_s.length
|
data/lib/ghost/linux-host.rb
CHANGED
@@ -66,6 +66,15 @@ class Host
|
|
66
66
|
hosts = hosts.delete_if {|host| host.name == name }
|
67
67
|
write_out!(hosts)
|
68
68
|
end
|
69
|
+
|
70
|
+
def delete_matching(pattern)
|
71
|
+
pattern = Regexp.escape(pattern)
|
72
|
+
hosts = list.select { |host| host.name.match(/#{pattern}/) }
|
73
|
+
hosts.each do |host|
|
74
|
+
delete(host.name)
|
75
|
+
end
|
76
|
+
hosts
|
77
|
+
end
|
69
78
|
|
70
79
|
protected
|
71
80
|
|
data/lib/ghost/mac-host.rb
CHANGED
@@ -53,6 +53,16 @@ class Host
|
|
53
53
|
flush!
|
54
54
|
end
|
55
55
|
|
56
|
+
def delete_matching(pattern)
|
57
|
+
pattern = Regexp.escape(pattern)
|
58
|
+
hosts = list.select { |h| h.to_s.match(/#{pattern}/) }
|
59
|
+
hosts.each do |h|
|
60
|
+
delete(h)
|
61
|
+
end
|
62
|
+
flush! unless hosts.empty?
|
63
|
+
hosts
|
64
|
+
end
|
65
|
+
|
56
66
|
# Flushes the DNS Cache
|
57
67
|
def flush!
|
58
68
|
`dscacheutil -flushcache`
|
data/spec/ghost_spec.rb
CHANGED
@@ -114,6 +114,19 @@ describe Host, ".empty!" do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
describe Host, ".delete_matching" do
|
118
|
+
it "should delete matching hostnames" do
|
119
|
+
keep = 'ghost-test-hostname-keep.local'
|
120
|
+
Host.add(keep)
|
121
|
+
Host.add('ghost-test-hostname-match1.local')
|
122
|
+
Host.add('ghost-test-hostname-match2.local')
|
123
|
+
Host.delete_matching('match')
|
124
|
+
Host.list.should have(1).thing
|
125
|
+
Host.list.first.hostname.should eql(keep)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
117
130
|
describe Host, ".backup and", Host, ".restore" do
|
118
131
|
it "should return a yaml file of all hosts and IPs when backing up"
|
119
132
|
it "should empty the hosts and restore only the ones in given yaml"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bodaniel Jeanes
|
@@ -9,7 +9,7 @@ autorequire: ghost
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-14 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|