trucker-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +1277 -0
- data/Rakefile +13 -0
- data/bin/truck +18 -0
- data/lib/admin/README.md +30 -0
- data/lib/admin/curl.rb +59 -0
- data/lib/admin/guid.rb +89 -0
- data/lib/admin/plugin.rb +8 -0
- data/lib/admin/service_auth_token.rb +93 -0
- data/lib/admin/service_broker/add.rb +54 -0
- data/lib/admin/service_broker/remove.rb +33 -0
- data/lib/admin/service_broker/service_brokers.rb +29 -0
- data/lib/admin/service_broker/update.rb +60 -0
- data/lib/admin/set_quota.rb +44 -0
- data/lib/cf.rb +14 -0
- data/lib/cf/cli.rb +495 -0
- data/lib/cf/cli/app/app.rb +43 -0
- data/lib/cf/cli/app/apps.rb +87 -0
- data/lib/cf/cli/app/base.rb +72 -0
- data/lib/cf/cli/app/delete.rb +95 -0
- data/lib/cf/cli/app/deprecated.rb +11 -0
- data/lib/cf/cli/app/env.rb +99 -0
- data/lib/cf/cli/app/events.rb +45 -0
- data/lib/cf/cli/app/files.rb +137 -0
- data/lib/cf/cli/app/health.rb +26 -0
- data/lib/cf/cli/app/instances.rb +53 -0
- data/lib/cf/cli/app/logs.rb +76 -0
- data/lib/cf/cli/app/push.rb +104 -0
- data/lib/cf/cli/app/push/create.rb +108 -0
- data/lib/cf/cli/app/push/interactions.rb +90 -0
- data/lib/cf/cli/app/push/sync.rb +57 -0
- data/lib/cf/cli/app/rename.rb +35 -0
- data/lib/cf/cli/app/restart.rb +31 -0
- data/lib/cf/cli/app/scale.rb +63 -0
- data/lib/cf/cli/app/start.rb +175 -0
- data/lib/cf/cli/app/stats.rb +66 -0
- data/lib/cf/cli/app/stop.rb +27 -0
- data/lib/cf/cli/domain/base.rb +9 -0
- data/lib/cf/cli/domain/domains.rb +40 -0
- data/lib/cf/cli/domain/map.rb +55 -0
- data/lib/cf/cli/domain/unmap.rb +56 -0
- data/lib/cf/cli/help.rb +15 -0
- data/lib/cf/cli/interactive.rb +104 -0
- data/lib/cf/cli/login_requirements.rb +13 -0
- data/lib/cf/cli/organization/base.rb +12 -0
- data/lib/cf/cli/organization/create.rb +36 -0
- data/lib/cf/cli/organization/delete.rb +61 -0
- data/lib/cf/cli/organization/org.rb +45 -0
- data/lib/cf/cli/organization/orgs.rb +30 -0
- data/lib/cf/cli/organization/rename.rb +36 -0
- data/lib/cf/cli/populators/base.rb +16 -0
- data/lib/cf/cli/populators/organization.rb +32 -0
- data/lib/cf/cli/populators/populator_methods.rb +64 -0
- data/lib/cf/cli/populators/space.rb +33 -0
- data/lib/cf/cli/populators/target.rb +14 -0
- data/lib/cf/cli/route/base.rb +9 -0
- data/lib/cf/cli/route/delete.rb +28 -0
- data/lib/cf/cli/route/map.rb +68 -0
- data/lib/cf/cli/route/routes.rb +26 -0
- data/lib/cf/cli/route/unmap.rb +56 -0
- data/lib/cf/cli/service/base.rb +9 -0
- data/lib/cf/cli/service/bind.rb +43 -0
- data/lib/cf/cli/service/create.rb +158 -0
- data/lib/cf/cli/service/delete.rb +82 -0
- data/lib/cf/cli/service/rename.rb +35 -0
- data/lib/cf/cli/service/service.rb +40 -0
- data/lib/cf/cli/service/service_helper.rb +25 -0
- data/lib/cf/cli/service/service_instance_helper.rb +100 -0
- data/lib/cf/cli/service/services.rb +110 -0
- data/lib/cf/cli/service/unbind.rb +36 -0
- data/lib/cf/cli/space/base.rb +27 -0
- data/lib/cf/cli/space/create.rb +66 -0
- data/lib/cf/cli/space/delete.rb +55 -0
- data/lib/cf/cli/space/rename.rb +38 -0
- data/lib/cf/cli/space/space.rb +66 -0
- data/lib/cf/cli/space/spaces.rb +57 -0
- data/lib/cf/cli/space/switch.rb +18 -0
- data/lib/cf/cli/start/base.rb +35 -0
- data/lib/cf/cli/start/colors.rb +13 -0
- data/lib/cf/cli/start/login.rb +104 -0
- data/lib/cf/cli/start/logout.rb +17 -0
- data/lib/cf/cli/start/target.rb +50 -0
- data/lib/cf/cli/start/target_prettifier.rb +35 -0
- data/lib/cf/cli/start/targets.rb +16 -0
- data/lib/cf/cli/user/base.rb +29 -0
- data/lib/cf/cli/user/create.rb +51 -0
- data/lib/cf/cli/user/passwd.rb +36 -0
- data/lib/cf/cli/user/register.rb +42 -0
- data/lib/cf/cli/user/users.rb +32 -0
- data/lib/cf/constants.rb +10 -0
- data/lib/cf/errors.rb +19 -0
- data/lib/cf/plugin.rb +56 -0
- data/lib/cf/spacing.rb +89 -0
- data/lib/cf/spec_helper.rb +1 -0
- data/lib/cf/test_support.rb +6 -0
- data/lib/cf/version.rb +3 -0
- data/lib/console/README.md +16 -0
- data/lib/console/console.rb +187 -0
- data/lib/console/plugin.rb +32 -0
- data/lib/manifests/errors.rb +35 -0
- data/lib/manifests/loader.rb +31 -0
- data/lib/manifests/loader/builder.rb +39 -0
- data/lib/manifests/loader/normalizer.rb +145 -0
- data/lib/manifests/loader/resolver.rb +79 -0
- data/lib/manifests/manifests.rb +343 -0
- data/lib/manifests/plugin.rb +140 -0
- data/lib/micro/README.md +25 -0
- data/lib/micro/errors.rb +4 -0
- data/lib/micro/micro.rb +56 -0
- data/lib/micro/plugin.rb +197 -0
- data/lib/micro/switcher/base.rb +79 -0
- data/lib/micro/switcher/darwin.rb +21 -0
- data/lib/micro/switcher/dummy.rb +15 -0
- data/lib/micro/switcher/linux.rb +16 -0
- data/lib/micro/switcher/windows.rb +31 -0
- data/lib/micro/vmrun.rb +175 -0
- data/lib/tasks/gem_release.rake +56 -0
- data/lib/tasks/windows_build.rake +14 -0
- data/lib/tunnel/README.md +29 -0
- data/lib/tunnel/config/clients.yml +17 -0
- data/lib/tunnel/helper-app/Gemfile +10 -0
- data/lib/tunnel/helper-app/Gemfile.lock +48 -0
- data/lib/tunnel/helper-app/server.rb +43 -0
- data/lib/tunnel/plugin.rb +183 -0
- data/lib/tunnel/tunnel.rb +295 -0
- data/spec/admin/curl_spec.rb +52 -0
- data/spec/admin/guid_spec.rb +85 -0
- data/spec/admin/service_broker/add_spec.rb +64 -0
- data/spec/admin/service_broker/remove_spec.rb +46 -0
- data/spec/admin/service_broker/service_brokers_spec.rb +34 -0
- data/spec/admin/service_broker/update_spec.rb +51 -0
- data/spec/admin/set_quota_spec.rb +89 -0
- data/spec/assets/env/Gemfile +4 -0
- data/spec/assets/env/Gemfile.lock +20 -0
- data/spec/assets/env/env_test.rb +58 -0
- data/spec/assets/hello-sinatra/Gemfile +3 -0
- data/spec/assets/hello-sinatra/Gemfile.lock +17 -0
- data/spec/assets/hello-sinatra/config.ru +3 -0
- data/spec/assets/hello-sinatra/fat-cat-makes-app-larger.png +0 -0
- data/spec/assets/hello-sinatra/main.rb +8 -0
- data/spec/assets/rails328_ruby187_app/Gemfile +39 -0
- data/spec/assets/rails328_ruby187_app/README.rdoc +261 -0
- data/spec/assets/rails328_ruby187_app/Rakefile +7 -0
- data/spec/assets/rails328_ruby187_app/app/assets/images/rails.png +0 -0
- data/spec/assets/rails328_ruby187_app/app/assets/javascripts/application.js +15 -0
- data/spec/assets/rails328_ruby187_app/app/assets/stylesheets/application.css +13 -0
- data/spec/assets/rails328_ruby187_app/app/controllers/application_controller.rb +3 -0
- data/spec/assets/rails328_ruby187_app/app/helpers/application_helper.rb +2 -0
- data/spec/assets/rails328_ruby187_app/app/views/layouts/application.html.erb +14 -0
- data/spec/assets/rails328_ruby187_app/config.ru +4 -0
- data/spec/assets/rails328_ruby187_app/config/application.rb +62 -0
- data/spec/assets/rails328_ruby187_app/config/boot.rb +6 -0
- data/spec/assets/rails328_ruby187_app/config/database.yml +25 -0
- data/spec/assets/rails328_ruby187_app/config/environment.rb +5 -0
- data/spec/assets/rails328_ruby187_app/config/environments/development.rb +37 -0
- data/spec/assets/rails328_ruby187_app/config/environments/production.rb +67 -0
- data/spec/assets/rails328_ruby187_app/config/environments/test.rb +37 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/inflections.rb +15 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/mime_types.rb +5 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/secret_token.rb +7 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/session_store.rb +8 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/assets/rails328_ruby187_app/config/locales/en.yml +5 -0
- data/spec/assets/rails328_ruby187_app/config/routes.rb +58 -0
- data/spec/assets/rails328_ruby187_app/db/seeds.rb +7 -0
- data/spec/assets/rails328_ruby187_app/doc/README_FOR_APP +2 -0
- data/spec/assets/rails328_ruby187_app/manifest.yml +7 -0
- data/spec/assets/rails328_ruby187_app/public/404.html +26 -0
- data/spec/assets/rails328_ruby187_app/public/422.html +26 -0
- data/spec/assets/rails328_ruby187_app/public/500.html +25 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js +17 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.css +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.css.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.js +17 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.js.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/manifest.yml +4 -0
- data/spec/assets/rails328_ruby187_app/public/assets/rails-be8732dac73d845ac5b142c8fb5f9fb0.png +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/rails.png +0 -0
- data/spec/assets/rails328_ruby187_app/public/favicon.ico +0 -0
- data/spec/assets/rails328_ruby187_app/public/index.html +241 -0
- data/spec/assets/rails328_ruby187_app/public/robots.txt +5 -0
- data/spec/assets/rails328_ruby187_app/script/rails +6 -0
- data/spec/assets/rails328_ruby187_app/test/performance/browsing_test.rb +12 -0
- data/spec/assets/rails328_ruby187_app/test/test_helper.rb +13 -0
- data/spec/cf/cli/app/base_spec.rb +17 -0
- data/spec/cf/cli/app/delete_spec.rb +197 -0
- data/spec/cf/cli/app/env_spec.rb +261 -0
- data/spec/cf/cli/app/events_spec.rb +72 -0
- data/spec/cf/cli/app/help_spec.rb +39 -0
- data/spec/cf/cli/app/instances_spec.rb +69 -0
- data/spec/cf/cli/app/push/create_spec.rb +444 -0
- data/spec/cf/cli/app/push/interactions_spec.rb +32 -0
- data/spec/cf/cli/app/push_spec.rb +332 -0
- data/spec/cf/cli/app/rename_spec.rb +108 -0
- data/spec/cf/cli/app/restart_spec.rb +47 -0
- data/spec/cf/cli/app/scale_spec.rb +63 -0
- data/spec/cf/cli/app/start_spec.rb +255 -0
- data/spec/cf/cli/app/stats_spec.rb +66 -0
- data/spec/cf/cli/domain/help_spec.rb +39 -0
- data/spec/cf/cli/domain/map_spec.rb +140 -0
- data/spec/cf/cli/domain/unmap_spec.rb +77 -0
- data/spec/cf/cli/help_spec.rb +21 -0
- data/spec/cf/cli/organization/create_spec.rb +121 -0
- data/spec/cf/cli/organization/delete_spec.rb +105 -0
- data/spec/cf/cli/organization/help_spec.rb +39 -0
- data/spec/cf/cli/organization/orgs_spec.rb +116 -0
- data/spec/cf/cli/organization/rename_spec.rb +116 -0
- data/spec/cf/cli/populators/organization_spec.rb +179 -0
- data/spec/cf/cli/populators/space_spec.rb +156 -0
- data/spec/cf/cli/populators/target_spec.rb +39 -0
- data/spec/cf/cli/route/delete_spec.rb +92 -0
- data/spec/cf/cli/route/help_spec.rb +32 -0
- data/spec/cf/cli/route/map_spec.rb +148 -0
- data/spec/cf/cli/route/unmap_spec.rb +114 -0
- data/spec/cf/cli/service/bind_spec.rb +25 -0
- data/spec/cf/cli/service/create_spec.rb +147 -0
- data/spec/cf/cli/service/delete_spec.rb +22 -0
- data/spec/cf/cli/service/help_spec.rb +39 -0
- data/spec/cf/cli/service/rename_spec.rb +103 -0
- data/spec/cf/cli/service/service_helper_spec.rb +66 -0
- data/spec/cf/cli/service/service_instance_helper_spec.rb +155 -0
- data/spec/cf/cli/service/service_spec.rb +23 -0
- data/spec/cf/cli/service/services_spec.rb +156 -0
- data/spec/cf/cli/service/unbind_spec.rb +25 -0
- data/spec/cf/cli/space/base_spec.rb +49 -0
- data/spec/cf/cli/space/create_spec.rb +144 -0
- data/spec/cf/cli/space/delete_spec.rb +109 -0
- data/spec/cf/cli/space/help_spec.rb +39 -0
- data/spec/cf/cli/space/rename_spec.rb +110 -0
- data/spec/cf/cli/space/space_spec.rb +80 -0
- data/spec/cf/cli/space/spaces_spec.rb +107 -0
- data/spec/cf/cli/space/switch_space_spec.rb +57 -0
- data/spec/cf/cli/start/help_spec.rb +39 -0
- data/spec/cf/cli/start/login_spec.rb +142 -0
- data/spec/cf/cli/start/logout_spec.rb +49 -0
- data/spec/cf/cli/start/target_prettifier_spec.rb +78 -0
- data/spec/cf/cli/start/target_spec.rb +123 -0
- data/spec/cf/cli/user/create_spec.rb +98 -0
- data/spec/cf/cli/user/help_spec.rb +32 -0
- data/spec/cf/cli/user/passwd_spec.rb +94 -0
- data/spec/cf/cli/user/register_spec.rb +145 -0
- data/spec/cf/cli_spec.rb +474 -0
- data/spec/console/console_spec.rb +189 -0
- data/spec/factories/cfoundry/v2/apps_factory.rb +12 -0
- data/spec/factories/cfoundry/v2/clients_factory.rb +7 -0
- data/spec/factories/cfoundry/v2/domains_factory.rb +8 -0
- data/spec/factories/cfoundry/v2/managed_service_instances_factory.rb +13 -0
- data/spec/factories/cfoundry/v2/organizations_factory.rb +14 -0
- data/spec/factories/cfoundry/v2/quota_definitions.rb +13 -0
- data/spec/factories/cfoundry/v2/routes_factory.rb +8 -0
- data/spec/factories/cfoundry/v2/service_bindings_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/service_brokers_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/service_plans_factory.rb +17 -0
- data/spec/factories/cfoundry/v2/services_factory.rb +14 -0
- data/spec/factories/cfoundry/v2/spaces_factory.rb +13 -0
- data/spec/factories/cfoundry/v2/stacks_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/user_provided_service_instances_factory.rb +12 -0
- data/spec/factories/cfoundry/v2/users_factory.rb +7 -0
- data/spec/features/backspace_spec.rb +46 -0
- data/spec/features/create_user_spec.rb +74 -0
- data/spec/features/delete_orphaned_service_spec.rb +64 -0
- data/spec/features/login_spec.rb +65 -0
- data/spec/features/manifests_spec.rb +86 -0
- data/spec/features/org_spec.rb +50 -0
- data/spec/features/push_flow_spec.rb +169 -0
- data/spec/features/service_brokers_spec.rb +173 -0
- data/spec/features/services_spec.rb +122 -0
- data/spec/features/space_spec.rb +107 -0
- data/spec/features/switching_targets_spec.rb +70 -0
- data/spec/manifests/errors_spec.rb +43 -0
- data/spec/manifests/loader/builder_spec.rb +80 -0
- data/spec/manifests/loader/normalizer_spec.rb +158 -0
- data/spec/manifests/manifests_spec.rb +335 -0
- data/spec/manifests/plugin_spec.rb +410 -0
- data/spec/micro/plugin_spec.rb +64 -0
- data/spec/spec_helper.rb +69 -0
- data/spec/support/cli_helper.rb +87 -0
- data/spec/support/config_helper.rb +15 -0
- data/spec/support/factory_girl.rb +6 -0
- data/spec/support/fake_home_dir.rb +55 -0
- data/spec/support/features_helper.rb +99 -0
- data/spec/support/interact_helper.rb +27 -0
- data/spec/support/matchers.rb +16 -0
- data/spec/support/mock_commands/mock_restart.rb +16 -0
- data/spec/support/mock_commands/mock_start.rb +17 -0
- data/spec/support/shared_examples/errors.rb +40 -0
- data/spec/support/shared_examples/input.rb +14 -0
- data/spec/tunnel/plugin_spec.rb +31 -0
- data/spec/tunnel/tunnel_spec.rb +54 -0
- metadata +814 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
require "cf/cli/route/base"
|
2
|
+
|
3
|
+
module CF::Route
|
4
|
+
class Routes < Base
|
5
|
+
desc "List routes in a space"
|
6
|
+
group :routes
|
7
|
+
|
8
|
+
def routes
|
9
|
+
# TODO: scope to space once space.routes is possible
|
10
|
+
routes =
|
11
|
+
with_progress("Getting routes") do
|
12
|
+
client.routes
|
13
|
+
end
|
14
|
+
|
15
|
+
line unless quiet?
|
16
|
+
|
17
|
+
table(
|
18
|
+
%w{host domain},
|
19
|
+
routes.sort_by { |r| "#{r.domain.name} #{r.host}" }.collect { |r|
|
20
|
+
[c(r.host, :name),
|
21
|
+
r.domain.name
|
22
|
+
]
|
23
|
+
})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "cf/cli/route/base"
|
2
|
+
|
3
|
+
module CF::Route
|
4
|
+
class Unmap < Base
|
5
|
+
desc "Remove a URL mapping"
|
6
|
+
group :apps, :info
|
7
|
+
input :url, :desc => "URL to unmap", :argument => :optional,
|
8
|
+
:from_given => find_by_name("route") { client.routes }
|
9
|
+
input :app, :desc => "Application to remove the URL from",
|
10
|
+
:argument => :optional, :from_given => by_name(:app)
|
11
|
+
input :all, :desc => "Act on all routes", :type => :boolean
|
12
|
+
input :really, :type => :boolean, :forget => true, :hidden => true,
|
13
|
+
:default => proc { force? || interact }
|
14
|
+
|
15
|
+
def unmap
|
16
|
+
if input[:all]
|
17
|
+
if input.has?(:app)
|
18
|
+
app = target = input[:app]
|
19
|
+
else
|
20
|
+
target = client
|
21
|
+
end
|
22
|
+
|
23
|
+
target.routes.each do |r|
|
24
|
+
begin
|
25
|
+
invoke :unmap, :url => r, :really => true, :app => app
|
26
|
+
rescue CFoundry::APIError => e
|
27
|
+
err "#{e.class}: #{e.message}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
app = input[:app]
|
35
|
+
url = input[:url, app ? app.routes : client.routes]
|
36
|
+
|
37
|
+
if app
|
38
|
+
with_progress("Unbinding #{c(url.name, :name)} from #{c(app.name, :name)}") do
|
39
|
+
app.remove_route(url)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
fail "Missing --app."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def ask_url(choices)
|
49
|
+
ask("Which URL?", :choices => choices.sort_by(&:name), :display => proc(&:name))
|
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,43 @@
|
|
1
|
+
require "cf/cli/service/base"
|
2
|
+
|
3
|
+
module CF::Service
|
4
|
+
class Bind < Base
|
5
|
+
desc "Bind a service to an application"
|
6
|
+
group :services, :manage
|
7
|
+
input :service, :desc => "Service to bind", :argument => :optional,
|
8
|
+
:from_given => by_name(:service_instance, "service")
|
9
|
+
input :app, :desc => "Application to bind to", :argument => :optional,
|
10
|
+
:from_given => by_name(:app)
|
11
|
+
def bind_service
|
12
|
+
app = input[:app]
|
13
|
+
service = input[:service, app]
|
14
|
+
finalize
|
15
|
+
|
16
|
+
with_progress(
|
17
|
+
"Binding #{c(service.name, :name)} to #{c(app.name, :name)}") do |s|
|
18
|
+
if app.binds?(service)
|
19
|
+
s.skip do
|
20
|
+
err "App #{b(app.name)} already binds #{b(service.name)}."
|
21
|
+
end
|
22
|
+
else
|
23
|
+
app.bind(service)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def ask_service(app)
|
31
|
+
services = client.service_instances
|
32
|
+
fail "No services." if services.empty?
|
33
|
+
|
34
|
+
ask "Which service?", :choices => services - app.services,
|
35
|
+
:display => proc(&:name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def ask_app
|
39
|
+
ask "Which application?", :choices => client.apps,
|
40
|
+
:display => proc(&:name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require "cf/cli/service/base"
|
2
|
+
|
3
|
+
module CF::Service
|
4
|
+
USER_PROVIDED_OFFERING = "user-provided" # I'd rather move this to CFoundry
|
5
|
+
|
6
|
+
class UPDummy
|
7
|
+
def label
|
8
|
+
"user-provided"
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :version, :provider
|
12
|
+
end
|
13
|
+
|
14
|
+
class Create < Base
|
15
|
+
offerings_from_label = proc { |label, offerings|
|
16
|
+
offerings.select { |s| s.label == label }
|
17
|
+
}
|
18
|
+
|
19
|
+
desc "Create a service"
|
20
|
+
group :services, :manage
|
21
|
+
input :offering, :desc => "What kind of service (e.g. redis, mysql)",
|
22
|
+
:argument => :optional, :from_given => offerings_from_label
|
23
|
+
input :name, :desc => "Name for your service", :argument => :optional
|
24
|
+
input :plan, :desc => "Service plan",
|
25
|
+
:from_given => find_by_name_insensitive("plan"),
|
26
|
+
:default => proc {
|
27
|
+
interact
|
28
|
+
}
|
29
|
+
input :provider, :desc => "Service provider"
|
30
|
+
input :version, :desc => "Service version"
|
31
|
+
input :app, :desc => "Application to immediately bind to",
|
32
|
+
:alias => "--bind", :from_given => by_name(:app)
|
33
|
+
|
34
|
+
def create_service
|
35
|
+
offerings = client.services
|
36
|
+
|
37
|
+
if input[:provider]
|
38
|
+
offerings.reject! { |s| s.provider != input[:provider] }
|
39
|
+
end
|
40
|
+
|
41
|
+
if input[:version]
|
42
|
+
offerings.reject! { |s| s.version != input[:version] }
|
43
|
+
end
|
44
|
+
|
45
|
+
# filter the offerings based on a given plan value, which will be a
|
46
|
+
# string if the user provided it with a flag, or a ServicePlan if
|
47
|
+
# something invoked this command with a particular plan
|
48
|
+
if plan = input.direct(:plan)
|
49
|
+
offerings.reject! do |s|
|
50
|
+
if plan.is_a?(String)
|
51
|
+
s.service_plans.none? { |p| p.name.casecmp(plan) == 0 }
|
52
|
+
else
|
53
|
+
!s.service_plans.include? plan
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
finalize
|
58
|
+
|
59
|
+
offerings << UPDummy.new
|
60
|
+
|
61
|
+
selected_offerings = offerings.any? ? Array(input[:offering, offerings.sort_by(&:label)]) : []
|
62
|
+
finalize
|
63
|
+
|
64
|
+
if selected_offerings.empty?
|
65
|
+
fail "Cannot find services matching the given criteria."
|
66
|
+
end
|
67
|
+
|
68
|
+
offering = selected_offerings.first
|
69
|
+
|
70
|
+
if offering.label == CF::Service::USER_PROVIDED_OFFERING
|
71
|
+
service_instance = client.user_provided_service_instance
|
72
|
+
service_instance.name = input[:name, offering]
|
73
|
+
finalize
|
74
|
+
|
75
|
+
# at this point there's no way input[:credentials] can work interactively...
|
76
|
+
service_instance.credentials = input[:credentials, nil] || ask_credentials
|
77
|
+
else
|
78
|
+
service_instance = client.managed_service_instance
|
79
|
+
service_instance.name = input[:name, offering]
|
80
|
+
finalize
|
81
|
+
|
82
|
+
plan = input[:plan, offering.service_plans]
|
83
|
+
finalize
|
84
|
+
service_instance.service_plan = if plan.is_a?(String)
|
85
|
+
offering.service_plans.find { |p| p.name.casecmp(plan) == 0 }
|
86
|
+
else
|
87
|
+
plan
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
service_instance.space = client.current_space
|
92
|
+
|
93
|
+
with_progress("Creating service #{c(service_instance.name, :name)}") do
|
94
|
+
service_instance.create!
|
95
|
+
end
|
96
|
+
|
97
|
+
app = input[:app]
|
98
|
+
finalize
|
99
|
+
|
100
|
+
if app
|
101
|
+
invoke :bind_service, :service => service_instance, :app => app
|
102
|
+
end
|
103
|
+
service_instance
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def ask_credentials
|
109
|
+
credentials = {}
|
110
|
+
|
111
|
+
while keys = ask("What credential parameters should applications use to connect to this service instance?\n(e.g. hostname, port, password)").split(/\s*,\s*/).map(&:strip)
|
112
|
+
if bad_key = keys.detect { |key| key !~ /^[-\w]+$/ }
|
113
|
+
line("'#{bad_key}' is not a valid key")
|
114
|
+
else
|
115
|
+
break
|
116
|
+
end
|
117
|
+
end
|
118
|
+
finalize
|
119
|
+
keys.each do |key|
|
120
|
+
value = ask(key)
|
121
|
+
finalize
|
122
|
+
credentials[key] = value
|
123
|
+
end
|
124
|
+
|
125
|
+
credentials
|
126
|
+
end
|
127
|
+
|
128
|
+
def ask_offering(offerings)
|
129
|
+
[ask("What kind?", :choices => offerings.sort_by(&:label),
|
130
|
+
:display => proc do |s|
|
131
|
+
str = "#{c(s.label, :name)} #{s.version}"
|
132
|
+
if s.provider != "core"
|
133
|
+
str << ", via #{s.provider}"
|
134
|
+
end
|
135
|
+
str
|
136
|
+
end,
|
137
|
+
:complete => proc { |s| "#{s.label} #{s.version}" })]
|
138
|
+
end
|
139
|
+
|
140
|
+
def ask_name(offering)
|
141
|
+
default = nil
|
142
|
+
unless offering == CF::Service::USER_PROVIDED_OFFERING
|
143
|
+
random = sprintf("%x", rand(1000000))
|
144
|
+
default = "#{offering.label}-#{random}"
|
145
|
+
end
|
146
|
+
|
147
|
+
ask "Name?", :default => default
|
148
|
+
end
|
149
|
+
|
150
|
+
def ask_plan(plans)
|
151
|
+
ask "Which plan?",
|
152
|
+
:choices => plans.sort_by(&:name),
|
153
|
+
:indexed => true,
|
154
|
+
:display => proc { |p| "#{p.name}: #{p.description || 'No description'}" },
|
155
|
+
:complete => proc(&:name)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "cf/cli/service/base"
|
2
|
+
|
3
|
+
module CF::Service
|
4
|
+
class Delete < Base
|
5
|
+
desc "Delete a service"
|
6
|
+
group :services, :manage
|
7
|
+
input :service, :desc => "Service to delete", :argument => :optional,
|
8
|
+
:from_given => by_name(:service_instance, :service)
|
9
|
+
input :unbind, :desc => "Unbind from applications before deleting?",
|
10
|
+
:type => :boolean, :default => proc { force? || interact }
|
11
|
+
input :all, :desc => "Delete all services", :default => false
|
12
|
+
input :really, :type => :boolean, :forget => true, :hidden => true,
|
13
|
+
:default => proc { force? || interact }
|
14
|
+
def delete_service
|
15
|
+
if input[:all]
|
16
|
+
return unless input[:really, "ALL SERVICES", :bad]
|
17
|
+
|
18
|
+
client.service_instances.each do |i|
|
19
|
+
invoke :delete_service, :service => i, :really => true
|
20
|
+
end
|
21
|
+
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
service = input[:service]
|
26
|
+
|
27
|
+
return unless input[:really, service.name, :name]
|
28
|
+
|
29
|
+
bindings = service.service_bindings
|
30
|
+
|
31
|
+
unless bindings.empty? || !input[:unbind, bindings.collect(&:app)]
|
32
|
+
bindings.each do |b|
|
33
|
+
invoke :unbind_service, :service => service, :app => b.app
|
34
|
+
end
|
35
|
+
|
36
|
+
bindings = []
|
37
|
+
end
|
38
|
+
|
39
|
+
with_progress("Deleting #{c(service.name, :name)}") do |s|
|
40
|
+
if bindings.empty?
|
41
|
+
service.delete!
|
42
|
+
else
|
43
|
+
s.skip do
|
44
|
+
apps = bindings.collect(&:app).collect { |a| b(a.name) }
|
45
|
+
err "Service is bound to #{human_list(apps)}."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def ask_service
|
54
|
+
services = client.service_instances
|
55
|
+
fail "No services." if services.empty?
|
56
|
+
|
57
|
+
ask "Which service?", :choices => services,
|
58
|
+
:display => proc(&:name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def ask_unbind(apps)
|
62
|
+
names = human_list(apps.collect { |a| c(a.name, :name) })
|
63
|
+
|
64
|
+
ask("Unbind from #{names} before deleting?", :default => true)
|
65
|
+
end
|
66
|
+
|
67
|
+
def ask_really(name, color)
|
68
|
+
ask("Really delete #{c(name, color)}?", :default => false)
|
69
|
+
end
|
70
|
+
|
71
|
+
def human_list(xs)
|
72
|
+
if xs.size == 1
|
73
|
+
xs.first
|
74
|
+
elsif xs.size == 2
|
75
|
+
"#{xs.first} and #{xs.last}"
|
76
|
+
else
|
77
|
+
last = xs.pop
|
78
|
+
xs.join(", ") + ", and #{last}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "cf/cli/service/base"
|
2
|
+
|
3
|
+
module CF::Service
|
4
|
+
class Rename < Base
|
5
|
+
desc "Rename a service"
|
6
|
+
group :services, :manage
|
7
|
+
input :service, :desc => "Service to rename", :argument => :optional,
|
8
|
+
:from_given => by_name(:service_instance, :service)
|
9
|
+
input :name, :desc => "New service name", :argument => :optional
|
10
|
+
def rename_service
|
11
|
+
service = input[:service]
|
12
|
+
name = input[:name]
|
13
|
+
|
14
|
+
service.name = name
|
15
|
+
|
16
|
+
with_progress("Renaming to #{c(name, :name)}") do
|
17
|
+
service.update!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def ask_service
|
24
|
+
services = client.service_instances
|
25
|
+
fail "No services." if services.empty?
|
26
|
+
|
27
|
+
ask("Rename which service?", :choices => services.sort_by(&:name),
|
28
|
+
:display => proc(&:name))
|
29
|
+
end
|
30
|
+
|
31
|
+
def ask_name
|
32
|
+
ask("New name")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "cf/cli/service/base"
|
2
|
+
|
3
|
+
module CF::Service
|
4
|
+
class Service < Base
|
5
|
+
desc "Show service information"
|
6
|
+
group :services
|
7
|
+
input :service, :desc => "Service to show", :argument => :required,
|
8
|
+
:from_given => by_name(:service_instance, :service)
|
9
|
+
def service
|
10
|
+
display_service(input[:service])
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def display_service(i)
|
16
|
+
if quiet?
|
17
|
+
line i.name
|
18
|
+
else
|
19
|
+
plan = i.service_plan
|
20
|
+
service = plan.service
|
21
|
+
|
22
|
+
apps = i.service_bindings.collect { |b|
|
23
|
+
c(b.app.name, :name)
|
24
|
+
}.join(", ")
|
25
|
+
|
26
|
+
line "#{c(i.name, :name)}: #{service.label} #{service.version}"
|
27
|
+
|
28
|
+
indented do
|
29
|
+
line "provider: #{c(service.provider, :name)}"
|
30
|
+
line "bound to: #{apps}" unless apps.empty?
|
31
|
+
line "plan: #{c(plan.name, :name)}"
|
32
|
+
|
33
|
+
indented do
|
34
|
+
line "description: #{plan.description}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|