lds-cf-plugin 0.1.0 → 0.2.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.
@@ -0,0 +1,109 @@
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 an Oracle service"
11
+ group :lds
12
+ input :name, :desc => "Name for your service", :argument => :optional
13
+ input :service, :desc => "The Oracle database to connect to", :argument => :optional
14
+ input :schema, :desc => "The schema (user) to use", :argument => :optional
15
+ input :password, :desc => "The password used to conenct to the database", :argument => :optional
16
+ input :plan, :desc => "Service plan",
17
+ :from_given => find_by_name_insensitive("plan"),
18
+ :default => proc {
19
+ interact
20
+ }
21
+ def create_oracle_service
22
+ offerings = client.services
23
+ offerings.keep_if { |s| s.label == 'oracle-service' && s.provider == 'ICS' }
24
+ service = offerings.first
25
+
26
+ if !service
27
+ fail "Cannot find Oracle service on #{client.target}"
28
+ end
29
+
30
+ rest_client = CFoundry::RestClient.new(service.url, client.token)
31
+ rest_client.trace = client.trace
32
+
33
+ instance_name = input[:name]
34
+ if !instance_name
35
+ instance_name = ask("Name")
36
+ end
37
+
38
+ if plan = input.direct(:plan)
39
+ service.reject! do |s|
40
+ if plan.is_a?(String)
41
+ s.service_plans.none? { |p| p.name == plan.upcase }
42
+ else
43
+ s.service_plans.include? plan
44
+ end
45
+ end
46
+ end
47
+ plan = service.service_plans.first
48
+
49
+ service = input[:service]
50
+ if !service
51
+ service = ask("Oracle service (database name/alias)")
52
+ end
53
+
54
+ schema = input[:schema]
55
+ if !schema
56
+ schema = ask("Oracle schema (user)")
57
+ end
58
+
59
+ password = input[:password]
60
+ if !password
61
+ password = ask("Oracle schema password", :echo => "*", :forget => true)
62
+ end
63
+
64
+ # Register service with gateway
65
+
66
+ payload = {
67
+ :space_guid => client.current_space.guid,
68
+ :name => instance_name,
69
+ :service => service,
70
+ :schema => schema,
71
+ :password => password
72
+ }
73
+ options = {
74
+ :payload => Yajl::Encoder.encode(payload)
75
+ }
76
+ request, response = rest_client.request("POST", "/register", options)
77
+ if response[:status].to_i != 200
78
+ fail "Error registering Oracle service with gateway: #{response[:body]}"
79
+ end
80
+
81
+
82
+ # Create service instance
83
+ instance = client.service_instance
84
+ instance.name = instance_name
85
+
86
+ instance.service_plan = plan
87
+ instance.space = client.current_space
88
+
89
+ with_progress("Creating service #{c(instance.name, :name)}") do
90
+ instance.create!
91
+ end
92
+
93
+ instance
94
+ end
95
+
96
+ private
97
+
98
+ def ask_plan(plans, default_plan = nil)
99
+ ask "Which plan?",
100
+ :choices => plans.sort_by(&:name),
101
+ :indexed => true,
102
+ :display => proc { |p| "#{p.name}: #{p.description || 'No description'}" },
103
+ :default => default_plan,
104
+ :complete => proc(&:name)
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -5,4 +5,5 @@ Mothership::Help.groups(
5
5
  )
6
6
 
7
7
  require "lds-cf-plugin/custom_service"
8
+ require "lds-cf-plugin/oracle_service"
8
9
 
@@ -1,3 +1,3 @@
1
1
  module LdsCfPlugin
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lds-cf-plugin
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike Heath
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-05-07 00:00:00 Z
13
+ date: 2013-05-20 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: cfoundry
@@ -38,6 +38,7 @@ extra_rdoc_files: []
38
38
  files:
39
39
  - Rakefile
40
40
  - lib/lds-cf-plugin/custom_service.rb
41
+ - lib/lds-cf-plugin/oracle_service.rb
41
42
  - lib/lds-cf-plugin/version.rb
42
43
  - lib/lds-cf-plugin/plugin.rb
43
44
  homepage: http://cloudfoundry.com/