Class: LdsCfPlugin::CustomService
- Inherits:
-
CF::CLI
- Object
- CF::CLI
- LdsCfPlugin::CustomService
- Defined in:
- lib/lds-cf-plugin/custom_service.rb,
lib/lds-cf-plugin/oracle_service.rb
Instance Method Summary collapse
Instance Method Details
#create_custom_service ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lds-cf-plugin/custom_service.rb', line 19 def create_custom_service offerings = client.services offerings.keep_if { |s| s.label == 'custom-service' && s.provider == 'ICS' } service = offerings.first if !service fail "Cannot find custom service on #{client.target}" end rest_client = CFoundry::RestClient.new(service.url, client.token) rest_client.trace = client.trace instance_name = input[:name] if !instance_name instance_name = ask("Name") end if plan = input.direct(:plan) service.reject! do |s| if plan.is_a?(String) s.service_plans.none? { |p| p.name == plan.upcase } else s.service_plans.include? plan end end end plan = service.service_plans.first credentials = input[:credentials] if !credentials credentials = ask("Service credentials JSON string") end creds = Yajl::Parser.new.parse(credentials) # Register custom service with gateway payload = { :space_guid => client.current_space.guid, :name => instance_name, :credentials => creds } = { :payload => Yajl::Encoder.encode(payload) } request, response = rest_client.request("POST", "/register", ) if response[:status].to_i != 200 fail "Error registering custom service with gateway: #{response[:body]}" end # Create service instance instance = client.service_instance instance.name = instance_name instance.service_plan = plan instance.space = client.current_space with_progress("Creating service #{c(instance.name, :name)}") do instance.create! end instance end |
#create_oracle_service ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lds-cf-plugin/oracle_service.rb', line 21 def create_oracle_service offerings = client.services offerings.keep_if { |s| s.label == 'oracle-service' && s.provider == 'ICS' } service = offerings.first if !service fail "Cannot find Oracle service on #{client.target}" end rest_client = CFoundry::RestClient.new(service.url, client.token) rest_client.trace = client.trace instance_name = input[:name] if !instance_name instance_name = ask("Name") end if plan = input.direct(:plan) service.reject! do |s| if plan.is_a?(String) s.service_plans.none? { |p| p.name == plan.upcase } else s.service_plans.include? plan end end end plan = service.service_plans.first service = input[:service] if !service service = ask("Oracle service (database name/alias)") end schema = input[:schema] if !schema schema = ask("Oracle schema (user)") end password = input[:password] if !password password = ask("Oracle schema password", :echo => "*", :forget => true) end # Register service with gateway payload = { :space_guid => client.current_space.guid, :name => instance_name, :service => service, :schema => schema, :password => password } = { :payload => Yajl::Encoder.encode(payload) } request, response = rest_client.request("POST", "/register", ) if response[:status].to_i != 200 fail "Error registering Oracle service with gateway: #{response[:body]}" end # Create service instance instance = client.service_instance instance.name = instance_name instance.service_plan = plan instance.space = client.current_space with_progress("Creating service #{c(instance.name, :name)}") do instance.create! end instance end |
#precondition ⇒ Object
6 7 8 |
# File 'lib/lds-cf-plugin/custom_service.rb', line 6 def precondition check_target end |