Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated micro helper with linux support

Change-Id: Ib0d448ff135a834b5f943d13bd784fcf99117e8a
  • Loading branch information...
commit 2052a7fed95a6f4c952948978d599e587298cd09 1 parent 85c5922
@pmenglund pmenglund authored
View
1  config/micro/paths.yml
@@ -1,6 +1,7 @@
darwin:
vmrun:
- "/Applications/VMware Fusion.app/Contents/Library/"
+ - "/Applications/Fusion.app/Contents/Library/"
vmx:
- "~/Documents/Virtual Machines.localized/"
- "~/Documents/Virtual Machines/"
View
1  lib/cli.rb
@@ -10,6 +10,7 @@ module Micro
module Switcher
autoload :Base, "#{ROOT}/vmc/micro/switcher/base"
autoload :Darwin, "#{ROOT}/vmc/micro/switcher/darwin"
+ autoload :Dummy, "#{ROOT}/vmc/micro/switcher/dummy"
autoload :Linux, "#{ROOT}/vmc/micro/switcher/linux"
autoload :Windows, "#{ROOT}/vmc/micro/switcher/windows"
end
View
6 lib/cli/commands/micro.rb
@@ -28,9 +28,11 @@ def switcher(config)
when :darwin
switcher = VMC::Micro::Switcher::Darwin.new(config)
when :linux
- switcher = ::Micro::Switcher::Linux.new(config)
+ switcher = VMC::Micro::Switcher::Linux.new(config)
when :windows
- switcher = ::Micro::Switcher::Windows.new(config)
+ switcher = VMC::Micro::Switcher::Windows.new(config)
+ when :dummy # for testing only
+ switcher = VMC::Micro::Switcher::Dummy.new(config)
else
err "unsupported platform: #{Micro.platform}"
end
View
2  lib/cli/usage.rb
@@ -93,7 +93,7 @@ def command_usage
Micro Cloud Foundry
micro status Display Micro Cloud Foundry VM status
- mciro offline Configure Micro Cloud Foundry VM for offline mode
+ micro offline Configure Micro Cloud Foundry VM for offline mode
micro online Configure Micro Cloud Foundry VM for online mode
[--vmx file] Path to micro.vmx
[--vmrun executable] Path to vmrun executable
View
2  lib/vmc/micro.rb
@@ -14,7 +14,7 @@ def escape_path(path)
return path
end
else
- return path.sub(' ', '\ ')
+ return path.gsub(' ', '\ ')
end
end
View
54 lib/vmc/micro/switcher/base.rb
@@ -26,7 +26,16 @@ def offline
# save online connection type so we can restore it later
@config['online_connection_type'] = @vmrun.connection_type
- validate_nat(@config['online_connection_type'])
+ if (@config['online_connection_type'] != 'nat')
+ if ask("Reconfigure Micro Cloud Foundry VM network to nat mode and reboot?", :choices => ['y', 'n']) == 'y'
+ display "Rebooting Micro Cloud Foundry VM: ", false
+ @vmrun.connection_type = 'nat'
+ @vmrun.reset
+ say "done".green
+ else
+ err "Aborted"
+ end
+ end
display "Setting Micro Cloud Foundry VM to offline mode: ", false
@vmrun.offline!
@@ -47,7 +56,18 @@ def online
current_connection_type = @vmrun.connection_type
@config['online_connection_type'] ||= current_connection_type
- restore_network(current_connection_type)
+ if (@config['online_connection_type'] != current_connection_type)
+ # TODO handle missing connection type in saved config
+ question = "Reconfigure Micro Cloud Foundry VM network to #{@config['online_connection_type']} mode and reboot?"
+ if ask(question, :choices => ['y', 'n']) == 'y'
+ display "Rebooting Micro Cloud Foundry VM: ", false
+ @vmrun.connection_type = @config['online_connection_type']
+ @vmrun.reset
+ say "done".green
+ else
+ err "Aborted"
+ end
+ end
display "Unsetting host DNS server: ", false
# TODO handle missing domain and ip in saved config (look at the VM)
@@ -74,34 +94,4 @@ def status
end
end
- private
-
- def validate_nat(current_connection_type)
- if (current_connection_type != 'nat')
- if ask("Reconfigure Micro Cloud Foundry VM network to nat mode and reboot?", :choices => ['y', 'n']) == 'y'
- display "Rebooting Micro Cloud Foundry VM: ", false
- @vmrun.connection_type = 'nat'
- @vmrun.reset
- say "done".green
- else
- err "Aborted"
- end
- end
- end
-
- def restore_network(current_connection_type)
- if (@config['online_connection_type'] != current_connection_type)
- # TODO handle missing connection type in saved config
- question = "Reconfigure Micro Cloud Foundry VM network to #{@config['online_connection_type']} mode and reboot?"
- if ask(question, :choices => ['y', 'n']) == 'y'
- display "Rebooting Micro Cloud Foundry VM: ", false
- @vmrun.connection_type = @config['online_connection_type']
- @vmrun.reset
- say "done".green
- else
- err "Aborted"
- end
- end
- end
-
end
View
15 lib/vmc/micro/switcher/dummy.rb
@@ -0,0 +1,15 @@
+# only used for testing
+module VMC::Micro::Switcher
+
+ class Dummy < Base
+ def adminrun(command)
+ end
+
+ def set_nameserver(domain, ip)
+ end
+
+ def unset_nameserver(domain, ip)
+ end
+ end
+
+end
View
9 lib/vmc/micro/switcher/linux.rb
@@ -2,13 +2,14 @@ module VMC::Micro::Switcher
class Linux < Base
def set_nameserver(domain, ip)
- puts "Not implemented yet, need to set #{ip} as nameserver in resolv.conf"
- #run_command("sudo", "sed -i'.backup' '1 i nameserver #{ip}' /etc/resolv.conf")
+ VMC::Micro.run_command("sudo", "sed -i'.backup' '1 i nameserver #{ip}' /etc/resolv.conf")
+ # lock resolv.conf so Network Manager doesn't clear out the file when offline
+ VMC::Micro.run_command("sudo", "chattr +i /etc/resolv.conf")
end
def unset_nameserver(domain, ip)
- puts "Not implemented yet, need to unset #{ip} in resolv.conf"
- #run_command("sudo", "sed -i'.backup' '/#{ip}/d' /etc/resolv.conf")
+ VMC::Micro.run_command("sudo", "chattr -i /etc/resolv.conf")
+ VMC::Micro.run_command("sudo", "sed -i'.backup' '/#{ip}/d' /etc/resolv.conf")
end
end
View
22 spec/unit/switcher_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe VMC::Micro::Switcher::Base do
+ it "should go online" do
+ vmrun = double(VMC::Micro::VMrun)
+ vmrun.should_receive(:running?).and_return(true)
+ vmrun.should_receive(:ready?).and_return(true)
+ vmrun.should_receive(:offline?).and_return(false)
+ VMC::Micro::VMrun.should_receive(:new).and_return(vmrun)
+ switcher = VMC::Micro::Switcher::Dummy.new({})
+ switcher.online
+ end
+ it "should go offline" do
+ vmrun = double(VMC::Micro::VMrun)
+ vmrun.should_receive(:running?).and_return(true)
+ vmrun.should_receive(:ready?).and_return(true)
+ vmrun.should_receive(:offline?).and_return(true)
+ VMC::Micro::VMrun.should_receive(:new).and_return(vmrun)
+ switcher = VMC::Micro::Switcher::Dummy.new({})
+ switcher.offline
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.