pauper 0.1.5 → 0.1.6

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.
Files changed (4) hide show
  1. data/bin/pauper +51 -3
  2. data/lib/dhcpd.rb +23 -17
  3. data/lib/pauper.rb +7 -20
  4. metadata +3 -3
data/bin/pauper CHANGED
@@ -3,6 +3,8 @@
3
3
  require 'rubygems'
4
4
  require 'thor'
5
5
  require 'pauper'
6
+ require 'vmx'
7
+ require 'dhcpd'
6
8
 
7
9
  class CLI < Thor
8
10
  desc "bootstrap", "Initialize the base image"
@@ -74,16 +76,62 @@ class CLI < Thor
74
76
  end
75
77
  end
76
78
 
79
+
77
80
  desc 'write_hosts', 'Write out a new /etc/hosts file'
78
81
  def write_hosts
79
82
  pauper = Pauper.new
80
83
  pauper.write_hosts
81
84
  end
82
85
 
83
- desc 'write_dhcpd', 'Write out a new dhcpd.conf file'
84
- def write_dhcpd
86
+
87
+ desc 'setup_osx [VMNAME]', 'Set up things for OS X'
88
+ def setup_osx(vm_name=nil)
85
89
  pauper = Pauper.new
86
- pauper.write_dhcpd
90
+
91
+ vms = Dir["#{ENV['HOME']}/Documents/Virtual Machines*/#{vm_name}*"]
92
+ if vms.size > 1
93
+ puts "I'm not sure which VM I should use!"
94
+ vms.each do |vm|
95
+ puts "\t#{File.basename(vm)}"
96
+ end
97
+ exit
98
+ end
99
+
100
+ vmx_file = Dir[vms[0] + '/*.vmx'][0]
101
+ vmx = VMX.new(vmx_file)
102
+
103
+ mac = vmx.data['ethernet0.generatedAddress']
104
+ arpmac = mac.gsub(/0([0-9a-f])/, '\1') # switch it to the format that arp likes
105
+
106
+ match = `arp -a | grep #{arpmac}`.match(/\(([0-9.]+)\)/)
107
+ unless match
108
+ puts "Could not find any running VM with MAC addr: #{arpmac}"
109
+ exit
110
+ end
111
+
112
+ ip = match.captures[0]
113
+
114
+ # Set up DHCPD
115
+
116
+ dhcpd = DHCPD.new('/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf')
117
+ unless dhcpd.config['dev'] &&
118
+ dhcpd.config['dev']['hardware ethernet'] == mac &&
119
+ dhcpd.config['dev']['fixed-address'] == ip
120
+
121
+ puts "Writing correct IP/MAC combo into dhcpd.conf file..."
122
+ dhcpd.config['dev'] = { 'hardware ethernet' => mac, 'fixed-address' => ip }
123
+ dhcpd.save
124
+ end
125
+
126
+ # Set up route
127
+ gateway = `route -n get 10.215.0.0`.match(/gateway: (.*)$/).captures[0]
128
+ unless gateway == ip
129
+ puts "Adding route to LXC hosts..."
130
+ system 'sudo', 'route', 'add', '10.215.0.0/24', ip
131
+ end
132
+
133
+ # Write hosts
134
+ pauper.write_osx_hosts(ip)
87
135
  end
88
136
  end
89
137
 
data/lib/dhcpd.rb CHANGED
@@ -14,22 +14,28 @@ class DHCPD
14
14
  @preamble.match(/subnet (\d+\.\d+\.\d+)\.0 netmask/)[1]
15
15
  end
16
16
 
17
+ def serialize
18
+ out = @preamble
19
+ out += BEGIN_PAUPER + "\n"
20
+
21
+ @config.each do |host, host_config|
22
+ out += "host #{host} {\n"
23
+ host_config.each do |key, value|
24
+ out += "\t#{key} #{value};\n"
25
+ end
26
+ out += "}\n"
27
+ end
28
+
29
+ out += END_PAUPER + "\n"
30
+ out += @postamble
31
+
32
+ out
33
+ end
34
+
17
35
  def save
18
36
  tmp_path = '.tmp.dhcpd.conf'
19
37
  File.open(tmp_path, 'w') do |f|
20
- f.write @preamble
21
- f.puts BEGIN_BUM
22
-
23
- @config.each do |host, host_config|
24
- f.puts "host #{host} {"
25
- host_config.each do |key, value|
26
- f.puts "\t#{key} #{value};"
27
- end
28
- f.puts "}"
29
- end
30
-
31
- f.puts END_BUM
32
- f.write @postamble
38
+ f.write serialize
33
39
  end
34
40
 
35
41
  system 'sudo', 'mv', tmp_path, @conf_path
@@ -41,8 +47,8 @@ class DHCPD
41
47
 
42
48
  private
43
49
 
44
- BEGIN_BUM = "#### BEGIN BUM ####"
45
- END_BUM = "#### END BUM ####"
50
+ BEGIN_PAUPER = "#### BEGIN PAUPER ####"
51
+ END_PAUPER = "#### END PAUPER ####"
46
52
 
47
53
  def parse
48
54
  state = :preamble
@@ -53,7 +59,7 @@ class DHCPD
53
59
 
54
60
  case state
55
61
  when :preamble
56
- if line == BEGIN_BUM
62
+ if line == BEGIN_PAUPER
57
63
  state = :outside_host
58
64
  else
59
65
  @preamble << rawline
@@ -71,7 +77,7 @@ class DHCPD
71
77
  if line == '}'
72
78
  state = :outside_host
73
79
  host = nil
74
- elsif line == END_BUM
80
+ elsif line == END_PAUPER
75
81
  state = :postamble
76
82
  else
77
83
  parts = line.chomp(';').split(' ')
data/lib/pauper.rb CHANGED
@@ -243,29 +243,16 @@ EOF
243
243
  hosts.save(@pauper_config.config[:dev_domain])
244
244
  end
245
245
 
246
- def write_dhcpd
247
- puts "Writing dhcpd.conf file..."
248
-
249
- dhcpd = DHCPD.new(DHCPD_CONF_PATH)
250
-
246
+ def write_osx_hosts(dev_ip)
247
+ puts "Writing /etc/hosts file..."
248
+ hosts = Hosts.new
251
249
  @pauper_config.config[:nodes].each do |node|
252
- vmx = node_vmx(node.name)
253
- mac = vmx.data['ethernet0.address']
254
-
255
- node_config = get_node_config(node.name)
256
- ip = node_ip(node_config)
257
-
258
- dhcpd.config[node.name] = {
259
- 'hardware ethernet' => mac,
260
- 'fixed-address' => ip
261
- }
262
- dhcpd.save
250
+ hosts.config[node_ip(node)] = node.name
263
251
  end
264
-
265
- puts "Restarting dhcpd..."
266
- dhcpd.restart
252
+ hosts.config[dev_ip] = 'dev'
253
+ hosts.save(@pauper_config.config[:dev_domain])
267
254
  end
268
-
255
+
269
256
  def start_all
270
257
  puts "Starting all nodes..."
271
258
  @pauper_config.config[:nodes].each { |n| start(n.name) }
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tyler McMullen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-04-05 00:00:00 -07:00
18
+ date: 2013-04-07 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency