Module: CloudFoundry::Client::Services

Included in:
CloudFoundry::Client
Defined in:
lib/cloudfoundry/client/services.rb

Overview

CloudFoundry API Provisioned Services methods.

Instance Method Summary collapse

Instance Method Details

#bind_service(name, appname) ⇒ Boolean

Binds a provisioned service to an application on the target cloud.

Parameters:

  • name (String)

    The provisioned service name.

  • appname (String)

    The application name.

Returns:

  • (Boolean)

    Returns true if provisioned service is binded to application.

Raises:

Requires a user logged in:

  • True



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/cloudfoundry/client/services.rb', line 84

def bind_service(name, appname)
  
  raise CloudFoundry::Client::Exception::BadParams, "Service Name cannot be blank" if name.nil? || name.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Application Name cannot be blank" if appname.nil? || appname.empty?
  service = service_info(name)
  app = app_info(appname)
  services = app[:services] || []
  service_exists = services.index(name)
  raise CloudFoundry::Client::Exception::BadParams, "Service [#{name}] is already binded to [#{appname}]" if service_exists
  app[:services] = services << name
  update_app(appname, app)
  true
end

#create_service(service, name) ⇒ Boolean

Creates a new provisioned service on the target cloud.

Parameters:

  • service (String)

    The system service to provision.

  • name (String)

    The provisioned service name.

Returns:

  • (Boolean)

    Returns true if provisioned service is created.

Raises:

Requires a user logged in:

  • True



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
# File 'lib/cloudfoundry/client/services.rb', line 35

def create_service(service, name)
  
  raise CloudFoundry::Client::Exception::BadParams, "Service cannot be blank" if service.nil? || service.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  service_hash = nil
  services = cloud_services_info() || []
  services.each do |service_type, service_value|
    service_value.each do |vendor, vendor_value|
      vendor_value.each do |version, service_info|
        if service == service_info[:vendor]
          service_hash = {
            :type => service_info[:type],
            :vendor => vendor,
            :version => version,
            :tier => "free"
          }
          break
        end
      end
    end
  end
  raise CloudFoundry::Client::Exception::BadParams, "Service [#{service}] is not a valid service" unless service_hash
  service_hash[:name] = name
  post(CloudFoundry::Client::SERVICES_PATH, service_hash)
  true
end

#delete_service(name) ⇒ Boolean

Deletes a provisioned service on the target cloud.

Parameters:

  • name (String)

    The provisioned service name.

Returns:

  • (Boolean)

    Returns true if provisioned service is deleted.

Raises:

Requires a user logged in:

  • True



68
69
70
71
72
73
# File 'lib/cloudfoundry/client/services.rb', line 68

def delete_service(name)
  
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  delete("#{CloudFoundry::Client::SERVICES_PATH}/#{name}", :raw => true)
  true
end

#list_servicesHash

Returns a list of provisioned services that are available on the target cloud.

Returns:

  • (Hash)

    List of provisioned services available on the target cloud.

Requires a user logged in:

  • True



9
10
11
12
# File 'lib/cloudfoundry/client/services.rb', line 9

def list_services
  
  get(CloudFoundry::Client::SERVICES_PATH)
end

#service_info(name) ⇒ Hash

Returns information about a provisioned service on the target cloud.

Parameters:

  • name (String)

    The provisioned service name.

Returns:

  • (Hash)

    Provisioned service information on the target cloud.

Raises:

Requires a user logged in:

  • True



20
21
22
23
24
# File 'lib/cloudfoundry/client/services.rb', line 20

def service_info(name)
  
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  get("#{CloudFoundry::Client::SERVICES_PATH}/#{name}")
end

#unbind_service(name, appname) ⇒ Boolean

Unbinds a provisioned service from an application on the target cloud.

Parameters:

  • name (String)

    The provisioned service name.

  • appname (String)

    The application name.

Returns:

  • (Boolean)

    Returns true if provisioned service is unbinded from application.

Raises:

Requires a user logged in:

  • True



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/cloudfoundry/client/services.rb', line 107

def unbind_service(name, appname)
  
  raise CloudFoundry::Client::Exception::BadParams, "Service Name cannot be blank" if name.nil? || name.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Application Name cannot be blank" if appname.nil? || appname.empty?
  service = service_info(name)
  app = app_info(appname)
  services = app[:services] || []
  service_deleted = services.delete(name)
  raise CloudFoundry::Client::Exception::BadParams, "Service [#{name}] is not binded to [#{name}]" unless service_deleted
  app[:services] = services
  update_app(appname, app)
  true
end