Class: JDC::Micro::Switcher::Base
- Inherits:
-
Object
- Object
- JDC::Micro::Switcher::Base
show all
- Includes:
- Interactive
- Defined in:
- lib/jdc/micro/switcher/base.rb
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/jdc/micro/switcher/base.rb', line 7
def initialize(config)
@config = config
@vmrun = JDC::Micro::VMrun.new(config)
unless @vmrun.running?
if ask("JingDong Cloud VM is not running. Do you want to start it?", :choices => ['y', 'n']) == 'y'
display "Starting JingDong Cloud VM: ", false
@vmrun.start
say "done".green
else
err "JingDong Cloud VM needs to be running."
end
end
err "JingDong Cloud VM initial setup needs to be completed before using 'jdc micro'" unless @vmrun.ready?
end
|
Instance Method Details
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/jdc/micro/switcher/base.rb', line 24
def offline
unless @vmrun.offline?
@config['online_connection_type'] = @vmrun.connection_type
if (@config['online_connection_type'] != 'nat')
if ask("Reconfigure JingDong Cloud VM network to nat mode and reboot?", :choices => ['y', 'n']) == 'y'
display "Rebooting JingDong Cloud VM: ", false
@vmrun.connection_type = 'nat'
@vmrun.reset
say "done".green
else
err "Aborted"
end
end
display "Setting JingDong Cloud 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 "JingDong Cloud VM already in offline mode".yellow
end
end
|
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/jdc/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)
question = "Reconfigure JingDong Cloud VM network to #{@config['online_connection_type']} mode and reboot?"
if ask(question, :choices => ['y', 'n']) == 'y'
display "Rebooting JingDong Cloud 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
@config['domain'] ||= @vmrun.domain
@config['ip'] ||= @vmrun.ip
unset_nameserver(@config['domain'], @config['ip'])
say "done".green
display "Setting JingDong Cloud VM to online mode: ", false
@vmrun.online!
say "done".green
else
say "JingDong Cloud already in online mode".yellow
end
end
|
87
88
89
90
91
92
93
94
|
# File 'lib/jdc/micro/switcher/base.rb', line 87
def status
mode = @vmrun.offline? ? 'offline' : 'online'
say "JingDong Cloud VM currently in #{mode.green} mode"
say "VMX Path: #{@vmrun.vmx}"
say "Domain: #{@vmrun.domain.green}"
say "IP Address: #{@vmrun.ip.green}"
end
|