rightstuff 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/rightstuff.rb +25 -22
- metadata +3 -3
data/README.rdoc
CHANGED
data/lib/rightstuff.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
#!ruby
|
2
|
-
|
3
1
|
require 'rubygems' if RUBY_VERSION < '1.9'
|
4
2
|
require 'yaml'
|
5
3
|
require 'net/https'
|
@@ -11,7 +9,7 @@ module Rightstuff
|
|
11
9
|
module VERSION #:nodoc:
|
12
10
|
MAJOR = 0
|
13
11
|
MINOR = 0
|
14
|
-
TINY =
|
12
|
+
TINY = 2
|
15
13
|
|
16
14
|
STRING = [ MAJOR, MINOR, TINY ].join('.')
|
17
15
|
end
|
@@ -51,10 +49,10 @@ module Rightstuff
|
|
51
49
|
node.class == Nokogiri::XML::Element ? node : nil
|
52
50
|
end
|
53
51
|
elements.compact!
|
54
|
-
elements.reduce({}) do | memo, element |
|
52
|
+
elements.reduce( {} ) do | memo, element |
|
55
53
|
name = element.name
|
56
54
|
name.gsub!( /-/, '_' )
|
57
|
-
memo[ name.intern ] = element.children[0].to_s
|
55
|
+
memo[ name.intern ] = element.children[ 0 ].to_s
|
58
56
|
memo
|
59
57
|
end
|
60
58
|
end
|
@@ -73,7 +71,8 @@ module Rightstuff
|
|
73
71
|
class Server < Base
|
74
72
|
|
75
73
|
def initialize( client, item )
|
76
|
-
@settings =
|
74
|
+
@settings = nil
|
75
|
+
@inputs = nil
|
77
76
|
super
|
78
77
|
end
|
79
78
|
|
@@ -84,6 +83,7 @@ module Rightstuff
|
|
84
83
|
def method_missing( name , *args, &block )
|
85
84
|
result = super
|
86
85
|
return result unless result.nil?
|
86
|
+
return nil unless @attributes[ :state ] == 'operational'
|
87
87
|
settings unless @settings
|
88
88
|
return @attributes[ name ]
|
89
89
|
end
|
@@ -93,15 +93,17 @@ module Rightstuff
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def inputs
|
96
|
+
return @inputs if @inputs
|
96
97
|
# Add inputs to instance data
|
97
98
|
# @client.get( @attributes[ 'href' ] )
|
98
99
|
end
|
99
100
|
|
100
101
|
def settings
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
@settings =
|
102
|
+
return @settings if @settings
|
103
|
+
doc = @client.get_rest( 'servers/' + id + '/settings' )
|
104
|
+
xml = Nokogiri::XML( doc )
|
105
|
+
@settings = Base.extract_attributes( xml.children )
|
106
|
+
@attributes.merge!( settings )
|
105
107
|
end
|
106
108
|
|
107
109
|
end
|
@@ -109,29 +111,29 @@ module Rightstuff
|
|
109
111
|
class Client
|
110
112
|
|
111
113
|
def initialize( options = {} )
|
112
|
-
@base_url = 'https://my.rightscale.com/api/acct'
|
113
114
|
@username = options[ :username ] or raise 'no username supplied'
|
114
115
|
@password = options[ :password ] or raise 'no password supplied'
|
115
116
|
@account = options[ :account ] or raise 'no account id supplied'
|
116
117
|
@account = @account.to_s
|
118
|
+
|
119
|
+
@base_url = 'https://my.rightscale.com/api/acct'
|
120
|
+
url = URI.parse( @base_url )
|
121
|
+
@connection = Net::HTTP.new( url.host, url.port )
|
122
|
+
@connection.use_ssl = true
|
123
|
+
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
117
124
|
end
|
118
125
|
|
119
126
|
def get_rest( rest )
|
120
127
|
get( account_url( rest ) )
|
121
128
|
end
|
122
129
|
|
123
|
-
def get(
|
124
|
-
|
125
|
-
|
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 )
|
130
|
+
def get( address )
|
131
|
+
url = URI.parse( address )
|
132
|
+
request = Net::HTTP::Get.new( url.request_uri )
|
131
133
|
request.add_field( 'X-API-VERSION', '1.0' )
|
132
134
|
request.basic_auth @username, @password
|
133
135
|
|
134
|
-
response =
|
136
|
+
response = @connection.request( request )
|
135
137
|
|
136
138
|
case response.code
|
137
139
|
when '200'
|
@@ -142,8 +144,9 @@ module Rightstuff
|
|
142
144
|
end
|
143
145
|
|
144
146
|
def servers
|
145
|
-
|
146
|
-
|
147
|
+
return @servers if @servers
|
148
|
+
body = Nokogiri::XML( get_rest( 'servers' ) )
|
149
|
+
@servers = Server.load_collection( self, body )
|
147
150
|
end
|
148
151
|
|
149
152
|
def account_url( rest )
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rightstuff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Yates
|