rightscale-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +37 -0
- data/VERSION +1 -0
- data/lib/rightscale/api.rb +48 -0
- data/lib/rightscale/client.rb +35 -0
- data/lib/rightscale/deployments.rb +5 -0
- data/lib/rightscale/right_scripts.rb +5 -0
- data/lib/rightscale/servers.rb +37 -0
- data/lib/rightscale/statuses.rb +16 -0
- data/lib/rightscale.rb +17 -0
- metadata +63 -0
data/README.markdown
ADDED
@@ -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)
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,48 @@
|
|
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
|
+
return response["#{@singular}"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
# implement in derivative classes
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
# implement in derivative classes
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy(identifier)
|
32
|
+
response = client.delete("/#{@resource}/#{identifier}")
|
33
|
+
end
|
34
|
+
|
35
|
+
# As discussed in more detail in the RightScale API Overview Guide, every
|
36
|
+
# major resource exported by the RightScale API will always have an href
|
37
|
+
# field that corresponds to the URL of the resource listed.
|
38
|
+
|
39
|
+
def formatted_uri(identifier)
|
40
|
+
if identifier.is_a?(String)
|
41
|
+
identifier.gsub(client.class.base_uri, '')
|
42
|
+
else
|
43
|
+
"/#{@resource}/#{identifier}.#{@format}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
options.merge!({
|
12
|
+
:basic_auth => {:username => @email, :password => @password},
|
13
|
+
:headers => {'X-API-VERSION' => '1.0'}
|
14
|
+
})
|
15
|
+
|
16
|
+
self.class.get("#{path}", options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def deployments
|
20
|
+
@deployments ||= Deployments.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def servers
|
24
|
+
@servers ||= Servers.new(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def statuses
|
28
|
+
@statuses ||= Statuses.new(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def right_scripts
|
32
|
+
@right_scripts ||= RightScripts.new(self, :resource => 'right_scripts')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
end
|
22
|
+
|
23
|
+
def attach_volume(ec2_ebs_volume_href, device)
|
24
|
+
response = client.post("/servers/#{identifier}/attach_volume", :query => {
|
25
|
+
:server => {
|
26
|
+
:ec2_ebs_volume_href => ec2_ebs_volume_href,
|
27
|
+
:device => device
|
28
|
+
}
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
def settings(identifier)
|
33
|
+
response = client.get("#{formatted_uri(identifier)}/settings")
|
34
|
+
return response['settings']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RightScale
|
2
|
+
class Statuses
|
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
|
data/lib/rightscale.rb
ADDED
@@ -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'
|
10
|
+
require dir + 'rightscale/client'
|
11
|
+
|
12
|
+
# Management API
|
13
|
+
require dir + 'rightscale/deployments'
|
14
|
+
require dir + 'rightscale/servers'
|
15
|
+
require dir + 'rightscale/right_scripts'
|
16
|
+
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rightscale-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Michael
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-30 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Ruby Wrapper for the RightScale API
|
17
|
+
email: david.michael@sonymusic.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
- VERSION
|
27
|
+
- lib/rightscale.rb
|
28
|
+
- lib/rightscale/api.rb
|
29
|
+
- lib/rightscale/client.rb
|
30
|
+
- lib/rightscale/deployments.rb
|
31
|
+
- lib/rightscale/right_scripts.rb
|
32
|
+
- lib/rightscale/servers.rb
|
33
|
+
- lib/rightscale/statuses.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/dmichael/rightscale-api
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: A Ruby Wrapper for the RightScale API
|
62
|
+
test_files: []
|
63
|
+
|