cloulu 0.0.0 → 0.1.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.
Files changed (152) hide show
  1. data/bin/{cloulu → cl} +0 -0
  2. data/lib/cc_api_stub/applications.rb +53 -0
  3. data/lib/cc_api_stub/domains.rb +16 -0
  4. data/lib/cc_api_stub/frameworks.rb +22 -0
  5. data/lib/cc_api_stub/helper.rb +131 -0
  6. data/lib/cc_api_stub/login.rb +21 -0
  7. data/lib/cc_api_stub/organization_users.rb +21 -0
  8. data/lib/cc_api_stub/organizations.rb +70 -0
  9. data/lib/cc_api_stub/routes.rb +26 -0
  10. data/lib/cc_api_stub/runtimes.rb +22 -0
  11. data/lib/cc_api_stub/service_bindings.rb +22 -0
  12. data/lib/cc_api_stub/service_instances.rb +22 -0
  13. data/lib/cc_api_stub/services.rb +25 -0
  14. data/lib/cc_api_stub/spaces.rb +49 -0
  15. data/lib/cc_api_stub/users.rb +84 -0
  16. data/lib/cc_api_stub.rb +17 -0
  17. data/lib/cfoundry/auth_token.rb +63 -0
  18. data/lib/cfoundry/baseclient.rb +201 -0
  19. data/lib/cfoundry/chatty_hash.rb +46 -0
  20. data/lib/cfoundry/client.rb +46 -0
  21. data/lib/cfoundry/concerns/login_helpers.rb +13 -0
  22. data/lib/cfoundry/errors.rb +160 -0
  23. data/lib/cfoundry/rest_client.rb +299 -0
  24. data/lib/cfoundry/test_support.rb +3 -0
  25. data/lib/cfoundry/trace_helpers.rb +40 -0
  26. data/lib/cfoundry/uaaclient.rb +112 -0
  27. data/lib/cfoundry/upload_helpers.rb +187 -0
  28. data/lib/cfoundry/v1/app.rb +363 -0
  29. data/lib/cfoundry/v1/base.rb +72 -0
  30. data/lib/cfoundry/v1/client.rb +193 -0
  31. data/lib/cfoundry/v1/framework.rb +21 -0
  32. data/lib/cfoundry/v1/model.rb +178 -0
  33. data/lib/cfoundry/v1/model_magic.rb +129 -0
  34. data/lib/cfoundry/v1/runtime.rb +24 -0
  35. data/lib/cfoundry/v1/service.rb +39 -0
  36. data/lib/cfoundry/v1/service_instance.rb +32 -0
  37. data/lib/cfoundry/v1/service_plan.rb +19 -0
  38. data/lib/cfoundry/v1/user.rb +22 -0
  39. data/lib/cfoundry/v2/app.rb +392 -0
  40. data/lib/cfoundry/v2/base.rb +83 -0
  41. data/lib/cfoundry/v2/client.rb +138 -0
  42. data/lib/cfoundry/v2/domain.rb +11 -0
  43. data/lib/cfoundry/v2/framework.rb +14 -0
  44. data/lib/cfoundry/v2/model.rb +148 -0
  45. data/lib/cfoundry/v2/model_magic.rb +449 -0
  46. data/lib/cfoundry/v2/organization.rb +16 -0
  47. data/lib/cfoundry/v2/route.rb +15 -0
  48. data/lib/cfoundry/v2/runtime.rb +12 -0
  49. data/lib/cfoundry/v2/service.rb +19 -0
  50. data/lib/cfoundry/v2/service_auth_token.rb +9 -0
  51. data/lib/cfoundry/v2/service_binding.rb +10 -0
  52. data/lib/cfoundry/v2/service_instance.rb +14 -0
  53. data/lib/cfoundry/v2/service_plan.rb +12 -0
  54. data/lib/cfoundry/v2/space.rb +18 -0
  55. data/lib/cfoundry/v2/user.rb +64 -0
  56. data/lib/cfoundry/validator.rb +39 -0
  57. data/lib/cfoundry/version.rb +4 -0
  58. data/lib/cfoundry/zip.rb +56 -0
  59. data/lib/cfoundry.rb +2 -0
  60. data/lib/manifests-vmc-plugin/errors.rb +21 -0
  61. data/lib/manifests-vmc-plugin/loader/builder.rb +34 -0
  62. data/lib/manifests-vmc-plugin/loader/normalizer.rb +149 -0
  63. data/lib/manifests-vmc-plugin/loader/resolver.rb +79 -0
  64. data/lib/manifests-vmc-plugin/loader.rb +31 -0
  65. data/lib/manifests-vmc-plugin/plugin.rb +145 -0
  66. data/lib/manifests-vmc-plugin/version.rb +3 -0
  67. data/lib/manifests-vmc-plugin.rb +313 -0
  68. data/lib/mothership/base.rb +99 -0
  69. data/lib/mothership/callbacks.rb +85 -0
  70. data/lib/mothership/command.rb +146 -0
  71. data/lib/mothership/errors.rb +38 -0
  72. data/lib/mothership/help/commands.rb +53 -0
  73. data/lib/mothership/help/printer.rb +170 -0
  74. data/lib/mothership/help.rb +64 -0
  75. data/lib/mothership/inputs.rb +189 -0
  76. data/lib/mothership/parser.rb +182 -0
  77. data/lib/mothership/version.rb +3 -0
  78. data/lib/mothership.rb +64 -0
  79. data/lib/tunnel-vmc-plugin/plugin.rb +178 -0
  80. data/lib/tunnel-vmc-plugin/tunnel.rb +308 -0
  81. data/lib/tunnel-vmc-plugin/version.rb +3 -0
  82. data/lib/uaa/http.rb +168 -0
  83. data/lib/uaa/misc.rb +121 -0
  84. data/lib/uaa/scim.rb +292 -0
  85. data/lib/uaa/token_coder.rb +196 -0
  86. data/lib/uaa/token_issuer.rb +255 -0
  87. data/lib/uaa/util.rb +235 -0
  88. data/lib/uaa/version.rb +19 -0
  89. data/lib/uaa.rb +18 -0
  90. data/lib/vmc/cli/app/app.rb +45 -0
  91. data/lib/vmc/cli/app/apps.rb +99 -0
  92. data/lib/vmc/cli/app/base.rb +90 -0
  93. data/lib/vmc/cli/app/crashes.rb +42 -0
  94. data/lib/vmc/cli/app/delete.rb +95 -0
  95. data/lib/vmc/cli/app/deprecated.rb +11 -0
  96. data/lib/vmc/cli/app/env.rb +78 -0
  97. data/lib/vmc/cli/app/files.rb +137 -0
  98. data/lib/vmc/cli/app/health.rb +26 -0
  99. data/lib/vmc/cli/app/instances.rb +53 -0
  100. data/lib/vmc/cli/app/logs.rb +76 -0
  101. data/lib/vmc/cli/app/push/create.rb +165 -0
  102. data/lib/vmc/cli/app/push/interactions.rb +94 -0
  103. data/lib/vmc/cli/app/push/sync.rb +64 -0
  104. data/lib/vmc/cli/app/push.rb +109 -0
  105. data/lib/vmc/cli/app/rename.rb +35 -0
  106. data/lib/vmc/cli/app/restart.rb +20 -0
  107. data/lib/vmc/cli/app/scale.rb +71 -0
  108. data/lib/vmc/cli/app/start.rb +143 -0
  109. data/lib/vmc/cli/app/stats.rb +67 -0
  110. data/lib/vmc/cli/app/stop.rb +27 -0
  111. data/lib/vmc/cli/help.rb +11 -0
  112. data/lib/vmc/cli/interactive.rb +105 -0
  113. data/lib/vmc/cli/route/base.rb +12 -0
  114. data/lib/vmc/cli/route/map.rb +82 -0
  115. data/lib/vmc/cli/route/routes.rb +25 -0
  116. data/lib/vmc/cli/route/unmap.rb +94 -0
  117. data/lib/vmc/cli/service/base.rb +8 -0
  118. data/lib/vmc/cli/service/bind.rb +44 -0
  119. data/lib/vmc/cli/service/create.rb +126 -0
  120. data/lib/vmc/cli/service/delete.rb +86 -0
  121. data/lib/vmc/cli/service/rename.rb +35 -0
  122. data/lib/vmc/cli/service/service.rb +42 -0
  123. data/lib/vmc/cli/service/services.rb +114 -0
  124. data/lib/vmc/cli/service/unbind.rb +38 -0
  125. data/lib/vmc/cli/start/base.rb +94 -0
  126. data/lib/vmc/cli/start/colors.rb +13 -0
  127. data/lib/vmc/cli/start/info.rb +126 -0
  128. data/lib/vmc/cli/start/login.rb +97 -0
  129. data/lib/vmc/cli/start/logout.rb +17 -0
  130. data/lib/vmc/cli/start/target.rb +60 -0
  131. data/lib/vmc/cli/start/target_interactions.rb +37 -0
  132. data/lib/vmc/cli/start/targets.rb +16 -0
  133. data/lib/vmc/cli/user/base.rb +29 -0
  134. data/lib/vmc/cli/user/create.rb +39 -0
  135. data/lib/vmc/cli/user/delete.rb +27 -0
  136. data/lib/vmc/cli/user/passwd.rb +50 -0
  137. data/lib/vmc/cli/user/register.rb +42 -0
  138. data/lib/vmc/cli/user/users.rb +32 -0
  139. data/lib/vmc/cli/v2_check_cli.rb +16 -0
  140. data/lib/vmc/cli.rb +474 -0
  141. data/lib/vmc/constants.rb +13 -0
  142. data/lib/vmc/detect.rb +129 -0
  143. data/lib/vmc/errors.rb +19 -0
  144. data/lib/vmc/plugin.rb +56 -0
  145. data/lib/vmc/spacing.rb +89 -0
  146. data/lib/vmc/spec_helper.rb +1 -0
  147. data/lib/vmc/test_support.rb +6 -0
  148. data/lib/vmc/version.rb +3 -0
  149. data/lib/vmc.rb +8 -0
  150. data/vendor/errors/v1.yml +189 -0
  151. data/vendor/errors/v2.yml +360 -0
  152. metadata +303 -190
@@ -0,0 +1,19 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ # Cloud Foundry namespace
15
+ module CF
16
+ module UAA
17
+ VERSION = "1.3.10"
18
+ end
19
+ end
data/lib/uaa.rb ADDED
@@ -0,0 +1,18 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ require "uaa/version"
15
+ require "uaa/misc"
16
+ require "uaa/token_issuer"
17
+ require "uaa/token_coder"
18
+ require "uaa/scim"
@@ -0,0 +1,45 @@
1
+ require "vmc/cli/app/base"
2
+
3
+ module VMC::App
4
+ class Apps < Base
5
+ IS_UTF8 = !!(ENV["LC_ALL"] || ENV["LC_CTYPE"] || ENV["LANG"] || "")["UTF-8"].freeze
6
+
7
+ desc "Show app information"
8
+ group :apps
9
+ input :app, :desc => "App to show", :argument => :required,
10
+ :from_given => by_name(:app)
11
+ def app
12
+ app = input[:app]
13
+
14
+ if quiet?
15
+ line app.name
16
+ else
17
+ display_app(app)
18
+ end
19
+ end
20
+
21
+ def display_app(a)
22
+ status = app_status(a)
23
+
24
+ line "#{c(a.name, :name)}: #{status}"
25
+
26
+ indented do
27
+ line "platform: #{b(a.framework.name)} on #{b(a.runtime.name)}"
28
+
29
+ start_line "usage: #{b(human_mb(a.memory))}"
30
+ print " #{d(IS_UTF8 ? "\xc3\x97" : "x")} #{b(a.total_instances)}"
31
+ print " instance#{a.total_instances == 1 ? "" : "s"}"
32
+
33
+ line
34
+
35
+ unless a.urls.empty?
36
+ line "urls: #{a.urls.collect { |u| b(u) }.join(", ")}"
37
+ end
38
+
39
+ unless a.services.empty?
40
+ line "services: #{a.services.collect { |s| b(s.name) }.join(", ")}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,99 @@
1
+ require "vmc/cli/app/base"
2
+
3
+ module VMC::App
4
+ class Apps < Base
5
+ desc "List your applications"
6
+ group :apps
7
+ input :space, :desc => "Show apps in given space",
8
+ :default => proc { client.current_space },
9
+ :from_given => by_name(:space)
10
+ input :name, :desc => "Filter by name regexp"
11
+ input :runtime, :desc => "Filter by runtime regexp"
12
+ input :framework, :desc => "Filter by framework regexp"
13
+ input :url, :desc => "Filter by url regexp"
14
+ input :full, :desc => "Verbose output format", :default => false
15
+ def apps
16
+ if space = input[:space]
17
+ begin
18
+ space.summarize!
19
+ rescue CFoundry::APIError
20
+ end
21
+
22
+ apps =
23
+ with_progress("Getting applications in #{c(space.name, :name)}") do
24
+ space.apps
25
+ end
26
+ else
27
+ apps =
28
+ with_progress("Getting applications") do
29
+ client.apps(:depth => 2)
30
+ end
31
+ end
32
+
33
+ line unless quiet?
34
+
35
+ if apps.empty? and !quiet?
36
+ line "No applications."
37
+ return
38
+ end
39
+
40
+ apps.reject! do |a|
41
+ !app_matches?(a, input)
42
+ end
43
+
44
+ apps = apps.sort_by(&:name)
45
+
46
+ if input[:full]
47
+ spaced(apps) do |a|
48
+ invoke :app, :app => a
49
+ end
50
+ elsif quiet?
51
+ apps.each do |a|
52
+ line a.name
53
+ end
54
+ else
55
+ display_apps_table(apps)
56
+ end
57
+ end
58
+
59
+ def display_apps_table(apps)
60
+ table(
61
+ ["name", "status", "usage", v2? && "plan", "runtime", "url"],
62
+ apps.collect { |a|
63
+ [ c(a.name, :name),
64
+ app_status(a),
65
+ "#{a.total_instances} x #{human_mb(a.memory)}",
66
+ v2? && (a.production ? "prod" : "dev"),
67
+ a.runtime.name,
68
+ if a.urls.empty?
69
+ d("none")
70
+ elsif a.urls.size == 1
71
+ a.url
72
+ else
73
+ "#{a.url}, ..."
74
+ end
75
+ ]
76
+ })
77
+ end
78
+
79
+ def app_matches?(a, options)
80
+ if name = options[:name]
81
+ return false if a.name !~ /#{name}/
82
+ end
83
+
84
+ if runtime = options[:runtime]
85
+ return false if a.runtime.name !~ /#{runtime}/
86
+ end
87
+
88
+ if framework = options[:framework]
89
+ return false if a.framework.name !~ /#{framework}/
90
+ end
91
+
92
+ if url = options[:url]
93
+ return false if a.urls.none? { |u| u =~ /#{url}/ }
94
+ end
95
+
96
+ true
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,90 @@
1
+ require "vmc/cli/v2_check_cli"
2
+
3
+ module VMC
4
+ module App
5
+ class Base < V2CheckCLI
6
+ # choose the right color for app/instance state
7
+ def state_color(s)
8
+ case s
9
+ when "STARTING"
10
+ :neutral
11
+ when "STARTED", "RUNNING"
12
+ :good
13
+ when "DOWN"
14
+ :bad
15
+ when "FLAPPING"
16
+ :error
17
+ when "N/A"
18
+ :unknown
19
+ else
20
+ :warning
21
+ end
22
+ end
23
+
24
+ def app_status(a)
25
+ health = a.health
26
+
27
+ if a.debug_mode == "suspend" && health == "0%"
28
+ c("suspended", :neutral)
29
+ else
30
+ c(health.downcase, state_color(health))
31
+ end
32
+ end
33
+
34
+ def memory_choices(exclude = 0)
35
+ info = client.info
36
+
37
+ usage = info[:usage]
38
+ limit = info[:limits][:memory]
39
+
40
+ ceiling =
41
+ if usage
42
+ used = usage[:memory]
43
+ limit - used + exclude
44
+ else
45
+ limit
46
+ end
47
+
48
+ mem = 64
49
+ choices = []
50
+ until mem > ceiling
51
+ choices << human_mb(mem)
52
+ mem *= 2
53
+ end
54
+
55
+ choices
56
+ end
57
+
58
+ def human_mb(num)
59
+ human_size(num * 1024 * 1024, 0)
60
+ end
61
+
62
+ def human_size(num, precision = 1)
63
+ sizes = %w(G M K)
64
+ sizes.each.with_index do |suf, i|
65
+ pow = sizes.size - i
66
+ unit = 1024.0 ** pow
67
+ if num >= unit
68
+ return format("%.#{precision}f%s", num / unit, suf)
69
+ end
70
+ end
71
+
72
+ format("%.#{precision}fB", num)
73
+ end
74
+
75
+ def megabytes(str)
76
+ if str =~ /T$/i
77
+ str.to_i * 1024 * 1024
78
+ elsif str =~ /G$/i
79
+ str.to_i * 1024
80
+ elsif str =~ /M$/i
81
+ str.to_i
82
+ elsif str =~ /K$/i
83
+ str.to_i / 1024
84
+ else # assume megabytes
85
+ str.to_i
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,42 @@
1
+ require "vmc/cli/app/base"
2
+
3
+ module VMC::App
4
+ class Crashes < Base
5
+ desc "List an app's crashed instances"
6
+ group :apps, :info
7
+ input :apps, :desc => "Applications whose crashed instances to list",
8
+ :argument => :splat, :singular => :app, :from_given => by_name(:app)
9
+ def crashes
10
+ apps = input[:apps]
11
+ fail "No applications given." if apps.empty?
12
+
13
+ spaced(apps) do |app|
14
+ instances =
15
+ with_progress("Getting crashed instances for #{c(app.name, :name)}") do
16
+ app.crashes
17
+ end
18
+
19
+ line unless quiet?
20
+
21
+ spaced(instances) do |i|
22
+ if quiet?
23
+ line i.id
24
+ else
25
+ display_crashed_instance(i)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def display_crashed_instance(i)
32
+ start_line "instance #{c("\##{i.id}", :instance)}: "
33
+ puts "#{b(c("crashed", :error))} "
34
+
35
+ indented do
36
+ if s = i.since
37
+ line "since: #{c(s.strftime("%F %r"), :neutral)}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,95 @@
1
+ require "set"
2
+
3
+ require "vmc/cli/app/base"
4
+
5
+ module VMC::App
6
+ class Delete < Base
7
+ desc "Delete an application"
8
+ group :apps, :manage
9
+ input :apps, :desc => "Applications to delete", :argument => :splat,
10
+ :singular => :app, :from_given => by_name(:app)
11
+ input :routes, :desc => "Delete associated routes", :default => false
12
+ input :delete_orphaned, :desc => "Delete orphaned services",
13
+ :aliases => "-o", :default => proc { force? ? false : interact },
14
+ :forget => true
15
+ input :all, :desc => "Delete all applications", :default => false
16
+ input :really, :type => :boolean, :forget => true, :hidden => true,
17
+ :default => proc { force? || interact }
18
+ def delete
19
+ apps = client.apps
20
+
21
+ if input[:all]
22
+ return unless input[:really, "ALL APPS", :bad]
23
+
24
+ to_delete = apps
25
+ others = []
26
+ else
27
+ to_delete = input[:apps]
28
+ others = apps - to_delete
29
+ end
30
+
31
+ all_services = apps.collect(&:services).flatten
32
+ deleted_app_services = []
33
+
34
+ spaced(to_delete) do |app|
35
+ really = input[:all] || input[:really, app.name, :name]
36
+ next unless really
37
+
38
+ deleted_app_services += app.services
39
+
40
+ with_progress("Deleting #{c(app.name, :name)}") do
41
+ app.routes.collect(&:delete!) if input[:routes]
42
+ app.delete!
43
+ end
44
+ end
45
+
46
+ delete_orphaned_services(
47
+ find_orphaned_services(deleted_app_services, all_services))
48
+
49
+ to_delete
50
+ end
51
+
52
+ def find_orphaned_services(deleted, all)
53
+ orphaned = []
54
+
55
+ leftover = all.dup
56
+ deleted.each do |svc|
57
+ leftover.slice!(leftover.index(svc))
58
+ orphaned << svc unless leftover.include?(svc)
59
+ end
60
+
61
+ # clear out the relationships as the apps are now deleted
62
+ orphaned.each(&:invalidate!)
63
+ end
64
+
65
+ def delete_orphaned_services(orphans)
66
+ return if orphans.empty?
67
+
68
+ line unless quiet? || force?
69
+
70
+ orphans.select { |o| input[:delete_orphaned, o] }.each do |service|
71
+ # TODO: splat
72
+ invoke :delete_service, :service => service, :really => true
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def ask_apps
79
+ apps = client.apps
80
+ fail "No applications." if apps.empty?
81
+
82
+ [ask("Delete which application?", :choices => apps.sort_by(&:name),
83
+ :display => proc(&:name))]
84
+ end
85
+
86
+ def ask_really(name, color)
87
+ ask("Really delete #{c(name, color)}?", :default => false)
88
+ end
89
+
90
+ def ask_delete_orphaned(service)
91
+ ask("Delete orphaned service #{c(service.name, :name)}?",
92
+ :default => false)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,11 @@
1
+ require "vmc/cli/app/base"
2
+
3
+ module VMC::App
4
+ class Deprecated < Base
5
+ desc "DEPRECATED. Use 'push' instead."
6
+ input :app, :argument => :optional
7
+ def update
8
+ fail "The 'update' command is no longer needed; use 'push' instead."
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,78 @@
1
+ require "vmc/cli/app/base"
2
+
3
+ module VMC::App
4
+ class Env < Base
5
+ VALID_ENV_VAR = /^[a-zA-Za-z_][[:alnum:]_]*$/
6
+
7
+ desc "Show all environment variables set for an app"
8
+ group :apps, :info
9
+ input :app, :desc => "Application to inspect the environment of",
10
+ :argument => true, :from_given => by_name(:app)
11
+ def env
12
+ app = input[:app]
13
+
14
+ vars =
15
+ with_progress("Getting env for #{c(app.name, :name)}") do |s|
16
+ app.env
17
+ end
18
+
19
+ line unless quiet?
20
+
21
+ vars.each do |name, val|
22
+ line "#{c(name, :name)}: #{val}"
23
+ end
24
+ end
25
+
26
+ desc "Set an environment variable"
27
+ group :apps, :info, :hidden => true
28
+ input :app, :desc => "Application to set the variable for",
29
+ :argument => true, :from_given => by_name(:app)
30
+ input :name, :desc => "Variable name", :argument => true
31
+ input :value, :desc => "Variable value", :argument => :optional
32
+ input :restart, :desc => "Restart app after updating?", :default => true
33
+ def set_env
34
+ app = input[:app]
35
+ name = input[:name]
36
+
37
+ if value = input[:value]
38
+ name = input[:name]
39
+ elsif name["="]
40
+ name, value = name.split("=")
41
+ end
42
+
43
+ unless name =~ VALID_ENV_VAR
44
+ fail "Invalid variable name; must match #{VALID_ENV_VAR.inspect}"
45
+ end
46
+
47
+ with_progress("Updating #{c(app.name, :name)}") do
48
+ app.env[name] = value
49
+ app.update!
50
+ end
51
+
52
+ if app.started? && input[:restart]
53
+ invoke :restart, :app => app
54
+ end
55
+ end
56
+
57
+
58
+ desc "Remove an environment variable"
59
+ group :apps, :info, :hidden => true
60
+ input :app, :desc => "Application to set the variable for",
61
+ :argument => true, :from_given => by_name(:app)
62
+ input :name, :desc => "Variable name", :argument => true
63
+ input :restart, :desc => "Restart app after updating?", :default => true
64
+ def unset_env
65
+ app = input[:app]
66
+ name = input[:name]
67
+
68
+ with_progress("Updating #{c(app.name, :name)}") do
69
+ app.env.delete(name)
70
+ app.update!
71
+ end
72
+
73
+ if app.started? && input[:restart]
74
+ invoke :restart, :app => app
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,137 @@
1
+ require "thread"
2
+ require "vmc/cli/app/base"
3
+
4
+ module VMC::App
5
+ class Files < Base
6
+ desc "Print out an app's file contents"
7
+ group :apps, :info, :hidden => true
8
+ input :app, :desc => "Application to inspect the files of",
9
+ :argument => true, :from_given => by_name(:app)
10
+ input :path, :desc => "Path of file to read", :argument => :optional,
11
+ :default => "/"
12
+ def file
13
+ app = input[:app]
14
+ path = input[:path]
15
+
16
+ file =
17
+ with_progress("Getting file contents") do
18
+ app.file(*path.split("/"))
19
+ end
20
+
21
+ if quiet?
22
+ print file
23
+ else
24
+ line
25
+
26
+ file.split("\n").each do |l|
27
+ line l
28
+ end
29
+ end
30
+ rescue CFoundry::NotFound
31
+ fail "Invalid path #{b(path)} for app #{b(app.name)}"
32
+ rescue CFoundry::FileError => e
33
+ fail e.description
34
+ end
35
+
36
+ desc "Examine an app's files"
37
+ group :apps, :info, :hidden => true
38
+ input :app, :desc => "Application to inspect the files of",
39
+ :argument => true, :from_given => by_name(:app)
40
+ input :path, :desc => "Path of directory to list", :argument => :optional,
41
+ :default => "/"
42
+ def files
43
+ app = input[:app]
44
+ path = input[:path]
45
+
46
+ if quiet?
47
+ files =
48
+ with_progress("Getting file listing") do
49
+ app.files(*path.split("/"))
50
+ end
51
+
52
+ files.each do |file|
53
+ line file.join("/")
54
+ end
55
+ else
56
+ invoke :file, :app => app, :path => path
57
+ end
58
+ rescue CFoundry::NotFound
59
+ fail "Invalid path #{b(path)} for app #{b(app.name)}"
60
+ rescue CFoundry::FileError => e
61
+ fail e.description
62
+ end
63
+
64
+ desc "Stream an app's file contents"
65
+ group :apps, :info, :hidden => true
66
+ input :app, :desc => "Application to inspect the files of",
67
+ :argument => true, :from_given => by_name(:app)
68
+ input :path, :desc => "Path of file to stream", :argument => :optional
69
+ def tail
70
+ app = input[:app]
71
+
72
+ lines = Queue.new
73
+ max_len = 0
74
+
75
+ if path = input[:path]
76
+ max_len = path.size
77
+ app.instances.each do |i|
78
+ Thread.new do
79
+ stream_path(lines, i, path.split("/"))
80
+ end
81
+ end
82
+ else
83
+ app.instances.each do |i|
84
+ i.files("logs").each do |path|
85
+ len = path.join("/").size
86
+ max_len = len if len > max_len
87
+
88
+ Thread.new do
89
+ stream_path(lines, i, path)
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ while line = lines.pop
96
+ instance, path, log = line
97
+
98
+ unless log.end_with?("\n")
99
+ log += i("%") if color?
100
+ log += "\n"
101
+ end
102
+
103
+ print "\##{c(instance.id, :instance)} "
104
+ print "#{c(path.join("/").ljust(max_len), :name)} "
105
+ print log
106
+ end
107
+ rescue CFoundry::NotFound
108
+ fail "Invalid path #{b(path)} for app #{b(app.name)}"
109
+ rescue CFoundry::FileError => e
110
+ fail e.description
111
+ end
112
+
113
+ def stream_path(lines, instance, path)
114
+ if verbose?
115
+ lines << [instance, path, c("streaming...", :good) + "\n"]
116
+ end
117
+
118
+ instance.stream_file(*path) do |contents|
119
+ contents.each_line do |line|
120
+ lines << [instance, path, line]
121
+ end
122
+ end
123
+
124
+ lines << [instance, path, c("end of file", :bad) + "\n"]
125
+ rescue Timeout::Error
126
+ if verbose?
127
+ lines << [
128
+ instance,
129
+ path,
130
+ c("timed out; reconnecting...", :bad) + "\n"
131
+ ]
132
+ end
133
+
134
+ retry
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,26 @@
1
+ require "vmc/cli/app/base"
2
+
3
+ module VMC::App
4
+ class Health < Base
5
+ desc "Get application health"
6
+ group :apps, :info
7
+ input :apps, :desc => "Applications to start", :argument => :splat,
8
+ :singular => :app, :from_given => by_name(:app)
9
+ def health
10
+ apps = input[:apps]
11
+ fail "No applications given." if apps.empty?
12
+
13
+ health =
14
+ with_progress("Getting health status") do
15
+ apps.collect { |a| [a, app_status(a)] }
16
+ end
17
+
18
+ line unless quiet?
19
+
20
+ spaced(health) do |app, status|
21
+ start_line "#{c(app.name, :name)}: " unless quiet?
22
+ puts status
23
+ end
24
+ end
25
+ end
26
+ end