micro-cf-plugin 0.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require "rake"
2
+ require "rspec/core/rake_task"
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
5
+ require "micro-cf-plugin/version"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task :default => :spec
9
+
10
+ namespace :deploy do
11
+ def last_staging_sha
12
+ `git rev-parse latest-staging`.strip
13
+ end
14
+
15
+ def last_release_sha
16
+ `git rev-parse latest-release`.strip
17
+ end
18
+
19
+ def last_staging_ref_was_released?
20
+ last_staging_sha == last_release_sha
21
+ end
22
+
23
+ task :staging, :version do |_, args|
24
+ sh "gem bump --push #{"--version #{args.version}" if args.version}" if last_staging_ref_was_released?
25
+ sh "git tag -f latest-staging"
26
+ sh "git push origin :latest-staging"
27
+ sh "git push origin latest-staging"
28
+ end
29
+
30
+ task :gem do
31
+ sh "git fetch"
32
+ sh "git checkout #{last_staging_sha}"
33
+ sh "gem release --tag"
34
+ sh "git tag -f latest-release"
35
+ sh "git push origin :latest-release"
36
+ sh "git push origin latest-release"
37
+ end
38
+ end
@@ -0,0 +1,2 @@
1
+ no-resolv
2
+ log-queries
data/config/paths.yml ADDED
@@ -0,0 +1,22 @@
1
+ darwin:
2
+ vmrun:
3
+ - "/Applications/VMware Fusion.app/Contents/Library/"
4
+ - "/Applications/Fusion.app/Contents/Library/"
5
+ vmx:
6
+ - "~/Documents/Virtual Machines.localized/"
7
+ - "~/Documents/Virtual Machines/"
8
+ - "~/Desktop/"
9
+
10
+ linux:
11
+ vmrun:
12
+ - "/usr/bin/"
13
+ vmx:
14
+ - "~/"
15
+
16
+ windows:
17
+ vmrun:
18
+ - "c:\\Program Files (x86)\\"
19
+ - "c:\\Program Files\\"
20
+ vmx:
21
+ - "~\\Documents\\"
22
+ - "~\\Desktop\\"
@@ -0,0 +1,24 @@
1
+ #!/var/vcap/bosh/bin/ruby
2
+ require 'socket'
3
+
4
+ A_ROOT_SERVER = '198.41.0.4'
5
+
6
+ begin
7
+ retries ||= 0
8
+ route ||= A_ROOT_SERVER
9
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
10
+ ip_address = UDPSocket.open do |s|
11
+ s.connect(route, 1); s.addr.last
12
+ end
13
+ rescue Errno::ENETUNREACH
14
+ # happens on boot when dhcp hasn't completed when we get here
15
+ sleep 3
16
+ retries += 1
17
+ retry if retries < 10
18
+ ensure
19
+ Socket.do_not_reverse_lookup = orig
20
+ end
21
+
22
+ File.open("/tmp/ip.txt", 'w') do |file|
23
+ file.write(ip_address)
24
+ end
@@ -0,0 +1,4 @@
1
+ module CFMicro
2
+ class MCFError < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ require "mothership/help"
2
+
3
+ Mothership::Help.groups(
4
+ [:micro, "Micro Cloud Foundry"])
@@ -0,0 +1,56 @@
1
+ require 'find'
2
+ require "micro-cf-plugin/errors"
3
+
4
+ module CFMicro
5
+ def config_file(file)
6
+ File.expand_path("../../../../config/#{file}", __FILE__)
7
+ end
8
+
9
+ def escape_path(path)
10
+ path = File.expand_path(path)
11
+ if RUBY_PLATFORM =~ /mingw|mswin32|cygwin/
12
+ if path.include?(' ')
13
+ '"' + path + '"'
14
+ else
15
+ path
16
+ end
17
+ else
18
+ path.gsub(' ', '\ ')
19
+ end
20
+ end
21
+
22
+ def locate_file(file, directory, search_paths)
23
+ search_paths.each do |path|
24
+ expanded_path = File.expand_path(path)
25
+ next unless File.exists?(expanded_path)
26
+ Find.find(expanded_path) do |current|
27
+ if File.directory?(current) && current.include?(directory)
28
+ full_path = File.join(current, file)
29
+ return escape_path(full_path) if File.exists?(full_path)
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
+ if $?.exitstatus == 0
41
+ result.split(/\n/)
42
+ else
43
+ if block_given?
44
+ yield
45
+ else
46
+ raise CFMicro::MCFError, "failed to execute #{command} #{args}:\n#{result}"
47
+ end
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
@@ -0,0 +1,79 @@
1
+ require "micro-cf-plugin/errors"
2
+
3
+ module CFMicro::Switcher
4
+ class Base
5
+
6
+ def initialize(config)
7
+ @config = config
8
+
9
+ @vmrun = CFMicro::VMrun.new(config)
10
+ end
11
+
12
+ #wrapper methods
13
+ def vmx
14
+ @vmrun.vmx
15
+ end
16
+
17
+ def domain
18
+ @vmrun.domain
19
+ end
20
+
21
+ def ip
22
+ @vmrun.ip
23
+ end
24
+
25
+ def running?
26
+ @vmrun.running?
27
+ end
28
+
29
+ def start!
30
+ @vmrun.start!
31
+ end
32
+
33
+ def ready?
34
+ @vmrun.ready?
35
+ end
36
+
37
+ def offline?
38
+ @vmrun.offline?
39
+ end
40
+
41
+ def nat?
42
+ @config['online_connection_type'] ||= @vmrun.connection_type
43
+ @config["online_connection_type"] == "nat"
44
+ end
45
+
46
+ def reset_to_nat!
47
+ @vmrun.connection_type = 'nat'
48
+ @vmrun.reset
49
+ end
50
+
51
+ def set_host_dns!
52
+ @config['domain'] ||= @vmrun.domain
53
+ @config['ip'] ||= @vmrun.ip
54
+ set_nameserver(@config['domain'], @config['ip'])
55
+ end
56
+
57
+ def unset_host_dns!
58
+ @config['domain'] ||= @vmrun.domain
59
+ @config['ip'] ||= @vmrun.ip
60
+ unset_nameserver(@config['domain'], @config['ip'])
61
+ end
62
+
63
+ def offline!
64
+ if @vmrun.offline?
65
+ raise CFMicro::MCFError, "Micro Cloud Foundry VM already in offline mode"
66
+ else
67
+ @vmrun.offline!
68
+ end
69
+ end
70
+
71
+ def online!
72
+ if @vmrun.offline?
73
+ @vmrun.online!
74
+ else
75
+ raise CFMirco::MCFError, "Micro Cloud Foundry already in online mode"
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,21 @@
1
+ require "micro-cf-plugin/errors"
2
+
3
+ module CFMicro::Switcher
4
+
5
+ class Darwin < Base
6
+ def adminrun(command)
7
+ CFMicro.run_command("osascript", "-e 'do shell script \"#{command}\" with administrator privileges'")
8
+ end
9
+
10
+ def set_nameserver(domain, ip)
11
+ File.open("/tmp/#{domain}", 'w') { |file| file.write("nameserver #{ip}") }
12
+ adminrun("mkdir -p /etc/resolver;mv /tmp/#{domain} /etc/resolver/")
13
+ end
14
+
15
+ def unset_nameserver(domain, ip)
16
+ raise CFMicro::MCFError, "domain missing" unless domain
17
+ adminrun("rm -f /etc/resolver/#{domain}")
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,15 @@
1
+ # only used for testing
2
+ module CFMicro::Switcher
3
+
4
+ class Dummy < Base
5
+ def adminrun(command)
6
+ end
7
+
8
+ def set_nameserver(domain, ip)
9
+ end
10
+
11
+ def unset_nameserver(domain, ip)
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+ module CFMicro::Switcher
2
+
3
+ class Linux < Base
4
+ def set_nameserver(domain, ip)
5
+ CFMicro.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
+ CFMicro.run_command("sudo", "chattr +i /etc/resolv.conf")
8
+ end
9
+
10
+ def unset_nameserver(domain, ip)
11
+ CFMicro.run_command("sudo", "chattr -i /etc/resolv.conf")
12
+ CFMicro.run_command("sudo", "sed -i'.backup' '/#{ip}/d' /etc/resolv.conf")
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,31 @@
1
+ module CFMicro::Switcher
2
+
3
+ class Windows < Base
4
+ def version
5
+ CFMicro.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
+ CFMicro.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,175 @@
1
+ require "micro-cf-plugin/errors"
2
+
3
+ module CFMicro
4
+ class VMrun
5
+ attr_reader :vmx, :vmrun
6
+
7
+ def initialize(config)
8
+ @platform = config[:platform]
9
+ @user = 'root' # must use root as we muck around with system settings
10
+ @password = config[:password]
11
+ @vmrun = config[:vmrun]
12
+ @vmx = config[:vmx]
13
+
14
+ # TODO honor TMPDIR
15
+ if @platform == :windows
16
+ @temp_dir = ENV['temp']
17
+ else
18
+ @temp_dir = '/tmp'
19
+ end
20
+ end
21
+
22
+ def vmx
23
+ @vmx
24
+ end
25
+
26
+ def connection_type
27
+ read_variable('ethernet0.connectionType')
28
+ end
29
+
30
+ def connection_type=(type)
31
+ write_variable("ethernet0.connectionType", type)
32
+ end
33
+
34
+ def nat?
35
+ connection_type == "nat"
36
+ end
37
+
38
+ def bridged?
39
+ connection_type == "bridged"
40
+ end
41
+
42
+ def domain
43
+ # switch to Dir.mktmpdir
44
+ state_config = CFMicro.escape_path(File.join(@temp_dir, 'state.yml'))
45
+ run('CopyFileFromGuestToHost', "/var/vcap/bosh/state.yml #{state_config}")
46
+ bosh_config = YAML.load_file(state_config)
47
+ bosh_config['properties']['domain']
48
+ end
49
+
50
+ def ip
51
+ # switch to Dir.mktmpdir
52
+ path = CFMicro.escape_path(CFMicro.config_file('refresh_ip.rb'))
53
+ ip_file = CFMicro.escape_path(File.join(@temp_dir, 'ip.txt'))
54
+ run('CopyFileFromHostToGuest', "#{path} /tmp/refresh_ip.rb")
55
+ run('runProgramInGuest', '/tmp/refresh_ip.rb')
56
+ run('CopyFileFromGuestToHost', "/tmp/ip.txt #{ip_file}")
57
+ File.open(ip_file, 'r') { |file| file.read }
58
+ end
59
+
60
+ def list
61
+ vms = run("list")
62
+ vms.delete_if { |line| line =~ /^Total/ }
63
+ vms.map { |line| CFMicro.escape_path(File.expand_path(line)) }
64
+ end
65
+
66
+ def offline?
67
+ command = "-gu #{@user} -gp #{@password} runProgramInGuest"
68
+ args = '/usr/bin/test -e /var/vcap/micro/offline'
69
+ # why not use run_command?
70
+ result = %x{#{@vmrun} #{command} #{@vmx} #{args}}
71
+
72
+ if result.include?('Guest program exited with non-zero exit code: 1')
73
+ return false
74
+ elsif $?.exitstatus == 0
75
+ return true
76
+ else
77
+ raise CFMicro::MCFError, "failed to execute vmrun:\n#{result}"
78
+ end
79
+ end
80
+
81
+ def offline!
82
+ path = CFMicro.escape_path(CFMicro.config_file('offline.conf'))
83
+ run('CopyFileFromHostToGuest', "#{path} /etc/dnsmasq.d/offline.conf")
84
+ run('runProgramInGuest', '/usr/bin/touch /var/vcap/micro/offline')
85
+ run('runProgramInGuest',
86
+ "/bin/sed -i -e 's/^[^#]/# &/g' /etc/dnsmasq.d/server || true")
87
+ restart_dnsmasq
88
+ end
89
+
90
+ def online!
91
+ run('runProgramInGuest', '/bin/rm -f /etc/dnsmasq.d/offline.conf')
92
+ run('runProgramInGuest', '/bin/rm -f /var/vcap/micro/offline')
93
+ run('runProgramInGuest',
94
+ "/bin/sed -i -e 's/^# //g' /etc/dnsmasq.d/server || true")
95
+ restart_dnsmasq
96
+ end
97
+
98
+ # check to see if the micro cloud has been configured
99
+ # uses default password to check
100
+ def ready?
101
+ command = "-gu root -gp 'ca$hc0w' runProgramInGuest"
102
+ args = '/usr/bin/test -e /var/vcap/micro/micro.json'
103
+ result = %x{#{@vmrun} #{command} #{@vmx} #{args}}
104
+
105
+ if result.include?('Invalid user name or password for the guest OS') || $?.exitstatus == 0
106
+ return true
107
+ elsif $?.exitstatus == 1
108
+ return false
109
+ else
110
+ raise CFMicro::MCFError, "failed to execute vmrun:\n#{result}"
111
+ end
112
+ end
113
+
114
+ def read_variable(var)
115
+ # TODO deal with non-ok return
116
+ run("readVariable", "runtimeConfig #{var}").first
117
+ end
118
+
119
+ def write_variable(var, value)
120
+ run('writeVariable', "runtimeConfig #{var} #{value}")
121
+ end
122
+
123
+ def reset
124
+ run('reset', 'soft')
125
+ end
126
+
127
+ def restart_dnsmasq
128
+ # restart command doesn't always work, start and stop seems to be more reliable
129
+ run('runProgramInGuest', '/etc/init.d/dnsmasq stop')
130
+ run('runProgramInGuest', '/etc/init.d/dnsmasq start')
131
+ end
132
+
133
+ def run(command, args=nil)
134
+ if command.include?('Guest')
135
+ command = "-gu #{@user} -gp #{@password} #{command}"
136
+ end
137
+ CFMicro.run_command(@vmrun, "#{command} #{@vmx} #{args}")
138
+ end
139
+
140
+ def running?
141
+ vms = list
142
+ if @platform == :windows
143
+ vms.any? { |x|
144
+ x.downcase == @vmx.downcase
145
+ }
146
+ else
147
+ # Handle vmx being in a symlinked dir.
148
+ real_path = nil
149
+ begin
150
+ real_path = File.realpath(@vmx)
151
+ rescue
152
+ end
153
+ vms.include?(@vmx) || (real_path && vms.include?(real_path))
154
+ end
155
+ end
156
+
157
+ def start!
158
+ run('start') unless running?
159
+ end
160
+
161
+ def stop!
162
+ run('stop') if running?
163
+ end
164
+
165
+ def self.locate(platform)
166
+ paths = YAML.load_file(CFMicro.config_file('paths.yml'))
167
+ vmrun_paths = paths[platform.to_s]['vmrun']
168
+ vmrun_exe = @platform == :windows ? 'vmrun.exe' : 'vmrun'
169
+ vmrun = CFMicro.locate_file(vmrun_exe, "VMware", vmrun_paths)
170
+ err "Unable to locate vmrun, please supply --vmrun option" unless vmrun
171
+ vmrun
172
+ end
173
+ end
174
+
175
+ end
@@ -0,0 +1,203 @@
1
+ require "yaml"
2
+ require "multi_json"
3
+ require "cf/cli"
4
+
5
+ require "micro-cf-plugin/help"
6
+ require "micro-cf-plugin/micro/micro"
7
+ require "micro-cf-plugin/micro/vmrun"
8
+ require "micro-cf-plugin/micro/switcher/base"
9
+ require "micro-cf-plugin/micro/switcher/darwin"
10
+ require "micro-cf-plugin/micro/switcher/linux"
11
+ require "micro-cf-plugin/micro/switcher/windows"
12
+
13
+ module CFMicro
14
+ class McfCommand < CF::CLI
15
+ MICRO_FILE = '~/.cf/micro.yml'
16
+
17
+ desc "Display Micro Cloud Foundry VM status"
18
+ group :micro
19
+ input :vmx, :argument => :required,
20
+ :desc => "Path to micro.vmx"
21
+ input :password, :argument => :optional,
22
+ :desc => "Cleartext password for guest VM vcap user"
23
+ def micro_status
24
+ mode = runner.offline? ? 'offline' : 'online'
25
+
26
+ line "Micro Cloud Foundry VM currently in #{b(mode)} mode"
27
+ # should the VMX path be unescaped?
28
+ line "VMX Path: #{c(runner.vmx, :good)}"
29
+ line "Domain: #{c(runner.domain, :good)}"
30
+ line "IP Address: #{c(runner.ip, :good)}"
31
+ end
32
+
33
+ desc "Micro Cloud Foundry offline mode"
34
+ group :micro
35
+ input :vmx, :argument => :required,
36
+ :desc => "Path to micro.vmx"
37
+ input :password, :argument => :optional,
38
+ :desc => "Cleartext password for guest VM vcap user"
39
+ def micro_offline
40
+ if !runner.nat?
41
+ if ask("Reconfigure MCF VM network to nat mode and reboot?", :default => true)
42
+ with_progress("Rebooting MCF VM") do
43
+ runner.reset_to_nat!
44
+ end
45
+ else
46
+ fail "Aborted"
47
+ end
48
+ end
49
+
50
+ with_progress("Setting MCF VM to offline mode") do
51
+ runner.offline!
52
+ end
53
+
54
+ with_progress("Setting host DNS server") do
55
+ runner.set_host_dns!
56
+ end
57
+ end
58
+
59
+ desc "Micro Cloud Foundry online mode"
60
+ group :micro
61
+ input :vmx, :argument => :required,
62
+ :desc => "Path to micro.vmx"
63
+ input :password, :argument => :optional,
64
+ :desc => "Cleartext password for guest VM vcap user"
65
+ def micro_online
66
+ runner
67
+ with_progress("Unsetting host DNS server") do
68
+ runner.unset_host_dns!
69
+ end
70
+
71
+ with_progress("Setting MCF VM to online mode") do
72
+ runner.online!
73
+ end
74
+ end
75
+
76
+ def runner
77
+ return @runner if @runner
78
+
79
+ config = build_config
80
+ @runner = switcher(config)
81
+ check_vm_running
82
+ store_config(config)
83
+
84
+ @runner
85
+ end
86
+
87
+ def check_vm_running
88
+ unless runner.running?
89
+ if ask("MCF VM is not running. Do you want to start it?", :default => true)
90
+ with_progress("Starting MCF VM") do
91
+ runner.start!
92
+ end
93
+ else
94
+ fail "MCF VM needs to be running."
95
+ end
96
+ end
97
+
98
+ unless runner.ready?
99
+ fail "MCF VM initial setup needs to be completed before using 'cf micro'"
100
+ end
101
+ end
102
+
103
+ def switcher(config)
104
+ case McfCommand.platform
105
+ when :darwin
106
+ CFMicro::Switcher::Darwin.new(config)
107
+ when :linux
108
+ CFMicro::Switcher::Linux.new(config)
109
+ when :windows
110
+ CFMicro::Switcher::Windows.new(config)
111
+ when :dummy # for testing only
112
+ CFMicro::Switcher::Dummy.new(config)
113
+ else
114
+ fail "unsupported platform: #{McfCommand.platform}"
115
+ end
116
+ end
117
+
118
+ # Returns the configuration needed to run the micro related subcommands.
119
+ # First loads saved config from file (if there is any), then overrides
120
+ # loaded values with command line arguments, and finally tries to guess
121
+ # in case neither was used:
122
+ # vmx location of micro.vmx file
123
+ # vmrun location of vmrun command
124
+ # password password for vcap user (in the guest vm)
125
+ # platform current platform
126
+ def build_config
127
+ conf = micro # returns {} if there isn't a saved config
128
+
129
+ override(conf, :vmx, true) do
130
+ locate_vmx(McfCommand.platform)
131
+ end
132
+
133
+ override(conf, :vmrun, true) do
134
+ CFMicro::VMrun.locate(McfCommand.platform)
135
+ end
136
+
137
+ override(conf, :password) do
138
+ ask("Please enter your MCF VM password (vcap user) password", :echo => "*")
139
+ end
140
+
141
+ conf[:platform] = McfCommand.platform
142
+
143
+ conf
144
+ end
145
+
146
+ # Save the cleartext password if --save is supplied.
147
+ # Note: it is due to vix we have to use a cleartext password :(
148
+ # Only if --password is used and not --save is the password deleted from the
149
+ # config file before it is stored to disk.
150
+ def store_config(config)
151
+ if input[:save]
152
+ warn("cleartext password saved in: #{MICRO_FILE}")
153
+ end
154
+
155
+ store_micro(config)
156
+ end
157
+
158
+ # override with command line arguments and yield the block in case the option isn't set
159
+ def override(config, option, escape=false, &blk)
160
+ # override if given on the command line
161
+ if opt = input[option]
162
+ opt = CFMicro.escape_path(opt) if escape
163
+ config[option] = opt
164
+ end
165
+ config[option] = yield unless config[option]
166
+ end
167
+
168
+ def locate_vmx(platform)
169
+ paths = YAML.load_file(CFMicro.config_file('paths.yml'))
170
+ vmx_paths = paths[platform.to_s]['vmx']
171
+ vmx = CFMicro.locate_file('micro.vmx', 'micro', vmx_paths)
172
+ fail "Unable to locate micro.vmx, please supply --vmx option" unless vmx
173
+ vmx
174
+ end
175
+
176
+ def self.platform
177
+ case RUBY_PLATFORM
178
+ when /darwin/ # x86_64-darwin11.2.0
179
+ :darwin
180
+ when /linux/ # x86_64-linux
181
+ :linux
182
+ when /mingw|mswin32|cygwin/ # i386-mingw32
183
+ :windows
184
+ else
185
+ RUBY_PLATFORM
186
+ end
187
+ end
188
+
189
+ def micro
190
+ micro_file = File.expand_path(MICRO_FILE)
191
+ return {} unless File.exists? micro_file
192
+ contents = File.read(micro_file).strip
193
+ MultiJson.load(contents)
194
+ end
195
+
196
+ def store_micro(micro)
197
+ micro_file = File.expand_path(MICRO_FILE)
198
+ File.open(micro_file, 'w') do |file|
199
+ file.write(MultiJson.dump(micro))
200
+ end
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,3 @@
1
+ module CFMicro
2
+ VERSION = "0.1.0.rc1".freeze
3
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'micro-cf-plugin/plugin'
3
+
4
+ describe CFMicro::McfCommand do
5
+ describe 'micro_status' do
6
+ shared_examples 'micro common inputs' do
7
+ describe 'inputs' do
8
+ subject { command.inputs }
9
+ it { expect(subject[:vmx][:description]).to eq "Path to micro.vmx" }
10
+ it { expect(subject[:password][:description]).to eq "Cleartext password for guest VM vcap user" }
11
+ end
12
+
13
+ describe 'arguments' do
14
+ subject { command.arguments }
15
+
16
+ it 'has the correct argument order' do
17
+ should eq([
18
+ {:type => :required, :value => nil, :name => :vmx},
19
+ {:type => :optional, :value => nil, :name => :password}
20
+ ])
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '#metadata' do
26
+ let(:command) { Mothership.commands[:micro_status] }
27
+
28
+ include_examples 'micro common inputs'
29
+
30
+ describe 'command' do
31
+ subject { command }
32
+
33
+ its(:description) { should eq "Display Micro Cloud Foundry VM status" }
34
+ it { expect(Mothership::Help.group(:micro)).to include(subject) }
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#micro_offline' do
40
+ describe 'metadata' do
41
+ let(:command) { Mothership.commands[:micro_offline] }
42
+
43
+ include_examples 'micro common inputs'
44
+
45
+ describe 'command' do
46
+ subject { command }
47
+
48
+ its(:description) { should eq "Micro Cloud Foundry offline mode" }
49
+ it { expect(Mothership::Help.group(:micro)).to include(subject) }
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '#micro_online' do
55
+ describe 'metadata' do
56
+ let(:command) { Mothership.commands[:micro_online] }
57
+
58
+ include_examples 'micro common inputs'
59
+
60
+ describe 'command' do
61
+ subject { command }
62
+
63
+ its(:description) { should eq "Micro Cloud Foundry online mode" }
64
+ it { expect(Mothership::Help.group(:micro)).to include(subject) }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ SPEC_ROOT = File.dirname(__FILE__).freeze
2
+
3
+ require "rspec"
4
+ require "cf"
5
+ require "cfoundry"
6
+ require "cfoundry/test_support"
7
+
8
+ RSpec.configure do |c|
9
+ c.include Fake::FakeMethods
10
+ c.mock_with :rr
11
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micro-cf-plugin
3
+ version: !ruby/object:Gem::Version
4
+ hash: 140091367
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ - rc
11
+ - 1
12
+ version: 0.1.0.rc1
13
+ platform: ruby
14
+ authors:
15
+ - Alex Suraci
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2013-03-18 00:00:00 Z
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rake
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 25
31
+ segments:
32
+ - 0
33
+ - 9
34
+ version: "0.9"
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 21
46
+ segments:
47
+ - 2
48
+ - 11
49
+ version: "2.11"
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: webmock
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 29
61
+ segments:
62
+ - 1
63
+ - 9
64
+ version: "1.9"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rr
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 15
76
+ segments:
77
+ - 1
78
+ - 0
79
+ version: "1.0"
80
+ type: :development
81
+ version_requirements: *id004
82
+ description:
83
+ email:
84
+ - asuraci@vmware.com
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files: []
90
+
91
+ files:
92
+ - Rakefile
93
+ - lib/micro-cf-plugin/errors.rb
94
+ - lib/micro-cf-plugin/help.rb
95
+ - lib/micro-cf-plugin/micro/micro.rb
96
+ - lib/micro-cf-plugin/micro/switcher/base.rb
97
+ - lib/micro-cf-plugin/micro/switcher/darwin.rb
98
+ - lib/micro-cf-plugin/micro/switcher/dummy.rb
99
+ - lib/micro-cf-plugin/micro/switcher/linux.rb
100
+ - lib/micro-cf-plugin/micro/switcher/windows.rb
101
+ - lib/micro-cf-plugin/micro/vmrun.rb
102
+ - lib/micro-cf-plugin/plugin.rb
103
+ - lib/micro-cf-plugin/version.rb
104
+ - config/offline.conf
105
+ - config/paths.yml
106
+ - config/refresh_ip.rb
107
+ - spec/plugin_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: http://cloudfoundry.com/
110
+ licenses: []
111
+
112
+ post_install_message:
113
+ rdoc_options: []
114
+
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">"
130
+ - !ruby/object:Gem::Version
131
+ hash: 25
132
+ segments:
133
+ - 1
134
+ - 3
135
+ - 1
136
+ version: 1.3.1
137
+ requirements: []
138
+
139
+ rubyforge_project: micro-cf-plugin
140
+ rubygems_version: 1.8.24
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: Provides a fake tunnel command that tells you to install the real plugin.
144
+ test_files:
145
+ - spec/plugin_spec.rb
146
+ - spec/spec_helper.rb