trucker-cli 0.0.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.
- 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,140 @@
|
|
|
1
|
+
require "pathname"
|
|
2
|
+
require "cf/plugin"
|
|
3
|
+
require "manifests/manifests"
|
|
4
|
+
|
|
5
|
+
class ManifestsPlugin < CF::App::Base
|
|
6
|
+
include CFManifests
|
|
7
|
+
|
|
8
|
+
def self.default_to_app_from_manifest(command, fail_without_app)
|
|
9
|
+
name_made_optional = change_argument(command, :app, :optional)
|
|
10
|
+
around(command) do |cmd, input|
|
|
11
|
+
wrap_with_optional_name(name_made_optional, cmd, input, fail_without_app)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
option :manifest, :aliases => "-m", :value => :file, :desc => "Path to manifest file to use"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
[:start, :restart, :instances, :logs, :env, :health, :stats, :scale, :app, :stop, :delete, :events].each do |command|
|
|
19
|
+
::ManifestsPlugin.default_to_app_from_manifest command, true
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
add_input :push, :reset, :desc => "Reset to values in the manifest", :default => false
|
|
23
|
+
|
|
24
|
+
around(:push) do |push, input|
|
|
25
|
+
wrap_push(push, input)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def wrap_with_optional_name(name_made_optional, cmd, input, fail_without_app)
|
|
31
|
+
return cmd.call if input[:all]
|
|
32
|
+
|
|
33
|
+
unless manifest
|
|
34
|
+
# if the command knows how to handle this
|
|
35
|
+
if input.has?(:app) || !name_made_optional || !fail_without_app
|
|
36
|
+
return cmd.call
|
|
37
|
+
else
|
|
38
|
+
return no_apps
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
internal, external = apps_in_manifest(input)
|
|
43
|
+
|
|
44
|
+
return cmd.call if internal.empty? && !external.empty?
|
|
45
|
+
|
|
46
|
+
show_manifest_usage
|
|
47
|
+
|
|
48
|
+
if internal.empty? && external.empty?
|
|
49
|
+
internal = current_apps if internal.empty?
|
|
50
|
+
internal = all_apps if internal.empty?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
internal = internal.collect { |app| app[:name] }
|
|
54
|
+
|
|
55
|
+
apps = internal + external
|
|
56
|
+
return no_apps if fail_without_app && apps.empty?
|
|
57
|
+
|
|
58
|
+
apps.each.with_index do |app, num|
|
|
59
|
+
line unless quiet? || num == 0
|
|
60
|
+
cmd.call(input.without(:apps).merge_given(:app => app))
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def apply_changes(app, input)
|
|
65
|
+
app.memory = megabytes(input[:memory]) if input.has?(:memory)
|
|
66
|
+
app.total_instances = input[:instances] if input.has?(:instances)
|
|
67
|
+
app.command = input[:command] if input.has?(:command)
|
|
68
|
+
app.buildpack = input[:buildpack] if input.has?(:buildpack)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def wrap_push(push, input)
|
|
72
|
+
unless manifest
|
|
73
|
+
create_and_save_manifest(push, input)
|
|
74
|
+
return
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
line(c("--path is ignored when using a manifest. Please specify the path in the manifest.", :warning)) if input.has?(:path)
|
|
78
|
+
|
|
79
|
+
particular, external = apps_in_manifest(input)
|
|
80
|
+
|
|
81
|
+
unless external.empty?
|
|
82
|
+
fail "Could not find #{b(external.join(", "))}' in the manifest."
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
apps = particular.empty? ? all_apps : particular
|
|
86
|
+
|
|
87
|
+
show_manifest_usage
|
|
88
|
+
|
|
89
|
+
spaced(apps) do |app_manifest|
|
|
90
|
+
push_with_manifest(app_manifest, push, input)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def push_with_manifest(app_manifest, push, input)
|
|
95
|
+
with_filters(
|
|
96
|
+
:push => {
|
|
97
|
+
:create_app => proc { |a|
|
|
98
|
+
setup_env(a, app_manifest)
|
|
99
|
+
a
|
|
100
|
+
},
|
|
101
|
+
:push_app => proc { |a|
|
|
102
|
+
setup_services(a, app_manifest)
|
|
103
|
+
a
|
|
104
|
+
}
|
|
105
|
+
}) do
|
|
106
|
+
app_input = push_input_for(app_manifest, input)
|
|
107
|
+
|
|
108
|
+
push.call(app_input)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def push_input_for(app_manifest, input)
|
|
113
|
+
existing_app = client.app_by_name(app_manifest[:name])
|
|
114
|
+
rebased_input = input.rebase_given(app_manifest)
|
|
115
|
+
|
|
116
|
+
if !existing_app || input[:reset]
|
|
117
|
+
input = rebased_input
|
|
118
|
+
else
|
|
119
|
+
warn_reset_changes if manifest_differs?(existing_app, rebased_input)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
input.merge(
|
|
123
|
+
:path => from_manifest(app_manifest[:path]),
|
|
124
|
+
:name => app_manifest[:name],
|
|
125
|
+
:bind_services => false,
|
|
126
|
+
:create_services => false)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def manifest_differs?(app, input)
|
|
130
|
+
apply_changes(app, input)
|
|
131
|
+
app.changed?
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def create_and_save_manifest(push, input)
|
|
135
|
+
with_filters(
|
|
136
|
+
:push => { :push_app => proc { |a| ask_to_save(input, a); a } }) do
|
|
137
|
+
push.call
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
data/lib/micro/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[](https://travis-ci.org/cloudfoundry/micro-cf-plugin)
|
|
2
|
+
[](http://badge.fury.io/rb/micro-cf-plugin)
|
|
3
|
+
|
|
4
|
+
## Micro Cloud Foundry
|
|
5
|
+
### Info
|
|
6
|
+
This plugin allows you to manage your Micro Cloud Foundry VM.
|
|
7
|
+
|
|
8
|
+
### Installation
|
|
9
|
+
|
|
10
|
+
If you have installed CF via gem install, use:
|
|
11
|
+
```
|
|
12
|
+
gem install micro-cf-plugin
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If you have installed CF through bundler and the Gemfile, add the following to your Gemfile:
|
|
16
|
+
```
|
|
17
|
+
gem "micro-cf-plugin"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Usage
|
|
21
|
+
```
|
|
22
|
+
micro-status VMX [PASSWORD] Display Micro Cloud Foundry VM status
|
|
23
|
+
micro-offline VMX [PASSWORD] Micro Cloud Foundry offline mode
|
|
24
|
+
micro-online VMX [PASSWORD] Micro Cloud Foundry online mode
|
|
25
|
+
```
|
data/lib/micro/errors.rb
ADDED
data/lib/micro/micro.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'find'
|
|
2
|
+
require "micro/errors"
|
|
3
|
+
|
|
4
|
+
module CFMicro
|
|
5
|
+
def config_file(file)
|
|
6
|
+
File.expand_path("../../../../config/#{file}", __FILE__)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def escape_path(path)
|
|
10
|
+
path = File.expand_path(path)
|
|
11
|
+
if RUBY_PLATFORM =~ /mingw|mswin32|cygwin/
|
|
12
|
+
if path.include?(' ')
|
|
13
|
+
'"' + path + '"'
|
|
14
|
+
else
|
|
15
|
+
path
|
|
16
|
+
end
|
|
17
|
+
else
|
|
18
|
+
path.gsub(' ', '\ ')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def locate_file(file, directory, search_paths)
|
|
23
|
+
search_paths.each do |path|
|
|
24
|
+
expanded_path = File.expand_path(path)
|
|
25
|
+
next unless File.exists?(expanded_path)
|
|
26
|
+
Find.find(expanded_path) do |current|
|
|
27
|
+
if File.directory?(current) && current.include?(directory)
|
|
28
|
+
full_path = File.join(current, file)
|
|
29
|
+
return escape_path(full_path) if File.exists?(full_path)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def run_command(command, args=nil)
|
|
38
|
+
# TODO switch to using posix-spawn instead
|
|
39
|
+
result = %x{#{command} #{args} 2>&1}
|
|
40
|
+
if $?.exitstatus == 0
|
|
41
|
+
result.split(/\n/)
|
|
42
|
+
else
|
|
43
|
+
if block_given?
|
|
44
|
+
yield
|
|
45
|
+
else
|
|
46
|
+
raise CFMicro::MCFError, "failed to execute #{command} #{args}:\n#{result}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
module_function :config_file
|
|
52
|
+
module_function :escape_path
|
|
53
|
+
module_function :locate_file
|
|
54
|
+
module_function :run_command
|
|
55
|
+
|
|
56
|
+
end
|
data/lib/micro/plugin.rb
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
require "multi_json"
|
|
3
|
+
require "cf/cli"
|
|
4
|
+
require "micro/micro"
|
|
5
|
+
require "micro/vmrun"
|
|
6
|
+
require "micro/switcher/base"
|
|
7
|
+
require "micro/switcher/darwin"
|
|
8
|
+
require "micro/switcher/linux"
|
|
9
|
+
require "micro/switcher/windows"
|
|
10
|
+
|
|
11
|
+
module CFMicro
|
|
12
|
+
class McfCommand < CF::CLI
|
|
13
|
+
MICRO_FILE = '~/.truck/micro.yml'
|
|
14
|
+
|
|
15
|
+
desc "Display Micro Cloud Foundry VM status"
|
|
16
|
+
input :vmx, :argument => :required,
|
|
17
|
+
:desc => "Path to micro.vmx"
|
|
18
|
+
input :password, :argument => :optional,
|
|
19
|
+
:desc => "Cleartext password for guest VM vcap user"
|
|
20
|
+
def micro_status
|
|
21
|
+
mode = runner.offline? ? 'offline' : 'online'
|
|
22
|
+
|
|
23
|
+
line "Micro Cloud Foundry VM currently in #{b(mode)} mode"
|
|
24
|
+
line "VMX Path: #{c(runner.vmx, :good)}"
|
|
25
|
+
line "Domain: #{c(runner.domain, :good)}"
|
|
26
|
+
line "IP Address: #{c(runner.ip, :good)}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
desc "Micro Cloud Foundry offline mode"
|
|
30
|
+
input :vmx, :argument => :required,
|
|
31
|
+
:desc => "Path to micro.vmx"
|
|
32
|
+
input :password, :argument => :optional,
|
|
33
|
+
:desc => "Cleartext password for guest VM vcap user"
|
|
34
|
+
def micro_offline
|
|
35
|
+
if !runner.nat?
|
|
36
|
+
if ask("Reconfigure MCF VM network to nat mode and reboot?", :default => true)
|
|
37
|
+
with_progress("Rebooting MCF VM") do
|
|
38
|
+
runner.reset_to_nat!
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
fail "Aborted"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
with_progress("Setting MCF VM to offline mode") do
|
|
46
|
+
runner.offline!
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
with_progress("Setting host DNS server") do
|
|
50
|
+
runner.set_host_dns!
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
desc "Micro Cloud Foundry online mode"
|
|
55
|
+
input :vmx, :argument => :required,
|
|
56
|
+
:desc => "Path to micro.vmx"
|
|
57
|
+
input :password, :argument => :optional,
|
|
58
|
+
:desc => "Cleartext password for guest VM vcap user"
|
|
59
|
+
def micro_online
|
|
60
|
+
runner
|
|
61
|
+
with_progress("Unsetting host DNS server") do
|
|
62
|
+
runner.unset_host_dns!
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
with_progress("Setting MCF VM to online mode") do
|
|
66
|
+
runner.online!
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def runner
|
|
71
|
+
return @runner if @runner
|
|
72
|
+
|
|
73
|
+
config = build_config
|
|
74
|
+
@runner = switcher(config)
|
|
75
|
+
check_vm_running
|
|
76
|
+
store_config(config)
|
|
77
|
+
|
|
78
|
+
@runner
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def check_vm_running
|
|
82
|
+
unless runner.running?
|
|
83
|
+
if ask("MCF VM is not running. Do you want to start it?", :default => true)
|
|
84
|
+
with_progress("Starting MCF VM") do
|
|
85
|
+
runner.start!
|
|
86
|
+
end
|
|
87
|
+
else
|
|
88
|
+
fail "MCF VM needs to be running."
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
unless runner.ready?
|
|
93
|
+
fail "MCF VM initial setup needs to be completed before using 'truck micro'"
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def switcher(config)
|
|
98
|
+
case McfCommand.platform
|
|
99
|
+
when :darwin
|
|
100
|
+
CFMicro::Switcher::Darwin.new(config)
|
|
101
|
+
when :linux
|
|
102
|
+
CFMicro::Switcher::Linux.new(config)
|
|
103
|
+
when :windows
|
|
104
|
+
CFMicro::Switcher::Windows.new(config)
|
|
105
|
+
when :dummy # for testing only
|
|
106
|
+
CFMicro::Switcher::Dummy.new(config)
|
|
107
|
+
else
|
|
108
|
+
fail "unsupported platform: #{McfCommand.platform}"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Returns the configuration needed to run the micro related subcommands.
|
|
113
|
+
# First loads saved config from file (if there is any), then overrides
|
|
114
|
+
# loaded values with command line arguments, and finally tries to guess
|
|
115
|
+
# in case neither was used:
|
|
116
|
+
# vmx location of micro.vmx file
|
|
117
|
+
# vmrun location of vmrun command
|
|
118
|
+
# password password for vcap user (in the guest vm)
|
|
119
|
+
# platform current platform
|
|
120
|
+
def build_config
|
|
121
|
+
conf = micro # returns {} if there isn't a saved config
|
|
122
|
+
|
|
123
|
+
override(conf, :vmx, true) do
|
|
124
|
+
locate_vmx(McfCommand.platform)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
override(conf, :vmrun, true) do
|
|
128
|
+
CFMicro::VMrun.locate(McfCommand.platform)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
override(conf, :password) do
|
|
132
|
+
ask("Please enter your MCF VM password (vcap user) password", :echo => "*")
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
conf[:platform] = McfCommand.platform
|
|
136
|
+
|
|
137
|
+
conf
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Save the cleartext password if --save is supplied.
|
|
141
|
+
# Note: it is due to vix we have to use a cleartext password :(
|
|
142
|
+
# Only if --password is used and not --save is the password deleted from the
|
|
143
|
+
# config file before it is stored to disk.
|
|
144
|
+
def store_config(config)
|
|
145
|
+
if input[:save]
|
|
146
|
+
warn("cleartext password saved in: #{MICRO_FILE}")
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
store_micro(config)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# override with command line arguments and yield the block in case the option isn't set
|
|
153
|
+
def override(config, option, escape=false, &blk)
|
|
154
|
+
# override if given on the command line
|
|
155
|
+
if opt = input[option]
|
|
156
|
+
opt = CFMicro.escape_path(opt) if escape
|
|
157
|
+
config[option] = opt
|
|
158
|
+
end
|
|
159
|
+
config[option] = yield unless config[option]
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def locate_vmx(platform)
|
|
163
|
+
paths = YAML.load_file(CFMicro.config_file('paths.yml'))
|
|
164
|
+
vmx_paths = paths[platform.to_s]['vmx']
|
|
165
|
+
vmx = CFMicro.locate_file('micro.vmx', 'micro', vmx_paths)
|
|
166
|
+
fail "Unable to locate micro.vmx, please supply --vmx option" unless vmx
|
|
167
|
+
vmx
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def self.platform
|
|
171
|
+
case RUBY_PLATFORM
|
|
172
|
+
when /darwin/ # x86_64-darwin11.2.0
|
|
173
|
+
:darwin
|
|
174
|
+
when /linux/ # x86_64-linux
|
|
175
|
+
:linux
|
|
176
|
+
when /mingw|mswin32|cygwin/ # i386-mingw32
|
|
177
|
+
:windows
|
|
178
|
+
else
|
|
179
|
+
RUBY_PLATFORM
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def micro
|
|
184
|
+
micro_file = File.expand_path(MICRO_FILE)
|
|
185
|
+
return {} unless File.exists? micro_file
|
|
186
|
+
contents = File.read(micro_file).strip
|
|
187
|
+
MultiJson.load(contents)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def store_micro(micro)
|
|
191
|
+
micro_file = File.expand_path(MICRO_FILE)
|
|
192
|
+
File.open(micro_file, 'w') do |file|
|
|
193
|
+
file.write(MultiJson.dump(micro))
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require "micro/errors"
|
|
2
|
+
|
|
3
|
+
module CFMicro::Switcher
|
|
4
|
+
class Base
|
|
5
|
+
|
|
6
|
+
def initialize(config)
|
|
7
|
+
@config = config
|
|
8
|
+
|
|
9
|
+
@vmrun = CFMicro::VMrun.new(config)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
#wrapper methods
|
|
13
|
+
def vmx
|
|
14
|
+
@vmrun.vmx
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def domain
|
|
18
|
+
@vmrun.domain
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def ip
|
|
22
|
+
@vmrun.ip
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def running?
|
|
26
|
+
@vmrun.running?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def start!
|
|
30
|
+
@vmrun.start!
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def ready?
|
|
34
|
+
@vmrun.ready?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def offline?
|
|
38
|
+
@vmrun.offline?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def nat?
|
|
42
|
+
@config['online_connection_type'] ||= @vmrun.connection_type
|
|
43
|
+
@config["online_connection_type"] == "nat"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def reset_to_nat!
|
|
47
|
+
@vmrun.connection_type = 'nat'
|
|
48
|
+
@vmrun.reset
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def set_host_dns!
|
|
52
|
+
@config['domain'] ||= @vmrun.domain
|
|
53
|
+
@config['ip'] ||= @vmrun.ip
|
|
54
|
+
set_nameserver(@config['domain'], @config['ip'])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def unset_host_dns!
|
|
58
|
+
@config['domain'] ||= @vmrun.domain
|
|
59
|
+
@config['ip'] ||= @vmrun.ip
|
|
60
|
+
unset_nameserver(@config['domain'], @config['ip'])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def offline!
|
|
64
|
+
if @vmrun.offline?
|
|
65
|
+
raise CFMicro::MCFError, "Micro Cloud Foundry VM already in offline mode"
|
|
66
|
+
else
|
|
67
|
+
@vmrun.offline!
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def online!
|
|
72
|
+
if @vmrun.offline?
|
|
73
|
+
@vmrun.online!
|
|
74
|
+
else
|
|
75
|
+
raise CFMirco::MCFError, "Micro Cloud Foundry already in online mode"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|