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.
- checksums.yaml +14 -6
- data/LICENSE +1277 -24
- data/Rakefile +24 -87
- data/bin/af +7 -2
- data/lib/af/version.rb +3 -0
- data/lib/vmc.rb +7 -2
- data/lib/vmc/cli.rb +475 -0
- data/lib/vmc/cli/app/app.rb +45 -0
- data/lib/vmc/cli/app/apps.rb +105 -0
- data/lib/vmc/cli/app/base.rb +82 -0
- data/lib/vmc/cli/app/crashes.rb +46 -0
- data/lib/vmc/cli/app/delete.rb +95 -0
- data/lib/vmc/cli/app/deprecated.rb +11 -0
- data/lib/vmc/cli/app/env.rb +78 -0
- data/lib/vmc/cli/app/files.rb +137 -0
- data/lib/vmc/cli/app/health.rb +26 -0
- data/lib/vmc/cli/app/instances.rb +53 -0
- data/lib/vmc/cli/app/logs.rb +76 -0
- data/lib/vmc/cli/app/push.rb +107 -0
- data/lib/vmc/cli/app/push/create.rb +150 -0
- data/lib/vmc/cli/app/push/interactions.rb +100 -0
- data/lib/vmc/cli/app/push/sync.rb +64 -0
- data/lib/vmc/cli/app/rename.rb +39 -0
- data/lib/vmc/cli/app/restart.rb +20 -0
- data/lib/vmc/cli/app/scale.rb +71 -0
- data/lib/vmc/cli/app/start.rb +93 -0
- data/lib/vmc/cli/app/stats.rb +67 -0
- data/lib/vmc/cli/app/stop.rb +27 -0
- data/lib/vmc/cli/domain/base.rb +12 -0
- data/lib/vmc/cli/domain/domains.rb +40 -0
- data/lib/vmc/cli/domain/map.rb +55 -0
- data/lib/vmc/cli/domain/unmap.rb +56 -0
- data/lib/vmc/cli/help.rb +16 -0
- data/lib/vmc/cli/interactive.rb +105 -0
- data/lib/vmc/cli/organization/base.rb +14 -0
- data/lib/vmc/cli/organization/create.rb +32 -0
- data/lib/vmc/cli/organization/delete.rb +73 -0
- data/lib/vmc/cli/organization/org.rb +45 -0
- data/lib/vmc/cli/organization/orgs.rb +35 -0
- data/lib/vmc/cli/organization/rename.rb +36 -0
- data/lib/vmc/cli/route/base.rb +12 -0
- data/lib/vmc/cli/route/map.rb +80 -0
- data/lib/vmc/cli/route/routes.rb +26 -0
- data/lib/vmc/cli/route/unmap.rb +94 -0
- data/lib/vmc/cli/service/base.rb +8 -0
- data/lib/vmc/cli/service/bind.rb +44 -0
- data/lib/vmc/cli/service/create.rb +126 -0
- data/lib/vmc/cli/service/delete.rb +86 -0
- data/lib/vmc/cli/service/rename.rb +35 -0
- data/lib/vmc/cli/service/service.rb +42 -0
- data/lib/vmc/cli/service/services.rb +115 -0
- data/lib/vmc/cli/service/unbind.rb +38 -0
- data/lib/vmc/cli/space/base.rb +21 -0
- data/lib/vmc/cli/space/create.rb +56 -0
- data/lib/vmc/cli/space/delete.rb +95 -0
- data/lib/vmc/cli/space/rename.rb +39 -0
- data/lib/vmc/cli/space/space.rb +64 -0
- data/lib/vmc/cli/space/spaces.rb +55 -0
- data/lib/vmc/cli/space/take.rb +16 -0
- data/lib/vmc/cli/start/base.rb +80 -0
- data/lib/vmc/cli/start/colors.rb +13 -0
- data/lib/vmc/cli/start/info.rb +122 -0
- data/lib/vmc/cli/start/login.rb +92 -0
- data/lib/vmc/cli/start/logout.rb +13 -0
- data/lib/vmc/cli/start/target.rb +64 -0
- data/lib/vmc/cli/start/target_interactions.rb +37 -0
- data/lib/vmc/cli/start/targets.rb +16 -0
- data/lib/vmc/cli/user/base.rb +29 -0
- data/lib/vmc/cli/user/create.rb +39 -0
- data/lib/vmc/cli/user/delete.rb +25 -0
- data/lib/vmc/cli/user/passwd.rb +50 -0
- data/lib/vmc/cli/user/register.rb +42 -0
- data/lib/vmc/cli/user/users.rb +32 -0
- data/lib/vmc/constants.rb +13 -0
- data/lib/vmc/detect.rb +134 -0
- data/lib/vmc/errors.rb +17 -0
- data/lib/vmc/plugin.rb +56 -0
- data/lib/vmc/spacing.rb +89 -0
- data/lib/vmc/spec_helper.rb +1 -0
- data/lib/vmc/test_support.rb +4 -0
- data/lib/vmc/test_support/command_helper.rb +32 -0
- data/lib/vmc/test_support/common_input_examples.rb +14 -0
- data/lib/vmc/test_support/fake_home_dir.rb +16 -0
- data/lib/vmc/test_support/interact_helper.rb +29 -0
- data/lib/vmc/version.rb +3 -0
- data/spec/assets/hello-sinatra/Gemfile +3 -0
- data/spec/assets/hello-sinatra/main.rb +6 -0
- data/spec/features/new_user_flow_spec.rb +71 -0
- data/spec/spec_helper.rb +63 -0
- data/spec/vmc/cli/app/base_spec.rb +17 -0
- data/spec/vmc/cli/app/delete_spec.rb +188 -0
- data/spec/vmc/cli/app/instances_spec.rb +65 -0
- data/spec/vmc/cli/app/push/create_spec.rb +571 -0
- data/spec/vmc/cli/app/push_spec.rb +369 -0
- data/spec/vmc/cli/app/rename_spec.rb +104 -0
- data/spec/vmc/cli/app/scale_spec.rb +81 -0
- data/spec/vmc/cli/app/stats_spec.rb +62 -0
- data/spec/vmc/cli/domain/map_spec.rb +140 -0
- data/spec/vmc/cli/domain/unmap_spec.rb +73 -0
- data/spec/vmc/cli/organization/orgs_spec.rb +108 -0
- data/spec/vmc/cli/organization/rename_spec.rb +113 -0
- data/spec/vmc/cli/route/map_spec.rb +138 -0
- data/spec/vmc/cli/route/unmap_spec.rb +215 -0
- data/spec/vmc/cli/service/bind_spec.rb +25 -0
- data/spec/vmc/cli/service/delete_spec.rb +22 -0
- data/spec/vmc/cli/service/rename_spec.rb +105 -0
- data/spec/vmc/cli/service/service_spec.rb +23 -0
- data/spec/vmc/cli/service/unbind_spec.rb +25 -0
- data/spec/vmc/cli/space/rename_spec.rb +102 -0
- data/spec/vmc/cli/space/spaces_spec.rb +104 -0
- data/spec/vmc/cli/start/info_spec.rb +153 -0
- data/spec/vmc/cli/start/login_spec.rb +71 -0
- data/spec/vmc/cli/user/create_spec.rb +54 -0
- data/spec/vmc/cli/user/passwd_spec.rb +102 -0
- data/spec/vmc/cli/user/register_spec.rb +148 -0
- data/spec/vmc/cli_spec.rb +448 -0
- data/spec/vmc/detect_spec.rb +54 -0
- metadata +231 -124
- data/README.md +0 -155
- data/caldecott_helper/Gemfile +0 -10
- data/caldecott_helper/Gemfile.lock +0 -48
- data/caldecott_helper/server.rb +0 -43
- data/config/clients.yml +0 -17
- data/config/micro/offline.conf +0 -2
- data/config/micro/paths.yml +0 -22
- data/config/micro/refresh_ip.rb +0 -20
- data/lib/cli.rb +0 -48
- data/lib/cli/commands/admin.rb +0 -81
- data/lib/cli/commands/apps.rb +0 -1358
- data/lib/cli/commands/base.rb +0 -233
- data/lib/cli/commands/manifest.rb +0 -56
- data/lib/cli/commands/micro.rb +0 -115
- data/lib/cli/commands/misc.rb +0 -147
- data/lib/cli/commands/services.rb +0 -217
- data/lib/cli/commands/user.rb +0 -70
- data/lib/cli/config.rb +0 -176
- data/lib/cli/console_helper.rb +0 -163
- data/lib/cli/core_ext.rb +0 -122
- data/lib/cli/errors.rb +0 -19
- data/lib/cli/file_helper.rb +0 -123
- data/lib/cli/frameworks.rb +0 -265
- data/lib/cli/manifest_helper.rb +0 -316
- data/lib/cli/runner.rb +0 -633
- data/lib/cli/services_helper.rb +0 -104
- data/lib/cli/tunnel_helper.rb +0 -336
- data/lib/cli/usage.rb +0 -129
- data/lib/cli/version.rb +0 -7
- data/lib/cli/zip_util.rb +0 -102
- data/lib/vmc/client.rb +0 -574
- data/lib/vmc/const.rb +0 -27
- data/lib/vmc/micro.rb +0 -56
- data/lib/vmc/micro/switcher/base.rb +0 -97
- data/lib/vmc/micro/switcher/darwin.rb +0 -19
- data/lib/vmc/micro/switcher/dummy.rb +0 -15
- data/lib/vmc/micro/switcher/linux.rb +0 -16
- data/lib/vmc/micro/switcher/windows.rb +0 -31
- data/lib/vmc/micro/vmrun.rb +0 -158
@@ -0,0 +1,35 @@
|
|
1
|
+
require "vmc/cli/organization/base"
|
2
|
+
|
3
|
+
module VMC::Organization
|
4
|
+
class Orgs < Base
|
5
|
+
desc "List available organizations"
|
6
|
+
group :organizations, :hidden => true
|
7
|
+
input :full, :desc => "Show full information for apps, services, etc.",
|
8
|
+
:default => false
|
9
|
+
def orgs
|
10
|
+
orgs =
|
11
|
+
with_progress("Getting organizations") do
|
12
|
+
client.organizations.sort_by(&:name)
|
13
|
+
end
|
14
|
+
|
15
|
+
return if orgs.empty?
|
16
|
+
|
17
|
+
line unless quiet?
|
18
|
+
|
19
|
+
if input[:full]
|
20
|
+
orgs.each do |o|
|
21
|
+
invoke :org, :organization => o, :full => true
|
22
|
+
end
|
23
|
+
else
|
24
|
+
table(
|
25
|
+
%w{name spaces domains},
|
26
|
+
orgs.collect { |o|
|
27
|
+
[ c(o.name, :name),
|
28
|
+
name_list(o.spaces),
|
29
|
+
name_list(o.domains)
|
30
|
+
]
|
31
|
+
})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "vmc/cli/organization/base"
|
2
|
+
|
3
|
+
module VMC::Organization
|
4
|
+
class Rename < Base
|
5
|
+
desc "Rename an organization"
|
6
|
+
group :organizations, :hidden => true
|
7
|
+
input :organization, :desc => "Organization to rename",
|
8
|
+
:aliases => ["--org", "-o"], :argument => :optional,
|
9
|
+
:from_given => by_name(:organization)
|
10
|
+
input :name, :desc => "New organization name", :argument => :optional
|
11
|
+
def rename_org
|
12
|
+
organization = input[:organization]
|
13
|
+
name = input[:name]
|
14
|
+
|
15
|
+
organization.name = name
|
16
|
+
|
17
|
+
with_progress("Renaming to #{c(name, :name)}") do
|
18
|
+
organization.update!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def ask_name
|
25
|
+
ask("New name")
|
26
|
+
end
|
27
|
+
|
28
|
+
def ask_organization
|
29
|
+
organizations = client.organizations
|
30
|
+
fail "No organizations." if organizations.empty?
|
31
|
+
|
32
|
+
ask("Rename which organization?", :choices => organizations.sort_by(&:name),
|
33
|
+
:display => proc(&:name))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require "vmc/cli/route/base"
|
2
|
+
|
3
|
+
module VMC::Route
|
4
|
+
class Map < Base
|
5
|
+
def precondition; end
|
6
|
+
|
7
|
+
desc "Add a URL mapping"
|
8
|
+
group :apps, :info, :hidden => true
|
9
|
+
input :app, :desc => "Application to add the URL to",
|
10
|
+
:argument => :optional, :from_given => by_name(:app)
|
11
|
+
input :host, :desc => "Host name for the route",
|
12
|
+
:argument => :optional, :default => ""
|
13
|
+
input :domain, :desc => "Domain to add the route to",
|
14
|
+
:argument => true,
|
15
|
+
:from_given => proc { |name, space|
|
16
|
+
if v2?
|
17
|
+
space.domain_by_name(name) ||
|
18
|
+
fail_unknown("domain", name)
|
19
|
+
else
|
20
|
+
name
|
21
|
+
end
|
22
|
+
}
|
23
|
+
def map
|
24
|
+
app = input[:app]
|
25
|
+
space = app.space if v2?
|
26
|
+
|
27
|
+
host = input[:host]
|
28
|
+
domain = input[:domain, space]
|
29
|
+
|
30
|
+
if v2?
|
31
|
+
route = find_or_create_route(domain, host, space)
|
32
|
+
bind_route(route, app) if app
|
33
|
+
else
|
34
|
+
with_progress("Updating #{c(app.name, :name)}") do
|
35
|
+
app.urls << domain
|
36
|
+
app.update!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def bind_route(route, app)
|
44
|
+
with_progress("Binding #{c(route.name, :name)} to #{c(app.name, :name)}") do
|
45
|
+
app.add_route(route)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_or_create_route(domain, host, space)
|
50
|
+
find_route(domain, host) || create_route(domain, host, space)
|
51
|
+
end
|
52
|
+
|
53
|
+
def find_route(domain, host)
|
54
|
+
client.routes_by_host(host, :depth => 0).find { |r| r.domain == domain }
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_route(domain, host, space)
|
58
|
+
route = client.route
|
59
|
+
route.host = host
|
60
|
+
route.domain = domain
|
61
|
+
route.space = space
|
62
|
+
|
63
|
+
with_progress("Creating route #{c(route.name, :name)}") do
|
64
|
+
route.create!
|
65
|
+
end
|
66
|
+
|
67
|
+
route
|
68
|
+
end
|
69
|
+
|
70
|
+
def find_domain(space, name)
|
71
|
+
domain = space.domain_by_name(name, :depth => 0)
|
72
|
+
fail "Invalid domain '#{name}'" unless domain
|
73
|
+
domain
|
74
|
+
end
|
75
|
+
|
76
|
+
def ask_app
|
77
|
+
ask("Which application?", :choices => client.apps, :display => proc(&:name))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "vmc/cli/route/base"
|
2
|
+
|
3
|
+
module VMC::Route
|
4
|
+
class Routes < Base
|
5
|
+
desc "List routes in a space"
|
6
|
+
group :routes, :hidden => true
|
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,94 @@
|
|
1
|
+
require "vmc/cli/route/base"
|
2
|
+
|
3
|
+
module VMC::Route
|
4
|
+
class Unmap < Base
|
5
|
+
desc "Remove a URL mapping"
|
6
|
+
group :apps, :info, :hidden => true
|
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 :delete, :desc => "Delete route", :type => :boolean
|
12
|
+
input :all, :desc => "Act on all routes", :type => :boolean
|
13
|
+
input :really, :type => :boolean, :forget => true, :hidden => true,
|
14
|
+
:default => proc { force? || interact }
|
15
|
+
def unmap
|
16
|
+
return invoke :v1_unmap, input.inputs, input.given unless v2?
|
17
|
+
|
18
|
+
if input[:all]
|
19
|
+
if input.has?(:app)
|
20
|
+
app = target = input[:app]
|
21
|
+
return unless !input[:delete] || input[:really, "ALL URLS bound to #{target.name}", :bad]
|
22
|
+
else
|
23
|
+
target = client
|
24
|
+
return unless !input[:delete] || input[:really, "ALL URLS", :bad]
|
25
|
+
end
|
26
|
+
|
27
|
+
target.routes.each do |r|
|
28
|
+
begin
|
29
|
+
invoke :unmap, :delete => input[:delete], :url => r, :really => true, :app => app
|
30
|
+
rescue CFoundry::APIError => e
|
31
|
+
err "#{e.class}: #{e.message}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
app = input[:app]
|
39
|
+
url = input[:url, app ? app.routes : client.routes]
|
40
|
+
|
41
|
+
if input[:delete]
|
42
|
+
with_progress("Deleting route #{c(url.name, :name)}") do
|
43
|
+
url.delete!
|
44
|
+
end
|
45
|
+
elsif app
|
46
|
+
with_progress("Unbinding #{c(url.name, :name)} from #{c(app.name, :name)}") do
|
47
|
+
app.remove_route(url)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
fail "Missing either --delete or --app."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
desc "V1 ONLY UNMAP YOU SHOULD NOT SEE THIS"
|
56
|
+
input :url, :desc => "URL to unmap", :argument => :optional,
|
57
|
+
:interact => :v1_ask_url
|
58
|
+
input :app, :desc => "Application to remove the URL from",
|
59
|
+
:argument => :optional, :from_given => by_name(:app)
|
60
|
+
input :all, :desc => "Act on all routes", :type => :boolean
|
61
|
+
def v1_unmap
|
62
|
+
app = input[:app]
|
63
|
+
url = input[:url, app.urls] unless input[:all]
|
64
|
+
|
65
|
+
with_progress("Updating #{c(app.name, :name)}") do |s|
|
66
|
+
if input[:all]
|
67
|
+
app.urls = []
|
68
|
+
else
|
69
|
+
simple = url.sub(/^https?:\/\/(.*)\/?/i, '\1')
|
70
|
+
|
71
|
+
unless app.urls.delete(simple)
|
72
|
+
fail "URL #{url} is not mapped to this application."
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
app.update!
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def ask_url(choices)
|
83
|
+
ask("Which URL?", :choices => choices.sort_by(&:name), :display => proc(&:name))
|
84
|
+
end
|
85
|
+
|
86
|
+
def v1_ask_url(choices)
|
87
|
+
ask("Which URL?", :choices => choices.sort)
|
88
|
+
end
|
89
|
+
|
90
|
+
def ask_really(name, color)
|
91
|
+
ask("Really delete #{c(name, color)}?", :default => false)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "vmc/detect"
|
2
|
+
|
3
|
+
require "vmc/cli/service/base"
|
4
|
+
|
5
|
+
module VMC::Service
|
6
|
+
class Bind < Base
|
7
|
+
desc "Bind a service to an application"
|
8
|
+
group :services, :manage
|
9
|
+
input :service, :desc => "Service to bind", :argument => :optional,
|
10
|
+
:from_given => by_name(:service_instance, "service")
|
11
|
+
input :app, :desc => "Application to bind to", :argument => :optional,
|
12
|
+
:from_given => by_name(:app)
|
13
|
+
def bind_service
|
14
|
+
app = input[:app]
|
15
|
+
service = input[:service, app]
|
16
|
+
|
17
|
+
with_progress(
|
18
|
+
"Binding #{c(service.name, :name)} to #{c(app.name, :name)}") do |s|
|
19
|
+
if app.binds?(service)
|
20
|
+
s.skip do
|
21
|
+
err "App #{b(app.name)} already binds #{b(service.name)}."
|
22
|
+
end
|
23
|
+
else
|
24
|
+
app.bind(service)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def ask_service(app)
|
32
|
+
services = client.service_instances
|
33
|
+
fail "No services." if services.empty?
|
34
|
+
|
35
|
+
ask "Which service?", :choices => services - app.services,
|
36
|
+
:display => proc(&:name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def ask_app
|
40
|
+
ask "Which application?", :choices => client.apps,
|
41
|
+
:display => proc(&:name)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require "vmc/cli/service/base"
|
2
|
+
|
3
|
+
module VMC::Service
|
4
|
+
class Create < Base
|
5
|
+
offerings_from_label = proc { |label, offerings|
|
6
|
+
offerings.select { |s| s.label == label }
|
7
|
+
}
|
8
|
+
|
9
|
+
desc "Create a service"
|
10
|
+
group :services, :manage
|
11
|
+
input :infra, :desc => "Infrastructure to use", :from_given => by_name(:infra)
|
12
|
+
input :offering, :desc => "What kind of service (e.g. redis, mysql)",
|
13
|
+
:argument => :optional, :from_given => offerings_from_label
|
14
|
+
input :name, :desc => "Name for your service", :argument => :optional
|
15
|
+
input :plan, :desc => "Service plan",
|
16
|
+
:from_given => find_by_name_insensitive("plan"),
|
17
|
+
:default => proc { |plans|
|
18
|
+
plans.find { |p| p.name == "D100" } ||
|
19
|
+
interact
|
20
|
+
}
|
21
|
+
input :provider, :desc => "Service provider"
|
22
|
+
input :version, :desc => "Service version"
|
23
|
+
input :app, :desc => "Application to immediately bind to",
|
24
|
+
:alias => "--bind", :from_given => by_name(:app)
|
25
|
+
def create_service
|
26
|
+
offerings = client.services
|
27
|
+
|
28
|
+
if input[:infra]
|
29
|
+
offerings.reject! { |s| s.infra.to_s != input[:infra].name }
|
30
|
+
end
|
31
|
+
|
32
|
+
if input[:provider]
|
33
|
+
offerings.reject! { |s| s.provider != input[:provider] }
|
34
|
+
end
|
35
|
+
|
36
|
+
if input[:version]
|
37
|
+
offerings.reject! { |s| s.version != input[:version] }
|
38
|
+
elsif !v2?
|
39
|
+
offerings.reject!(&:deprecated?)
|
40
|
+
end
|
41
|
+
|
42
|
+
# filter the offerings based on a given plan value, which will be a
|
43
|
+
# string if the user provided it with a flag, or a ServicePlan if
|
44
|
+
# something invoked this command with a particular plan
|
45
|
+
if v2? && plan = input.direct(:plan)
|
46
|
+
offerings.reject! do |s|
|
47
|
+
if plan.is_a?(String)
|
48
|
+
s.service_plans.none? { |p| p.name == plan.upcase }
|
49
|
+
else
|
50
|
+
s.service_plans.include? plan
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
until offerings.size < 2
|
56
|
+
# cast to Array since it might be given as a Service with #invoke
|
57
|
+
offerings = Array(input[:offering, offerings.sort_by(&:label)])
|
58
|
+
input.forget(:offering)
|
59
|
+
end
|
60
|
+
|
61
|
+
if offerings.empty?
|
62
|
+
fail "Cannot find services matching the given criteria."
|
63
|
+
end
|
64
|
+
|
65
|
+
offering = offerings.first
|
66
|
+
|
67
|
+
service = client.service_instance
|
68
|
+
|
69
|
+
service.infra_name = input[:infra].name
|
70
|
+
service.name = input[:name, offering]
|
71
|
+
|
72
|
+
if v2?
|
73
|
+
service.service_plan = input[:plan, offering.service_plans]
|
74
|
+
service.space = client.current_space
|
75
|
+
else
|
76
|
+
service.type = offering.type
|
77
|
+
service.vendor = offering.label
|
78
|
+
service.version = offering.version
|
79
|
+
service.tier = "free"
|
80
|
+
end
|
81
|
+
|
82
|
+
with_progress("Creating service #{c(service.name, :name)}") do
|
83
|
+
service.create!
|
84
|
+
end
|
85
|
+
|
86
|
+
if app = input[:app]
|
87
|
+
invoke :bind_service, :service => service, :app => app
|
88
|
+
end
|
89
|
+
|
90
|
+
service
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def ask_infra(choices, default, other)
|
96
|
+
[ask("Infrastructure?", :choices => client.infras,
|
97
|
+
:display => proc { |s|
|
98
|
+
str = "#{c(s.name, :name)} - #{s.description}"
|
99
|
+
},
|
100
|
+
:complete => proc { |s| "#{s.name} #{s.description}" })]
|
101
|
+
end
|
102
|
+
|
103
|
+
def ask_offering(offerings)
|
104
|
+
[ask("What kind?", :choices => offerings.sort_by(&:label),
|
105
|
+
:display => proc { |s|
|
106
|
+
str = "#{c(s.label, :name)} #{s.version}"
|
107
|
+
if s.provider != "core"
|
108
|
+
str << ", via #{s.provider}"
|
109
|
+
end
|
110
|
+
str
|
111
|
+
},
|
112
|
+
:complete => proc { |s| "#{s.label} #{s.version}" })]
|
113
|
+
end
|
114
|
+
|
115
|
+
def ask_name(offering)
|
116
|
+
random = sprintf("%x", rand(1000000))
|
117
|
+
ask "Name?", :default => "#{offering.label}-#{random}"
|
118
|
+
end
|
119
|
+
|
120
|
+
def ask_plan(plans)
|
121
|
+
ask "Which plan?", :choices => plans.sort_by(&:name),
|
122
|
+
:display => proc { |p| "#{p.name}: #{p.description}" },
|
123
|
+
:complete => proc(&:name)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|