cloudfoundry-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/.yardopts +9 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +122 -0
- data/Rakefile +28 -0
- data/cloudfoundry.gemspec +29 -0
- data/lib/cloudfoundry.rb +34 -0
- data/lib/cloudfoundry/client.rb +93 -0
- data/lib/cloudfoundry/client/apps.rb +192 -0
- data/lib/cloudfoundry/client/info.rb +29 -0
- data/lib/cloudfoundry/client/request.rb +89 -0
- data/lib/cloudfoundry/client/resources.rb +16 -0
- data/lib/cloudfoundry/client/response.rb +68 -0
- data/lib/cloudfoundry/client/services.rb +122 -0
- data/lib/cloudfoundry/client/users.rb +121 -0
- data/lib/cloudfoundry/constants.rb +30 -0
- data/lib/cloudfoundry/exception.rb +24 -0
- data/lib/cloudfoundry/version.rb +27 -0
- data/spec/client/apps_spec.rb +423 -0
- data/spec/client/info_spec.rb +92 -0
- data/spec/client/resources_spec.rb +52 -0
- data/spec/client/services_spec.rb +230 -0
- data/spec/client/users_spec.rb +367 -0
- data/spec/client_spec.rb +110 -0
- data/spec/cloudfoundry_spec.rb +62 -0
- data/spec/fixtures/admin_logged/client.yml +85 -0
- data/spec/fixtures/admin_logged/users.yml +363 -0
- data/spec/fixtures/admin_logged/users_create_action.yml +36 -0
- data/spec/fixtures/admin_logged/users_proxy_action.yml +46 -0
- data/spec/fixtures/admin_logged/users_proxy_nouser_action.yml +44 -0
- data/spec/fixtures/admin_logged/users_unproxy_action.yml +44 -0
- data/spec/fixtures/app.js +16 -0
- data/spec/fixtures/app.zip +0 -0
- data/spec/fixtures/client.yml +151 -0
- data/spec/fixtures/client_invalid.yml +85 -0
- data/spec/fixtures/cloudfoundry.yml +124 -0
- data/spec/fixtures/cloudfoundry_vs_client.yml +159 -0
- data/spec/fixtures/no_logged/apps.yml +42 -0
- data/spec/fixtures/no_logged/client.yml +42 -0
- data/spec/fixtures/no_logged/info.yml +81 -0
- data/spec/fixtures/no_logged/resources.yml +42 -0
- data/spec/fixtures/no_logged/services.yml +42 -0
- data/spec/fixtures/no_logged/users.yml +108 -0
- data/spec/fixtures/no_logged/users_login_action.yml +81 -0
- data/spec/fixtures/no_logged/users_proxy_action.yml +42 -0
- data/spec/fixtures/no_logged/users_unproxy_action.yml +42 -0
- data/spec/fixtures/user_logged/apps.yml +828 -0
- data/spec/fixtures/user_logged/apps_create_action.yml +42 -0
- data/spec/fixtures/user_logged/apps_directory_action.yml +48 -0
- data/spec/fixtures/user_logged/apps_download_action.yml +55 -0
- data/spec/fixtures/user_logged/apps_file_action.yml +54 -0
- data/spec/fixtures/user_logged/apps_start_action.yml +81 -0
- data/spec/fixtures/user_logged/apps_stats_action.yml +44 -0
- data/spec/fixtures/user_logged/apps_update_info_action.yml +44 -0
- data/spec/fixtures/user_logged/apps_upload_filename_action.yml +62 -0
- data/spec/fixtures/user_logged/apps_upload_zipfile_action.yml +62 -0
- data/spec/fixtures/user_logged/client.yml +85 -0
- data/spec/fixtures/user_logged/info.yml +126 -0
- data/spec/fixtures/user_logged/resources.yml +44 -0
- data/spec/fixtures/user_logged/resources_check_action.yml +42 -0
- data/spec/fixtures/user_logged/services.yml +354 -0
- data/spec/fixtures/user_logged/services_bind_action.yml +161 -0
- data/spec/fixtures/user_logged/services_create_action.yml +83 -0
- data/spec/fixtures/user_logged/services_unbind_action.yml +122 -0
- data/spec/fixtures/user_logged/services_unbind_fail_action.yml +122 -0
- data/spec/fixtures/user_logged/users.yml +299 -0
- data/spec/fixtures/user_logged/users_proxy_action.yml +44 -0
- data/spec/fixtures/user_logged/users_unproxy_action.yml +44 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/cf_connection_helper.rb +26 -0
- data/spec/support/vcr.rb +8 -0
- metadata +235 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Ferran Rodenas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
CloudFoundry Ruby Client Gem
|
2
|
+
============================
|
3
|
+
|
4
|
+
This is a Ruby wrapper for the [CloudFoundry](http://cloudfoundry.org/) API, the industry’s first open Platform as a
|
5
|
+
Service (PaaS) offering.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
gem install cloudfoundry-client
|
11
|
+
|
12
|
+
Continuous Integration
|
13
|
+
----------------------
|
14
|
+
|
15
|
+
[](http://travis-ci.org/frodenas/cloudfoundry-client)
|
16
|
+
|
17
|
+
Documentation
|
18
|
+
-------------
|
19
|
+
|
20
|
+
[http://rdoc.info/gems/cloudfoundry-client](http://rdoc.info/gems/cloudfoundry-client)
|
21
|
+
|
22
|
+
Usage Examples
|
23
|
+
--------------
|
24
|
+
|
25
|
+
### Connection and login:
|
26
|
+
|
27
|
+
require "cloudfoundry-client"
|
28
|
+
cf_client = CloudFoundry::Client.new({:target_url => "https://api.cloudfoundry.com"})
|
29
|
+
cf_client.login("user@vcap.me", "password")
|
30
|
+
|
31
|
+
### Retrieve information from target cloud:
|
32
|
+
|
33
|
+
cloud_info = cf_client.cloud_info()
|
34
|
+
cloud_runtimes_info = cf_client.cloud_runtimes_info()
|
35
|
+
cloud_services_info = cf_client.cloud_services_info()
|
36
|
+
|
37
|
+
### Actions for applications:
|
38
|
+
|
39
|
+
apps = cf_client.list_apps()
|
40
|
+
app_info = cf_client.app_info("appname")
|
41
|
+
app_instances = cf_client.app_instances("appname")
|
42
|
+
app_stats = cf_client.app_stats("appname")
|
43
|
+
app_crashes = cf_client.app_crashes("appname")
|
44
|
+
app_files = cf_client.app_files("appname", "/")
|
45
|
+
app_files = cf_client.app_files("appname", "/logs/stdout.log")
|
46
|
+
created = cf_client.create_app("appname", manifest)
|
47
|
+
updated = cf_client.update_app("appname", manifest)
|
48
|
+
update_info = cf_client.update_app_info("appname")
|
49
|
+
deleted = cf_client.delete_app("appname")
|
50
|
+
uploaded = cf_client.upload_app("appname", zipfile, manifest)
|
51
|
+
zipfile = cf_client.download_app("appname")
|
52
|
+
|
53
|
+
### Actions for services:
|
54
|
+
|
55
|
+
services = cf_client.list_services()
|
56
|
+
service_info = cf_client.service_info("redis-12345")
|
57
|
+
created = cf_client.create_service("redis", "redis-12345")
|
58
|
+
deleted = cf_client.delete_service("redis-12345")
|
59
|
+
binded = cf_client.bind_service("redis-12345", "appname")
|
60
|
+
unbinded = cf_client.unbind_service("redis-12345", "appname")
|
61
|
+
|
62
|
+
### Actions for users (some of them require an admin user):
|
63
|
+
|
64
|
+
users = cf_client.list_users()
|
65
|
+
user_info = cf_client.user_info("user@vcap.me")
|
66
|
+
created = cf_client.create_user("user@vcap.me", "password")
|
67
|
+
updated = cf_client.update_user("user@vcap.me", "new_password")
|
68
|
+
deleted = cf_client.delete_user("user@vcap.me")
|
69
|
+
|
70
|
+
Contributing
|
71
|
+
------------
|
72
|
+
In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help
|
73
|
+
improve this project.
|
74
|
+
|
75
|
+
Here are some ways *you* can contribute:
|
76
|
+
|
77
|
+
* by using alpha, beta, and prerelease versions
|
78
|
+
* by reporting bugs
|
79
|
+
* by suggesting new features
|
80
|
+
* by writing or editing documentation
|
81
|
+
* by writing specifications
|
82
|
+
* by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
|
83
|
+
* by refactoring code
|
84
|
+
* by closing [issues](http://github.com/frodenas/cloudfoundry-client/issues)
|
85
|
+
* by reviewing patches
|
86
|
+
|
87
|
+
|
88
|
+
Submitting an Issue
|
89
|
+
-------------------
|
90
|
+
We use the [GitHub issue tracker](http://github.com/frodenas/cloudfoundry-client/issues) to track bugs and features.
|
91
|
+
Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. You can indicate
|
92
|
+
support for an existing issuse by voting it up. When submitting a bug report, please include a
|
93
|
+
[Gist](http://gist.github.com/) that includes a stack trace and any details that may be necessary to reproduce the bug,
|
94
|
+
including your gem version, Ruby version, and operating system. Ideally, a bug report should include a pull request with
|
95
|
+
failing specs.
|
96
|
+
|
97
|
+
|
98
|
+
Submitting a Pull Request
|
99
|
+
-------------------------
|
100
|
+
1. Fork the project.
|
101
|
+
2. Create a topic branch.
|
102
|
+
3. Implement your feature or bug fix.
|
103
|
+
4. Add documentation for your feature or bug fix.
|
104
|
+
5. Run <tt>rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
|
105
|
+
6. Add specs for your feature or bug fix.
|
106
|
+
7. Run <tt>rake spec</tt>. If your changes are not 100% covered, go back to step 6.
|
107
|
+
8. Commit and push your changes.
|
108
|
+
9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create
|
109
|
+
your own version for some reason, please do so in a separate commit.)
|
110
|
+
|
111
|
+
|
112
|
+
Authors
|
113
|
+
-------
|
114
|
+
|
115
|
+
By [Ferran Rodenas](http://www.rodenas.org/) <frodenas@gmail.com>
|
116
|
+
Based on the [VMC - VMware Cloud CLI](https://github.com/cloudfoundry/vmc)
|
117
|
+
|
118
|
+
Copyright
|
119
|
+
---------
|
120
|
+
|
121
|
+
See [LICENSE](https://github.com/frodenas/cloudfoundry-client/blob/master/LICENSE) for details.
|
122
|
+
Copyright (c) 2011 [Ferran Rodenas](http://www.rodenas.org/).
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :test => :spec
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
namespace :doc do
|
11
|
+
begin
|
12
|
+
require 'yard'
|
13
|
+
rescue LoadError
|
14
|
+
# ignore
|
15
|
+
else
|
16
|
+
YARD::Rake::YardocTask.new do |task|
|
17
|
+
task.files = ["lib/**/*.rb", "-", "CHANGELOG.md", "LICENSE"]
|
18
|
+
task.options = [
|
19
|
+
"--no-private",
|
20
|
+
"--protected",
|
21
|
+
"--output-dir", "doc/yard",
|
22
|
+
"--tag", "authenticated:Requires a user logged in",
|
23
|
+
"--tag", "admin:Requires an admin user logged in",
|
24
|
+
"--markup", "markdown",
|
25
|
+
]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cloudfoundry/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cloudfoundry-client"
|
7
|
+
s.version = CloudFoundry::Client::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ferran Rodenas"]
|
10
|
+
s.email = ["frodenas@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/frodenas/cloudfoundry-client"
|
12
|
+
s.summary = %q{A Ruby wrapper for the CloudFoundry API PaaS}
|
13
|
+
s.description = %q{This is a Ruby wrapper for the CloudFoundry API, the industry’s first open Platform as a Service (PaaS) offering.}
|
14
|
+
s.licenses = ["MIT"]
|
15
|
+
|
16
|
+
s.add_development_dependency("rspec", ">= 2.7.0")
|
17
|
+
s.add_development_dependency("webmock", ">= 1.7.8")
|
18
|
+
s.add_development_dependency("vcr", ">= 2.0.0.beta2")
|
19
|
+
|
20
|
+
s.add_runtime_dependency("faraday", ">= 0.7.5")
|
21
|
+
s.add_runtime_dependency("json_pure", ">= 1.6.2")
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
|
27
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
28
|
+
s.extra_rdoc_files = ["CHANGELOG.md", "LICENSE", "README.md"]
|
29
|
+
end
|
data/lib/cloudfoundry.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json/pure'
|
3
|
+
|
4
|
+
# This is a Ruby wrapper for the CloudFoundry API, the industry’s first open Platform as a Service (PaaS) offering.
|
5
|
+
module CloudFoundry
|
6
|
+
require 'cloudfoundry/client'
|
7
|
+
require 'cloudfoundry/constants'
|
8
|
+
require 'cloudfoundry/exception'
|
9
|
+
require 'cloudfoundry/version'
|
10
|
+
|
11
|
+
# @private
|
12
|
+
VERSION = CloudFoundry::Client::VERSION #:nodoc;
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# Alias for CloudFoundry::Client.new
|
16
|
+
#
|
17
|
+
# @return [CloudFoundry::Client] A CloudFoundry::Client Object.
|
18
|
+
# @see CloudFoundry::Client#initialize CloudFoundry::Client.new()
|
19
|
+
def new(options = {})
|
20
|
+
CloudFoundry::Client.new(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Delegate all methods to CloudFoundry::Client.
|
24
|
+
def method_missing(method, *arguments, &block)
|
25
|
+
return super unless new.respond_to?(method)
|
26
|
+
new.send(method, *arguments, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Delegate all methods to CloudFoundry::Client.
|
30
|
+
def respond_to?(method, include_private = false)
|
31
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'cloudfoundry/client/apps'
|
2
|
+
require 'cloudfoundry/client/info'
|
3
|
+
require 'cloudfoundry/client/request'
|
4
|
+
require 'cloudfoundry/client/resources'
|
5
|
+
require 'cloudfoundry/client/response'
|
6
|
+
require 'cloudfoundry/client/services'
|
7
|
+
require 'cloudfoundry/client/users'
|
8
|
+
|
9
|
+
module CloudFoundry
|
10
|
+
# This is a Ruby wrapper for the CloudFoundry API, the industry’s first open Platform as a Service (PaaS) offering.
|
11
|
+
class Client
|
12
|
+
include CloudFoundry::Client::Apps
|
13
|
+
include CloudFoundry::Client::Info
|
14
|
+
include CloudFoundry::Client::Request
|
15
|
+
include CloudFoundry::Client::Resources
|
16
|
+
include CloudFoundry::Client::Services
|
17
|
+
include CloudFoundry::Client::Users
|
18
|
+
|
19
|
+
# Returns the HTTP connection adapter that will be used to connect.
|
20
|
+
attr_reader :net_adapter
|
21
|
+
# Returns the Proxy URL that will be used to connect.
|
22
|
+
attr_reader :proxy_url
|
23
|
+
# Returns the CloudFoundry API Target URL.
|
24
|
+
attr_reader :target_url
|
25
|
+
# Returns the CloudFoundry API Trace Key.
|
26
|
+
attr_reader :trace_key
|
27
|
+
# Returns the CloudFoundry API Authorization Token.
|
28
|
+
attr_reader :auth_token
|
29
|
+
# Returns the CloudFoundry Logged User.
|
30
|
+
attr_reader :user
|
31
|
+
# Returns the CloudFoundry Proxied User.
|
32
|
+
attr_reader :proxy_user
|
33
|
+
|
34
|
+
# Creates a new CloudFoundry::Client object.
|
35
|
+
#
|
36
|
+
# @param [Hash] options
|
37
|
+
# @option options [Faraday::Adapter] :adapter The HTTP connection adapter that will be used to connect.
|
38
|
+
# @option options [String] :proxy_url The Proxy URL that will be used to connect.
|
39
|
+
# @option options [String] :target_url The CloudFoundry API Target URL.
|
40
|
+
# @option options [String] :trace_key The CloudFoundry API Trace Key.
|
41
|
+
# @option options [String] :auth_token The CloudFoundry API Authorization Token.
|
42
|
+
# @return [CloudFoundry::Client] A CloudFoundry::Client Object.
|
43
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when target_url is not a valid CloudFoundry API URL.
|
44
|
+
# @raise [CloudFoundry::Client::Exception::AuthError] when auth_token is not a valid CloudFoundry API authorization token.
|
45
|
+
def initialize(options = {})
|
46
|
+
@net_adapter = options[:adapter] || DEFAULT_ADAPTER
|
47
|
+
@proxy_url = options[:proxy_url] || nil
|
48
|
+
@target_url = options[:target_url] || DEFAULT_TARGET
|
49
|
+
@target_url = sanitize_url(@target_url)
|
50
|
+
@trace_key = options[:trace_key] || nil
|
51
|
+
@auth_token = options[:auth_token] || nil
|
52
|
+
@user = nil
|
53
|
+
@proxy_user = nil
|
54
|
+
|
55
|
+
raise CloudFoundry::Client::Exception::BadParams, "Invalid CloudFoundry API URL: " + @target_url unless valid_target_url?
|
56
|
+
if @auth_token
|
57
|
+
raise CloudFoundry::Client::Exception::AuthError, "Invalid CloudFoundry API authorization token" unless logged_in?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# Sanitizes an URL.
|
64
|
+
#
|
65
|
+
# @param [String] url URL to sanitize.
|
66
|
+
# @return [String] URL sanitized.
|
67
|
+
def sanitize_url(url)
|
68
|
+
url = url =~ /^(http|https).*/i ? url : "http://#{url}"
|
69
|
+
url = url.gsub(/\/+$/, "")
|
70
|
+
end
|
71
|
+
|
72
|
+
# Checks if the target_url is a valid CloudFoundry target.
|
73
|
+
#
|
74
|
+
# @return [Boolean] Returns true if target_url is a valid CloudFoundry API URL, false otherwise.
|
75
|
+
def valid_target_url?
|
76
|
+
return false unless cloud_info = cloud_info()
|
77
|
+
return false unless cloud_info[:name]
|
78
|
+
return false unless cloud_info[:build]
|
79
|
+
return false unless cloud_info[:support]
|
80
|
+
return false unless cloud_info[:version]
|
81
|
+
true
|
82
|
+
rescue
|
83
|
+
false
|
84
|
+
end
|
85
|
+
|
86
|
+
# Requires a logged in user.
|
87
|
+
#
|
88
|
+
# @raise [CloudFoundry::Client::Exception::AuthError] if user is not logged in.
|
89
|
+
def require_login
|
90
|
+
raise CloudFoundry::Client::Exception::AuthError unless @user || logged_in?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
module CloudFoundry
|
2
|
+
class Client
|
3
|
+
# CloudFoundry API Applications methods.
|
4
|
+
module Apps
|
5
|
+
# Returns the list of applications deployed on the target cloud.
|
6
|
+
#
|
7
|
+
# @return [Hash] List of applications deployed on the target cloud.
|
8
|
+
# @authenticated True
|
9
|
+
def list_apps()
|
10
|
+
require_login
|
11
|
+
get(CloudFoundry::Client::APPS_PATH)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns basic information about an application deployed on the target cloud.
|
15
|
+
#
|
16
|
+
# @param [String] name The application name.
|
17
|
+
# @return [Hash] Basic application information on the target cloud.
|
18
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
19
|
+
# @authenticated True
|
20
|
+
def app_info(name)
|
21
|
+
require_login
|
22
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
23
|
+
get("#{CloudFoundry::Client::APPS_PATH}/#{name}")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns information about application instances on the target cloud.
|
27
|
+
#
|
28
|
+
# @param [String] name The application name.
|
29
|
+
# @return [Hash] Application instances information on the target cloud.
|
30
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
31
|
+
# @authenticated True
|
32
|
+
def app_instances(name)
|
33
|
+
require_login
|
34
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
35
|
+
get("#{CloudFoundry::Client::APPS_PATH}/#{name}/instances")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns information about application statistics on the target cloud.
|
39
|
+
#
|
40
|
+
# @param [String] name The application name.
|
41
|
+
# @return [Hash] Application statistics information on the target cloud.
|
42
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
43
|
+
# @authenticated True
|
44
|
+
def app_stats(name)
|
45
|
+
require_login
|
46
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
47
|
+
stats = []
|
48
|
+
stats_raw = get("#{CloudFoundry::Client::APPS_PATH}/#{name}/stats")
|
49
|
+
stats_raw.each_pair do |key, entry|
|
50
|
+
next unless entry[:stats]
|
51
|
+
entry[:instance] = key.to_s.to_i
|
52
|
+
entry[:state] = entry[:state].to_sym if entry[:state]
|
53
|
+
stats << entry
|
54
|
+
end
|
55
|
+
stats.sort { |a,b| a[:instance] - b[:instance] }
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns information about application crashes on the target cloud.
|
59
|
+
#
|
60
|
+
# @param [String] name The application name.
|
61
|
+
# @return [Hash] Application crashes information on the target cloud.
|
62
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
63
|
+
# @authenticated True
|
64
|
+
def app_crashes(name)
|
65
|
+
require_login
|
66
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
67
|
+
get("#{CloudFoundry::Client::APPS_PATH}/#{name}/crashes")
|
68
|
+
end
|
69
|
+
|
70
|
+
# List the directory or a file indicated by the path and instance.
|
71
|
+
#
|
72
|
+
# @param [String] name The application name.
|
73
|
+
# @param [String] path The application directory or file to display.
|
74
|
+
# @param [Integer] instance The application instance where directories or files are located.
|
75
|
+
# @return [String] Directory list or file bits on the target cloud.
|
76
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
77
|
+
# @authenticated True
|
78
|
+
def app_files(name, path = "/", instance = 0)
|
79
|
+
require_login
|
80
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
81
|
+
url = "#{CloudFoundry::Client::APPS_PATH}/#{name}/instances/#{instance}/files/#{path}"
|
82
|
+
url.gsub!('//', '/')
|
83
|
+
response_info = get(url, :raw => true)
|
84
|
+
response_info.body
|
85
|
+
end
|
86
|
+
|
87
|
+
# Creates a new application at target cloud.
|
88
|
+
#
|
89
|
+
# @param [String] name The application name.
|
90
|
+
# @param [Hash] manifest The manifest of the application.
|
91
|
+
# @return [Boolean] Returns true if application is created.
|
92
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
93
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application manifest is blank.
|
94
|
+
# @authenticated True
|
95
|
+
def create_app(name, manifest = {})
|
96
|
+
require_login
|
97
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
98
|
+
raise CloudFoundry::Client::Exception::BadParams, "Manifest cannot be blank" if manifest.nil? || manifest.empty?
|
99
|
+
app = manifest.dup
|
100
|
+
app[:name] = name
|
101
|
+
app[:instances] ||= 1
|
102
|
+
post(CloudFoundry::Client::APPS_PATH, app)
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
# Updates an application at target cloud.
|
107
|
+
#
|
108
|
+
# @param [String] name The application name.
|
109
|
+
# @param [Hash] manifest The manifest of the application.
|
110
|
+
# @return [Boolean] Returns true if application is updated.
|
111
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
112
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application manifest is blank.
|
113
|
+
# @authenticated True
|
114
|
+
def update_app(name, manifest = {})
|
115
|
+
require_login
|
116
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
117
|
+
raise CloudFoundry::Client::Exception::BadParams, "Manifest cannot be blank" if manifest.nil? || manifest.empty?
|
118
|
+
put("#{CloudFoundry::Client::APPS_PATH}/#{name}", manifest)
|
119
|
+
true
|
120
|
+
end
|
121
|
+
|
122
|
+
# Checks the status of the latest application update at target cloud.
|
123
|
+
#
|
124
|
+
# @param [String] name The application name.
|
125
|
+
# @return [Hash] Status of the latest application update at target cloud.
|
126
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
127
|
+
# @authenticated True
|
128
|
+
def update_app_info(name)
|
129
|
+
require_login
|
130
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
131
|
+
get("#{CloudFoundry::Client::APPS_PATH}/#{name}/update")
|
132
|
+
end
|
133
|
+
|
134
|
+
# Deletes an application at target cloud.
|
135
|
+
#
|
136
|
+
# @param [String] name The application name.
|
137
|
+
# @return [Boolean] Returns true if application is deleted.
|
138
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
139
|
+
# @authenticated True
|
140
|
+
def delete_app(name)
|
141
|
+
require_login
|
142
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
143
|
+
delete("#{CloudFoundry::Client::APPS_PATH}/#{name}", :raw => true)
|
144
|
+
true
|
145
|
+
end
|
146
|
+
|
147
|
+
# Uploads the application bits to the target cloud.
|
148
|
+
#
|
149
|
+
# @param [String] name The application name.
|
150
|
+
# @param [File, String] zipfile The application bits, can be a File Object or a filename String.
|
151
|
+
# @param [Array] resource_manifest The application resources manifest.
|
152
|
+
# @return [Boolean] Returns true if application is uploaded.
|
153
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
154
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application zipfile is blank.
|
155
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application zipfile is invalid.
|
156
|
+
# @authenticated True
|
157
|
+
def upload_app(name, zipfile, resource_manifest = [])
|
158
|
+
require_login
|
159
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
160
|
+
raise CloudFoundry::Client::Exception::BadParams, "Zipfile cannot be blank" if zipfile.nil?
|
161
|
+
upload_data = {}
|
162
|
+
begin
|
163
|
+
if zipfile.is_a? File
|
164
|
+
file = Faraday::UploadIO.new(zipfile, "application/zip")
|
165
|
+
else
|
166
|
+
filebits = File.new(zipfile, "rb")
|
167
|
+
file = Faraday::UploadIO.new(filebits, "application/zip")
|
168
|
+
end
|
169
|
+
rescue SystemCallError => error
|
170
|
+
raise CloudFoundry::Client::Exception::BadParams, "Invalid Zipfile: " + error.message
|
171
|
+
end
|
172
|
+
upload_data[:application] = file
|
173
|
+
upload_data[:resources] = resource_manifest.to_json if resource_manifest
|
174
|
+
put("#{CloudFoundry::Client::APPS_PATH}/#{name}/application", upload_data, :raw => true)
|
175
|
+
true
|
176
|
+
end
|
177
|
+
|
178
|
+
# Downloads the application bits from the target cloud.
|
179
|
+
#
|
180
|
+
# @param [String] name The application name.
|
181
|
+
# @return [String] Application bits.
|
182
|
+
# @raise [CloudFoundry::Client::Exception::BadParams] when application name is blank.
|
183
|
+
# @authenticated True
|
184
|
+
def download_app(name)
|
185
|
+
require_login
|
186
|
+
raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
|
187
|
+
response_info = get("#{CloudFoundry::Client::APPS_PATH}/#{name}/application", :raw => true)
|
188
|
+
response_info.body
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|