Class: VMC::Micro::Switcher::Base

Inherits:
Object
  • Object
show all
Includes:
Interactive
Defined in:
lib/vmc/micro/switcher/base.rb

Direct Known Subclasses

Darwin, Dummy, Linux, Windows

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vmc/micro/switcher/base.rb', line 7

def initialize(config)
  @config = config

  @vmrun = VMC::Micro::VMrun.new(config)
  unless @vmrun.running?
    if ask("Micro Cloud Foundry VM is not running. Do you want to start it?", :choices => ['y', 'n']) == 'y'
      display "Starting Micro Cloud Foundry VM: ", false
      @vmrun.start
      say "done".green
    else
      err "Micro Cloud Foundry VM needs to be running."
    end
  end

  err "Micro Cloud Foundry VM initial setup needs to be completed before using 'vmc micro'" unless @vmrun.ready?
end

Instance Method Details

#offlineObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vmc/micro/switcher/base.rb', line 24

def offline
  unless @vmrun.offline?
    # save online connection type so we can restore it later
    @config['online_connection_type'] = @vmrun.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!
    say "done".green
    display "Setting host DNS server: ", false

    @config['domain'] = @vmrun.domain
    @config['ip'] = @vmrun.ip
    set_nameserver(@config['domain'], @config['ip'])
    say "done".green
  else
    say "Micro Cloud Foundry VM already in offline mode".yellow
  end
end

#onlineObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vmc/micro/switcher/base.rb', line 54

def online
  if @vmrun.offline?
    current_connection_type = @vmrun.connection_type
    @config['online_connection_type'] ||= 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)
    @config['domain'] ||= @vmrun.domain
    @config['ip'] ||= @vmrun.ip
    unset_nameserver(@config['domain'], @config['ip'])
    say "done".green

    display "Setting Micro Cloud Foundry VM to online mode: ", false
    @vmrun.online!
    say "done".green
  else
    say "Micro Cloud Foundry already in online mode".yellow
  end
end

#statusObject



87
88
89
90
91
92
93
94
# File 'lib/vmc/micro/switcher/base.rb', line 87

def status
  mode = @vmrun.offline? ? 'offline' : 'online'
  say "Micro Cloud Foundry VM currently in #{mode.green} mode"
  # should the VMX path be unescaped?
  say "VMX Path: #{@vmrun.vmx}"
  say "Domain: #{@vmrun.domain.green}"
  say "IP Address: #{@vmrun.ip.green}"
end