Module: CloudFoundry::Client::Apps

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

Overview

CloudFoundry API Applications methods.

Instance Method Summary collapse

Instance Method Details

#app_crashes(name) ⇒ Hash

Returns information about application crashes on the target cloud.

Parameters:

  • name (String)

    The application name.

Returns:

  • (Hash)

    Application crashes information on the target cloud.

Raises:

Requires a user logged in:

  • True



64
65
66
67
68
# File 'lib/cloudfoundry/client/apps.rb', line 64

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

#app_files(name, path = "/", instance = 0) ⇒ String

List the directory or a file indicated by the path and instance.

Parameters:

  • name (String)

    The application name.

  • path (String) (defaults to: "/")

    The application directory or file to display.

  • instance (Integer) (defaults to: 0)

    The application instance where directories or files are located.

Returns:

  • (String)

    Directory list or file bits on the target cloud.

Raises:

Requires a user logged in:

  • True



78
79
80
81
82
83
84
85
# File 'lib/cloudfoundry/client/apps.rb', line 78

def app_files(name, path = "/", instance = 0)
  
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  url = "#{CloudFoundry::Client::APPS_PATH}/#{name}/instances/#{instance}/files/#{path}"
  url.gsub!('//', '/')
  response_info = get(url, :raw => true)
  response_info.body
end

#app_info(name) ⇒ Hash

Returns basic information about an application deployed on the target cloud.

Parameters:

  • name (String)

    The application name.

Returns:

  • (Hash)

    Basic application information on the target cloud.

Raises:

Requires a user logged in:

  • True



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

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

#app_instances(name) ⇒ Hash

Returns information about application instances on the target cloud.

Parameters:

  • name (String)

    The application name.

Returns:

  • (Hash)

    Application instances information on the target cloud.

Raises:

Requires a user logged in:

  • True



32
33
34
35
36
# File 'lib/cloudfoundry/client/apps.rb', line 32

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

#app_stats(name) ⇒ Hash

Returns information about application statistics on the target cloud.

Parameters:

  • name (String)

    The application name.

Returns:

  • (Hash)

    Application statistics information on the target cloud.

Raises:

Requires a user logged in:

  • True



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cloudfoundry/client/apps.rb', line 44

def app_stats(name)
  
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  stats = []
  stats_raw = get("#{CloudFoundry::Client::APPS_PATH}/#{name}/stats")
  stats_raw.each_pair do |key, entry|
    next unless entry[:stats]
    entry[:instance] = key.to_s.to_i
    entry[:state] = entry[:state].to_sym if entry[:state]
    stats << entry
  end
  stats.sort { |a,b| a[:instance] - b[:instance] }
end

#create_app(name, manifest = {}) ⇒ Boolean

Creates a new application at target cloud.

Parameters:

  • name (String)

    The application name.

  • manifest (Hash) (defaults to: {})

    The manifest of the application.

Returns:

  • (Boolean)

    Returns true if application is created.

Raises:

Requires a user logged in:

  • True



95
96
97
98
99
100
101
102
103
104
# File 'lib/cloudfoundry/client/apps.rb', line 95

def create_app(name, manifest = {})
  
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Manifest cannot be blank" if manifest.nil? || manifest.empty?
  app = manifest.dup
  app[:name] = name
  app[:instances] ||= 1
  post(CloudFoundry::Client::APPS_PATH, app)
  true
end

#delete_app(name) ⇒ Boolean

Deletes an application at target cloud.

Parameters:

  • name (String)

    The application name.

Returns:

  • (Boolean)

    Returns true if application is deleted.

Raises:

Requires a user logged in:

  • True



140
141
142
143
144
145
# File 'lib/cloudfoundry/client/apps.rb', line 140

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

#download_app(name) ⇒ String

Downloads the application bits from the target cloud.

Parameters:

  • name (String)

    The application name.

Returns:

  • (String)

    Application bits.

Raises:

Requires a user logged in:

  • True



184
185
186
187
188
189
# File 'lib/cloudfoundry/client/apps.rb', line 184

def download_app(name)
  
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  response_info = get("#{CloudFoundry::Client::APPS_PATH}/#{name}/download", :raw => true)
  response_info.body
end

#list_appsHash

Returns the list of applications deployed on the target cloud.

Returns:

  • (Hash)

    List of applications deployed on the target cloud.

Requires a user logged in:

  • True



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

def list_apps()
  
  get(CloudFoundry::Client::APPS_PATH)
end

#update_app(name, manifest = {}) ⇒ Boolean

Updates an application at target cloud.

Parameters:

  • name (String)

    The application name.

  • manifest (Hash) (defaults to: {})

    The manifest of the application.

Returns:

  • (Boolean)

    Returns true if application is updated.

Raises:

Requires a user logged in:

  • True



114
115
116
117
118
119
120
# File 'lib/cloudfoundry/client/apps.rb', line 114

def update_app(name, manifest = {})
  
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Manifest cannot be blank" if manifest.nil? || manifest.empty?
  put("#{CloudFoundry::Client::APPS_PATH}/#{name}", manifest)
  true
end

#update_app_info(name) ⇒ Hash

Checks the status of the latest application update at target cloud.

Parameters:

  • name (String)

    The application name.

Returns:

  • (Hash)

    Status of the latest application update at target cloud.

Raises:

Requires a user logged in:

  • True



128
129
130
131
132
# File 'lib/cloudfoundry/client/apps.rb', line 128

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

#upload_app(name, zipfile, resource_manifest = []) ⇒ Boolean

Uploads the application bits to the target cloud.

Parameters:

  • name (String)

    The application name.

  • zipfile (File, String)

    The application bits, can be a File Object or a filename String.

  • resource_manifest (Array) (defaults to: [])

    The application resources manifest.

Returns:

  • (Boolean)

    Returns true if application is uploaded.

Raises:

Requires a user logged in:

  • True



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/cloudfoundry/client/apps.rb', line 157

def upload_app(name, zipfile, resource_manifest = [])
  
  raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Zipfile cannot be blank" if zipfile.nil?
  upload_data = {:_method=>'put'}
  begin
    if zipfile.is_a? File
      file = Faraday::UploadIO.new(zipfile, "application/zip")
    else
      filebits = File.new(zipfile, "rb")
      file = Faraday::UploadIO.new(filebits, "application/zip")
    end
  rescue SystemCallError => error
    raise CloudFoundry::Client::Exception::BadParams, "Invalid Zipfile: " + error.message
  end
  upload_data[:application] = file
  upload_data[:resources] = resource_manifest.to_json if resource_manifest
  put("#{CloudFoundry::Client::APPS_PATH}/#{name}/application", upload_data, :raw => true)
  true
end