threetee-rightscale-api 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.
@@ -0,0 +1,37 @@
1
+ RightScale API
2
+ ===================
3
+
4
+ This is a light Ruby wrapper around the RightScale API.
5
+ It, like the RightScale API itself is a little incomplete. It should however be ready soon for general use as it is being developed for a production application.
6
+ Below is an example of usage. Please contact if with bug reports or if you would like to contribute.
7
+
8
+ At the moment only GET requests are implemented.
9
+ Depends upon [HTTParty](http://github.com/jnunemaker/httparty)
10
+
11
+ Usage
12
+ -----
13
+
14
+ account = 1234
15
+ username = 'alibaba@example.com'
16
+ password = 'opensezme'
17
+
18
+ rightscale = RightScale::Client.new(account, username, password)
19
+
20
+ deployments = rightscale.deployments
21
+ servers = rightscale.servers
22
+ right_scripts = rightscale.right_scripts
23
+
24
+
25
+ production = deployments.index.find {|d| d['nickname'] ==
26
+ 'Production Deployment V1'
27
+ }
28
+
29
+ production['servers'].each {|server|
30
+ settings = servers.settings(server['href'])
31
+ dns = settings['dns_name']
32
+ pp IPSocket.getaddress(dns) if dns
33
+ }
34
+
35
+ pp rightscale.right_scripts.show(1234)
36
+ pp rightscale.deployments.show(1234)
37
+ pp rightscale.servers.show(1234)
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib', 'rightscale-api')
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gemspec|
6
+ gemspec.name = "rightscale-api"
7
+ gemspec.summary = "A Ruby Wrapper for the RightScale API"
8
+ gemspec.description = "A Ruby Wrapper for the RightScale API"
9
+ gemspec.email = "david.michael@sonymusic.com"
10
+ gemspec.homepage = "http://github.com/dmichael/rightscale-api"
11
+ gemspec.authors = ["David Michael"]
12
+ gemspec.add_dependency "httparty"
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.2
@@ -0,0 +1,18 @@
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/server_arrays'
16
+ require dir + 'rightscale-api/right_scripts'
17
+ require dir + 'rightscale-api/statuses'
18
+
@@ -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,49 @@
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 server_arrays
38
+ @server_arrays ||= ServerArrays.new(self, :resource => 'server_arrays')
39
+ end
40
+
41
+ def statuses
42
+ @statuses ||= Statuses.new(self)
43
+ end
44
+
45
+ def right_scripts
46
+ @right_scripts ||= RightScripts.new(self, :resource => 'right_scripts')
47
+ end
48
+ end
49
+ 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,5 @@
1
+ module RightScale
2
+ # http://support.rightscale.com/15-References/RightScale_API_Reference_Guide/02-Management/09-Server_Arrays
3
+ class ServerArrays < 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
@@ -0,0 +1,49 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "threetee-rightscale-api"
8
+ s.version = "0.4.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Michael"]
12
+ s.date = "2012-04-05"
13
+ s.description = "A Ruby Wrapper for the RightScale API"
14
+ s.email = "david.michael@sonymusic.com"
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ "README.markdown",
20
+ "Rakefile",
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/server_arrays.rb",
28
+ "lib/rightscale-api/servers.rb",
29
+ "lib/rightscale-api/statuses.rb",
30
+ "threetee-rightscale-api.gemspec"
31
+ ]
32
+ s.homepage = "http://github.com/dmichael/rightscale-api"
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "1.8.15"
35
+ s.summary = "A Ruby Wrapper for the RightScale API"
36
+
37
+ if s.respond_to? :specification_version then
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
42
+ else
43
+ s.add_dependency(%q<httparty>, [">= 0"])
44
+ end
45
+ else
46
+ s.add_dependency(%q<httparty>, [">= 0"])
47
+ end
48
+ end
49
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: threetee-rightscale-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Michael
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70214742184360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70214742184360
25
+ description: A Ruby Wrapper for the RightScale API
26
+ email: david.michael@sonymusic.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files:
30
+ - README.markdown
31
+ files:
32
+ - README.markdown
33
+ - Rakefile
34
+ - VERSION
35
+ - lib/rightscale-api.rb
36
+ - lib/rightscale-api/api.rb
37
+ - lib/rightscale-api/client.rb
38
+ - lib/rightscale-api/deployments.rb
39
+ - lib/rightscale-api/right_scripts.rb
40
+ - lib/rightscale-api/server_arrays.rb
41
+ - lib/rightscale-api/servers.rb
42
+ - lib/rightscale-api/statuses.rb
43
+ - threetee-rightscale-api.gemspec
44
+ homepage: http://github.com/dmichael/rightscale-api
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.15
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: A Ruby Wrapper for the RightScale API
68
+ test_files: []