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
@@ -0,0 +1,9 @@
1
+ require "jdc/cli"
2
+
3
+ module JDC
4
+ module Domain
5
+ class Base < CLI
6
+ include LoginRequirements
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,40 @@
1
+ require "jdc/cli/domain/base"
2
+
3
+ module JDC::Domain
4
+ class Domains < Base
5
+ desc "List domains in a space"
6
+ group :domains
7
+ input :space, :desc => "Space to list the domains from",
8
+ :argument => :optional, :default => proc { client.current_space },
9
+ :from_given => by_name(:space)
10
+ input :all, :desc => "List all domains", :default => false
11
+ def domains
12
+ space = input[:space]
13
+
14
+ domains =
15
+ if input[:all]
16
+ with_progress("Getting all domains") do
17
+ client.domains
18
+ end
19
+ else
20
+ with_progress("Getting domains in #{c(space.name, :name)}") do
21
+ space.domains
22
+ end
23
+ end
24
+
25
+ line unless quiet?
26
+
27
+ table(
28
+ %w{name owner},
29
+ domains.sort_by(&:name).collect { |r|
30
+ [c(r.name, :name),
31
+ if org = r.owning_organization
32
+ c(org.name, :name)
33
+ else
34
+ d("none")
35
+ end
36
+ ]
37
+ })
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ require "jdc/cli/domain/base"
2
+
3
+ module JDC::Domain
4
+ class Map < Base
5
+ desc "Map a domain to an organization or space"
6
+ group :domains
7
+ input :name, :desc => "Domain to map", :argument => :required
8
+ input :organization, :desc => "Organization to map the domain to",
9
+ :aliases => %w{--org -o},
10
+ :default => proc { client.current_organization },
11
+ :from_given => by_name(:organization)
12
+ input :space, :desc => "Space to map the domain to",
13
+ :default => proc { client.current_space },
14
+ :from_given => by_name(:space)
15
+ input :shared, :desc => "Create a shared domain", :default => false
16
+ def map_domain
17
+ domain = client.domain_by_name(input[:name])
18
+
19
+ given_org = input.has?(:organization)
20
+ given_space = input.has?(:space)
21
+
22
+ org = input[:organization]
23
+ space = input[:space]
24
+
25
+ given_space = true unless given_org || given_space
26
+
27
+ unless domain
28
+ domain = client.domain
29
+ domain.name = input[:name]
30
+ domain.owning_organization = org unless input[:shared]
31
+ domain.wildcard = true
32
+
33
+ with_progress("Creating domain #{c(domain.name, :name)}") do
34
+ domain.create!
35
+ org.add_domain(domain) if org && !given_org && !given_space
36
+ end
37
+ end
38
+
39
+ if given_space
40
+ add_domain(domain, space.organization)
41
+ add_domain(domain, space)
42
+ elsif given_org
43
+ add_domain(domain, org)
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def add_domain(domain, target)
50
+ with_progress("Mapping #{c(domain.name, :name)} to #{c(target.name, :name)}") do
51
+ target.add_domain(domain)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,56 @@
1
+ require "jdc/cli/domain/base"
2
+
3
+ module JDC::Domain
4
+ class Unmap < Base
5
+ desc "Unmap a domain from an organization or space"
6
+ group :domains
7
+ input :domain, :desc => "Domain to unmap", :argument => :required,
8
+ :from_given => by_name("domain")
9
+ input :organization, :desc => "Organization to unmap the domain from",
10
+ :aliases => %w{--org -o},
11
+ :default => proc { client.current_organization },
12
+ :from_given => by_name(:organization)
13
+ input :space, :desc => "Space to unmap the domain from",
14
+ :default => proc { client.current_space },
15
+ :from_given => by_name(:space)
16
+ input :delete, :desc => "Delete domain", :type => :boolean
17
+ input :really, :type => :boolean, :forget => true, :hidden => true,
18
+ :default => proc { force? || interact }
19
+ def unmap_domain
20
+ domain = input[:domain]
21
+
22
+ given_org = input.has?(:organization)
23
+ given_space = input.has?(:space)
24
+
25
+ org = input[:organization]
26
+ space = input[:space]
27
+
28
+ if input[:delete]
29
+ return unless input[:really, domain.name, :name]
30
+
31
+ with_progress("Deleting domain #{c(domain.name, :name)}") do
32
+ domain.delete!
33
+ end
34
+
35
+ return
36
+ end
37
+
38
+ given_space = true unless given_org || given_space
39
+
40
+ remove_domain(domain, space) if given_space
41
+ remove_domain(domain, org) if given_org
42
+ end
43
+
44
+ private
45
+
46
+ def remove_domain(domain, target)
47
+ with_progress("Unmapping #{c(domain.name, :name)} from #{c(target.name, :name)}") do
48
+ target.remove_domain(domain)
49
+ end
50
+ end
51
+
52
+ def ask_really(name, color)
53
+ ask("Really delete #{c(name, color)}?", :default => false)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ require "mothership/help"
2
+
3
+ Mothership::Help.groups(
4
+ [:start, "Getting Started"],
5
+ [:apps, "Applications",
6
+ [:manage, "Management"],
7
+ [:info, "Information"]],
8
+ #[:services, "Services",
9
+ # [:manage, "Management"]],
10
+ [:organizations, "Organizations"],
11
+ [:spaces, "Spaces"],
12
+ [:routes, "Routes"],
13
+ [:domains, "Domains"],
14
+ [:admin, "Administration",
15
+ [:user, "User Management"]])
@@ -0,0 +1,105 @@
1
+ require "interact"
2
+ require "interact/pretty"
3
+ require "interact/progress"
4
+
5
+ module JDC
6
+ module Interactive
7
+ include ::Interactive::Rewindable
8
+ include Interact::Pretty
9
+ include Interact::Progress
10
+
11
+ def ask(question, options = {})
12
+ if force? and options.key?(:default)
13
+ options[:default]
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def list_choices(choices, options = {})
20
+ choices.each_with_index do |o, i|
21
+ puts "#{c(i + 1, :number)}: #{show_choice(o, options)}"
22
+ end
23
+ end
24
+
25
+ def input_state(options)
26
+ if options.key? :default
27
+ answer = show_default(options)
28
+ end
29
+
30
+ JDCState.new(options, answer)
31
+ end
32
+
33
+ def show_default(options)
34
+ case options[:default]
35
+ when true
36
+ "y"
37
+ when false
38
+ "n"
39
+ when nil
40
+ ""
41
+ else
42
+ show_choice(options[:default], options)
43
+ end
44
+ end
45
+
46
+ def prompt(question, options)
47
+ value = show_default(options)
48
+
49
+ print "#{question}"
50
+ print c("> ", :prompt)
51
+
52
+ unless value.empty?
53
+ print "#{d(value) + "\b" * value.size}"
54
+ end
55
+ end
56
+
57
+ def handler(event, state)
58
+ ans = state.answer
59
+ pos = state.position
60
+
61
+ exit if event == :eof
62
+
63
+ if state.default?
64
+ if event.is_a?(Array) and event[0] == :key
65
+ # initial non-movement keypress clears default answer
66
+ clear_input(state)
67
+ else
68
+ # wipe away any coloring
69
+ redraw_input(state)
70
+ end
71
+
72
+ state.clear_default! if(event != :up)
73
+
74
+ # tab with a default accepts it and moves to the end
75
+ if event == :tab
76
+ state.goto(ans.size)
77
+ else
78
+ super
79
+ end
80
+ else
81
+ super
82
+ end
83
+
84
+ print "\n" if event == :enter
85
+ end
86
+
87
+ class JDCState < ::Interactive::InputState
88
+ def initialize(options = {}, answer = nil, position = 0)
89
+ @options = options
90
+ @answer = answer || ""
91
+ @default = options.key? :default
92
+ @position = position
93
+ @done = false
94
+ end
95
+
96
+ def clear_default!
97
+ @default = false
98
+ end
99
+
100
+ def default?
101
+ @default
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,15 @@
1
+ module LoginRequirements
2
+ def precondition
3
+ check_key
4
+ check_organization_and_space
5
+ #check_logged_in
6
+
7
+ unless client.current_organization
8
+ fail "Please select an organization with 'jdc target --organization ORGANIZATION_NAME'. (Get organization names from 'jdc orgs'.)"
9
+ end
10
+
11
+ unless client.current_space
12
+ fail "Please select a space with 'jdc target --space SPACE_NAME'. (Get space names from 'jdc spaces'.)"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require "jdc/cli"
2
+
3
+ module JDC
4
+ module Organization
5
+ class Base < CLI
6
+ def precondition
7
+ check_key
8
+ check_target
9
+ check_organization_and_space
10
+ #check_logged_in
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require "jdc/cli/organization/base"
2
+ =begin
3
+ module JDC::Organization
4
+ class Create < Base
5
+ desc "Create an organization"
6
+ group :organizations
7
+ input :name, :desc => "Organization name", :argument => :optional
8
+ input :target, :desc => "Switch to the organization after creation",
9
+ :alias => "-t", :default => true
10
+ input :add_self, :desc => "Add yourself to the organization",
11
+ :default => true
12
+ input :find_if_exists, :desc => "Use an existing organization if one already exists with the given name", :default => false
13
+ def create_org
14
+ org = client.organization
15
+ org.name = input[:name]
16
+ org.users = [client.current_user] if input[:add_self]
17
+
18
+ begin
19
+ with_progress("Creating organization #{c(org.name, :name)}") { org.create! }
20
+ rescue JFoundry::OrganizationNameTaken
21
+ raise unless input[:find_if_exists]
22
+ org = client.organization_by_name(input[:name])
23
+ end
24
+
25
+ if input[:target]
26
+ invoke :target, :organization => org
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def ask_name
33
+ ask("Name")
34
+ end
35
+ end
36
+ end
37
+ =end
@@ -0,0 +1,63 @@
1
+ require "jdc/cli/organization/base"
2
+ =begin
3
+ module JDC::Organization
4
+ class Delete < Base
5
+ desc "Delete an organization"
6
+ group :organizations
7
+ input :organization, :desc => "Organization to delete",
8
+ :aliases => %w{--org -o}, :argument => :optional,
9
+ :from_given => by_name(:organization)
10
+ input :recursive, :desc => "Delete recursively", :alias => "-r",
11
+ :default => false, :forget => true
12
+ input :warn, :desc => "Show warning if it was the last org",
13
+ :default => true
14
+ input :really, :type => :boolean, :forget => true, :hidden => true,
15
+ :default => proc { force? || interact }
16
+ def delete_org
17
+ org = input[:organization]
18
+ return unless input[:really, org]
19
+
20
+ is_current = org == client.current_organization
21
+ @orgs ||= client.organizations(:depth => 0)
22
+ with_progress("Deleting organization #{c(org.name, :name)}") do
23
+ deleted = org.delete!(:recursive => !!input[:recursive])
24
+ @orgs.delete(org) if deleted
25
+ end
26
+
27
+ if @orgs.empty?
28
+ return unless input[:warn]
29
+
30
+ line
31
+ line c("There are no longer any organizations.", :warning)
32
+ line "You may want to create one with #{c("create-org", :good)}."
33
+ elsif is_current
34
+ invalidate_client
35
+ invoke :target
36
+ end
37
+ rescue JFoundry::AssociationNotEmpty => boom
38
+ line
39
+ line c(boom.description, :bad)
40
+ line c("If you want to delete the organization along with all dependent objects, rerun the command with the #{b("'--recursive'")} flag.", :bad)
41
+ exit_status(1)
42
+ end
43
+
44
+ private
45
+
46
+ def ask_organization
47
+ @orgs = client.organizations(:depth => 0)
48
+ fail "No organizations." if @orgs.empty?
49
+
50
+ ask("Which organization", :choices => @orgs.sort_by(&:name),
51
+ :display => proc(&:name))
52
+ end
53
+
54
+ def ask_really(org)
55
+ ask("Really delete #{c(org.name, :name)}?", :default => false)
56
+ end
57
+
58
+ def ask_recursive
59
+ ask "Delete #{c("EVERYTHING", :bad)}?", :default => false
60
+ end
61
+ end
62
+ end
63
+ =end
@@ -0,0 +1,45 @@
1
+ require "jdc/cli/organization/base"
2
+
3
+ module JDC::Organization
4
+ class Org < Base
5
+ desc "Show organization information"
6
+ group :organizations
7
+ input :organization, :desc => "Organization to show",
8
+ :aliases => %w{--org -o}, :argument => :optional,
9
+ :from_given => by_name(:organization),
10
+ :default => proc { client.current_organization }
11
+ input :full, :desc => "Show full information for spaces, domains, etc.",
12
+ :default => false
13
+ def org
14
+ org = input[:organization]
15
+
16
+ unless org
17
+ return if quiet?
18
+ fail "No current organization."
19
+ end
20
+
21
+ if quiet?
22
+ puts org.name
23
+ return
24
+ end
25
+
26
+ line "#{c(org.name, :name)}:"
27
+
28
+ indented do
29
+ line "domains: #{name_list(org.domains)}"
30
+
31
+ if input[:full]
32
+ line "spaces:"
33
+
34
+ spaced(org.spaces(:depth => 2)) do |s|
35
+ indented do
36
+ invoke :space, :space => s
37
+ end
38
+ end
39
+ else
40
+ line "spaces: #{name_list(org.spaces)}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end