eymigrate 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/bin/eymigrate +178 -0
- data/lib/host_list.rb +86 -0
- metadata +93 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 wjessop
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= eymigrate
|
2
|
+
|
3
|
+
simple gem for helping migrate EY customers
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 wjessop. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "eymigrate"
|
8
|
+
gem.summary = %Q{EY Migration tool}
|
9
|
+
gem.description = %Q{simple gem for helping migrate EY customers}
|
10
|
+
gem.email = "wjessop@engineyard.com"
|
11
|
+
gem.homepage = "http://github.com/wjessop/eymigrate"
|
12
|
+
gem.authors = ["wjessop"]
|
13
|
+
gem.add_dependency 'ghost'
|
14
|
+
gem.add_dependency 'highline'
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "eymigrate #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/bin/eymigrate
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
# tra-la-la
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'highline/import'
|
10
|
+
require 'host_list'
|
11
|
+
require 'etc'
|
12
|
+
CONFIG_FILE = File.join Etc.getpwuid.dir, ".eymigrate.yml"
|
13
|
+
HostList.config_file = CONFIG_FILE
|
14
|
+
|
15
|
+
def help_text(exit_code = 0)
|
16
|
+
script_name = File.basename $0
|
17
|
+
puts """USAGE: #{script_name} on
|
18
|
+
#{script_name} off
|
19
|
+
#{script_name} list
|
20
|
+
#{script_name} configure
|
21
|
+
"""
|
22
|
+
exit(exit_code)
|
23
|
+
end
|
24
|
+
|
25
|
+
def config_file?
|
26
|
+
File.exists? CONFIG_FILE
|
27
|
+
end
|
28
|
+
|
29
|
+
def formatted_entry(host, ip)
|
30
|
+
# puts "#{domain}: #{ip}"
|
31
|
+
sprintf("%-20s -> #{ip}", host)
|
32
|
+
end
|
33
|
+
|
34
|
+
def display_hosts
|
35
|
+
say "----------------------------"
|
36
|
+
say "- Existing entries -"
|
37
|
+
say "----------------------------"
|
38
|
+
if HostList.has_entries?
|
39
|
+
HostList.each do |host, ip|
|
40
|
+
say formatted_entry(host, ip)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
say "No IP mappings in place"
|
44
|
+
end
|
45
|
+
say "----------------------------"
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_host
|
49
|
+
host = ask("Please enter the hostname (eg. www.mycorp.com): ")
|
50
|
+
ip = ask("Please enter the ip address (eg. 127.0.0.1): ")
|
51
|
+
HostList.add(host, ip)
|
52
|
+
end
|
53
|
+
|
54
|
+
def edit_host(host)
|
55
|
+
ip = ask("Enter the new IP (eg. 127.0.0.1): ")
|
56
|
+
HostList.update(host, ip)
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete_host(host)
|
60
|
+
HostList.remove(host)
|
61
|
+
end
|
62
|
+
|
63
|
+
##########################################
|
64
|
+
#
|
65
|
+
# Menus
|
66
|
+
#
|
67
|
+
##########################################
|
68
|
+
|
69
|
+
def main_menu
|
70
|
+
if config_file?
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
exit = false
|
75
|
+
begin
|
76
|
+
|
77
|
+
display_hosts
|
78
|
+
|
79
|
+
choose do |menu|
|
80
|
+
menu.select_by = :index
|
81
|
+
menu.prompt = "Where would you like to go today?"
|
82
|
+
|
83
|
+
menu.choice("Add hostname") { add_host }
|
84
|
+
menu.choice("Edit hostname") { edit_menu }
|
85
|
+
menu.choice("Delete hostname") { delete_menu }
|
86
|
+
menu.choice(:quit) { exit = true }
|
87
|
+
end
|
88
|
+
end while exit == false
|
89
|
+
end
|
90
|
+
|
91
|
+
def edit_menu
|
92
|
+
exit = false
|
93
|
+
begin
|
94
|
+
choose do |menu|
|
95
|
+
menu.select_by = :index
|
96
|
+
menu.prompt = "Choose a hostname to edit:"
|
97
|
+
say "----------------------------"
|
98
|
+
say "- Existing entries -"
|
99
|
+
say "----------------------------"
|
100
|
+
if HostList.has_entries?
|
101
|
+
HostList.each do |host, ip|
|
102
|
+
menu.choice(formatted_entry(host, ip)) { |c| edit_host(c.match(/^(\w|\.)+/)[0]) }
|
103
|
+
end
|
104
|
+
else
|
105
|
+
say "No IP mappings in place"
|
106
|
+
end
|
107
|
+
say "----------------------------"
|
108
|
+
|
109
|
+
menu.choice(:back) { exit = true }
|
110
|
+
end
|
111
|
+
end while exit == false
|
112
|
+
end
|
113
|
+
|
114
|
+
def delete_menu
|
115
|
+
exit = false
|
116
|
+
begin
|
117
|
+
choose do |menu|
|
118
|
+
menu.select_by = :index
|
119
|
+
menu.prompt = "Choose a hostname delete:"
|
120
|
+
say "----------------------------"
|
121
|
+
say "- Existing entries -"
|
122
|
+
say "----------------------------"
|
123
|
+
if HostList.has_entries?
|
124
|
+
HostList.each do |host, ip|
|
125
|
+
menu.choice(formatted_entry(host, ip)) { |c| delete_host(c.match(/^(\w|\.)+/)[0]) }
|
126
|
+
end
|
127
|
+
else
|
128
|
+
say "No IP mappings in place"
|
129
|
+
end
|
130
|
+
say "----------------------------"
|
131
|
+
|
132
|
+
menu.choice(:back) { exit = true }
|
133
|
+
end
|
134
|
+
end while exit == false
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
##########################################
|
139
|
+
|
140
|
+
if ARGV.size.zero? || ['-h', '--help', 'help'].include?(ARGV.first)
|
141
|
+
help_text
|
142
|
+
end
|
143
|
+
|
144
|
+
def list_mappings
|
145
|
+
HostList.each do |host, ip|
|
146
|
+
puts formatted_entry(host, ip)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
case ARGV[0]
|
151
|
+
when 'on'
|
152
|
+
if config_file?
|
153
|
+
puts "Applying hostname mappings:"
|
154
|
+
list_mappings
|
155
|
+
HostList.apply
|
156
|
+
else
|
157
|
+
main_menu
|
158
|
+
end
|
159
|
+
when 'off'
|
160
|
+
puts "Reversing hostname mappings:"
|
161
|
+
list_mappings
|
162
|
+
HostList.unapply
|
163
|
+
when 'list'
|
164
|
+
puts "Current hostname mappings:"
|
165
|
+
list_mappings
|
166
|
+
when 'configure'
|
167
|
+
main_menu
|
168
|
+
when 'moo'
|
169
|
+
puts <<EOF
|
170
|
+
(__)
|
171
|
+
(oo)
|
172
|
+
/------\\/
|
173
|
+
/ | ||
|
174
|
+
* /\\---/\\
|
175
|
+
~~ ~~
|
176
|
+
...."Have you mooed today?"...
|
177
|
+
EOF
|
178
|
+
end
|
data/lib/host_list.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'ghost'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class HostList
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def config_file=(path)
|
9
|
+
@@config_file = path
|
10
|
+
end
|
11
|
+
|
12
|
+
def each
|
13
|
+
read_entries
|
14
|
+
@@entries.each do |host|
|
15
|
+
yield host
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_entry(host, ip = nil)
|
20
|
+
if ip
|
21
|
+
@@entries[host.strip] = ip.strip
|
22
|
+
else
|
23
|
+
@@entries.delete(host.strip)
|
24
|
+
end
|
25
|
+
save_entries
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(host, ip)
|
29
|
+
begin
|
30
|
+
Host.add(host, ip)
|
31
|
+
set_entry(host,ip)
|
32
|
+
rescue => e
|
33
|
+
puts "Error adding entry: #{e}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def update(host, ip)
|
38
|
+
set_entry(host,ip)
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove(host)
|
42
|
+
begin
|
43
|
+
Host.delete(host)
|
44
|
+
set_entry(host)
|
45
|
+
rescue => e
|
46
|
+
puts "Error removing entry: #{e}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def apply
|
51
|
+
each do |host, ip|
|
52
|
+
if Host.find_by_host(host)
|
53
|
+
Host.delete(host)
|
54
|
+
end
|
55
|
+
Host.add(host, ip)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def unapply
|
60
|
+
each do |host, ip|
|
61
|
+
Host.delete(host) if Host.find_by_host(host)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def has_entries?
|
66
|
+
read_entries
|
67
|
+
@@entries.size > 0
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def read_entries
|
73
|
+
if File.exists?(@@config_file)
|
74
|
+
@@entries = YAML.load_file(@@config_file)
|
75
|
+
else
|
76
|
+
@@entries = {}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def save_entries
|
81
|
+
File.open(@@config_file, "w") do |f|
|
82
|
+
f.write(YAML.dump(@@entries))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eymigrate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- wjessop
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-04 00:00:00 +01:00
|
18
|
+
default_executable: eymigrate
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: ghost
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: highline
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
description: simple gem for helping migrate EY customers
|
45
|
+
email: wjessop@engineyard.com
|
46
|
+
executables:
|
47
|
+
- eymigrate
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
extra_rdoc_files:
|
51
|
+
- LICENSE
|
52
|
+
- README.rdoc
|
53
|
+
files:
|
54
|
+
- .document
|
55
|
+
- .gitignore
|
56
|
+
- LICENSE
|
57
|
+
- README.rdoc
|
58
|
+
- Rakefile
|
59
|
+
- VERSION
|
60
|
+
- bin/eymigrate
|
61
|
+
- lib/host_list.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://github.com/wjessop/eymigrate
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --charset=UTF-8
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: EY Migration tool
|
92
|
+
test_files: []
|
93
|
+
|