rightscale-api 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib', 'rightscale-api')
2
+
1
3
  begin
2
4
  require 'jeweler'
3
5
  Jeweler::Tasks.new do |gemspec|
@@ -7,7 +9,7 @@ begin
7
9
  gemspec.email = "david.michael@sonymusic.com"
8
10
  gemspec.homepage = "http://github.com/dmichael/rightscale-api"
9
11
  gemspec.authors = ["David Michael"]
10
- gemspec.add_development_dependency "httparty"
12
+ gemspec.add_dependency "httparty"
11
13
  end
12
14
  Jeweler::GemcutterTasks.new
13
15
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -0,0 +1,17 @@
1
+ require 'pathname'
2
+ require 'rubygems'
3
+ require 'httparty'
4
+ require 'pp'
5
+ require 'socket'
6
+
7
+ dir = Pathname(__FILE__).dirname.expand_path
8
+
9
+ require dir + 'rightscale-api/api'
10
+ require dir + 'rightscale-api/client'
11
+
12
+ # Management API
13
+ require dir + 'rightscale-api/deployments'
14
+ require dir + 'rightscale-api/servers'
15
+ require dir + 'rightscale-api/right_scripts'
16
+ require dir + 'rightscale-api/statuses'
17
+
@@ -0,0 +1,49 @@
1
+ module RightScale
2
+ class API
3
+ attr_reader :client
4
+
5
+ def initialize(client, options = {})
6
+ @client = client
7
+ @resource = options[:resource] || self.class.name.split('::').last.downcase
8
+ @singular = @resource.chop
9
+ @format = 'xml'
10
+ end
11
+
12
+ def index
13
+ response = client.get("/#{@resource}.#{@format}")
14
+ return response["#{@resource}"]
15
+ end
16
+
17
+ def show(identifier)
18
+ # puts formatted_uri(identifier)
19
+ response = client.get formatted_uri(identifier)
20
+
21
+ return response["#{@singular}"] || response
22
+ end
23
+
24
+ def create
25
+ # implement in derivative classes
26
+ end
27
+
28
+ def update
29
+ # implement in derivative classes
30
+ end
31
+
32
+ def destroy(identifier)
33
+ response = client.delete("/#{@resource}/#{identifier}")
34
+ end
35
+
36
+ # As discussed in more detail in the RightScale API Overview Guide, every
37
+ # major resource exported by the RightScale API will always have an href
38
+ # field that corresponds to the URL of the resource listed.
39
+
40
+ def formatted_uri(identifier)
41
+ if identifier.is_a?(String)
42
+ identifier.gsub(client.class.base_uri, '')
43
+ else
44
+ "/#{@resource}/#{identifier}.#{@format}"
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ module RightScale
2
+ class Client
3
+ include HTTParty
4
+
5
+ def initialize(account, email, password)
6
+ @account, @email, @password = account, email, password
7
+ self.class.base_uri "https://my.rightscale.com/api/acct/#{@account}"
8
+ end
9
+
10
+ def get(path, options={})
11
+ request :get, path, options
12
+ end
13
+
14
+ def post(path, options={})
15
+ request :post, path, options
16
+ end
17
+
18
+ def request(method, path, options={})
19
+ options.merge!({
20
+ :basic_auth => {:username => @email, :password => @password},
21
+ :headers => {'X-API-VERSION' => '1.0'}
22
+ })
23
+
24
+ response = self.class.send(method, "#{path}", options)
25
+ # puts response.inspect
26
+ return response
27
+ end
28
+
29
+ def deployments
30
+ @deployments ||= Deployments.new(self)
31
+ end
32
+
33
+ def servers
34
+ @servers ||= Servers.new(self)
35
+ end
36
+
37
+ def statuses
38
+ @statuses ||= Statuses.new(self)
39
+ end
40
+
41
+ def right_scripts
42
+ @right_scripts ||= RightScripts.new(self, :resource => 'right_scripts')
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ module RightScale
2
+ # http://support.rightscale.com/15-References/RightScale_API_Reference_Guide/02-Management/01-Deployments
3
+ class Deployments < API
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module RightScale
2
+ # http://support.rightscale.com/15-References/RightScale_API_Reference_Guide/02-Management/01-Deployments
3
+ class RightScripts < API
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ module RightScale
2
+ # http://support.rightscale.com/15-References/RightScale_API_Reference_Guide/02-Management/02-Servers
3
+ class Servers < API
4
+ def start(identifier)
5
+ response = client.post("/servers/#{identifier}/start")
6
+ end
7
+
8
+ def stop(identifier)
9
+ response = client.post("/servers/#{identifier}/stop")
10
+ end
11
+
12
+ def reboot(identifier)
13
+ response = client.post("/servers/#{identifier}/reboot")
14
+ end
15
+
16
+ def run_script(identifier, right_script_href, params = {})
17
+ query = {:server => {:right_script_href => right_script_href}}
18
+ query[:server].merge(params) if !params.empty?
19
+
20
+ response = client.post("/servers/#{identifier}/run_script", :query => query)
21
+ return response
22
+ end
23
+
24
+ def attach_volume(ec2_ebs_volume_href, device)
25
+ response = client.post("/servers/#{identifier}/attach_volume", :query => {
26
+ :server => {
27
+ :ec2_ebs_volume_href => ec2_ebs_volume_href,
28
+ :device => device
29
+ }
30
+ })
31
+ end
32
+
33
+ def settings(identifier)
34
+ response = client.get("#{formatted_uri(identifier)}/settings")
35
+ return response['settings']
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ module RightScale
2
+ class Statuses < API
3
+ # attr_reader :client
4
+ #
5
+ # def initialize(client)
6
+ # @client = client
7
+ # @@resource = self.class.name.split('::').last.downcase
8
+ # @@format = 'xml'
9
+ # end
10
+ #
11
+ # def show(identifier)
12
+ # response = client.get("/#{@@resource}/#{identifier}.#{@@format}")
13
+ # return response["#{@@resource.chop}"]
14
+ # end
15
+ end
16
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rightscale-api}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Michael"]
@@ -19,6 +19,13 @@ Gem::Specification.new do |s|
19
19
  "README.markdown",
20
20
  "Rakefile",
21
21
  "VERSION",
22
+ "lib/rightscale-api.rb",
23
+ "lib/rightscale-api/api.rb",
24
+ "lib/rightscale-api/client.rb",
25
+ "lib/rightscale-api/deployments.rb",
26
+ "lib/rightscale-api/right_scripts.rb",
27
+ "lib/rightscale-api/servers.rb",
28
+ "lib/rightscale-api/statuses.rb",
22
29
  "pkg/rightscale-api-0.0.1.gem",
23
30
  "rightscale-api.gemspec"
24
31
  ]
@@ -33,7 +40,7 @@ Gem::Specification.new do |s|
33
40
  s.specification_version = 3
34
41
 
35
42
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
36
- s.add_development_dependency(%q<httparty>, [">= 0"])
43
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
37
44
  else
38
45
  s.add_dependency(%q<httparty>, [">= 0"])
39
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightscale-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Michael
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
- type: :development
17
+ type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
@@ -34,6 +34,13 @@ files:
34
34
  - README.markdown
35
35
  - Rakefile
36
36
  - VERSION
37
+ - lib/rightscale-api.rb
38
+ - lib/rightscale-api/api.rb
39
+ - lib/rightscale-api/client.rb
40
+ - lib/rightscale-api/deployments.rb
41
+ - lib/rightscale-api/right_scripts.rb
42
+ - lib/rightscale-api/servers.rb
43
+ - lib/rightscale-api/statuses.rb
37
44
  - pkg/rightscale-api-0.0.1.gem
38
45
  - rightscale-api.gemspec
39
46
  has_rdoc: true