jdc 0.2.1 → 0.2.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/LICENSE +1277 -24
  2. data/Rakefile +13 -0
  3. data/bin/jdc +12 -2
  4. data/lib/admin/README.md +15 -0
  5. data/lib/admin/curl.rb +60 -0
  6. data/lib/admin/guid.rb +89 -0
  7. data/lib/admin/plugin.rb +6 -0
  8. data/lib/admin/service_auth_token.rb +94 -0
  9. data/lib/admin/service_broker/add.rb +47 -0
  10. data/lib/admin/service_broker/service_brokers.rb +24 -0
  11. data/lib/admin/set_quota.rb +44 -0
  12. data/lib/console/README.md +8 -0
  13. data/lib/console/console.rb +187 -0
  14. data/lib/console/plugin.rb +33 -0
  15. data/lib/jdc.rb +15 -2
  16. data/lib/jdc/cli.rb +556 -0
  17. data/lib/jdc/cli/app/app.rb +43 -0
  18. data/lib/jdc/cli/app/apps.rb +87 -0
  19. data/lib/jdc/cli/app/base.rb +72 -0
  20. data/lib/jdc/cli/app/delete.rb +95 -0
  21. data/lib/jdc/cli/app/deprecated.rb +11 -0
  22. data/lib/jdc/cli/app/env.rb +78 -0
  23. data/lib/jdc/cli/app/events.rb +45 -0
  24. data/lib/jdc/cli/app/files.rb +137 -0
  25. data/lib/jdc/cli/app/health.rb +26 -0
  26. data/lib/jdc/cli/app/instances.rb +53 -0
  27. data/lib/jdc/cli/app/logs.rb +76 -0
  28. data/lib/jdc/cli/app/push.rb +103 -0
  29. data/lib/jdc/cli/app/push/create.rb +108 -0
  30. data/lib/jdc/cli/app/push/interactions.rb +86 -0
  31. data/lib/jdc/cli/app/push/sync.rb +57 -0
  32. data/lib/jdc/cli/app/rename.rb +35 -0
  33. data/lib/jdc/cli/app/restart.rb +31 -0
  34. data/lib/jdc/cli/app/scale.rb +63 -0
  35. data/lib/jdc/cli/app/start.rb +161 -0
  36. data/lib/jdc/cli/app/stats.rb +67 -0
  37. data/lib/jdc/cli/app/stop.rb +27 -0
  38. data/lib/jdc/cli/domain/base.rb +9 -0
  39. data/lib/jdc/cli/domain/domains.rb +40 -0
  40. data/lib/jdc/cli/domain/map.rb +55 -0
  41. data/lib/jdc/cli/domain/unmap.rb +56 -0
  42. data/lib/jdc/cli/help.rb +15 -0
  43. data/lib/jdc/cli/interactive.rb +105 -0
  44. data/lib/jdc/cli/login_requirements.rb +15 -0
  45. data/lib/jdc/cli/organization/base.rb +14 -0
  46. data/lib/jdc/cli/organization/create.rb +37 -0
  47. data/lib/jdc/cli/organization/delete.rb +63 -0
  48. data/lib/jdc/cli/organization/org.rb +45 -0
  49. data/lib/jdc/cli/organization/orgs.rb +30 -0
  50. data/lib/jdc/cli/organization/rename.rb +37 -0
  51. data/lib/jdc/cli/populators/base.rb +16 -0
  52. data/lib/jdc/cli/populators/organization.rb +32 -0
  53. data/lib/jdc/cli/populators/populator_methods.rb +64 -0
  54. data/lib/jdc/cli/populators/space.rb +33 -0
  55. data/lib/jdc/cli/populators/target.rb +13 -0
  56. data/lib/jdc/cli/route/base.rb +9 -0
  57. data/lib/jdc/cli/route/delete.rb +28 -0
  58. data/lib/jdc/cli/route/map.rb +68 -0
  59. data/lib/jdc/cli/route/routes.rb +26 -0
  60. data/lib/jdc/cli/route/unmap.rb +56 -0
  61. data/lib/jdc/cli/service/base.rb +9 -0
  62. data/lib/jdc/cli/service/bind.rb +44 -0
  63. data/lib/jdc/cli/service/create.rb +159 -0
  64. data/lib/jdc/cli/service/delete.rb +83 -0
  65. data/lib/jdc/cli/service/rename.rb +36 -0
  66. data/lib/jdc/cli/service/service.rb +42 -0
  67. data/lib/jdc/cli/service/service_instance_helper.rb +99 -0
  68. data/lib/jdc/cli/service/services.rb +111 -0
  69. data/lib/jdc/cli/service/unbind.rb +37 -0
  70. data/lib/jdc/cli/space/base.rb +29 -0
  71. data/lib/jdc/cli/space/create.rb +67 -0
  72. data/lib/jdc/cli/space/delete.rb +56 -0
  73. data/lib/jdc/cli/space/rename.rb +38 -0
  74. data/lib/jdc/cli/space/space.rb +66 -0
  75. data/lib/jdc/cli/space/spaces.rb +57 -0
  76. data/lib/jdc/cli/space/switch.rb +19 -0
  77. data/lib/jdc/cli/start/base.rb +41 -0
  78. data/lib/jdc/cli/start/colors.rb +13 -0
  79. data/lib/jdc/cli/start/target.rb +50 -0
  80. data/lib/jdc/cli/start/target_prettifier.rb +17 -0
  81. data/lib/jdc/cli/start/targets.rb +16 -0
  82. data/lib/jdc/cli/user/base.rb +30 -0
  83. data/lib/jdc/cli/user/create.rb +52 -0
  84. data/lib/jdc/cli/user/passwd.rb +37 -0
  85. data/lib/jdc/cli/user/register.rb +43 -0
  86. data/lib/jdc/cli/user/users.rb +32 -0
  87. data/lib/jdc/constants.rb +11 -0
  88. data/lib/jdc/errors.rb +19 -0
  89. data/lib/jdc/object_extensions.rb +15 -0
  90. data/lib/jdc/plugin.rb +56 -0
  91. data/lib/jdc/spacing.rb +89 -0
  92. data/lib/jdc/spec_helper.rb +1 -0
  93. data/lib/jdc/test_support.rb +6 -0
  94. data/lib/jdc/version.rb +3 -0
  95. data/lib/manifests/errors.rb +35 -0
  96. data/lib/manifests/loader.rb +31 -0
  97. data/lib/manifests/loader/builder.rb +39 -0
  98. data/lib/manifests/loader/normalizer.rb +145 -0
  99. data/lib/manifests/loader/resolver.rb +79 -0
  100. data/lib/manifests/manifests.rb +344 -0
  101. data/lib/manifests/plugin.rb +140 -0
  102. data/lib/micro/README.md +9 -0
  103. data/lib/micro/errors.rb +4 -0
  104. data/lib/{jdc → micro}/micro.rb +15 -15
  105. data/lib/micro/plugin.rb +197 -0
  106. data/lib/micro/switcher/base.rb +79 -0
  107. data/lib/{jdc/micro → micro}/switcher/darwin.rb +5 -3
  108. data/lib/{jdc/micro → micro}/switcher/dummy.rb +1 -1
  109. data/lib/micro/switcher/linux.rb +16 -0
  110. data/lib/{jdc/micro → micro}/switcher/windows.rb +5 -5
  111. data/lib/{jdc/micro → micro}/vmrun.rb +26 -19
  112. data/lib/tasks/gem_release.rake +42 -0
  113. data/lib/tunnel/README.md +29 -0
  114. data/{config → lib/tunnel/config}/clients.yml +2 -2
  115. data/lib/tunnel/helper-app/Gemfile +10 -0
  116. data/lib/tunnel/helper-app/Gemfile.lock +48 -0
  117. data/{caldecott_helper → lib/tunnel/helper-app}/server.rb +5 -5
  118. data/lib/tunnel/plugin.rb +183 -0
  119. data/lib/tunnel/tunnel.rb +295 -0
  120. metadata +371 -210
  121. data/README.md +0 -102
  122. data/config/micro/paths.yml +0 -22
  123. data/config/micro/refresh_ip.rb +0 -20
  124. data/lib/cli.rb +0 -53
  125. data/lib/cli/commands/admin.rb +0 -58
  126. data/lib/cli/commands/apps.rb +0 -1129
  127. data/lib/cli/commands/base.rb +0 -228
  128. data/lib/cli/commands/manifest.rb +0 -56
  129. data/lib/cli/commands/micro.rb +0 -115
  130. data/lib/cli/commands/misc.rb +0 -126
  131. data/lib/cli/commands/services.rb +0 -178
  132. data/lib/cli/commands/user.rb +0 -14
  133. data/lib/cli/config.rb +0 -173
  134. data/lib/cli/console_helper.rb +0 -170
  135. data/lib/cli/core_ext.rb +0 -122
  136. data/lib/cli/errors.rb +0 -19
  137. data/lib/cli/frameworks.rb +0 -265
  138. data/lib/cli/manifest_helper.rb +0 -300
  139. data/lib/cli/runner.rb +0 -505
  140. data/lib/cli/services_helper.rb +0 -84
  141. data/lib/cli/tunnel_helper.rb +0 -332
  142. data/lib/cli/usage.rb +0 -86
  143. data/lib/cli/version.rb +0 -7
  144. data/lib/cli/zip_util.rb +0 -77
  145. data/lib/jdc/client.rb +0 -457
  146. data/lib/jdc/const.rb +0 -25
  147. data/lib/jdc/micro/switcher/base.rb +0 -97
  148. data/lib/jdc/micro/switcher/linux.rb +0 -16
  149. data/lib/jdc/signature/version.rb +0 -27
  150. data/lib/jdc/signer.rb +0 -13
  151. data/lib/jdc/timer.rb +0 -12
@@ -1,84 +0,0 @@
1
-
2
- module JDC::Cli
3
- module ServicesHelper
4
- def display_system_services(services=nil)
5
- services ||= client.services_info
6
-
7
- display "\n============== System Services ==============\n\n"
8
-
9
- return display "No system services available" if services.empty?
10
-
11
- displayed_services = []
12
- services.each do |service_type, value|
13
- value.each do |vendor, version|
14
- version.each do |version_str, service|
15
- displayed_services << [ vendor, version_str, service[:description] ]
16
- end
17
- end
18
- end
19
- displayed_services.sort! { |a, b| a.first.to_s <=> b.first.to_s}
20
-
21
- services_table = table do |t|
22
- t.headings = 'Service', 'Version', 'Description'
23
- displayed_services.each { |s| t << s }
24
- end
25
- display services_table
26
- end
27
-
28
- def display_provisioned_services(services=nil)
29
- services ||= client.services
30
- display "\n=========== Provisioned Services ============\n\n"
31
- display_provisioned_services_table(services)
32
- end
33
-
34
- def display_provisioned_services_table(services)
35
- return unless services && !services.empty?
36
- services_table = table do |t|
37
- t.headings = 'Name', 'Service'
38
- services.each do |service|
39
- t << [ service[:name], service[:vendor] ]
40
- end
41
- end
42
- display services_table
43
- end
44
-
45
- def create_service_banner(service, name, display_name=false)
46
- sn = " [#{name}]" if display_name
47
- display "Creating Service#{sn}: ", false
48
- client.create_service(service, name)
49
- display 'OK'.green
50
- end
51
-
52
- def bind_service_banner(service, appname, check_restart=true)
53
- display "Binding Service [#{service}]: ", false
54
- client.bind_service(service, appname)
55
- display 'OK'.green
56
- check_app_for_restart(appname) if check_restart
57
- end
58
-
59
- def unbind_service_banner(service, appname, check_restart=true)
60
- display "Unbinding Service [#{service}]: ", false
61
- client.unbind_service(service, appname)
62
- display 'OK'.green
63
- check_app_for_restart(appname) if check_restart
64
- end
65
-
66
- def delete_service_banner(service)
67
- display "Deleting service [#{service}]: ", false
68
- client.delete_service(service)
69
- display 'OK'.green
70
- end
71
-
72
- def random_service_name(service)
73
- r = "%04x" % [rand(0x0100000)]
74
- "#{service.to_s}-#{r}"
75
- end
76
-
77
- def check_app_for_restart(appname)
78
- app = client.app_info(appname)
79
- cmd = JDC::Cli::Command::Apps.new(@options)
80
- cmd.restart(appname) if app[:state] == 'STARTED'
81
- end
82
-
83
- end
84
- end
@@ -1,332 +0,0 @@
1
- # Copyright (c) 2009-2011 VMware, Inc.
2
-
3
- require 'addressable/uri'
4
-
5
- begin
6
- require 'caldecott'
7
- rescue LoadError
8
- end
9
-
10
- module JDC::Cli
11
- module TunnelHelper
12
- PORT_RANGE = 10
13
-
14
- HELPER_APP = File.expand_path("../../../caldecott_helper", __FILE__)
15
-
16
- # bump this AND the version info reported by HELPER_APP/server.rb
17
- # this is to keep the helper in sync with any updates here
18
- HELPER_VERSION = '0.0.4'
19
-
20
- def tunnel_uniquename
21
- random_service_name(tunnel_appname)
22
- end
23
-
24
- def tunnel_appname
25
- "caldecott"
26
- end
27
-
28
- def tunnel_app_info
29
- return @tun_app_info if @tunnel_app_info
30
- begin
31
- @tun_app_info = client.app_info(tunnel_appname)
32
- rescue => e
33
- @tun_app_info = nil
34
- end
35
- end
36
-
37
- def tunnel_auth
38
- tunnel_app_info[:env].each do |e|
39
- name, val = e.split("=", 2)
40
- return val if name == "CALDECOTT_AUTH"
41
- end
42
- nil
43
- end
44
-
45
- def tunnel_url
46
- return @tunnel_url if @tunnel_url
47
-
48
- tun_url = tunnel_app_info[:uris][0]
49
-
50
- ["https", "http"].each do |scheme|
51
- url = "#{scheme}://#{tun_url}"
52
- begin
53
- RestClient.get(url)
54
-
55
- # https failed
56
- rescue Errno::ECONNREFUSED
57
-
58
- # we expect a 404 since this request isn't auth'd
59
- rescue RestClient::ResourceNotFound
60
- return @tunnel_url = url
61
- end
62
- end
63
-
64
- err "Cannot determine URL for #{tun_url}"
65
- end
66
-
67
- def invalidate_tunnel_app_info
68
- @tunnel_url = nil
69
- @tunnel_app_info = nil
70
- end
71
-
72
- def tunnel_pushed?
73
- not tunnel_app_info.nil?
74
- end
75
-
76
- def tunnel_healthy?(token)
77
- return false unless tunnel_app_info[:state] == 'STARTED'
78
-
79
- begin
80
- response = RestClient.get(
81
- "#{tunnel_url}/info",
82
- "Auth-Token" => token
83
- )
84
-
85
- info = JSON.parse(response)
86
- if info["version"] == HELPER_VERSION
87
- true
88
- else
89
- stop_caldecott
90
- false
91
- end
92
- rescue RestClient::Exception
93
- stop_caldecott
94
- false
95
- end
96
- end
97
-
98
- def tunnel_bound?(service)
99
- tunnel_app_info[:services].include?(service)
100
- end
101
-
102
- def tunnel_connection_info(type, service, token)
103
- display "Getting tunnel connection info: ", false
104
- response = nil
105
- 10.times do
106
- begin
107
- response = RestClient.get(tunnel_url + "/" + JDC::Client.path("services", service), "Auth-Token" => token)
108
- break
109
- rescue RestClient::Exception
110
- sleep 1
111
- end
112
-
113
- display ".", false
114
- end
115
-
116
- unless response
117
- err "Expected remote tunnel to know about #{service}, but it doesn't"
118
- end
119
-
120
- display "OK".green
121
-
122
- info = JSON.parse(response)
123
- case type
124
- when "rabbitmq"
125
- uri = Addressable::URI.parse info["url"]
126
- info["hostname"] = uri.host
127
- info["port"] = uri.port
128
- info["vhost"] = uri.path[1..-1]
129
- info["user"] = uri.user
130
- info["password"] = uri.password
131
- info.delete "url"
132
-
133
- # we use "db" as the "name" for mongo
134
- # existing "name" is junk
135
- when "mongodb"
136
- info["name"] = info["db"]
137
- info.delete "db"
138
-
139
- # our "name" is irrelevant for redis
140
- when "redis"
141
- info.delete "name"
142
- end
143
-
144
- ['hostname', 'port', 'password'].each do |k|
145
- err "Could not determine #{k} for #{service}" if info[k].nil?
146
- end
147
-
148
- info
149
- end
150
-
151
- def display_tunnel_connection_info(info)
152
- display ''
153
- display "Service connection info: "
154
-
155
- to_show = [nil, nil, nil] # reserved for user, pass, db name
156
- info.keys.each do |k|
157
- case k
158
- when "host", "hostname", "port", "node_id"
159
- # skip
160
- when "user", "username"
161
- # prefer "username" over "user"
162
- to_show[0] = k unless to_show[0] == "username"
163
- when "password"
164
- to_show[1] = k
165
- when "name"
166
- to_show[2] = k
167
- else
168
- to_show << k
169
- end
170
- end
171
- to_show.compact!
172
-
173
- align_len = to_show.collect(&:size).max + 1
174
-
175
- to_show.each do |k|
176
- # TODO: modify the server services rest call to have explicit knowledge
177
- # about the items to return. It should return all of them if
178
- # the service is unknown so that we don't have to do this weird
179
- # filtering.
180
- display " #{k.ljust align_len}: ", false
181
- display "#{info[k]}".yellow
182
- end
183
- display ''
184
- end
185
-
186
- def start_tunnel(local_port, conn_info, auth)
187
- @local_tunnel_thread = Thread.new do
188
- Caldecott::Client.start({
189
- :local_port => local_port,
190
- :tun_url => tunnel_url,
191
- :dst_host => conn_info['hostname'],
192
- :dst_port => conn_info['port'],
193
- :log_file => STDOUT,
194
- :log_level => ENV["JDC_TUNNEL_DEBUG"] || "ERROR",
195
- :auth_token => auth,
196
- :quiet => true
197
- })
198
- end
199
-
200
- at_exit { @local_tunnel_thread.kill }
201
- end
202
-
203
-
204
-
205
- def pick_tunnel_port(port)
206
- original = port
207
-
208
- PORT_RANGE.times do |n|
209
- begin
210
- TCPSocket.open('localhost', port)
211
- port += 1
212
- rescue
213
- return port
214
- end
215
- end
216
-
217
- grab_ephemeral_port
218
- end
219
-
220
- def grab_ephemeral_port
221
- socket = TCPServer.new('0.0.0.0', 0)
222
- socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
223
- Socket.do_not_reverse_lookup = true
224
- port = socket.addr[1]
225
- socket.close
226
- return port
227
- end
228
-
229
- def wait_for_tunnel_start(port)
230
- 10.times do |n|
231
- begin
232
- client = TCPSocket.open('localhost', port)
233
- display '' if n > 0
234
- client.close
235
- return true
236
- rescue => e
237
- display "Waiting for local tunnel to become available", false if n == 0
238
- display '.', false
239
- sleep 1
240
- end
241
- end
242
- err "Could not connect to local tunnel."
243
- end
244
-
245
- def wait_for_tunnel_end
246
- display "Open another shell to run command-line clients or"
247
- display "use a UI tool to connect using the displayed information."
248
- display "Press Ctrl-C to exit..."
249
- @local_tunnel_thread.join
250
- end
251
-
252
- def resolve_symbols(str, info, local_port)
253
- str.gsub(/\$\{\s*([^\}]+)\s*\}/) do
254
- case $1
255
- when "host"
256
- # TODO: determine proper host
257
- "localhost"
258
- when "port"
259
- local_port
260
- when "user", "username"
261
- info["username"]
262
- else
263
- info[$1] || ask($1)
264
- end
265
- end
266
- end
267
-
268
- def start_local_prog(clients, command, info, port)
269
- client = clients[File.basename(command)]
270
-
271
- cmdline = "#{command} "
272
-
273
- case client
274
- when Hash
275
- cmdline << resolve_symbols(client["command"], info, port)
276
- client["environment"].each do |e|
277
- if e =~ /([^=]+)=(["']?)([^"']*)\2/
278
- ENV[$1] = resolve_symbols($3, info, port)
279
- else
280
- err "Invalid environment variable: #{e}"
281
- end
282
- end
283
- when String
284
- cmdline << resolve_symbols(client, info, port)
285
- else
286
- err "Unknown client info: #{client.inspect}."
287
- end
288
-
289
- display "Launching '#{cmdline}'"
290
- display ''
291
-
292
- system(cmdline)
293
- end
294
-
295
- def push_caldecott(token)
296
- client.create_app(
297
- tunnel_appname,
298
- { :name => tunnel_appname,
299
- :staging => {:framework => "sinatra"},
300
- :uris => ["#{tunnel_uniquename}.#{target_base}"],
301
- :instances => 1,
302
- :resources => {:memory => 64},
303
- :env => ["CALDECOTT_AUTH=#{token}"]
304
- }
305
- )
306
-
307
- apps_cmd.send(:upload_app_bits, tunnel_appname, HELPER_APP)
308
-
309
- invalidate_tunnel_app_info
310
- end
311
-
312
- def stop_caldecott
313
- apps_cmd.stop(tunnel_appname)
314
-
315
- invalidate_tunnel_app_info
316
- end
317
-
318
- def start_caldecott
319
- apps_cmd.start(tunnel_appname)
320
-
321
- invalidate_tunnel_app_info
322
- end
323
-
324
- private
325
-
326
- def apps_cmd
327
- a = Command::Apps.new(@options)
328
- a.client client
329
- a
330
- end
331
- end
332
- end
data/lib/cli/usage.rb DELETED
@@ -1,86 +0,0 @@
1
- class JDC::Cli::Runner
2
-
3
- def basic_usage
4
- "Usage: jdc [options] command [<args>] [command_options]\n" +
5
- "Try 'jdc help [command]' or 'jdc help options' for more information."
6
- end
7
-
8
- def display_usage
9
- if @usage
10
- say @usage_error if @usage_error
11
- say "Usage: #{@usage}"
12
- return
13
- elsif @verb_usage
14
- say @verb_usage
15
- return
16
- end
17
- say command_usage
18
- end
19
-
20
- def command_usage
21
- <<-USAGE
22
-
23
- #{basic_usage}
24
-
25
- Currently available jdc commands are:
26
-
27
- Getting Started
28
- target [url] Reports current target or sets a new target
29
- info System and account information
30
-
31
- Applications
32
- user Display current user account information
33
- apps List deployed applications
34
-
35
- Application Creation
36
- push [appname] Create, push, map, and start a new application
37
- push [appname] --path Push application from specified path
38
- push [appname] --url Set the url for the application
39
- push [appname] --instances <N> Set the expected number <N> of instances
40
- push [appname] --mem M Set the memory reservation for the application
41
- push [appname] --runtime RUNTIME Set the runtime to use for the application
42
- push [appname] --debug [MODE] Push application and start in a debug mode
43
- push [appname] --no-start Do not auto-start the application
44
-
45
- Application Operations
46
- start <appname> [--debug [MODE]] Start the application
47
- stop <appname> Stop the application
48
- restart <appname> [--debug [MODE]] Restart the application
49
- delete <appname> Delete the application
50
-
51
- Application Updates
52
- update <appname> [--path,--debug [MODE]] Update the application bits
53
- mem <appname> [memsize] Update the memory reservation for an application
54
- map <appname> <url> Register the application to the url
55
- unmap <appname> <url> Unregister the application from the url
56
- instances <appname> <num|delta> Scale the application instances up or down
57
-
58
- Application Information
59
- crashes <appname> List recent application crashes
60
- crashlogs <appname> Display log information for crashed applications
61
- logs <appname> [--all] Display log information for the application
62
- files <appname> [path] [--all] Display directory listing or file download for [path]
63
- stats <appname> Display resource usage for the application
64
- instances <appname> List application instances
65
-
66
- Application Environment
67
- env <appname> List application environment variables
68
- env-add <appname> <variable[=]value> Add an environment variable to an application
69
- env-del <appname> <variable> Delete an environment variable to an application
70
-
71
- System
72
- runtimes Display the supported runtimes of the target system
73
- frameworks Display the recognized frameworks of the target system
74
-
75
- Misc
76
- aliases List aliases
77
- alias <alias[=]command> Create an alias for a command
78
- unalias <alias> Remove an alias
79
-
80
- Help
81
- help [command] Get general help or help on a specific command
82
- help options Get help on available options
83
- USAGE
84
-
85
- end
86
- end