rightstuff 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +20 -0
- data/README.rdoc +42 -0
- data/Rakefile +43 -0
- data/lib/rightstuff.rb +155 -0
- metadata +91 -0
data/COPYING
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Joe Yates
|
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.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= rightstuff - Another Ruby Interface for RightScale
|
2
|
+
|
3
|
+
Here is a typical example:
|
4
|
+
|
5
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
6
|
+
require 'rightstuff'
|
7
|
+
|
8
|
+
include Rightstuff::Credentials
|
9
|
+
|
10
|
+
rs = Rightstuff::Client.new( rightscale_data[ :main ][ :credentials ] )
|
11
|
+
servers = rs.servers
|
12
|
+
servers.each{ |server| puts server.private_ip_address }
|
13
|
+
|
14
|
+
Rightstuff::Credentials assumes you have a YAMl file called ~/.rightstuff
|
15
|
+
It should be of the form:
|
16
|
+
---
|
17
|
+
:main:
|
18
|
+
:credentials:
|
19
|
+
:username: myusername
|
20
|
+
:password: mypass
|
21
|
+
:account: 1234
|
22
|
+
|
23
|
+
= Installation
|
24
|
+
|
25
|
+
$ sudo gem install rightstuff
|
26
|
+
|
27
|
+
= Online
|
28
|
+
|
29
|
+
* {Source code}[http://github.com/joeyates/rightstuff]
|
30
|
+
* Documentation[http://rdoc.info/projects/joeyates/rightstuff]
|
31
|
+
* Gem[http://rubygems.org/gems/rightstuff]
|
32
|
+
|
33
|
+
= Alternatives
|
34
|
+
|
35
|
+
* http://github.com/rightscale/right_link - RightScale's messaging API for live servers
|
36
|
+
* http://github.com/rightscale/right_aws
|
37
|
+
* http://github.com/moneypools/right_api
|
38
|
+
|
39
|
+
= TODO
|
40
|
+
|
41
|
+
* Cache connections
|
42
|
+
* Don't query inactive serevrs for settings
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
$:.unshift( File.dirname( __FILE__ ) + '/lib' )
|
6
|
+
require 'rightstuff'
|
7
|
+
|
8
|
+
ADMIN_FILES = FileList[ 'COPYING', 'Rakefile', 'README.rdoc' ]
|
9
|
+
SOURCE_FILES = FileList[ 'lib/**/*.rb' ]
|
10
|
+
RDOC_FILES = FileList[ 'COPYING', 'README.rdoc' ] + SOURCE_FILES
|
11
|
+
RDOC_OPTS = [ '--quiet', '--main', 'README.rdoc', '--inline-source' ]
|
12
|
+
DESCRIPTION = 'Another Ruby Interface for RightScale, providing an OO interface for RightScale accounts'
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.name = 'rightstuff'
|
16
|
+
s.summary = 'Another Ruby Interface for RightScale'
|
17
|
+
s.description = DESCRIPTION
|
18
|
+
s.version = Rightstuff::VERSION::STRING
|
19
|
+
|
20
|
+
s.homepage = 'http://github.com/joeyates/rightstuff'
|
21
|
+
s.author = 'Joe Yates'
|
22
|
+
s.email = 'joe.g.yates@gmail.com'
|
23
|
+
|
24
|
+
s.files = ADMIN_FILES +
|
25
|
+
SOURCE_FILES
|
26
|
+
s.require_paths = [ 'lib' ]
|
27
|
+
s.add_dependency( 'nokogiri', '>= 1.4.3.1' )
|
28
|
+
|
29
|
+
s.has_rdoc = true
|
30
|
+
s.rdoc_options += RDOC_OPTS
|
31
|
+
s.extra_rdoc_files = RDOC_FILES
|
32
|
+
s.rubyforge_project = 'nowarning'
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::GemPackageTask.new( spec ) do |pkg|
|
36
|
+
end
|
37
|
+
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
rdoc.rdoc_dir = 'html'
|
40
|
+
rdoc.options += RDOC_OPTS
|
41
|
+
rdoc.title = DESCRIPTION
|
42
|
+
rdoc.rdoc_files.add RDOC_FILES
|
43
|
+
end
|
data/lib/rightstuff.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
#!ruby
|
2
|
+
|
3
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
4
|
+
require 'yaml'
|
5
|
+
require 'net/https'
|
6
|
+
require 'uri'
|
7
|
+
require 'nokogiri'
|
8
|
+
|
9
|
+
module Rightstuff
|
10
|
+
|
11
|
+
module VERSION #:nodoc:
|
12
|
+
MAJOR = 0
|
13
|
+
MINOR = 0
|
14
|
+
TINY = 1
|
15
|
+
|
16
|
+
STRING = [ MAJOR, MINOR, TINY ].join('.')
|
17
|
+
end
|
18
|
+
|
19
|
+
module Credentials
|
20
|
+
|
21
|
+
def rightscale_data_path
|
22
|
+
File.expand_path( '~/.rightscale' )
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_permissions
|
26
|
+
mode = File::Stat.new( rightscale_data_path ).mode
|
27
|
+
if mode & 0066 != 0
|
28
|
+
raise "Permissions on '#{ rightscale_data_path }' too open (currently 0%o), should be 0600" % ( mode & 0666 )
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def rightscale_data
|
33
|
+
return @rightscale_data if @rightscale_data
|
34
|
+
raise "Missing credentials file '#{ rightscale_data_path }'" if ! File.exist?( rightscale_data_path )
|
35
|
+
check_permissions
|
36
|
+
@rightscale_data = YAML.load_file( rightscale_data_path )
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
class Base
|
42
|
+
|
43
|
+
def self.load_collection( client, doc )
|
44
|
+
doc.xpath( self.collection_xpath ).collect do | item |
|
45
|
+
self.new( client, item )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.extract_attributes( parent )
|
50
|
+
elements = parent.children.collect do | node |
|
51
|
+
node.class == Nokogiri::XML::Element ? node : nil
|
52
|
+
end
|
53
|
+
elements.compact!
|
54
|
+
elements.reduce({}) do | memo, element |
|
55
|
+
name = element.name
|
56
|
+
name.gsub!( /-/, '_' )
|
57
|
+
memo[ name.intern ] = element.children[0].to_s
|
58
|
+
memo
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def initialize( client, item )
|
63
|
+
@client = client
|
64
|
+
@attributes = Base.extract_attributes( item )
|
65
|
+
end
|
66
|
+
|
67
|
+
def method_missing( name, *args, &block )
|
68
|
+
return @attributes[ name ]
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class Server < Base
|
74
|
+
|
75
|
+
def initialize( client, item )
|
76
|
+
@settings = false
|
77
|
+
super
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.collection_xpath
|
81
|
+
'/servers/server'
|
82
|
+
end
|
83
|
+
|
84
|
+
def method_missing( name , *args, &block )
|
85
|
+
result = super
|
86
|
+
return result unless result.nil?
|
87
|
+
settings unless @settings
|
88
|
+
return @attributes[ name ]
|
89
|
+
end
|
90
|
+
|
91
|
+
def id
|
92
|
+
@attributes[ :href ].split( '/' ).last
|
93
|
+
end
|
94
|
+
|
95
|
+
def inputs
|
96
|
+
# Add inputs to instance data
|
97
|
+
# @client.get( @attributes[ 'href' ] )
|
98
|
+
end
|
99
|
+
|
100
|
+
def settings
|
101
|
+
doc = @client.get_rest( 'servers/' + id + '/settings' )
|
102
|
+
xml = Nokogiri::XML( doc )
|
103
|
+
@attributes.merge!( Base.extract_attributes( xml.children ) )
|
104
|
+
@settings = true
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
class Client
|
110
|
+
|
111
|
+
def initialize( options = {} )
|
112
|
+
@base_url = 'https://my.rightscale.com/api/acct'
|
113
|
+
@username = options[ :username ] or raise 'no username supplied'
|
114
|
+
@password = options[ :password ] or raise 'no password supplied'
|
115
|
+
@account = options[ :account ] or raise 'no account id supplied'
|
116
|
+
@account = @account.to_s
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_rest( rest )
|
120
|
+
get( account_url( rest ) )
|
121
|
+
end
|
122
|
+
|
123
|
+
def get( path )
|
124
|
+
address = path
|
125
|
+
url = URI.parse( address )
|
126
|
+
con = Net::HTTP.new( url.host, url.port )
|
127
|
+
con.use_ssl = true
|
128
|
+
con.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
129
|
+
|
130
|
+
request = Net::HTTP::Get.new( url.request_uri )
|
131
|
+
request.add_field( 'X-API-VERSION', '1.0' )
|
132
|
+
request.basic_auth @username, @password
|
133
|
+
|
134
|
+
response = con.request( request )
|
135
|
+
|
136
|
+
case response.code
|
137
|
+
when '200'
|
138
|
+
return response.body
|
139
|
+
else
|
140
|
+
raise "Request '#{ address }' failed with response code #{ response.code }\n#{ response.body }"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def servers
|
145
|
+
body = Nokogiri::XML( get_rest( 'servers' ) )
|
146
|
+
Server.load_collection( self, body )
|
147
|
+
end
|
148
|
+
|
149
|
+
def account_url( rest )
|
150
|
+
@base_url + '/' + @account + '/' + rest
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rightstuff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joe Yates
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-28 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nokogiri
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 113
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 3
|
34
|
+
- 1
|
35
|
+
version: 1.4.3.1
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
description: Another Ruby Interface for RightScale, providing an OO interface for RightScale accounts
|
39
|
+
email: joe.g.yates@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- COPYING
|
46
|
+
- README.rdoc
|
47
|
+
- lib/rightstuff.rb
|
48
|
+
files:
|
49
|
+
- COPYING
|
50
|
+
- Rakefile
|
51
|
+
- README.rdoc
|
52
|
+
- lib/rightstuff.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/joeyates/rightstuff
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --quiet
|
60
|
+
- --main
|
61
|
+
- README.rdoc
|
62
|
+
- --inline-source
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project: nowarning
|
86
|
+
rubygems_version: 1.3.7
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Another Ruby Interface for RightScale
|
90
|
+
test_files: []
|
91
|
+
|