jdc 0.2.1.pre → 0.2.1
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 -1277
- data/README.md +102 -0
- data/bin/jdc +2 -12
- data/{lib/tunnel/helper-app → caldecott_helper}/server.rb +5 -5
- data/{lib/tunnel/config → config}/clients.yml +2 -2
- data/config/micro/paths.yml +22 -0
- data/config/micro/refresh_ip.rb +20 -0
- data/lib/cli/commands/admin.rb +58 -0
- data/lib/cli/commands/apps.rb +1129 -0
- data/lib/cli/commands/base.rb +228 -0
- data/lib/cli/commands/manifest.rb +56 -0
- data/lib/cli/commands/micro.rb +115 -0
- data/lib/cli/commands/misc.rb +126 -0
- data/lib/cli/commands/services.rb +178 -0
- data/lib/cli/commands/user.rb +14 -0
- data/lib/cli/config.rb +173 -0
- data/lib/cli/console_helper.rb +170 -0
- data/lib/cli/core_ext.rb +122 -0
- data/lib/cli/errors.rb +19 -0
- data/lib/cli/frameworks.rb +265 -0
- data/lib/cli/manifest_helper.rb +300 -0
- data/lib/cli/runner.rb +505 -0
- data/lib/cli/services_helper.rb +84 -0
- data/lib/cli/tunnel_helper.rb +332 -0
- data/lib/cli/usage.rb +86 -0
- data/lib/cli/version.rb +7 -0
- data/lib/cli/zip_util.rb +77 -0
- data/lib/cli.rb +53 -0
- data/lib/jdc/client.rb +457 -0
- data/lib/jdc/const.rb +25 -0
- data/lib/jdc/micro/switcher/base.rb +97 -0
- data/lib/{micro → jdc/micro}/switcher/darwin.rb +3 -5
- data/lib/{micro → jdc/micro}/switcher/dummy.rb +1 -1
- data/lib/jdc/micro/switcher/linux.rb +16 -0
- data/lib/{micro → jdc/micro}/switcher/windows.rb +5 -5
- data/lib/{micro → jdc/micro}/vmrun.rb +19 -26
- data/lib/{micro → jdc}/micro.rb +15 -15
- data/lib/jdc/signature/version.rb +27 -0
- data/lib/jdc/signer.rb +13 -0
- data/lib/jdc/timer.rb +12 -0
- data/lib/jdc.rb +2 -15
- metadata +210 -360
- data/Rakefile +0 -13
- data/lib/admin/README.md +0 -15
- data/lib/admin/curl.rb +0 -60
- data/lib/admin/guid.rb +0 -89
- data/lib/admin/plugin.rb +0 -6
- data/lib/admin/service_auth_token.rb +0 -94
- data/lib/admin/service_broker/add.rb +0 -47
- data/lib/admin/service_broker/service_brokers.rb +0 -24
- data/lib/admin/set_quota.rb +0 -44
- data/lib/console/README.md +0 -8
- data/lib/console/console.rb +0 -187
- data/lib/console/plugin.rb +0 -33
- data/lib/jdc/cli/app/app.rb +0 -43
- data/lib/jdc/cli/app/apps.rb +0 -87
- data/lib/jdc/cli/app/base.rb +0 -72
- data/lib/jdc/cli/app/delete.rb +0 -95
- data/lib/jdc/cli/app/deprecated.rb +0 -11
- data/lib/jdc/cli/app/env.rb +0 -78
- data/lib/jdc/cli/app/events.rb +0 -45
- data/lib/jdc/cli/app/files.rb +0 -137
- data/lib/jdc/cli/app/health.rb +0 -26
- data/lib/jdc/cli/app/instances.rb +0 -53
- data/lib/jdc/cli/app/logs.rb +0 -76
- data/lib/jdc/cli/app/push/create.rb +0 -108
- data/lib/jdc/cli/app/push/interactions.rb +0 -86
- data/lib/jdc/cli/app/push/sync.rb +0 -57
- data/lib/jdc/cli/app/push.rb +0 -103
- data/lib/jdc/cli/app/rename.rb +0 -35
- data/lib/jdc/cli/app/restart.rb +0 -31
- data/lib/jdc/cli/app/scale.rb +0 -63
- data/lib/jdc/cli/app/start.rb +0 -161
- data/lib/jdc/cli/app/stats.rb +0 -67
- data/lib/jdc/cli/app/stop.rb +0 -27
- data/lib/jdc/cli/domain/base.rb +0 -9
- data/lib/jdc/cli/domain/domains.rb +0 -40
- data/lib/jdc/cli/domain/map.rb +0 -55
- data/lib/jdc/cli/domain/unmap.rb +0 -56
- data/lib/jdc/cli/help.rb +0 -15
- data/lib/jdc/cli/interactive.rb +0 -105
- data/lib/jdc/cli/login_requirements.rb +0 -15
- data/lib/jdc/cli/organization/base.rb +0 -14
- data/lib/jdc/cli/organization/create.rb +0 -37
- data/lib/jdc/cli/organization/delete.rb +0 -63
- data/lib/jdc/cli/organization/org.rb +0 -45
- data/lib/jdc/cli/organization/orgs.rb +0 -30
- data/lib/jdc/cli/organization/rename.rb +0 -37
- data/lib/jdc/cli/populators/base.rb +0 -16
- data/lib/jdc/cli/populators/organization.rb +0 -32
- data/lib/jdc/cli/populators/populator_methods.rb +0 -64
- data/lib/jdc/cli/populators/space.rb +0 -33
- data/lib/jdc/cli/populators/target.rb +0 -13
- data/lib/jdc/cli/route/base.rb +0 -9
- data/lib/jdc/cli/route/delete.rb +0 -28
- data/lib/jdc/cli/route/map.rb +0 -68
- data/lib/jdc/cli/route/routes.rb +0 -26
- data/lib/jdc/cli/route/unmap.rb +0 -56
- data/lib/jdc/cli/service/base.rb +0 -9
- data/lib/jdc/cli/service/bind.rb +0 -44
- data/lib/jdc/cli/service/create.rb +0 -159
- data/lib/jdc/cli/service/delete.rb +0 -83
- data/lib/jdc/cli/service/rename.rb +0 -36
- data/lib/jdc/cli/service/service.rb +0 -42
- data/lib/jdc/cli/service/service_instance_helper.rb +0 -99
- data/lib/jdc/cli/service/services.rb +0 -111
- data/lib/jdc/cli/service/unbind.rb +0 -37
- data/lib/jdc/cli/space/base.rb +0 -29
- data/lib/jdc/cli/space/create.rb +0 -67
- data/lib/jdc/cli/space/delete.rb +0 -56
- data/lib/jdc/cli/space/rename.rb +0 -38
- data/lib/jdc/cli/space/space.rb +0 -66
- data/lib/jdc/cli/space/spaces.rb +0 -57
- data/lib/jdc/cli/space/switch.rb +0 -19
- data/lib/jdc/cli/start/base.rb +0 -41
- data/lib/jdc/cli/start/colors.rb +0 -13
- data/lib/jdc/cli/start/target.rb +0 -50
- data/lib/jdc/cli/start/target_prettifier.rb +0 -17
- data/lib/jdc/cli/start/targets.rb +0 -16
- data/lib/jdc/cli/user/base.rb +0 -30
- data/lib/jdc/cli/user/create.rb +0 -52
- data/lib/jdc/cli/user/passwd.rb +0 -37
- data/lib/jdc/cli/user/register.rb +0 -43
- data/lib/jdc/cli/user/users.rb +0 -32
- data/lib/jdc/cli.rb +0 -556
- data/lib/jdc/constants.rb +0 -11
- data/lib/jdc/errors.rb +0 -19
- data/lib/jdc/object_extensions.rb +0 -15
- data/lib/jdc/plugin.rb +0 -56
- data/lib/jdc/spacing.rb +0 -89
- data/lib/jdc/spec_helper.rb +0 -1
- data/lib/jdc/test_support.rb +0 -6
- data/lib/jdc/version.rb +0 -3
- data/lib/manifests/errors.rb +0 -35
- data/lib/manifests/loader/builder.rb +0 -39
- data/lib/manifests/loader/normalizer.rb +0 -145
- data/lib/manifests/loader/resolver.rb +0 -79
- data/lib/manifests/loader.rb +0 -31
- data/lib/manifests/manifests.rb +0 -344
- data/lib/manifests/plugin.rb +0 -140
- data/lib/micro/README.md +0 -9
- data/lib/micro/errors.rb +0 -4
- data/lib/micro/plugin.rb +0 -197
- data/lib/micro/switcher/base.rb +0 -79
- data/lib/micro/switcher/linux.rb +0 -16
- data/lib/tasks/gem_release.rake +0 -42
- data/lib/tunnel/README.md +0 -29
- data/lib/tunnel/helper-app/Gemfile +0 -10
- data/lib/tunnel/helper-app/Gemfile.lock +0 -48
- data/lib/tunnel/plugin.rb +0 -183
- data/lib/tunnel/tunnel.rb +0 -295
data/lib/manifests/manifests.rb
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
require "yaml"
|
|
2
|
-
require "set"
|
|
3
|
-
require "jdc/cli/service/create"
|
|
4
|
-
|
|
5
|
-
require "manifests/loader"
|
|
6
|
-
|
|
7
|
-
module JDCManifests
|
|
8
|
-
MANIFEST_FILE = "manifest.yml"
|
|
9
|
-
|
|
10
|
-
@@showed_manifest_usage = false
|
|
11
|
-
@@manifest = nil
|
|
12
|
-
|
|
13
|
-
def manifest
|
|
14
|
-
return @@manifest if @@manifest
|
|
15
|
-
|
|
16
|
-
if manifest_file && File.exists?(manifest_file)
|
|
17
|
-
@@manifest = load_manifest(manifest_file)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def save_manifest(save_to = manifest_file)
|
|
22
|
-
fail "No manifest to save!" unless @@manifest
|
|
23
|
-
|
|
24
|
-
File.open(save_to, "w") do |io|
|
|
25
|
-
YAML.dump(@@manifest, io)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# find the manifest file to work with
|
|
30
|
-
def manifest_file
|
|
31
|
-
return @manifest_file if @manifest_file
|
|
32
|
-
|
|
33
|
-
unless path = input[:manifest]
|
|
34
|
-
where = Dir.pwd
|
|
35
|
-
while true
|
|
36
|
-
if File.exists?(File.join(where, MANIFEST_FILE))
|
|
37
|
-
path = File.join(where, MANIFEST_FILE)
|
|
38
|
-
break
|
|
39
|
-
elsif File.basename(where) == "/"
|
|
40
|
-
path = nil
|
|
41
|
-
break
|
|
42
|
-
else
|
|
43
|
-
where = File.expand_path("../", where)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
return unless path
|
|
49
|
-
|
|
50
|
-
@manifest_file = File.expand_path(path)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# load and resolve a given manifest file
|
|
54
|
-
def load_manifest(file)
|
|
55
|
-
check_manifest! Loader.new(file, self).manifest
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def check_manifest!(manifest_hash, output = $stdout)
|
|
59
|
-
manifest_hash[:applications].each{ |app| check_attributes!(app, output) }
|
|
60
|
-
manifest_hash
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def check_attributes!(app, output = $stdout)
|
|
64
|
-
app.each do |k, v|
|
|
65
|
-
output.puts error_message_for_attribute(k) unless known_manifest_attributes.include? k
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def error_message_for_attribute(attribute)
|
|
70
|
-
"\e[31mWarning: #{attribute} is not a valid manifest attribute. Please " +
|
|
71
|
-
"remove this attribute from your manifest to get rid of this warning\e[0m"
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def known_manifest_attributes
|
|
75
|
-
[:applications, :buildpack, :command, :disk, :domain, :env,
|
|
76
|
-
:host, :inherit, :instances, :mem, :memory, :name,
|
|
77
|
-
:path, :properties, :runtime, :services, :stack]
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# dynamic symbol resolution
|
|
81
|
-
def resolve_symbol(sym)
|
|
82
|
-
case sym
|
|
83
|
-
when "target-url"
|
|
84
|
-
client_target
|
|
85
|
-
|
|
86
|
-
when "target-base"
|
|
87
|
-
target_base
|
|
88
|
-
|
|
89
|
-
when "random-word"
|
|
90
|
-
sprintf("%04x", rand(0x0100000))
|
|
91
|
-
|
|
92
|
-
when /^ask (.+)/
|
|
93
|
-
ask($1)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# find apps by an identifier, which may be either a tag, a name, or a path
|
|
98
|
-
def find_apps(identifier)
|
|
99
|
-
return [] unless manifest
|
|
100
|
-
|
|
101
|
-
apps = apps_by(:name, identifier)
|
|
102
|
-
|
|
103
|
-
if apps.empty?
|
|
104
|
-
apps = apps_by(:path, from_manifest(identifier))
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
apps
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# return all the apps described by the manifest
|
|
111
|
-
def all_apps
|
|
112
|
-
manifest[:applications]
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def current_apps
|
|
116
|
-
manifest[:applications].select do |app|
|
|
117
|
-
next unless app[:path]
|
|
118
|
-
from_manifest(app[:path]) == Dir.pwd
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# splits the user's input, resolving paths with the manifest,
|
|
123
|
-
# into internal/external apps
|
|
124
|
-
#
|
|
125
|
-
# internal apps are returned as their data in the manifest
|
|
126
|
-
#
|
|
127
|
-
# external apps are the strings that the user gave, to be
|
|
128
|
-
# passed along wholesale to the wrapped command
|
|
129
|
-
def apps_in_manifest(input = nil, use_name = true, &blk)
|
|
130
|
-
names_or_paths =
|
|
131
|
-
if input.has?(:apps)
|
|
132
|
-
# names may be given but be [], which will still cause
|
|
133
|
-
# interaction, so use #direct instead of #[] here
|
|
134
|
-
input.direct(:apps)
|
|
135
|
-
elsif input.has?(:app)
|
|
136
|
-
[input.direct(:app)]
|
|
137
|
-
elsif input.has?(:name)
|
|
138
|
-
[input.direct(:name)]
|
|
139
|
-
else
|
|
140
|
-
[]
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
internal = []
|
|
144
|
-
external = []
|
|
145
|
-
|
|
146
|
-
names_or_paths.each do |x|
|
|
147
|
-
if x.is_a?(String)
|
|
148
|
-
if x =~ %r([/\\])
|
|
149
|
-
apps = find_apps(File.expand_path(x))
|
|
150
|
-
|
|
151
|
-
if apps.empty?
|
|
152
|
-
fail("Path #{b(x)} is not present in manifest #{b(relative_manifest_file)}.")
|
|
153
|
-
end
|
|
154
|
-
else
|
|
155
|
-
apps = find_apps(x)
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
if !apps.empty?
|
|
159
|
-
internal += apps
|
|
160
|
-
else
|
|
161
|
-
external << x
|
|
162
|
-
end
|
|
163
|
-
else
|
|
164
|
-
external << x
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
[internal, external]
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def create_manifest_for(app, path)
|
|
172
|
-
meta = {
|
|
173
|
-
"name" => app.name,
|
|
174
|
-
"memory" => human_size(app.memory * 1024 * 1024, 0),
|
|
175
|
-
"instances" => app.total_instances,
|
|
176
|
-
"host" => app.host || "none",
|
|
177
|
-
"domain" => app.domain ? app.domain : "none",
|
|
178
|
-
"path" => path
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
services = app.services
|
|
182
|
-
|
|
183
|
-
unless services.empty?
|
|
184
|
-
meta["services"] = {}
|
|
185
|
-
|
|
186
|
-
services.each do |service_instance|
|
|
187
|
-
if service_instance.is_a?(JFoundry::V2::UserProvidedServiceInstance)
|
|
188
|
-
meta["services"][service_instance.name] = {
|
|
189
|
-
"label" => "user-provided",
|
|
190
|
-
"credentials" => service_instance.credentials.stringify_keys,
|
|
191
|
-
}
|
|
192
|
-
else
|
|
193
|
-
service_plan = service_instance.service_plan
|
|
194
|
-
service = service_plan.service
|
|
195
|
-
|
|
196
|
-
meta["services"][service_instance.name] = {
|
|
197
|
-
"label" => service.label,
|
|
198
|
-
"provider" => service.provider,
|
|
199
|
-
"version" => service.version,
|
|
200
|
-
"plan" => service_plan.name
|
|
201
|
-
}
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
if cmd = app.command
|
|
207
|
-
meta["command"] = cmd
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
if buildpack = app.buildpack
|
|
211
|
-
meta["buildpack"] = buildpack
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
meta
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
private
|
|
218
|
-
|
|
219
|
-
def relative_manifest_file
|
|
220
|
-
Pathname.new(manifest_file).relative_path_from(Pathname.pwd)
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def show_manifest_usage
|
|
224
|
-
return if @@showed_manifest_usage
|
|
225
|
-
|
|
226
|
-
path = relative_manifest_file
|
|
227
|
-
line "Using manifest file #{c(path, :name)}"
|
|
228
|
-
line
|
|
229
|
-
|
|
230
|
-
@@showed_manifest_usage = true
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
def no_apps
|
|
234
|
-
fail "No applications or manifest to operate on."
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def warn_reset_changes
|
|
238
|
-
line c("Not applying manifest changes without --reset", :warning)
|
|
239
|
-
line "See `jdc diff` for more details."
|
|
240
|
-
line
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def apps_by(attr, val)
|
|
244
|
-
manifest[:applications].select do |info|
|
|
245
|
-
info[attr] == val
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
# expand a path relative to the manifest file's directory
|
|
250
|
-
def from_manifest(path)
|
|
251
|
-
File.expand_path(path, File.dirname(manifest_file))
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
def ask_to_save(input, app)
|
|
256
|
-
return if manifest_file
|
|
257
|
-
return unless ask("Save configuration?", :default => false)
|
|
258
|
-
|
|
259
|
-
manifest = create_manifest_for(app, input[:path])
|
|
260
|
-
|
|
261
|
-
with_progress("Saving to #{c("manifest.yml", :name)}") do
|
|
262
|
-
File.open("manifest.yml", "w") do |io|
|
|
263
|
-
YAML.dump(
|
|
264
|
-
{ "applications" => [manifest] },
|
|
265
|
-
io)
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
def env_hash(val)
|
|
271
|
-
if val.is_a?(Hash)
|
|
272
|
-
val
|
|
273
|
-
else
|
|
274
|
-
hash = {}
|
|
275
|
-
|
|
276
|
-
val.each do |pair|
|
|
277
|
-
name, val = pair.split("=", 2)
|
|
278
|
-
hash[name] = val
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
hash
|
|
282
|
-
end
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
def setup_env(app, info)
|
|
286
|
-
return unless info[:env]
|
|
287
|
-
app.env = env_hash(info[:env])
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
def setup_services(app, info)
|
|
291
|
-
return if !info[:services] || info[:services].empty?
|
|
292
|
-
|
|
293
|
-
offerings = client.services
|
|
294
|
-
|
|
295
|
-
to_bind = []
|
|
296
|
-
|
|
297
|
-
info[:services].each do |name, svc|
|
|
298
|
-
name = name.to_s
|
|
299
|
-
|
|
300
|
-
if instance = client.service_instance_by_name(name)
|
|
301
|
-
to_bind << instance
|
|
302
|
-
else
|
|
303
|
-
if svc[:label] == "user-provided"
|
|
304
|
-
invoke :create_service,
|
|
305
|
-
name: name,
|
|
306
|
-
offering: JDC::Service::UPDummy.new,
|
|
307
|
-
app: app,
|
|
308
|
-
credentials: svc[:credentials]
|
|
309
|
-
else
|
|
310
|
-
offering = offerings.find { |o|
|
|
311
|
-
o.label == (svc[:label] || svc[:type] || svc[:vendor]) &&
|
|
312
|
-
(!svc[:version] || o.version == svc[:version]) &&
|
|
313
|
-
(o.provider == (svc[:provider] || "core"))
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
fail "Unknown service offering: #{svc.inspect}." unless offering
|
|
317
|
-
|
|
318
|
-
plan = offering.service_plans.find { |p|
|
|
319
|
-
p.name == (svc[:plan] || "D100")
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
fail "Unknown service plan: #{svc[:plan]}." unless plan
|
|
323
|
-
|
|
324
|
-
invoke :create_service,
|
|
325
|
-
:name => name,
|
|
326
|
-
:offering => offering,
|
|
327
|
-
:plan => plan,
|
|
328
|
-
:app => app
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
to_bind.each do |s|
|
|
334
|
-
next if app.binds?(s)
|
|
335
|
-
|
|
336
|
-
# TODO: splat
|
|
337
|
-
invoke :bind_service, :app => app, :service => s
|
|
338
|
-
end
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
def target_base
|
|
342
|
-
client_target.sub(/^[^\.]+\./, "")
|
|
343
|
-
end
|
|
344
|
-
end
|
data/lib/manifests/plugin.rb
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
require "pathname"
|
|
2
|
-
require "jdc/plugin"
|
|
3
|
-
require "manifests/manifests"
|
|
4
|
-
|
|
5
|
-
class ManifestsPlugin < JDC::App::Base
|
|
6
|
-
include JDCManifests
|
|
7
|
-
|
|
8
|
-
def self.default_to_app_from_manifest(command, fail_without_app)
|
|
9
|
-
name_made_optional = change_argument(command, :app, :optional)
|
|
10
|
-
around(command) do |cmd, input|
|
|
11
|
-
wrap_with_optional_name(name_made_optional, cmd, input, fail_without_app)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
option :manifest, :aliases => "-m", :value => :file, :desc => "Path to manifest file to use"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
[:start, :restart, :instances, :logs, :env, :health, :stats, :scale, :app, :stop, :delete, :events].each do |command|
|
|
19
|
-
::ManifestsPlugin.default_to_app_from_manifest command, true
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
add_input :push, :reset, :desc => "Reset to values in the manifest", :default => false
|
|
23
|
-
|
|
24
|
-
around(:push) do |push, input|
|
|
25
|
-
wrap_push(push, input)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def wrap_with_optional_name(name_made_optional, cmd, input, fail_without_app)
|
|
31
|
-
return cmd.call if input[:all]
|
|
32
|
-
|
|
33
|
-
unless manifest
|
|
34
|
-
# if the command knows how to handle this
|
|
35
|
-
if input.has?(:app) || !name_made_optional || !fail_without_app
|
|
36
|
-
return cmd.call
|
|
37
|
-
else
|
|
38
|
-
return no_apps
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
internal, external = apps_in_manifest(input)
|
|
43
|
-
|
|
44
|
-
return cmd.call if internal.empty? && !external.empty?
|
|
45
|
-
|
|
46
|
-
show_manifest_usage
|
|
47
|
-
|
|
48
|
-
if internal.empty? && external.empty?
|
|
49
|
-
internal = current_apps if internal.empty?
|
|
50
|
-
internal = all_apps if internal.empty?
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
internal = internal.collect { |app| app[:name] }
|
|
54
|
-
|
|
55
|
-
apps = internal + external
|
|
56
|
-
return no_apps if fail_without_app && apps.empty?
|
|
57
|
-
|
|
58
|
-
apps.each.with_index do |app, num|
|
|
59
|
-
line unless quiet? || num == 0
|
|
60
|
-
cmd.call(input.without(:apps).merge_given(:app => app))
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def apply_changes(app, input)
|
|
65
|
-
app.memory = megabytes(input[:memory]) if input.has?(:memory)
|
|
66
|
-
app.total_instances = input[:instances] if input.has?(:instances)
|
|
67
|
-
app.command = input[:command] if input.has?(:command)
|
|
68
|
-
app.buildpack = input[:buildpack] if input.has?(:buildpack)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def wrap_push(push, input)
|
|
72
|
-
unless manifest
|
|
73
|
-
create_and_save_manifest(push, input)
|
|
74
|
-
return
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
line(c("--path is ignored when using a manifest. Please specify the path in the manifest.", :warning)) if input.has?(:path)
|
|
78
|
-
|
|
79
|
-
particular, external = apps_in_manifest(input)
|
|
80
|
-
|
|
81
|
-
unless external.empty?
|
|
82
|
-
fail "Could not find #{b(external.join(", "))}' in the manifest."
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
apps = particular.empty? ? all_apps : particular
|
|
86
|
-
|
|
87
|
-
show_manifest_usage
|
|
88
|
-
|
|
89
|
-
spaced(apps) do |app_manifest|
|
|
90
|
-
push_with_manifest(app_manifest, push, input)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def push_with_manifest(app_manifest, push, input)
|
|
95
|
-
with_filters(
|
|
96
|
-
:push => {
|
|
97
|
-
:create_app => proc { |a|
|
|
98
|
-
setup_env(a, app_manifest)
|
|
99
|
-
a
|
|
100
|
-
},
|
|
101
|
-
:push_app => proc { |a|
|
|
102
|
-
setup_services(a, app_manifest)
|
|
103
|
-
a
|
|
104
|
-
}
|
|
105
|
-
}) do
|
|
106
|
-
app_input = push_input_for(app_manifest, input)
|
|
107
|
-
|
|
108
|
-
push.call(app_input)
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def push_input_for(app_manifest, input)
|
|
113
|
-
existing_app = client.app_by_name(app_manifest[:name])
|
|
114
|
-
rebased_input = input.rebase_given(app_manifest)
|
|
115
|
-
|
|
116
|
-
if !existing_app || input[:reset]
|
|
117
|
-
input = rebased_input
|
|
118
|
-
else
|
|
119
|
-
warn_reset_changes if manifest_differs?(existing_app, rebased_input)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
input.merge(
|
|
123
|
-
:path => from_manifest(app_manifest[:path]),
|
|
124
|
-
:name => app_manifest[:name],
|
|
125
|
-
:bind_services => false,
|
|
126
|
-
:create_services => false)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def manifest_differs?(app, input)
|
|
130
|
-
apply_changes(app, input)
|
|
131
|
-
app.changed?
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def create_and_save_manifest(push, input)
|
|
135
|
-
with_filters(
|
|
136
|
-
:push => { :push_app => proc { |a| ask_to_save(input, a); a } }) do
|
|
137
|
-
push.call
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
data/lib/micro/README.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
### Info
|
|
2
|
-
This plugin allows you to manage your Micro Jing Dong Foundry VM.
|
|
3
|
-
|
|
4
|
-
### Usage
|
|
5
|
-
```
|
|
6
|
-
micro-status VMX [PASSWORD] Display Micro Jing Dong Foundry VM status
|
|
7
|
-
micro-offline VMX [PASSWORD] Micro Jing Dong Foundry offline mode
|
|
8
|
-
micro-online VMX [PASSWORD] Micro Jing Dong Foundry online mode
|
|
9
|
-
```
|
data/lib/micro/errors.rb
DELETED
data/lib/micro/plugin.rb
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
require "yaml"
|
|
2
|
-
require "multi_json"
|
|
3
|
-
require "jdc/cli"
|
|
4
|
-
require "micro/micro"
|
|
5
|
-
require "micro/vmrun"
|
|
6
|
-
require "micro/switcher/base"
|
|
7
|
-
require "micro/switcher/darwin"
|
|
8
|
-
require "micro/switcher/linux"
|
|
9
|
-
require "micro/switcher/windows"
|
|
10
|
-
|
|
11
|
-
module JDCMicro
|
|
12
|
-
class McfCommand < JDC::CLI
|
|
13
|
-
MICRO_FILE = '~/.jdc/micro.yml'
|
|
14
|
-
|
|
15
|
-
desc "Display Micro Cloud Foundry VM status"
|
|
16
|
-
input :vmx, :argument => :required,
|
|
17
|
-
:desc => "Path to micro.vmx"
|
|
18
|
-
input :password, :argument => :optional,
|
|
19
|
-
:desc => "Cleartext password for guest VM vcap user"
|
|
20
|
-
def micro_status
|
|
21
|
-
mode = runner.offline? ? 'offline' : 'online'
|
|
22
|
-
|
|
23
|
-
line "Micro Cloud Foundry VM currently in #{b(mode)} mode"
|
|
24
|
-
line "VMX Path: #{c(runner.vmx, :good)}"
|
|
25
|
-
line "Domain: #{c(runner.domain, :good)}"
|
|
26
|
-
line "IP Address: #{c(runner.ip, :good)}"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
desc "Micro Cloud Foundry offline mode"
|
|
30
|
-
input :vmx, :argument => :required,
|
|
31
|
-
:desc => "Path to micro.vmx"
|
|
32
|
-
input :password, :argument => :optional,
|
|
33
|
-
:desc => "Cleartext password for guest VM vcap user"
|
|
34
|
-
def micro_offline
|
|
35
|
-
if !runner.nat?
|
|
36
|
-
if ask("Reconfigure MCF VM network to nat mode and reboot?", :default => true)
|
|
37
|
-
with_progress("Rebooting MCF VM") do
|
|
38
|
-
runner.reset_to_nat!
|
|
39
|
-
end
|
|
40
|
-
else
|
|
41
|
-
fail "Aborted"
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
with_progress("Setting MCF VM to offline mode") do
|
|
46
|
-
runner.offline!
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
with_progress("Setting host DNS server") do
|
|
50
|
-
runner.set_host_dns!
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
desc "Micro Cloud Foundry online mode"
|
|
55
|
-
input :vmx, :argument => :required,
|
|
56
|
-
:desc => "Path to micro.vmx"
|
|
57
|
-
input :password, :argument => :optional,
|
|
58
|
-
:desc => "Cleartext password for guest VM vcap user"
|
|
59
|
-
def micro_online
|
|
60
|
-
runner
|
|
61
|
-
with_progress("Unsetting host DNS server") do
|
|
62
|
-
runner.unset_host_dns!
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
with_progress("Setting MCF VM to online mode") do
|
|
66
|
-
runner.online!
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def runner
|
|
71
|
-
return @runner if @runner
|
|
72
|
-
|
|
73
|
-
config = build_config
|
|
74
|
-
@runner = switcher(config)
|
|
75
|
-
check_vm_running
|
|
76
|
-
store_config(config)
|
|
77
|
-
|
|
78
|
-
@runner
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def check_vm_running
|
|
82
|
-
unless runner.running?
|
|
83
|
-
if ask("MCF VM is not running. Do you want to start it?", :default => true)
|
|
84
|
-
with_progress("Starting MCF VM") do
|
|
85
|
-
runner.start!
|
|
86
|
-
end
|
|
87
|
-
else
|
|
88
|
-
fail "MCF VM needs to be running."
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
unless runner.ready?
|
|
93
|
-
fail "MCF VM initial setup needs to be completed before using 'jdc micro'"
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def switcher(config)
|
|
98
|
-
case McfCommand.platform
|
|
99
|
-
when :darwin
|
|
100
|
-
JDCMicro::Switcher::Darwin.new(config)
|
|
101
|
-
when :linux
|
|
102
|
-
JDCMicro::Switcher::Linux.new(config)
|
|
103
|
-
when :windows
|
|
104
|
-
JDCMicro::Switcher::Windows.new(config)
|
|
105
|
-
when :dummy # for testing only
|
|
106
|
-
JDCMicro::Switcher::Dummy.new(config)
|
|
107
|
-
else
|
|
108
|
-
fail "unsupported platform: #{McfCommand.platform}"
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
# Returns the configuration needed to run the micro related subcommands.
|
|
113
|
-
# First loads saved config from file (if there is any), then overrides
|
|
114
|
-
# loaded values with command line arguments, and finally tries to guess
|
|
115
|
-
# in case neither was used:
|
|
116
|
-
# vmx location of micro.vmx file
|
|
117
|
-
# vmrun location of vmrun command
|
|
118
|
-
# password password for vcap user (in the guest vm)
|
|
119
|
-
# platform current platform
|
|
120
|
-
def build_config
|
|
121
|
-
conf = micro # returns {} if there isn't a saved config
|
|
122
|
-
|
|
123
|
-
override(conf, :vmx, true) do
|
|
124
|
-
locate_vmx(McfCommand.platform)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
override(conf, :vmrun, true) do
|
|
128
|
-
JDCMicro::VMrun.locate(McfCommand.platform)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
override(conf, :password) do
|
|
132
|
-
ask("Please enter your MCF VM password (vcap user) password", :echo => "*")
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
conf[:platform] = McfCommand.platform
|
|
136
|
-
|
|
137
|
-
conf
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
# Save the cleartext password if --save is supplied.
|
|
141
|
-
# Note: it is due to vix we have to use a cleartext password :(
|
|
142
|
-
# Only if --password is used and not --save is the password deleted from the
|
|
143
|
-
# config file before it is stored to disk.
|
|
144
|
-
def store_config(config)
|
|
145
|
-
if input[:save]
|
|
146
|
-
warn("cleartext password saved in: #{MICRO_FILE}")
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
store_micro(config)
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# override with command line arguments and yield the block in case the option isn't set
|
|
153
|
-
def override(config, option, escape=false, &blk)
|
|
154
|
-
# override if given on the command line
|
|
155
|
-
if opt = input[option]
|
|
156
|
-
opt = JDCMicro.escape_path(opt) if escape
|
|
157
|
-
config[option] = opt
|
|
158
|
-
end
|
|
159
|
-
config[option] = yield unless config[option]
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def locate_vmx(platform)
|
|
163
|
-
paths = YAML.load_file(JDCMicro.config_file('paths.yml'))
|
|
164
|
-
vmx_paths = paths[platform.to_s]['vmx']
|
|
165
|
-
vmx = JDCMicro.locate_file('micro.vmx', 'micro', vmx_paths)
|
|
166
|
-
fail "Unable to locate micro.vmx, please supply --vmx option" unless vmx
|
|
167
|
-
vmx
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def self.platform
|
|
171
|
-
case RUBY_PLATFORM
|
|
172
|
-
when /darwin/ # x86_64-darwin11.2.0
|
|
173
|
-
:darwin
|
|
174
|
-
when /linux/ # x86_64-linux
|
|
175
|
-
:linux
|
|
176
|
-
when /mingw|mswin32|cygwin/ # i386-mingw32
|
|
177
|
-
:windows
|
|
178
|
-
else
|
|
179
|
-
RUBY_PLATFORM
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def micro
|
|
184
|
-
micro_file = File.expand_path(MICRO_FILE)
|
|
185
|
-
return {} unless File.exists? micro_file
|
|
186
|
-
contents = File.read(micro_file).strip
|
|
187
|
-
MultiJson.load(contents)
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
def store_micro(micro)
|
|
191
|
-
micro_file = File.expand_path(MICRO_FILE)
|
|
192
|
-
File.open(micro_file, 'w') do |file|
|
|
193
|
-
file.write(MultiJson.dump(micro))
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|