af 0.3.22 → 0.5.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +14 -6
  2. data/LICENSE +1277 -24
  3. data/Rakefile +24 -87
  4. data/bin/af +7 -2
  5. data/lib/af/version.rb +3 -0
  6. data/lib/vmc.rb +7 -2
  7. data/lib/vmc/cli.rb +475 -0
  8. data/lib/vmc/cli/app/app.rb +45 -0
  9. data/lib/vmc/cli/app/apps.rb +105 -0
  10. data/lib/vmc/cli/app/base.rb +82 -0
  11. data/lib/vmc/cli/app/crashes.rb +46 -0
  12. data/lib/vmc/cli/app/delete.rb +95 -0
  13. data/lib/vmc/cli/app/deprecated.rb +11 -0
  14. data/lib/vmc/cli/app/env.rb +78 -0
  15. data/lib/vmc/cli/app/files.rb +137 -0
  16. data/lib/vmc/cli/app/health.rb +26 -0
  17. data/lib/vmc/cli/app/instances.rb +53 -0
  18. data/lib/vmc/cli/app/logs.rb +76 -0
  19. data/lib/vmc/cli/app/push.rb +107 -0
  20. data/lib/vmc/cli/app/push/create.rb +150 -0
  21. data/lib/vmc/cli/app/push/interactions.rb +100 -0
  22. data/lib/vmc/cli/app/push/sync.rb +64 -0
  23. data/lib/vmc/cli/app/rename.rb +39 -0
  24. data/lib/vmc/cli/app/restart.rb +20 -0
  25. data/lib/vmc/cli/app/scale.rb +71 -0
  26. data/lib/vmc/cli/app/start.rb +93 -0
  27. data/lib/vmc/cli/app/stats.rb +67 -0
  28. data/lib/vmc/cli/app/stop.rb +27 -0
  29. data/lib/vmc/cli/domain/base.rb +12 -0
  30. data/lib/vmc/cli/domain/domains.rb +40 -0
  31. data/lib/vmc/cli/domain/map.rb +55 -0
  32. data/lib/vmc/cli/domain/unmap.rb +56 -0
  33. data/lib/vmc/cli/help.rb +16 -0
  34. data/lib/vmc/cli/interactive.rb +105 -0
  35. data/lib/vmc/cli/organization/base.rb +14 -0
  36. data/lib/vmc/cli/organization/create.rb +32 -0
  37. data/lib/vmc/cli/organization/delete.rb +73 -0
  38. data/lib/vmc/cli/organization/org.rb +45 -0
  39. data/lib/vmc/cli/organization/orgs.rb +35 -0
  40. data/lib/vmc/cli/organization/rename.rb +36 -0
  41. data/lib/vmc/cli/route/base.rb +12 -0
  42. data/lib/vmc/cli/route/map.rb +80 -0
  43. data/lib/vmc/cli/route/routes.rb +26 -0
  44. data/lib/vmc/cli/route/unmap.rb +94 -0
  45. data/lib/vmc/cli/service/base.rb +8 -0
  46. data/lib/vmc/cli/service/bind.rb +44 -0
  47. data/lib/vmc/cli/service/create.rb +126 -0
  48. data/lib/vmc/cli/service/delete.rb +86 -0
  49. data/lib/vmc/cli/service/rename.rb +35 -0
  50. data/lib/vmc/cli/service/service.rb +42 -0
  51. data/lib/vmc/cli/service/services.rb +115 -0
  52. data/lib/vmc/cli/service/unbind.rb +38 -0
  53. data/lib/vmc/cli/space/base.rb +21 -0
  54. data/lib/vmc/cli/space/create.rb +56 -0
  55. data/lib/vmc/cli/space/delete.rb +95 -0
  56. data/lib/vmc/cli/space/rename.rb +39 -0
  57. data/lib/vmc/cli/space/space.rb +64 -0
  58. data/lib/vmc/cli/space/spaces.rb +55 -0
  59. data/lib/vmc/cli/space/take.rb +16 -0
  60. data/lib/vmc/cli/start/base.rb +80 -0
  61. data/lib/vmc/cli/start/colors.rb +13 -0
  62. data/lib/vmc/cli/start/info.rb +122 -0
  63. data/lib/vmc/cli/start/login.rb +92 -0
  64. data/lib/vmc/cli/start/logout.rb +13 -0
  65. data/lib/vmc/cli/start/target.rb +64 -0
  66. data/lib/vmc/cli/start/target_interactions.rb +37 -0
  67. data/lib/vmc/cli/start/targets.rb +16 -0
  68. data/lib/vmc/cli/user/base.rb +29 -0
  69. data/lib/vmc/cli/user/create.rb +39 -0
  70. data/lib/vmc/cli/user/delete.rb +25 -0
  71. data/lib/vmc/cli/user/passwd.rb +50 -0
  72. data/lib/vmc/cli/user/register.rb +42 -0
  73. data/lib/vmc/cli/user/users.rb +32 -0
  74. data/lib/vmc/constants.rb +13 -0
  75. data/lib/vmc/detect.rb +134 -0
  76. data/lib/vmc/errors.rb +17 -0
  77. data/lib/vmc/plugin.rb +56 -0
  78. data/lib/vmc/spacing.rb +89 -0
  79. data/lib/vmc/spec_helper.rb +1 -0
  80. data/lib/vmc/test_support.rb +4 -0
  81. data/lib/vmc/test_support/command_helper.rb +32 -0
  82. data/lib/vmc/test_support/common_input_examples.rb +14 -0
  83. data/lib/vmc/test_support/fake_home_dir.rb +16 -0
  84. data/lib/vmc/test_support/interact_helper.rb +29 -0
  85. data/lib/vmc/version.rb +3 -0
  86. data/spec/assets/hello-sinatra/Gemfile +3 -0
  87. data/spec/assets/hello-sinatra/main.rb +6 -0
  88. data/spec/features/new_user_flow_spec.rb +71 -0
  89. data/spec/spec_helper.rb +63 -0
  90. data/spec/vmc/cli/app/base_spec.rb +17 -0
  91. data/spec/vmc/cli/app/delete_spec.rb +188 -0
  92. data/spec/vmc/cli/app/instances_spec.rb +65 -0
  93. data/spec/vmc/cli/app/push/create_spec.rb +571 -0
  94. data/spec/vmc/cli/app/push_spec.rb +369 -0
  95. data/spec/vmc/cli/app/rename_spec.rb +104 -0
  96. data/spec/vmc/cli/app/scale_spec.rb +81 -0
  97. data/spec/vmc/cli/app/stats_spec.rb +62 -0
  98. data/spec/vmc/cli/domain/map_spec.rb +140 -0
  99. data/spec/vmc/cli/domain/unmap_spec.rb +73 -0
  100. data/spec/vmc/cli/organization/orgs_spec.rb +108 -0
  101. data/spec/vmc/cli/organization/rename_spec.rb +113 -0
  102. data/spec/vmc/cli/route/map_spec.rb +138 -0
  103. data/spec/vmc/cli/route/unmap_spec.rb +215 -0
  104. data/spec/vmc/cli/service/bind_spec.rb +25 -0
  105. data/spec/vmc/cli/service/delete_spec.rb +22 -0
  106. data/spec/vmc/cli/service/rename_spec.rb +105 -0
  107. data/spec/vmc/cli/service/service_spec.rb +23 -0
  108. data/spec/vmc/cli/service/unbind_spec.rb +25 -0
  109. data/spec/vmc/cli/space/rename_spec.rb +102 -0
  110. data/spec/vmc/cli/space/spaces_spec.rb +104 -0
  111. data/spec/vmc/cli/start/info_spec.rb +153 -0
  112. data/spec/vmc/cli/start/login_spec.rb +71 -0
  113. data/spec/vmc/cli/user/create_spec.rb +54 -0
  114. data/spec/vmc/cli/user/passwd_spec.rb +102 -0
  115. data/spec/vmc/cli/user/register_spec.rb +148 -0
  116. data/spec/vmc/cli_spec.rb +448 -0
  117. data/spec/vmc/detect_spec.rb +54 -0
  118. metadata +231 -124
  119. data/README.md +0 -155
  120. data/caldecott_helper/Gemfile +0 -10
  121. data/caldecott_helper/Gemfile.lock +0 -48
  122. data/caldecott_helper/server.rb +0 -43
  123. data/config/clients.yml +0 -17
  124. data/config/micro/offline.conf +0 -2
  125. data/config/micro/paths.yml +0 -22
  126. data/config/micro/refresh_ip.rb +0 -20
  127. data/lib/cli.rb +0 -48
  128. data/lib/cli/commands/admin.rb +0 -81
  129. data/lib/cli/commands/apps.rb +0 -1358
  130. data/lib/cli/commands/base.rb +0 -233
  131. data/lib/cli/commands/manifest.rb +0 -56
  132. data/lib/cli/commands/micro.rb +0 -115
  133. data/lib/cli/commands/misc.rb +0 -147
  134. data/lib/cli/commands/services.rb +0 -217
  135. data/lib/cli/commands/user.rb +0 -70
  136. data/lib/cli/config.rb +0 -176
  137. data/lib/cli/console_helper.rb +0 -163
  138. data/lib/cli/core_ext.rb +0 -122
  139. data/lib/cli/errors.rb +0 -19
  140. data/lib/cli/file_helper.rb +0 -123
  141. data/lib/cli/frameworks.rb +0 -265
  142. data/lib/cli/manifest_helper.rb +0 -316
  143. data/lib/cli/runner.rb +0 -633
  144. data/lib/cli/services_helper.rb +0 -104
  145. data/lib/cli/tunnel_helper.rb +0 -336
  146. data/lib/cli/usage.rb +0 -129
  147. data/lib/cli/version.rb +0 -7
  148. data/lib/cli/zip_util.rb +0 -102
  149. data/lib/vmc/client.rb +0 -574
  150. data/lib/vmc/const.rb +0 -27
  151. data/lib/vmc/micro.rb +0 -56
  152. data/lib/vmc/micro/switcher/base.rb +0 -97
  153. data/lib/vmc/micro/switcher/darwin.rb +0 -19
  154. data/lib/vmc/micro/switcher/dummy.rb +0 -15
  155. data/lib/vmc/micro/switcher/linux.rb +0 -16
  156. data/lib/vmc/micro/switcher/windows.rb +0 -31
  157. data/lib/vmc/micro/vmrun.rb +0 -158
@@ -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,105 @@
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 :infra, :desc => "Filter by infra regexp"
12
+ input :runtime, :desc => "Filter by runtime regexp"
13
+ input :framework, :desc => "Filter by framework regexp"
14
+ input :url, :desc => "Filter by url regexp"
15
+ input :full, :desc => "Verbose output format", :default => false
16
+ def apps
17
+ if space = input[:space]
18
+ begin
19
+ space.summarize!
20
+ rescue CFoundry::APIError
21
+ end
22
+
23
+ apps =
24
+ with_progress("Getting applications in #{c(space.name, :name)}") do
25
+ space.apps
26
+ end
27
+ else
28
+ apps =
29
+ with_progress("Getting applications") do
30
+ client.apps(:depth => 2)
31
+ end
32
+ end
33
+
34
+ line unless quiet?
35
+
36
+ if apps.empty? and !quiet?
37
+ line "No applications."
38
+ return
39
+ end
40
+
41
+ apps.reject! do |a|
42
+ !app_matches?(a, input)
43
+ end
44
+
45
+ apps = apps.sort_by(&:name)
46
+
47
+ if input[:full]
48
+ spaced(apps) do |a|
49
+ invoke :app, :app => a
50
+ end
51
+ elsif quiet?
52
+ apps.each do |a|
53
+ line a.name
54
+ end
55
+ else
56
+ display_apps_table(apps)
57
+ end
58
+ end
59
+
60
+ def display_apps_table(apps)
61
+ table(
62
+ ["name", "infra", "status", "usage", v2? && "plan", "runtime", "url"],
63
+ apps.collect { |a|
64
+ [ c(a.name, :name),
65
+ c(a.infra.name, :infra),
66
+ app_status(a),
67
+ "#{a.total_instances} x #{human_mb(a.memory)}",
68
+ v2? && (a.production ? "prod" : "dev"),
69
+ a.runtime.name,
70
+ if a.urls.empty?
71
+ d("none")
72
+ elsif a.urls.size == 1
73
+ a.url
74
+ else
75
+ "#{a.url}, ..."
76
+ end
77
+ ]
78
+ })
79
+ end
80
+
81
+ def app_matches?(a, options)
82
+ if name = options[:name]
83
+ return false if a.name !~ /#{name}/
84
+ end
85
+
86
+ if infra = options[:infra]
87
+ return false if a.infra.name !~ /#{infra}/
88
+ end
89
+
90
+ if runtime = options[:runtime]
91
+ return false if a.runtime.name !~ /#{runtime}/
92
+ end
93
+
94
+ if framework = options[:framework]
95
+ return false if a.framework.name !~ /#{framework}/
96
+ end
97
+
98
+ if url = options[:url]
99
+ return false if a.urls.none? { |u| u =~ /#{url}/ }
100
+ end
101
+
102
+ true
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,82 @@
1
+ require "vmc/cli"
2
+
3
+ module VMC
4
+ module App
5
+ class Base < CLI
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
+ used = info[:usage][:memory]
37
+ limit = info[:limits][:memory]
38
+ available = limit - used + exclude
39
+
40
+ mem = 64
41
+ choices = []
42
+ until mem > available
43
+ choices << human_mb(mem)
44
+ mem *= 2
45
+ end
46
+
47
+ choices
48
+ end
49
+
50
+ def human_mb(num)
51
+ human_size(num * 1024 * 1024, 0)
52
+ end
53
+
54
+ def human_size(num, precision = 1)
55
+ sizes = %w(G M K)
56
+ sizes.each.with_index do |suf, i|
57
+ pow = sizes.size - i
58
+ unit = 1024.0 ** pow
59
+ if num >= unit
60
+ return format("%.#{precision}f%s", num / unit, suf)
61
+ end
62
+ end
63
+
64
+ format("%.#{precision}fB", num)
65
+ end
66
+
67
+ def megabytes(str)
68
+ if str =~ /T$/i
69
+ str.to_i * 1024 * 1024
70
+ elsif str =~ /G$/i
71
+ str.to_i * 1024
72
+ elsif str =~ /M$/i
73
+ str.to_i
74
+ elsif str =~ /K$/i
75
+ str.to_i / 1024
76
+ else # assume megabytes
77
+ str.to_i
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,46 @@
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, :hidden => true
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
+ if instances.empty?
22
+ puts "No crashed instances for #{c(app.name, :name)}"
23
+ else
24
+ spaced(instances) do |i|
25
+ if quiet?
26
+ line i.id
27
+ else
28
+ display_crashed_instance(i)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def display_crashed_instance(i)
36
+ start_line "instance #{c("\##{i.id}", :instance)}: "
37
+ puts "#{b(c("crashed", :error))} "
38
+
39
+ indented do
40
+ if s = i.since
41
+ line "since: #{c(s.strftime("%F %r"), :neutral)}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ 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
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
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