olympe 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/LICENSE +24 -0
  2. data/README.md +103 -0
  3. data/Rakefile +101 -0
  4. data/bin/olympe +6 -0
  5. data/caldecott_helper/Gemfile +10 -0
  6. data/caldecott_helper/Gemfile.lock +48 -0
  7. data/caldecott_helper/server.rb +43 -0
  8. data/config/clients.yml +17 -0
  9. data/config/micro/offline.conf +2 -0
  10. data/config/micro/paths.yml +22 -0
  11. data/config/micro/refresh_ip.rb +20 -0
  12. data/lib/cli/commands/admin.rb +80 -0
  13. data/lib/cli/commands/apps.rb +1208 -0
  14. data/lib/cli/commands/base.rb +233 -0
  15. data/lib/cli/commands/manifest.rb +56 -0
  16. data/lib/cli/commands/micro.rb +115 -0
  17. data/lib/cli/commands/misc.rb +140 -0
  18. data/lib/cli/commands/services.rb +217 -0
  19. data/lib/cli/commands/user.rb +65 -0
  20. data/lib/cli/config.rb +170 -0
  21. data/lib/cli/console_helper.rb +163 -0
  22. data/lib/cli/core_ext.rb +122 -0
  23. data/lib/cli/errors.rb +19 -0
  24. data/lib/cli/file_helper.rb +123 -0
  25. data/lib/cli/frameworks.rb +265 -0
  26. data/lib/cli/manifest_helper.rb +316 -0
  27. data/lib/cli/runner.rb +568 -0
  28. data/lib/cli/services_helper.rb +104 -0
  29. data/lib/cli/tunnel_helper.rb +336 -0
  30. data/lib/cli/usage.rb +125 -0
  31. data/lib/cli/version.rb +7 -0
  32. data/lib/cli/zip_util.rb +77 -0
  33. data/lib/cli.rb +48 -0
  34. data/lib/vmc/client.rb +558 -0
  35. data/lib/vmc/const.rb +27 -0
  36. data/lib/vmc/micro/switcher/base.rb +97 -0
  37. data/lib/vmc/micro/switcher/darwin.rb +19 -0
  38. data/lib/vmc/micro/switcher/dummy.rb +15 -0
  39. data/lib/vmc/micro/switcher/linux.rb +16 -0
  40. data/lib/vmc/micro/switcher/windows.rb +31 -0
  41. data/lib/vmc/micro/vmrun.rb +158 -0
  42. data/lib/vmc/micro.rb +56 -0
  43. data/lib/vmc.rb +3 -0
  44. metadata +279 -0
@@ -0,0 +1,16 @@
1
+ module VMC::Micro::Switcher
2
+
3
+ class Linux < Base
4
+ def set_nameserver(domain, ip)
5
+ VMC::Micro.run_command("sudo", "sed -i'.backup' '1 i nameserver #{ip}' /etc/resolv.conf")
6
+ # lock resolv.conf so Network Manager doesn't clear out the file when offline
7
+ VMC::Micro.run_command("sudo", "chattr +i /etc/resolv.conf")
8
+ end
9
+
10
+ def unset_nameserver(domain, ip)
11
+ VMC::Micro.run_command("sudo", "chattr -i /etc/resolv.conf")
12
+ VMC::Micro.run_command("sudo", "sed -i'.backup' '/#{ip}/d' /etc/resolv.conf")
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,31 @@
1
+ module VMC::Micro::Switcher
2
+
3
+ class Windows < Base
4
+ def version?
5
+ VMC::Micro.run_command("cmd", "/c ver").to_s.scan(/\d+\.\d+/).first.to_f
6
+ end
7
+
8
+ def adminrun(command, args=nil)
9
+ if version? > 5.2
10
+ require 'win32ole'
11
+ shell = WIN32OLE.new("Shell.Application")
12
+ shell.ShellExecute(command, args, nil, "runas", 0)
13
+ else
14
+ # on older version this will try to run the command, and if you don't have
15
+ # admin privilges it will tell you so and exit
16
+ VMC::Micro.run_command(command, args)
17
+ end
18
+ end
19
+
20
+ # TODO better method to figure out the interface name is to get the NAT ip and find the
21
+ # interface with the correct subnet
22
+ def set_nameserver(domain, ip)
23
+ adminrun("netsh", "interface ip set dns \"VMware Network Adapter VMnet8\" static #{ip}")
24
+ end
25
+
26
+ def unset_nameserver(domain, ip)
27
+ adminrun("netsh", "interface ip set dns \"VMware Network Adapter VMnet8\" static none")
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,158 @@
1
+ module VMC::Micro
2
+ class VMrun
3
+ attr_reader :vmx, :vmrun
4
+
5
+ def initialize(config)
6
+ @platform = config['platform']
7
+ @user = 'root' # must use root as we muck around with system settings
8
+ @password = config['password']
9
+ @vmrun = config['vmrun']
10
+ @vmx = config['vmx']
11
+
12
+ # TODO honor TMPDIR
13
+ if @platform == :windows
14
+ @temp_dir = ENV['temp']
15
+ else
16
+ @temp_dir = '/tmp'
17
+ end
18
+ end
19
+
20
+ def connection_type
21
+ read_variable('ethernet0.connectionType')
22
+ end
23
+
24
+ def connection_type=(type)
25
+ write_variable("ethernet0.connectionType", type)
26
+ end
27
+
28
+ def nat?
29
+ connection_type == "nat"
30
+ end
31
+
32
+ def bridged?
33
+ connection_type == "bridged"
34
+ end
35
+
36
+ def domain
37
+ # switch to Dir.mktmpdir
38
+ state_config = VMC::Micro.escape_path(File.join(@temp_dir, 'state.yml'))
39
+ run('CopyFileFromGuestToHost', "/var/vcap/bosh/state.yml #{state_config}")
40
+ bosh_config = YAML.load_file(state_config)
41
+ bosh_config['properties']['domain']
42
+ end
43
+
44
+ def ip
45
+ # switch to Dir.mktmpdir
46
+ path = VMC::Micro.escape_path(VMC::Micro.config_file('refresh_ip.rb'))
47
+ ip_file = VMC::Micro.escape_path(File.join(@temp_dir, 'ip.txt'))
48
+ run('CopyFileFromHostToGuest', "#{path} /tmp/refresh_ip.rb")
49
+ run('runProgramInGuest', '/tmp/refresh_ip.rb')
50
+ run('CopyFileFromGuestToHost', "/tmp/ip.txt #{ip_file}")
51
+ File.open(ip_file, 'r') { |file| file.read }
52
+ end
53
+
54
+ def list
55
+ vms = run("list")
56
+ vms.delete_if { |line| line =~ /^Total/ }
57
+ vms.map { |line| VMC::Micro.escape_path(File.expand_path(line)) }
58
+ end
59
+
60
+ def offline?
61
+ command = "-gu #{@user} -gp #{@password} runProgramInGuest"
62
+ args = '/usr/bin/test -e /var/vcap/micro/offline'
63
+ # why not use run_command?
64
+ result = %x{#{@vmrun} #{command} #{@vmx} #{args}}
65
+
66
+ if result.include?('Guest program exited with non-zero exit code: 1')
67
+ return false
68
+ elsif $?.exitstatus == 0
69
+ return true
70
+ else
71
+ raise "failed to execute vmrun:\n#{result}"
72
+ end
73
+ end
74
+
75
+ def offline!
76
+ path = VMC::Micro.escape_path(VMC::Micro.config_file('offline.conf'))
77
+ run('CopyFileFromHostToGuest', "#{path} /etc/dnsmasq.d/offline.conf")
78
+ run('runProgramInGuest', '/usr/bin/touch /var/vcap/micro/offline')
79
+ restart_dnsmasq
80
+ end
81
+
82
+ def online!
83
+ run('runProgramInGuest', '/bin/rm -f /etc/dnsmasq.d/offline.conf')
84
+ run('runProgramInGuest', '/bin/rm -f /var/vcap/micro/offline')
85
+ restart_dnsmasq
86
+ end
87
+
88
+ # check to see if the micro cloud has been configured
89
+ # uses default password to check
90
+ def ready?
91
+ command = "-gu root -gp 'ca$hc0w' runProgramInGuest"
92
+ args = '/usr/bin/test -e /var/vcap/micro/micro.json'
93
+ result = %x{#{@vmrun} #{command} #{@vmx} #{args}}
94
+
95
+ if result.include?('Invalid user name or password for the guest OS') || $?.exitstatus == 0
96
+ return true
97
+ elsif $?.exitstatus == 1
98
+ return false
99
+ else
100
+ raise "failed to execute vmrun:\n#{result}"
101
+ end
102
+ end
103
+
104
+ def read_variable(var)
105
+ # TODO deal with non-ok return
106
+ run("readVariable", "runtimeConfig #{var}").first
107
+ end
108
+
109
+ def write_variable(var, value)
110
+ run('writeVariable', "runtimeConfig #{var} #{value}")
111
+ end
112
+
113
+ def reset
114
+ run('reset', 'soft')
115
+ end
116
+
117
+ def restart_dnsmasq
118
+ # restart command doesn't always work, start and stop seems to be more reliable
119
+ run('runProgramInGuest', '/etc/init.d/dnsmasq stop')
120
+ run('runProgramInGuest', '/etc/init.d/dnsmasq start')
121
+ end
122
+
123
+ def run(command, args=nil)
124
+ if command.include?('Guest')
125
+ command = "-gu #{@user} -gp #{@password} #{command}"
126
+ end
127
+ VMC::Micro.run_command(@vmrun, "#{command} #{@vmx} #{args}")
128
+ end
129
+
130
+ def running?
131
+ vms = list
132
+ if @platform == :windows
133
+ vms.map! { |x| x.downcase }
134
+ vms.include?(@vmx.downcase)
135
+ else
136
+ vms.include?(@vmx)
137
+ end
138
+ end
139
+
140
+ def start
141
+ run('start') unless running?
142
+ end
143
+
144
+ def stop
145
+ run('stop') if running?
146
+ end
147
+
148
+ def self.locate(platform)
149
+ paths = YAML.load_file(VMC::Micro.config_file('paths.yml'))
150
+ vmrun_paths = paths[platform.to_s]['vmrun']
151
+ vmrun_exe = @platform == :windows ? 'vmrun.exe' : 'vmrun'
152
+ vmrun = VMC::Micro.locate_file(vmrun_exe, "VMware", vmrun_paths)
153
+ err "Unable to locate vmrun, please supply --vmrun option" unless vmrun
154
+ vmrun
155
+ end
156
+ end
157
+
158
+ end
data/lib/vmc/micro.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'find'
2
+
3
+ module VMC::Micro
4
+ def config_file(file)
5
+ File.join(File.dirname(__FILE__), '..', '..', 'config', 'micro', file)
6
+ end
7
+
8
+ def escape_path(path)
9
+ path = File.expand_path(path)
10
+ if RUBY_PLATFORM =~ /mingw|mswin32|cygwin/
11
+ if path.include?(' ')
12
+ return '"' + path + '"'
13
+ else
14
+ return path
15
+ end
16
+ else
17
+ return path.gsub(' ', '\ ')
18
+ end
19
+ end
20
+
21
+ def locate_file(file, directory, search_paths)
22
+ search_paths.each do |path|
23
+ expanded_path = File.expand_path(path)
24
+ if File.exists?(expanded_path)
25
+ Find.find(expanded_path) do |current|
26
+ if File.directory?(current) && current.include?(directory)
27
+ full_path = File.join(current, file)
28
+ return self.escape_path(full_path) if File.exists?(full_path)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ false
35
+ end
36
+
37
+ def run_command(command, args=nil)
38
+ # TODO switch to using posix-spawn instead
39
+ result = %x{#{command} #{args} 2>&1}
40
+ unless $?.exitstatus == 0
41
+ if block_given?
42
+ yield
43
+ else
44
+ raise "failed to execute #{command} #{args}:\n#{result}"
45
+ end
46
+ else
47
+ result.split(/\n/)
48
+ end
49
+ end
50
+
51
+ module_function :config_file
52
+ module_function :escape_path
53
+ module_function :locate_file
54
+ module_function :run_command
55
+
56
+ end
data/lib/vmc.rb ADDED
@@ -0,0 +1,3 @@
1
+ module VMC; end
2
+
3
+ require 'vmc/client'
metadata ADDED
@@ -0,0 +1,279 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: olympe
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Olympe Network
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json_pure
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.5.1
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: 1.7.0
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.5.1
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: 1.7.0
36
+ - !ruby/object:Gem::Dependency
37
+ name: rubyzip
38
+ requirement: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.4
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ~>
50
+ - !ruby/object:Gem::Version
51
+ version: 0.9.4
52
+ - !ruby/object:Gem::Dependency
53
+ name: rest-client
54
+ requirement: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: 1.6.1
60
+ - - <
61
+ - !ruby/object:Gem::Version
62
+ version: 1.7.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 1.6.1
71
+ - - <
72
+ - !ruby/object:Gem::Version
73
+ version: 1.7.0
74
+ - !ruby/object:Gem::Dependency
75
+ name: terminal-table
76
+ requirement: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: 1.4.2
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.4.2
90
+ - !ruby/object:Gem::Dependency
91
+ name: interact
92
+ requirement: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: 0.4.0
98
+ type: :runtime
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ version: 0.4.0
106
+ - !ruby/object:Gem::Dependency
107
+ name: addressable
108
+ requirement: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ~>
112
+ - !ruby/object:Gem::Version
113
+ version: 2.2.6
114
+ type: :runtime
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ~>
120
+ - !ruby/object:Gem::Version
121
+ version: 2.2.6
122
+ - !ruby/object:Gem::Dependency
123
+ name: uuidtools
124
+ requirement: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ~>
128
+ - !ruby/object:Gem::Version
129
+ version: 2.1.0
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ~>
136
+ - !ruby/object:Gem::Version
137
+ version: 2.1.0
138
+ - !ruby/object:Gem::Dependency
139
+ name: rb-readline
140
+ requirement: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 0.4.2
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: 0.4.2
154
+ - !ruby/object:Gem::Dependency
155
+ name: rake
156
+ requirement: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ - !ruby/object:Gem::Dependency
171
+ name: rspec
172
+ requirement: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ~>
176
+ - !ruby/object:Gem::Version
177
+ version: 1.3.0
178
+ type: :development
179
+ prerelease: false
180
+ version_requirements: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ~>
184
+ - !ruby/object:Gem::Version
185
+ version: 1.3.0
186
+ - !ruby/object:Gem::Dependency
187
+ name: webmock
188
+ requirement: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ~>
192
+ - !ruby/object:Gem::Version
193
+ version: 1.5.0
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ~>
200
+ - !ruby/object:Gem::Version
201
+ version: 1.5.0
202
+ description: Olympe-Network.com CLI
203
+ email: contact@olympe-network.com
204
+ executables:
205
+ - olympe
206
+ extensions: []
207
+ extra_rdoc_files:
208
+ - README.md
209
+ - LICENSE
210
+ files:
211
+ - LICENSE
212
+ - README.md
213
+ - Rakefile
214
+ - config/clients.yml
215
+ - config/micro/offline.conf
216
+ - config/micro/paths.yml
217
+ - config/micro/refresh_ip.rb
218
+ - lib/cli.rb
219
+ - lib/cli/commands/admin.rb
220
+ - lib/cli/commands/base.rb
221
+ - lib/cli/commands/manifest.rb
222
+ - lib/cli/commands/micro.rb
223
+ - lib/cli/commands/user.rb
224
+ - lib/cli/commands/services.rb
225
+ - lib/cli/commands/misc.rb
226
+ - lib/cli/commands/apps.rb
227
+ - lib/cli/core_ext.rb
228
+ - lib/cli/errors.rb
229
+ - lib/cli/frameworks.rb
230
+ - lib/cli/manifest_helper.rb
231
+ - lib/cli/services_helper.rb
232
+ - lib/cli/tunnel_helper.rb
233
+ - lib/cli/version.rb
234
+ - lib/cli/zip_util.rb
235
+ - lib/cli/console_helper.rb
236
+ - lib/cli/config.rb
237
+ - lib/cli/runner.rb
238
+ - lib/cli/file_helper.rb
239
+ - lib/cli/usage.rb
240
+ - lib/vmc.rb
241
+ - lib/vmc/micro.rb
242
+ - lib/vmc/micro/switcher/base.rb
243
+ - lib/vmc/micro/switcher/darwin.rb
244
+ - lib/vmc/micro/switcher/dummy.rb
245
+ - lib/vmc/micro/switcher/linux.rb
246
+ - lib/vmc/micro/switcher/windows.rb
247
+ - lib/vmc/micro/vmrun.rb
248
+ - lib/vmc/const.rb
249
+ - lib/vmc/client.rb
250
+ - caldecott_helper/Gemfile
251
+ - caldecott_helper/Gemfile.lock
252
+ - caldecott_helper/server.rb
253
+ - bin/olympe
254
+ homepage: http://www.olympe-network.com
255
+ licenses: []
256
+ post_install_message:
257
+ rdoc_options: []
258
+ require_paths:
259
+ - lib
260
+ required_ruby_version: !ruby/object:Gem::Requirement
261
+ none: false
262
+ requirements:
263
+ - - ! '>='
264
+ - !ruby/object:Gem::Version
265
+ version: '0'
266
+ required_rubygems_version: !ruby/object:Gem::Requirement
267
+ none: false
268
+ requirements:
269
+ - - ! '>='
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ requirements: []
273
+ rubyforge_project:
274
+ rubygems_version: 1.8.24
275
+ signing_key:
276
+ specification_version: 3
277
+ summary: Olympe-Network.com CLI
278
+ test_files: []
279
+ has_rdoc: