Module: CloudFoundry::Client::Apps
- Included in:
- CloudFoundry::Client
- Defined in:
- lib/cloudfoundry/client/apps.rb
Overview
CloudFoundry API Applications methods.
Instance Method Summary collapse
-
#app_crashes(name) ⇒ Hash
Returns information about application crashes on the target cloud.
-
#app_files(name, path = "/", instance = 0) ⇒ String
List the directory or a file indicated by the path and instance.
-
#app_info(name) ⇒ Hash
Returns basic information about an application deployed on the target cloud.
-
#app_instances(name) ⇒ Hash
Returns information about application instances on the target cloud.
-
#app_stats(name) ⇒ Hash
Returns information about application statistics on the target cloud.
-
#create_app(name, manifest = {}) ⇒ Boolean
Creates a new application at target cloud.
-
#delete_app(name) ⇒ Boolean
Deletes an application at target cloud.
-
#download_app(name) ⇒ String
Downloads the application bits from the target cloud.
-
#list_apps ⇒ Hash
Returns the list of applications deployed on the target cloud.
-
#update_app(name, manifest = {}) ⇒ Boolean
Updates an application at target cloud.
-
#update_app_info(name) ⇒ Hash
Checks the status of the latest application update at target cloud.
-
#upload_app(name, zipfile, resource_manifest = []) ⇒ Boolean
Uploads the application bits to the target cloud.
Instance Method Details
#app_crashes(name) ⇒ Hash
Returns information about application crashes on the target cloud.
64 65 66 67 68 |
# File 'lib/cloudfoundry/client/apps.rb', line 64 def app_crashes(name) require_login 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.
78 79 80 81 82 83 84 85 |
# File 'lib/cloudfoundry/client/apps.rb', line 78 def app_files(name, path = "/", instance = 0) require_login 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.
20 21 22 23 24 |
# File 'lib/cloudfoundry/client/apps.rb', line 20 def app_info(name) require_login 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.
32 33 34 35 36 |
# File 'lib/cloudfoundry/client/apps.rb', line 32 def app_instances(name) require_login 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.
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) require_login 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.
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cloudfoundry/client/apps.rb', line 95 def create_app(name, manifest = {}) require_login 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.
140 141 142 143 144 145 |
# File 'lib/cloudfoundry/client/apps.rb', line 140 def delete_app(name) require_login 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.
184 185 186 187 188 189 |
# File 'lib/cloudfoundry/client/apps.rb', line 184 def download_app(name) require_login 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_apps ⇒ Hash
Returns the list of applications deployed on the target cloud.
9 10 11 12 |
# File 'lib/cloudfoundry/client/apps.rb', line 9 def list_apps() require_login get(CloudFoundry::Client::APPS_PATH) end |
#update_app(name, manifest = {}) ⇒ Boolean
Updates an application at target cloud.
114 115 116 117 118 119 120 |
# File 'lib/cloudfoundry/client/apps.rb', line 114 def update_app(name, manifest = {}) require_login 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.
128 129 130 131 132 |
# File 'lib/cloudfoundry/client/apps.rb', line 128 def update_app_info(name) require_login 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.
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 = []) require_login 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. 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 |