Class: CFMicro::Switcher::Darwin

Inherits:
Base
  • Object
show all
Defined in:
lib/micro/switcher/darwin.rb

Instance Method Summary collapse

Methods inherited from Base

#domain, #initialize, #ip, #nat?, #offline!, #offline?, #online!, #ready?, #reset_to_nat!, #running?, #set_host_dns!, #start!, #unset_host_dns!, #vmx

Constructor Details

This class inherits a constructor from CFMicro::Switcher::Base

Instance Method Details

#adminrun(command) ⇒ Object


6
7
8
# File 'lib/micro/switcher/darwin.rb', line 6

def adminrun(command)
  CFMicro.run_command("osascript", "-e 'do shell script \"#{command}\" with administrator privileges'")
end

#set_nameserver(domain, ip) ⇒ Object


10
11
12
13
# File 'lib/micro/switcher/darwin.rb', line 10

def set_nameserver(domain, ip)
  File.open("/tmp/#{domain}", 'w') { |file| file.write("nameserver #{ip}") }
  adminrun("mkdir -p /etc/resolver;mv /tmp/#{domain} /etc/resolver/")
end

#unset_nameserver(domain, ip) ⇒ Object

Raises:


15
16
17
18
# File 'lib/micro/switcher/darwin.rb', line 15

def unset_nameserver(domain, ip)
  raise CFMicro::MCFError, "domain missing" unless domain
  adminrun("rm -f /etc/resolver/#{domain}")
end