lds-cf-plugin 0.1.0
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.
- data/Rakefile +38 -0
- data/lib/lds-cf-plugin/custom_service.rb +97 -0
- data/lib/lds-cf-plugin/plugin.rb +8 -0
- data/lib/lds-cf-plugin/version.rb +3 -0
- metadata +71 -0
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
5
|
+
require "lds-cf-plugin/version"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
namespace :deploy do
|
11
|
+
def last_staging_sha
|
12
|
+
`git rev-parse latest-staging`.strip
|
13
|
+
end
|
14
|
+
|
15
|
+
def last_release_sha
|
16
|
+
`git rev-parse latest-release`.strip
|
17
|
+
end
|
18
|
+
|
19
|
+
def last_staging_ref_was_released?
|
20
|
+
last_staging_sha == last_release_sha
|
21
|
+
end
|
22
|
+
|
23
|
+
task :staging, :version do |_, args|
|
24
|
+
sh "gem bump --push #{"--version #{args.version}" if args.version}" if last_staging_ref_was_released?
|
25
|
+
sh "git tag -f latest-staging"
|
26
|
+
sh "git push origin :latest-staging"
|
27
|
+
sh "git push origin latest-staging"
|
28
|
+
end
|
29
|
+
|
30
|
+
task :gem do
|
31
|
+
sh "git fetch"
|
32
|
+
sh "git checkout #{last_staging_sha}"
|
33
|
+
sh "gem release --tag"
|
34
|
+
sh "git tag -f latest-release"
|
35
|
+
sh "git push origin :latest-release"
|
36
|
+
sh "git push origin latest-release"
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "cf/cli"
|
2
|
+
require "yajl"
|
3
|
+
|
4
|
+
module LdsCfPlugin
|
5
|
+
class CustomService < CF::CLI
|
6
|
+
def precondition
|
7
|
+
check_target
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Create a custom service"
|
11
|
+
group :lds
|
12
|
+
input :name, :desc => "Name for your service", :argument => :optional
|
13
|
+
input :credentials, :desc => "The service credentials JSON string to be passed to the application", :argument => :optional
|
14
|
+
input :plan, :desc => "Service plan",
|
15
|
+
:from_given => find_by_name_insensitive("plan"),
|
16
|
+
:default => proc {
|
17
|
+
interact
|
18
|
+
}
|
19
|
+
def create_custom_service
|
20
|
+
offerings = client.services
|
21
|
+
offerings.keep_if { |s| s.label == 'custom-service' && s.provider == 'ICS' }
|
22
|
+
service = offerings.first
|
23
|
+
|
24
|
+
if !service
|
25
|
+
fail "Cannot find custom service on #{client.target}"
|
26
|
+
end
|
27
|
+
|
28
|
+
rest_client = CFoundry::RestClient.new(service.url, client.token)
|
29
|
+
rest_client.trace = client.trace
|
30
|
+
|
31
|
+
instance_name = input[:name]
|
32
|
+
if !instance_name
|
33
|
+
instance_name = ask("Name")
|
34
|
+
end
|
35
|
+
|
36
|
+
if plan = input.direct(:plan)
|
37
|
+
service.reject! do |s|
|
38
|
+
if plan.is_a?(String)
|
39
|
+
s.service_plans.none? { |p| p.name == plan.upcase }
|
40
|
+
else
|
41
|
+
s.service_plans.include? plan
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
plan = service.service_plans.first
|
46
|
+
|
47
|
+
credentials = input[:credentials]
|
48
|
+
if !credentials
|
49
|
+
credentials = ask("Service credentials JSON string")
|
50
|
+
end
|
51
|
+
|
52
|
+
creds = Yajl::Parser.new.parse(credentials)
|
53
|
+
|
54
|
+
# Register custom service with gateway
|
55
|
+
|
56
|
+
payload = {
|
57
|
+
:space_guid => client.current_space.guid,
|
58
|
+
:name => instance_name,
|
59
|
+
:credentials => creds
|
60
|
+
}
|
61
|
+
options = {
|
62
|
+
:payload => Yajl::Encoder.encode(payload)
|
63
|
+
}
|
64
|
+
request, response = rest_client.request("POST", "/register", options)
|
65
|
+
if response[:status].to_i != 200
|
66
|
+
fail "Error registering custom service with gateway: #{response[:body]}"
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Create service instance
|
71
|
+
instance = client.service_instance
|
72
|
+
instance.name = instance_name
|
73
|
+
|
74
|
+
instance.service_plan = plan
|
75
|
+
instance.space = client.current_space
|
76
|
+
|
77
|
+
with_progress("Creating service #{c(instance.name, :name)}") do
|
78
|
+
instance.create!
|
79
|
+
end
|
80
|
+
|
81
|
+
instance
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def ask_plan(plans, default_plan = nil)
|
87
|
+
ask "Which plan?",
|
88
|
+
:choices => plans.sort_by(&:name),
|
89
|
+
:indexed => true,
|
90
|
+
:display => proc { |p| "#{p.name}: #{p.description || 'No description'}" },
|
91
|
+
:default => default_plan,
|
92
|
+
:complete => proc(&:name)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lds-cf-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mike Heath
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2013-05-07 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: cfoundry
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
- - <
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: "1.1"
|
27
|
+
type: :runtime
|
28
|
+
version_requirements: *id001
|
29
|
+
description:
|
30
|
+
email:
|
31
|
+
- heathma@ldschurch.org
|
32
|
+
executables: []
|
33
|
+
|
34
|
+
extensions: []
|
35
|
+
|
36
|
+
extra_rdoc_files: []
|
37
|
+
|
38
|
+
files:
|
39
|
+
- Rakefile
|
40
|
+
- lib/lds-cf-plugin/custom_service.rb
|
41
|
+
- lib/lds-cf-plugin/version.rb
|
42
|
+
- lib/lds-cf-plugin/plugin.rb
|
43
|
+
homepage: http://cloudfoundry.com/
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.24
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Cloud Foundry commands for LDS PaaS.
|
70
|
+
test_files: []
|
71
|
+
|