scalarium-api-wrapper 0.3.0 → 0.4.2

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.
@@ -3,16 +3,24 @@ Scalarium API wrapper
3
3
 
4
4
  About
5
5
  --
6
- Since Scalarium is currently (June 2011) not supporting roles and therefore it is troublesome/risky to give all the development team members full access to the clouds/applications this library will allow easy setup of local environments for anyone minimizing the risk of 'stoping' the production environment.
7
- For example limiting only to one cloud or application (development environment).
8
-
6
+ This library simplifies and automates the interaction with Scalarium's API. It makes all the common operations for obtaining
7
+ Clouds with their instances and roles a breeze. <br />
8
+ It is very easy to integrate this library with
9
+ your application to control your instances (restart, stop, start) and applications (deploy/redeploy) from the command line
10
+
11
+ <!--
12
+ Since Scalarium is currently (June 2011) not supporting members' roles and therefore it is troublesome/risky to give all the development team members full access to the clouds/applications this library will allow easy setup of local environments for anyone minimizing the risk of 'stoping' the production environment.
13
+ For example limiting only to one cloud or application (development environment).
14
+ -->
15
+
9
16
  All the documentation for Scalarium API - ([http://support.scalarium.com/kb/api](http://support.scalarium.com/kb/api))
10
17
 
11
18
  It can:
12
19
 
13
- * Obtain a list of all clouds
14
- * Obtain a list of all applications
15
- * Perform deploy of specified application, stop/start/restart clouds
20
+ * Obtain a list of all clouds with their instances & roles
21
+ * Obtain a list of all applications plus their deployements
22
+ * Perform deploy of specified application, with custom comment and enabled migrations command
23
+ * Interact with the clouds stop/start/restart clouds (Still under development)
16
24
 
17
25
 
18
26
 
@@ -119,6 +127,22 @@ Here is a simple [RAKE task](https://gist.github.com/1037410) that illustrates h
119
127
 
120
128
 
121
129
 
130
+ Contributing
131
+ --
132
+
133
+ * Fork this project
134
+
135
+ * Check with TODO.txt what could be worked on
136
+
137
+ * Push your contribution to a branch named after your change
138
+ ie: git push origin master:added-feature-name
139
+
140
+ * Try to write tests first, so we know it works beforehand
141
+
142
+ * Send me a pull request through GitHub with a description of
143
+ what you are contributing.
144
+
145
+
122
146
 
123
147
  License
124
148
  --
data/Rakefile CHANGED
@@ -1 +1,20 @@
1
+ namespace :test do
2
+
3
+ desc "run spec/unit tests"
4
+ task :spec do
5
+ print %x[rspec -c -f s spec/*_spec.rb]
6
+ end
7
+
8
+ desc "run functional tests"
9
+ task :functional do
10
+ print %x[rspec -c -f s spec/functional/*_spec.rb]
11
+ end
12
+
13
+ desc "run all the tests"
14
+ task :all => [:spec, :functional] do
15
+ end
16
+
17
+ end
18
+
1
19
  require 'bundler/gem_tasks'
20
+
@@ -0,0 +1,7 @@
1
+ 1 - Call to obtain all the deployments for application [currently talking to Scalarium's support about this - 28th of June]
2
+ 2 - Getting Clouds' roles, instances of particular cloud and instance of role [DONE] (http://support.scalarium.com/kb/api/listing-clouds-roles-and-instances)
3
+ 3 - Creating, starting, stopping and rebooting instances
4
+ 4 - Listing and deploying applications [DONE]
5
+ 5a - abstract HTTP REST Client calls into separate class [DONE]
6
+ 5b - Move cloud specific stuff to API::Clouds and applications to API::Applications
7
+ 6 - add the rake task to run the tests from the APP_ROOT
@@ -28,4 +28,5 @@ end
28
28
 
29
29
  require "scalarium-api-wrapper/version"
30
30
  require "scalarium-api-wrapper/configuration"
31
+ require "scalarium-api-wrapper/abstract_api"
31
32
  require "scalarium-api-wrapper/api"
@@ -0,0 +1,28 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module Scalarium
5
+
6
+ class AbstractAPI
7
+
8
+ private
9
+ def get_headers
10
+ # quick validation if the header is set
11
+ if Scalarium.headers['X-Scalarium-Token'].nil? || Scalarium.headers['X-Scalarium-Token'] == ""
12
+ raise ArgumentError "X-Scalarium-Token is not set"
13
+ end
14
+ Scalarium.headers
15
+ end
16
+
17
+ # Method uses RestClient to make a HTTP POST request to Scalarium API
18
+ def http_post_request(url, json_command)
19
+ JSON.parse(RestClient.post(url, json_command, get_headers))
20
+ end
21
+
22
+ # Method uses RestClient to make a HTTP GET request to Scalarium API
23
+ def http_get_request(url)
24
+ JSON.parse(RestClient.get(url, get_headers))
25
+ end
26
+ end
27
+
28
+ end
@@ -1,21 +1,72 @@
1
- require 'rest-client'
2
- require 'json'
3
-
4
1
  module Scalarium
5
2
 
6
- class API
7
-
3
+ class API < AbstractAPI
8
4
  # Method fetches all clouds on the server
9
5
  #
10
- # @returns array [Array] - array containing all the clouds
6
+ # @option [String] - cloud id of the cloud we want to see or nothing then we get the list of all clouds
7
+ #
8
+ # @return [Array] - array containing all the clouds
9
+ # or when param is passed it gets the particular cloud and
10
+ # @return [Hash] - @see API#get_cloud
11
11
  #
12
- def get_clouds
12
+ def get_clouds(cloud_id=nil)
13
+ return get_cloud(cloud_id) unless cloud_id.nil?
13
14
  http_get_request(Scalarium.clouds_url)
14
15
  end
15
16
 
17
+ # Method gets single could details
18
+ #
19
+ # @param [String] cloud_id - id of the cloud we want to see
20
+ # @return [Hash] - hash containing details for particular cloud
21
+ #
22
+ def get_cloud(cloud_id)
23
+ http_get_request(Scalarium.clouds_url+"/#{cloud_id}")
24
+ end
25
+
26
+ # Method obtains roles per cloud
27
+ #
28
+ # @param [String] cloud_id - id of the cloud of which roles we want to see
29
+ # @return [Array] - list of the roles
30
+ #
31
+ def get_cloud_roles(cloud_id)
32
+ http_get_request(Scalarium.clouds_url+"/#{cloud_id}/roles")
33
+ end
34
+
35
+ # Method obtains instances of the cloud
36
+ #
37
+ # @param [String] cloud_id - id of the cloud of which instances we want to see
38
+ # @return [Array] - list of the instances
39
+ #
40
+ def get_cloud_instances(cloud_id)
41
+ http_get_request(Scalarium.clouds_url+"/#{cloud_id}/instances")
42
+ end
43
+
44
+ # Method obtains details of specified instance for a given cloud
45
+ #
46
+ # @param [String] cloud_id - id of the cloud instance detail we want to obtain
47
+ # @param [String] instance_id - id of the instance for specified cloud we want to see
48
+ # @return [Hash] - hash with details about the passed instance of the cloud
49
+ #
50
+ def get_instance_of_cloud(cloud_id, instance_of_cloud_id)
51
+ http_get_request(Scalarium.clouds_url+"/#{cloud_id}/instances/#{instance_of_cloud_id}")
52
+ end
53
+
54
+ # Method allows to send command to the instance of specified cloud
55
+ #
56
+ # @param [String] cloud_id
57
+ # @param [String] instance_id
58
+ # @param [Symbol] command - it can be one of :start, :stop, :reboot
59
+ #
60
+ def send_instance_command(cloud_id, instance_id, command)
61
+ commands = [:start, :reboot, :stop]
62
+ raise ArgumentError, "You have passed wrong command allowed ones are: #{commands}" if !commands.include?(command)
63
+
64
+ http_post_request(Scalarium.clouds_url+"/#{cloud_id}/instances/#{instance_id}/#{command.to_s}")
65
+ end
66
+
16
67
  # Method fetches all applications on the server
17
68
  #
18
- # @returns array [Array] - array containing all the applications
69
+ # @return [Array] - array containing all the applications
19
70
  #
20
71
  def get_applications
21
72
  http_get_request(Scalarium.applications_url)
@@ -24,21 +75,32 @@ module Scalarium
24
75
  # Method pings scalarium to check the details of the deploy (i.e. progress)
25
76
  # @see http://support.scalarium.com/kb/api/fetching-deployment-details
26
77
  #
27
- # @returns hash [Hash] - Hash contains all the deployment details
78
+ # @param [String] app_id - String app_id of application we want to see
79
+ # @param [String] deployment_id - String id of the deployment we want to see
80
+ # @return [Hash] - Hash contains all the deployment details
28
81
  #
29
82
  def fetch_deployment_details(app_id, deployment_id)
30
83
  http_get_request(Scalarium.applications_url+"/#{app_id}/deployments/#{deployment_id}")
31
84
  end
32
85
 
86
+ # @see http://support.scalarium.com/discussions/questions/83-is-it-possible-to-obtain-all-the-deployments-for-the-specified-application
87
+ # Method allows to fetch all the deployments for the specified application
88
+ #
89
+ # @param [String] app_id - String app_id of application that deployments we want to see
90
+ # @return [Array] - Delivers array of all the deployments for the application
91
+ def fetch_all_deployments(app_id)
92
+ warn "[WARRNING!] This functionality might not be yet supported by Scalarium!"
93
+ http_get_request(Scalarium.applications_url+"/#{app_id}/deployments/#{deployment_id}")
94
+ end
95
+
33
96
  # Method allows to deploy application in scalarium
97
+ #
98
+ # @param [String] app_id - The ID of application we want to deploy.
99
+ #
100
+ # @option options [String] :comment - comment to be displayed on the deployment
101
+ # @option options [Boolean] :migrate - boolean indicating if we should run the migrations too (false by default)
34
102
  #
35
- # @option app_id [String] - The ID of application we want to deploy.
36
- #
37
- # @option options [Hash] - Hash with options:
38
- # :comment - comment to be displayed on the deployment
39
- # :migrate - boolean indicating if we should run the migrations too (false by default)
40
- #
41
- # @returns [Hash] response of the progress and details
103
+ # @return [Hash] response of the progress and details
42
104
  #
43
105
  def deploy_application(app_id, options = {:comment => nil, :migrate => false})
44
106
  json_command = JSON.dump(:command => 'deploy',
@@ -46,27 +108,14 @@ module Scalarium
46
108
  :migrate => options[:migrate])
47
109
  http_post_request(Scalarium.applications_url+"/#{app_id}/deploy", json_command)
48
110
  end
49
-
50
-
51
- private
52
- def get_headers
53
- # quick validation if the header is set
54
- if Scalarium.headers['X-Scalarium-Token'].nil? || Scalarium.headers['X-Scalarium-Token'] == ""
55
- raise ArgumentError "X-Scalarium-Token is not set"
56
- end
57
- Scalarium.headers
58
- end
59
-
60
- # Method uses RestClient to make a HTTP POST request to Scalarium API
61
- def http_post_request(url, json_command)
62
- JSON.parse(RestClient.post(url, json_command, get_headers))
63
- end
64
-
65
- # Method uses RestClient to make a HTTP GET request to Scalarium API
66
- def http_get_request(url)
67
- JSON.parse(RestClient.get(url, get_headers))
68
- end
69
-
70
-
71
111
  end
112
+ end
113
+
114
+ # ALIASES:
115
+ #
116
+ # adding some better naming for the fetch_deployment_details -> get_deployment_details
117
+ # it is just an alias for existing method (so it stays backward compatible)
118
+ Scalarium::API.class_eval do
119
+ alias :get_deployment_details :fetch_deployment_details
120
+ alias :get_all_deployments :fetch_all_deployments
72
121
  end
@@ -1,7 +1,7 @@
1
1
  module Scalarium
2
2
  module Api
3
3
  module Wrapper
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.2"
5
5
  end
6
6
  end
7
7
  end
@@ -27,13 +27,33 @@ describe "Scalarium::API", "when first created" do
27
27
  Scalarium.clouds_url.should == @clouds_url
28
28
  end
29
29
 
30
- it "should be able to deploy application" do
31
- @api.should respond_to(:deploy_application)
32
- end
33
-
34
30
  it "should be able to get all the clouds" do
35
31
  @api.should respond_to(:get_clouds)
36
32
  end
33
+
34
+ it "should be able to get single cloud" do
35
+ @api.should respond_to(:get_cloud)
36
+ end
37
+
38
+ it "should be able to get list cloud's roles" do
39
+ @api.should respond_to(:get_cloud_roles)
40
+ end
41
+
42
+ it "should be able to get list cloud's instances" do
43
+ @api.should respond_to(:get_cloud_instances)
44
+ end
45
+
46
+ it "should be able to get cloud's instances of a specific role" do
47
+
48
+ end
49
+
50
+ it "should be able to get cloud's single instance" do
51
+ @api.should respond_to(:get_instance_of_cloud)
52
+ end
53
+
54
+ it "should be able to deploy application" do
55
+ @api.should respond_to(:deploy_application)
56
+ end
37
57
 
38
58
  it "should be able to get all the applications" do
39
59
  @api.should respond_to(:get_applications)
@@ -42,6 +62,19 @@ describe "Scalarium::API", "when first created" do
42
62
  it "should be able to get deployment status aka deployment details" do
43
63
  @api.should respond_to(:fetch_deployment_details)
44
64
  end
65
+
66
+ it "should be able to get deployment status aka deployment details with alias :get_deployment_details" do
67
+ @api.should respond_to(:get_deployment_details)
68
+ end
69
+
70
+ it "should be able to get all deployments details" do
71
+ @api.should respond_to(:fetch_all_deployments)
72
+ end
73
+
74
+ it "should be able to get all deployments details with alias :get_all_deployments" do
75
+ @api.should respond_to(:get_all_deployments)
76
+ end
77
+
45
78
 
46
79
 
47
80
  end
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe "Scalarium.configuration", "when first created" do
4
4
 
5
+ before(:all) do
6
+ Scalarium.configuration.api_token = nil
7
+ end
8
+
5
9
  it "should has no api token set yet" do
6
10
  Scalarium.configuration.api_token.should == nil
7
11
  end
@@ -6,7 +6,7 @@ describe "Scalarium functional tests", "when first created" do
6
6
 
7
7
  before(:all) do
8
8
  # we load configuration
9
- config = YAML::load(File.open("./scalarium.yml"))
9
+ config = YAML::load(File.open(File.dirname(__FILE__)+"/scalarium.yml"))
10
10
  raise "!!! scalarium.yml file is missing - have your renamed scalarium.yml.sample into scalarium.yml? !!!" if config.nil?
11
11
 
12
12
  Scalarium.configuration.api_token = config["api_token"]
@@ -14,22 +14,11 @@ describe "Scalarium functional tests", "when first created" do
14
14
  @comment = "This is test deploy by functional testing from scalarium-api-wrapper gem"
15
15
 
16
16
  @api = Scalarium::API.new
17
-
18
- # @response_status - this is initial response status
19
- # returned after we make initial call to deploy application
20
- @response_status = nil
21
- # @status_check_response - this is status response for when we check
22
- # progress of our deployment
23
- @status_check_response = nil
24
17
  end
25
18
 
26
19
  it "should obtain list of applications and present an array" do
27
20
  @api.get_applications.class.should == Array
28
21
  end
29
-
30
- it "should obtain list of clouds and present an array" do
31
- @api.get_clouds.class.should == Array
32
- end
33
22
 
34
23
  it "should redeploy application with specified ID and comment: #{@comment} returning status should be in proper state" do
35
24
  @response_status = @api.deploy_application(@application_id, :comment => @comment)
@@ -37,7 +26,7 @@ describe "Scalarium functional tests", "when first created" do
37
26
  @response_status["status"].should == "running"
38
27
  @response_status["command"].should == "deploy"
39
28
  @response_status["application_id"].should == @application_id
40
-
29
+
41
30
  sleep 2
42
31
  id_of_deployment = @response_status["id"]
43
32
  @status_check_response = @api.fetch_deployment_details(@application_id, id_of_deployment)
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+
5
+ describe "Scalarium api", "obtaining clouds and then single cloud details" do
6
+
7
+ before(:all) do
8
+ # we load configuration
9
+ config = YAML::load(File.open(File.dirname(__FILE__)+"/scalarium.yml"))
10
+ raise "!!! scalarium.yml file is missing - have your renamed scalarium.yml.sample into scalarium.yml? !!!" if config.nil?
11
+
12
+ @cloud_keys = %w( id name region nickname_theme custom_agent_version default_os deleted_at created_at updated_at custom_json use_custom_cookbooks scm_user scm_password scm_type scm_url scm_ssh_key scm_revision account_id user_id ssh_key_id credential_id )
13
+
14
+ Scalarium.configuration.api_token = config["api_token"]
15
+ @api = Scalarium::API.new
16
+ end
17
+
18
+ it "should obtain list of clouds and present an array" do
19
+ @api.get_clouds.class.should == Array
20
+ end
21
+
22
+ it "be able to obtain list of clouds and then get the details of first cloud from the list" do
23
+ # we should get at least one cloud
24
+ @api.get_clouds.first['id'].nil?.should == false
25
+ single_cloud = @api.get_cloud(@api.get_clouds.first['id'])
26
+
27
+ # checking if we received planed Hash structure
28
+ single_cloud.keys.each do |key|
29
+ @cloud_keys.include?(key).should == true
30
+ end
31
+ end
32
+
33
+ it "should get cloud's instances" do
34
+ @api.get_clouds.first['id'].nil?.should == false
35
+ single_cloud = @api.get_cloud(@api.get_clouds.first['id'])
36
+
37
+ # we should get array of instances back
38
+ @api.get_cloud_instances(single_cloud["id"]).class.should == Array
39
+ end
40
+
41
+ it "should get cloud's roles" do
42
+ @api.get_clouds.first['id'].nil?.should == false
43
+ single_cloud = @api.get_cloud(@api.get_clouds.first['id'])
44
+
45
+ # we should get array of roles back
46
+ @api.get_cloud_roles(single_cloud["id"]).class.should == Array
47
+ end
48
+
49
+
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scalarium-api-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-24 00:00:00.000000000 +02:00
12
+ date: 2011-07-06 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
- requirement: &2153054260 !ruby/object:Gem::Requirement
17
+ requirement: &2153560380 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2153054260
25
+ version_requirements: *2153560380
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rake
28
- requirement: &2153053800 !ruby/object:Gem::Requirement
28
+ requirement: &2153559960 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2153053800
36
+ version_requirements: *2153559960
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &2153053200 !ruby/object:Gem::Requirement
39
+ requirement: &2153559460 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '2.0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2153053200
47
+ version_requirements: *2153559460
48
48
  description: This is scalarium API wrapper, allowing to execute API calls to scalarium
49
49
  backend
50
50
  email:
@@ -57,14 +57,17 @@ files:
57
57
  - Gemfile
58
58
  - README.markdown
59
59
  - Rakefile
60
+ - TODO.txt
60
61
  - lib/scalarium-api-wrapper.rb
62
+ - lib/scalarium-api-wrapper/abstract_api.rb
61
63
  - lib/scalarium-api-wrapper/api.rb
62
64
  - lib/scalarium-api-wrapper/configuration.rb
63
65
  - lib/scalarium-api-wrapper/version.rb
64
66
  - scalarium-api-wrapper.gemspec
65
67
  - spec/api_spec.rb
66
68
  - spec/configuration_spec.rb
67
- - spec/functional/api_functional_spec.rb
69
+ - spec/functional/api_application_functional_spec.rb
70
+ - spec/functional/api_cloud_functional_spec.rb
68
71
  - spec/functional/scalarium.yml.sample
69
72
  - spec/spec_helper.rb
70
73
  has_rdoc: true
@@ -95,6 +98,7 @@ summary: This is scalarium API wrapper
95
98
  test_files:
96
99
  - spec/api_spec.rb
97
100
  - spec/configuration_spec.rb
98
- - spec/functional/api_functional_spec.rb
101
+ - spec/functional/api_application_functional_spec.rb
102
+ - spec/functional/api_cloud_functional_spec.rb
99
103
  - spec/functional/scalarium.yml.sample
100
104
  - spec/spec_helper.rb