lds-cf-plugin 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,110 @@
1
+ require "cf/cli"
2
+ require "json"
3
+ require "uri"
4
+
5
+ module LdsCfPlugin
6
+ class EnterpriseWSService < CF::CLI
7
+ def precondition
8
+ check_target
9
+ end
10
+
11
+ desc "Create an Enterprise WS service"
12
+ group :lds, :services
13
+ input :name, :desc => "Name for your service", :argument => :optional
14
+ input :env, :desc => "The environment of enterprise web services you wish to use.", :argument => :optional
15
+ input :username, :desc => "The enterprise web services username to use.", :argument => :optional
16
+ input :password, :desc => "The enterprise web services password to use.", :argument => :optional
17
+
18
+ def create_enterprise_ws_service
19
+ offerings = client.services
20
+ offerings.keep_if { |s| s.label == 'enterprise-ws-service' && s.provider == 'ICS' }
21
+ service = offerings.first
22
+
23
+ if !service
24
+ fail "Cannot find the Enterprise WS service on #{client.target}"
25
+ end
26
+
27
+ if service.version != "0.1"
28
+ fail "Your lds-cf-plugin version is out of date. To update execute `gem update lds-cf-plugin`"
29
+ end
30
+
31
+ rest_client = CFoundry::RestClient.new(service.url, client.token)
32
+ rest_client.trace = client.trace
33
+
34
+ instance_name = input[:name]
35
+ if !instance_name
36
+ instance_name = ask("Name")
37
+ end
38
+
39
+ plan = service.service_plans.first
40
+
41
+ choices = ["int", "load", "prod"]
42
+
43
+ env = input[:env]
44
+ if !env || !choices.include?(env)
45
+ options = {
46
+ :choices => choices,
47
+ :display => proc { |choice|
48
+ if choice == "int"
49
+ "Integration"
50
+ elsif choice == "load"
51
+ "Load"
52
+ elsif choice == "prod"
53
+ "Production"
54
+ end
55
+ },
56
+ :default => "int",
57
+ :allow_other => false
58
+ }
59
+ env = ask("Enterprise Web Services environment to use", options)
60
+ end
61
+
62
+ username = input[:username]
63
+ if !username
64
+ username = ask("Username")
65
+ end
66
+
67
+ password = input[:password]
68
+ if !password
69
+ password = ask("Password", :echo => "*", :forget => true, :default => "")
70
+ end
71
+
72
+ # Register service with gateway
73
+
74
+ payload = {
75
+ :space_guid => client.current_space.guid,
76
+ :name => instance_name,
77
+ :env => env,
78
+ :username => username,
79
+ :password => password
80
+ }
81
+
82
+ options = {
83
+ :payload => JSON.generate(payload)
84
+ }
85
+ request, response = rest_client.request("POST", "/register", options)
86
+ if response[:status].to_i != 200
87
+ fail "Error registering Enterprise WS service with broker:\n#{response[:body]}"
88
+ end
89
+
90
+ # Create service instance
91
+ instance = client.managed_service_instance
92
+ instance.name = instance_name
93
+
94
+ instance.service_plan = plan
95
+ instance.space = client.current_space
96
+
97
+ with_progress("Creating service #{c(instance.name, :name)}") do
98
+ instance.create!
99
+ end
100
+
101
+ result = JSON.parse(response[:body])
102
+ line "Detected access to:"
103
+ result['services'].each do |service|
104
+ line "* #{service}"
105
+ end
106
+
107
+ instance
108
+ end
109
+ end
110
+ end
@@ -9,10 +9,11 @@ module LdsCfPlugin
9
9
 
10
10
  desc "Create an Oracle service"
11
11
  group :lds, :services
12
+ input :plan, :desc => "The plan for your service. (Existing, or Provisioned)", :argument => :optional
12
13
  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 connect to the database", :argument => :optional
14
+ input :service, :desc => "The Oracle database to connect to if using 'Existing' plan.", :argument => :optional
15
+ input :schema, :desc => "The schema (user) to use if using 'Existing' plan.", :argument => :optional
16
+ input :password, :desc => "The password used to connect to the database if using 'Existing' plan.", :argument => :optional
16
17
 
17
18
  def create_oracle_service
18
19
  offerings = client.services
@@ -35,46 +36,83 @@ module LdsCfPlugin
35
36
  instance_name = ask("Name")
36
37
  end
37
38
 
38
- plan = service.service_plans.first
39
-
40
- service = input[:service]
41
- if !service
42
- service = ask("Oracle service (database name/alias)")
43
- end
39
+ plans = service.service_plans
40
+
41
+ selected_plan = nil
44
42
 
45
- schema = input[:schema]
46
- if !schema
47
- schema = ask("Oracle schema (user)")
43
+ plans.each do |plan|
44
+ selcted_plan = plan if plan.name == input[:plan]
45
+ end unless input[:plan].nil?
46
+
47
+ existing_plan = nil?
48
+ plans.each do | plan |
49
+ existing_plan = plan if plan.name == "Existing"
48
50
  end
49
-
50
- password = input[:password]
51
- if !password
52
- password = ask("Oracle schema password", :echo => "*", :forget => true)
51
+
52
+ plan_type = nil
53
+ plan_type = "Existing" unless existing_plan.nil?
54
+
55
+ if(plans.length > 1 && !existing_plan.nil? && selected_plan.nil?)
56
+ choices = ["Existing", "Create New"]
57
+ options = {
58
+ :choices => choices,
59
+ :default => "Existing",
60
+ :allow_other => false
61
+ }
62
+ plan_type = ask("What type of Oracle Service", options)
53
63
  end
54
64
 
55
- # Register service with gateway
56
-
57
- payload = {
58
- :space_guid => client.current_space.guid,
59
- :name => instance_name,
60
- :service => service,
61
- :schema => schema,
62
- :password => password
63
- }
64
- options = {
65
- :payload => JSON.generate(payload)
66
- }
67
- request, response = rest_client.request("POST", "/register", options)
68
- if response[:status].to_i != 200
69
- fail "Error registering Oracle service with gateway:\n#{response[:body]}"
65
+ if plan_type == "Existing"
66
+ selected_plan = existing_plan
67
+
68
+ service = input[:service]
69
+ if !service
70
+ service = ask("Oracle service (database name/alias)")
71
+ end
72
+
73
+ schema = input[:schema]
74
+ if !schema
75
+ schema = ask("Oracle schema (user)")
76
+ end
77
+
78
+ password = input[:password]
79
+ if !password
80
+ password = ask("Oracle schema password", :echo => "*", :forget => true)
81
+ end
82
+
83
+ # Register service with gateway
84
+
85
+ payload = {
86
+ :space_guid => client.current_space.guid,
87
+ :name => instance_name,
88
+ :service => service,
89
+ :schema => schema,
90
+ :password => password
91
+ }
92
+ options = {
93
+ :payload => JSON.generate(payload)
94
+ }
95
+ request, response = rest_client.request("POST", "/register", options)
96
+ if response[:status].to_i != 200
97
+ fail "Error registering Oracle service with gateway:\n#{response[:body]}"
98
+ end
99
+ else
100
+ plans.delete(existing_plan) unless existing_plan.nil?
101
+ options = {
102
+ :choices => plans,
103
+ :display => proc { |choice|
104
+ "#{choice.name}: #{choice.description}"
105
+ },
106
+ :allow_other => false
107
+ }
108
+ selected_plan = ask("What type of Schema do you want", options)
70
109
  end
71
110
 
72
-
73
111
  # Create service instance
74
112
  instance = client.managed_service_instance
75
113
  instance.name = instance_name
76
114
 
77
- instance.service_plan = plan
115
+ instance.service_plan = selected_plan
78
116
  instance.space = client.current_space
79
117
 
80
118
  with_progress("Creating service #{c(instance.name, :name)}") do
@@ -8,6 +8,7 @@ Mothership::Help.groups(
8
8
 
9
9
  require "lds-cf-plugin/app_dynamics_service"
10
10
  require "lds-cf-plugin/custom_service"
11
+ require "lds-cf-plugin/enterprise_ws_service"
11
12
  require "lds-cf-plugin/oracle_service"
12
13
  require "lds-cf-plugin/lds_account_service"
13
14
  require "lds-cf-plugin/http_service"
@@ -1,3 +1,3 @@
1
1
  module LdsCfPlugin
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
@@ -7,7 +7,7 @@ module LdsCfPlugin
7
7
  check_target
8
8
  end
9
9
 
10
- desc "Create a Wam Service"
10
+ desc "Create a WAM Service that, when bound to your app, will provide basic headers for dev and test lanes. Consult an ASE if you require more WAM than that."
11
11
  group :lds, :services
12
12
  input :name, :desc => "Name for your service", :argument => :optional
13
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lds-cf-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-10 00:00:00.000000000 Z
12
+ date: 2014-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cf
@@ -102,6 +102,7 @@ files:
102
102
  - lib/lds-cf-plugin/http_service.rb
103
103
  - lib/lds-cf-plugin/custom_service.rb
104
104
  - lib/lds-cf-plugin/lds_account_service.rb
105
+ - lib/lds-cf-plugin/enterprise_ws_service.rb
105
106
  - lib/lds-cf-plugin/marklogic_service.rb
106
107
  - lib/lds-cf-plugin/oracle_service.rb
107
108
  - lib/lds-cf-plugin/tunnel.rb