tac 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +24 -0
- data/README.md +102 -0
- data/Rakefile +101 -0
- data/bin/tac +6 -0
- data/caldecott_helper/Gemfile +10 -0
- data/caldecott_helper/Gemfile.lock +48 -0
- data/caldecott_helper/server.rb +43 -0
- data/config/clients.yml +17 -0
- data/config/micro/offline.conf +2 -0
- data/config/micro/paths.yml +22 -0
- data/config/micro/refresh_ip.rb +20 -0
- data/lib/cli/commands/admin.rb +108 -0
- data/lib/cli/commands/apps.rb +1133 -0
- data/lib/cli/commands/base.rb +232 -0
- data/lib/cli/commands/manifest.rb +56 -0
- data/lib/cli/commands/micro.rb +115 -0
- data/lib/cli/commands/misc.rb +129 -0
- data/lib/cli/commands/services.rb +242 -0
- data/lib/cli/commands/user.rb +65 -0
- data/lib/cli/config.rb +173 -0
- data/lib/cli/console_helper.rb +160 -0
- data/lib/cli/core_ext.rb +122 -0
- data/lib/cli/errors.rb +19 -0
- data/lib/cli/frameworks.rb +276 -0
- data/lib/cli/manifest_helper.rb +341 -0
- data/lib/cli/runner.rb +547 -0
- data/lib/cli/services_helper.rb +92 -0
- data/lib/cli/tunnel_helper.rb +332 -0
- data/lib/cli/usage.rb +115 -0
- data/lib/cli/version.rb +7 -0
- data/lib/cli/zip_util.rb +77 -0
- data/lib/cli.rb +47 -0
- data/lib/vmc/client.rb +573 -0
- data/lib/vmc/const.rb +24 -0
- data/lib/vmc/micro/switcher/base.rb +97 -0
- data/lib/vmc/micro/switcher/darwin.rb +19 -0
- data/lib/vmc/micro/switcher/dummy.rb +15 -0
- data/lib/vmc/micro/switcher/linux.rb +16 -0
- data/lib/vmc/micro/switcher/windows.rb +31 -0
- data/lib/vmc/micro/vmrun.rb +158 -0
- data/lib/vmc/micro.rb +56 -0
- data/lib/vmc.rb +3 -0
- metadata +295 -0
@@ -0,0 +1,341 @@
|
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
|
4
|
+
module VMC::Cli::ManifestHelper
|
5
|
+
include VMC::Cli::ServicesHelper
|
6
|
+
|
7
|
+
DEFAULTS = {
|
8
|
+
"url" => "${name}.${target-base}",
|
9
|
+
"mem" => "128M",
|
10
|
+
"instances" => 1
|
11
|
+
}
|
12
|
+
|
13
|
+
MANIFEST = "manifest.yml"
|
14
|
+
|
15
|
+
YES_SET = Set.new(["y", "Y", "yes", "YES"])
|
16
|
+
|
17
|
+
# take a block and call it once for each app to push/update.
|
18
|
+
# with @application and @app_info set appropriately
|
19
|
+
def each_app(panic=true)
|
20
|
+
if @manifest and all_apps = @manifest["applications"]
|
21
|
+
where = File.expand_path(@path)
|
22
|
+
single = false
|
23
|
+
|
24
|
+
all_apps.each do |path, info|
|
25
|
+
app = File.expand_path("../" + path, manifest_file)
|
26
|
+
if where.start_with?(app)
|
27
|
+
@application = app
|
28
|
+
@app_info = info
|
29
|
+
yield info["name"]
|
30
|
+
single = true
|
31
|
+
break
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
unless single
|
36
|
+
if where == File.expand_path("../", manifest_file)
|
37
|
+
ordered_by_deps(all_apps).each do |path, info|
|
38
|
+
app = File.expand_path("../" + path, manifest_file)
|
39
|
+
@application = app
|
40
|
+
@app_info = info
|
41
|
+
yield info["name"]
|
42
|
+
end
|
43
|
+
else
|
44
|
+
err "Path '#{@path}' is not known to manifest '#{manifest_file}'."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
@application = @path
|
49
|
+
@app_info = @manifest
|
50
|
+
if @app_info
|
51
|
+
yield @app_info["name"]
|
52
|
+
elsif panic
|
53
|
+
err "No applications."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
nil
|
58
|
+
ensure
|
59
|
+
@application = nil
|
60
|
+
@app_info = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def interact(many=false)
|
64
|
+
@manifest ||= {}
|
65
|
+
configure_app(many)
|
66
|
+
end
|
67
|
+
|
68
|
+
def target_manifest
|
69
|
+
@options[:manifest] || MANIFEST
|
70
|
+
end
|
71
|
+
|
72
|
+
def save_manifest(save_to = nil)
|
73
|
+
save_to ||= target_manifest
|
74
|
+
|
75
|
+
File.open(save_to, "w") do |f|
|
76
|
+
f.write @manifest.to_yaml
|
77
|
+
end
|
78
|
+
|
79
|
+
say "Manifest written to #{save_to}."
|
80
|
+
end
|
81
|
+
|
82
|
+
def configure_app(many=false)
|
83
|
+
name = manifest("name") ||
|
84
|
+
set(ask("Application Name", :default => manifest("name")), "name")
|
85
|
+
if manifest "framework"
|
86
|
+
framework = VMC::Cli::Framework.lookup_by_framework manifest("framework","name")
|
87
|
+
else
|
88
|
+
framework = detect_framework
|
89
|
+
set framework.name, "framework", "name"
|
90
|
+
set(
|
91
|
+
{ "mem" => framework.mem,
|
92
|
+
"description" => framework.description,
|
93
|
+
"exec" => framework.exec
|
94
|
+
},
|
95
|
+
"framework",
|
96
|
+
"info"
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
default_runtime = manifest "runtime"
|
101
|
+
if not default_runtime
|
102
|
+
default_runtime = framework.default_runtime(@application)
|
103
|
+
set(detect_runtime(default_runtime), "runtime") if framework.prompt_for_runtime?
|
104
|
+
end
|
105
|
+
default_command = manifest "command"
|
106
|
+
set ask("Start Command", :default => default_command), "command" if framework.require_start_command?
|
107
|
+
|
108
|
+
url_template = manifest("url") || DEFAULTS["url"]
|
109
|
+
url_resolved = url_template.dup
|
110
|
+
resolve_lexically(url_resolved)
|
111
|
+
|
112
|
+
if !framework.require_url?
|
113
|
+
url_resolved = "None"
|
114
|
+
end
|
115
|
+
url = ask("Application Deployed URL", :default => url_resolved)
|
116
|
+
|
117
|
+
if url == url_resolved && url != "None"
|
118
|
+
url = url_template
|
119
|
+
end
|
120
|
+
|
121
|
+
# common error case is for prompted users to answer y or Y or yes or
|
122
|
+
# YES to this ask() resulting in an unintended URL of y. Special
|
123
|
+
# case this common error
|
124
|
+
url = url_resolved if YES_SET.member? url
|
125
|
+
|
126
|
+
if(url == "None")
|
127
|
+
url = nil
|
128
|
+
end
|
129
|
+
|
130
|
+
set url, "url"
|
131
|
+
|
132
|
+
default_mem = manifest("mem")
|
133
|
+
default_mem = framework.memory(manifest("runtime")) if not default_mem
|
134
|
+
set ask(
|
135
|
+
"Memory reservation",
|
136
|
+
:default =>
|
137
|
+
default_mem ||
|
138
|
+
DEFAULTS["mem"],
|
139
|
+
:choices => ["128M", "256M", "512M", "1G", "2G"]
|
140
|
+
), "mem"
|
141
|
+
|
142
|
+
set ask(
|
143
|
+
"How many instances?",
|
144
|
+
:default => manifest("instances") || DEFAULTS["instances"]
|
145
|
+
), "instances"
|
146
|
+
|
147
|
+
unless manifest "services"
|
148
|
+
user_services = client.services
|
149
|
+
user_services.sort! {|a, b| a[:name] <=> b[:name] }
|
150
|
+
|
151
|
+
unless user_services.empty?
|
152
|
+
if ask "Bind existing services to '#{name}'?", :default => false
|
153
|
+
bind_services(user_services)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
services = client.services_info
|
158
|
+
unless services.empty?
|
159
|
+
if ask "Create services to bind to '#{name}'?", :default => false
|
160
|
+
create_services(services.values.collect(&:keys).flatten)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
if many and ask("Configure for another application?", :default => false)
|
166
|
+
@application = ask "Application path?"
|
167
|
+
configure_app
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def set(what, *where)
|
172
|
+
where.unshift "applications", @application
|
173
|
+
|
174
|
+
which = @manifest
|
175
|
+
where.each_with_index do |k, i|
|
176
|
+
if i + 1 == where.size
|
177
|
+
which[k] = what
|
178
|
+
else
|
179
|
+
which = (which[k] ||= {})
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
what
|
184
|
+
end
|
185
|
+
|
186
|
+
# Detect the appropriate framework.
|
187
|
+
def detect_framework(prompt_ok = true)
|
188
|
+
framework = VMC::Cli::Framework.detect(@application, frameworks_info)
|
189
|
+
framework_correct = ask("Detected a #{framework}, is this correct?", :default => true) if prompt_ok && framework
|
190
|
+
if prompt_ok && (framework.nil? || !framework_correct)
|
191
|
+
display "#{"[WARNING]".yellow} Can't determine the Application Type." unless framework
|
192
|
+
framework = nil if !framework_correct
|
193
|
+
framework = VMC::Cli::Framework.lookup(
|
194
|
+
ask(
|
195
|
+
"Select Application Type",
|
196
|
+
:indexed => true,
|
197
|
+
:default => framework,
|
198
|
+
:choices => VMC::Cli::Framework.known_frameworks(frameworks_info)
|
199
|
+
)
|
200
|
+
)
|
201
|
+
display "Selected #{framework}"
|
202
|
+
end
|
203
|
+
if framework_correct && framework.to_s == "Java Web Application"
|
204
|
+
framework = VMC::Cli::Framework.lookup(
|
205
|
+
ask(
|
206
|
+
"Select Java Web Application Server",
|
207
|
+
:indexed => true,
|
208
|
+
:default => "JavaWeb_tongweb",
|
209
|
+
:choices => VMC::Cli::Framework.javaweb_appservers
|
210
|
+
)
|
211
|
+
)
|
212
|
+
display "Selected #{framework}"
|
213
|
+
end
|
214
|
+
framework
|
215
|
+
end
|
216
|
+
|
217
|
+
# Detect the appropriate runtime.
|
218
|
+
def detect_runtime(default, prompt_ok=true)
|
219
|
+
runtime = nil
|
220
|
+
runtime_keys=[]
|
221
|
+
runtimes_info.keys.each {|runtime_key| runtime_keys << runtime_key.dup }
|
222
|
+
runtime_keys.sort!
|
223
|
+
if prompt_ok
|
224
|
+
runtime = ask(
|
225
|
+
"Select Runtime",
|
226
|
+
:indexed => true,
|
227
|
+
:default => default,
|
228
|
+
:choices => runtime_keys
|
229
|
+
)
|
230
|
+
display "Selected #{runtime}"
|
231
|
+
end
|
232
|
+
runtime
|
233
|
+
end
|
234
|
+
|
235
|
+
def bind_services(user_services, chosen = 0)
|
236
|
+
svcname = ask(
|
237
|
+
"Which one?",
|
238
|
+
:indexed => true,
|
239
|
+
:choices => user_services.collect { |p| p[:name] })
|
240
|
+
|
241
|
+
svc = user_services.find { |p| p[:name] == svcname }
|
242
|
+
|
243
|
+
set svc[:vendor], "services", svcname, "type"
|
244
|
+
|
245
|
+
if chosen + 1 < user_services.size && ask("Bind another?", :default => false)
|
246
|
+
bind_services(user_services, chosen + 1)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def create_services(services)
|
251
|
+
svcs = services.collect(&:to_s).sort!
|
252
|
+
|
253
|
+
configure_service(
|
254
|
+
ask(
|
255
|
+
"What kind of service?",
|
256
|
+
:indexed => true,
|
257
|
+
:choices => svcs
|
258
|
+
)
|
259
|
+
)
|
260
|
+
|
261
|
+
if ask "Create another?", :default => false
|
262
|
+
create_services(services)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def configure_service(vendor)
|
267
|
+
if "mysql" == vendor
|
268
|
+
databaseChoice = %w[internal_database external_database]
|
269
|
+
dbflag = ask("which type would you like to choice?", {
|
270
|
+
:indexed => true,
|
271
|
+
:choices => databaseChoice
|
272
|
+
}
|
273
|
+
)
|
274
|
+
dbsize = ask "max_db_size"
|
275
|
+
regix = /^[1-9]\d*$/
|
276
|
+
err "max_db_size required" unless dbsize
|
277
|
+
err "max_db_size must be int and max_db_size more than 0" unless regix.match(dbsize)
|
278
|
+
end
|
279
|
+
if "external_database" == dbflag
|
280
|
+
dbjndi = ask "jndi name"
|
281
|
+
dburl = ask "dburl"
|
282
|
+
dbuname = ask "dbusername "
|
283
|
+
dbpasswd = ask("dbpasswd", :echo => "*")
|
284
|
+
err "jndi required" unless dbjndi
|
285
|
+
err "dburl required" unless dburl
|
286
|
+
err "dbuname required" unless dbuname
|
287
|
+
err "dbpasswd required" unless dbpasswd
|
288
|
+
end
|
289
|
+
|
290
|
+
default_name = random_service_name(vendor)
|
291
|
+
name = ask "Specify the name of the service", :default => default_name
|
292
|
+
db_config = {
|
293
|
+
"dbflag" => dbflag,
|
294
|
+
"dbjndi" => dbjndi,
|
295
|
+
"dbuname" => dbuname,
|
296
|
+
"dbpasswd" => dbpasswd,
|
297
|
+
"dburl" => dburl,
|
298
|
+
"dbsize" => Integer(dbsize),
|
299
|
+
}
|
300
|
+
set vendor, "services", name, "type"
|
301
|
+
set db_config, "services", name, "db_config"
|
302
|
+
end
|
303
|
+
|
304
|
+
private
|
305
|
+
def ordered_by_deps(apps, abspaths = nil, processed = Set[])
|
306
|
+
unless abspaths
|
307
|
+
abspaths = {}
|
308
|
+
apps.each do |p, i|
|
309
|
+
ep = File.expand_path("../" + p, manifest_file)
|
310
|
+
abspaths[ep] = i
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
ordered = []
|
315
|
+
apps.each do |path, info|
|
316
|
+
epath = File.expand_path("../" + path, manifest_file)
|
317
|
+
|
318
|
+
if deps = info["depends-on"]
|
319
|
+
dep_apps = {}
|
320
|
+
deps.each do |dep|
|
321
|
+
edep = File.expand_path("../" + dep, manifest_file)
|
322
|
+
|
323
|
+
err "Circular dependency detected." if processed.include? edep
|
324
|
+
|
325
|
+
dep_apps[dep] = abspaths[edep]
|
326
|
+
end
|
327
|
+
|
328
|
+
processed.add(epath)
|
329
|
+
|
330
|
+
ordered += ordered_by_deps(dep_apps, abspaths, processed)
|
331
|
+
ordered << [path, info]
|
332
|
+
elsif not processed.include? epath
|
333
|
+
ordered << [path, info]
|
334
|
+
processed.add(epath)
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
ordered
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|