rightresource 0.4.0 → 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.
@@ -4,6 +4,28 @@
4
4
  # * +id+ - RightScale deployment resource id(https://my.rightscale.com/deployments/{id})
5
5
  class Deployment < RightResource::Base
6
6
  class << self
7
+ # Override RightResource::Base#index
8
+ # Hash2Object of RightScale servers
9
+ def index(params = {})
10
+ deployments = super
11
+ deployments.each do |deployment|
12
+ deployment.servers
13
+ end
14
+
15
+ deployments
16
+ end
17
+
18
+ # Override RightResource::Base#show
19
+ # Hash2Object of RightScale servers
20
+ def show(id, params = {})
21
+ deployment = super
22
+ unless deployment.nil?
23
+ deployment.servers
24
+ end
25
+
26
+ deployment
27
+ end
28
+
7
29
  [:start_all, :stop_all, :duplicate].each do |act_method|
8
30
  define_method(act_method) do |id|
9
31
  path = element_path(id, act_method).sub(/\.#{format.extension}$/, '') # response empty and format xml only
@@ -11,4 +33,15 @@ class Deployment < RightResource::Base
11
33
  end
12
34
  end
13
35
  end
36
+
37
+ # Convert servers
38
+ def servers
39
+ unless self.attributes[:servers].nil?
40
+ self.attributes[:servers].map! do |record|
41
+ record.is_a?(Hash) ? Server.new(record) : record
42
+ end
43
+ end
44
+
45
+ self.attributes[:servers]
46
+ end
14
47
  end
@@ -16,7 +16,7 @@ module RightResource
16
16
  end
17
17
 
18
18
  def decode(json)
19
- Crack::JSON.parse(json)
19
+ JSON.parse(json)
20
20
  end
21
21
  end
22
22
  end
@@ -115,4 +115,38 @@ class Server < RightResource::Base
115
115
  }.flatten]
116
116
  end
117
117
  end
118
+
119
+ # Get Server settings with merge to instance(attributes[:settings])
120
+ # === Examples
121
+ # server = Server.index(:filter => "nickname=dev-001").first
122
+ # Server.settings
123
+ # # => Server#attributes[:settings]
124
+ # # {:dns_name => "ec2-175-...", :aws_id => "i-12345", ..., :ip_address => "175...."}
125
+ def settings
126
+ # first access
127
+ if self.attributes[:settings].nil?
128
+ self.attributes[:settings] = _settings
129
+ end
130
+
131
+ self.attributes[:settings]
132
+ end
133
+
134
+ # Get Server settings with merge to instance(destructive)
135
+ # === Examples
136
+ # server = Server.index(:filter => "nickname=dev-001").first
137
+ # Server.settings!
138
+ # # => self
139
+ # #
140
+ # # > Server.attributes
141
+ # # => [:nickname => "server1", :aws_id => "i-12345", ..., :ip_address => "175..."]
142
+ def settings!
143
+ self.loads(_settings)
144
+
145
+ self
146
+ end
147
+
148
+ private
149
+ def _settings
150
+ self.class.settings(self.id) rescue nil
151
+ end
118
152
  end
@@ -44,6 +44,12 @@ class ServerArray < RightResource::Base
44
44
  RightResource::Formats::XmlFormat.decode(action(:post, path, h)).tap {|resource| correct_attributes(resource)}
45
45
  end
46
46
 
47
+ # Get Server Array instances(subresource)
48
+ # === Examples
49
+ # array_id = ServerArray.index.first.id
50
+ # instances = ServerArray.instances(array_id)
51
+ # => [{:nickname => "web #1", :resource_uid => "i-12345", ...},
52
+ # {:nickname => "web #2", :resource_uid => "i-67890", ...}]
47
53
  def instances(id)
48
54
  path = element_path(id, :instances)
49
55
  format.decode(action(:get, path)).map do |instance|
@@ -51,4 +57,20 @@ class ServerArray < RightResource::Base
51
57
  end
52
58
  end
53
59
  end
60
+
61
+ # Get Server Array with merge to ServerArray instance(attributes[:instances])
62
+ # === Examples
63
+ # array = ServerArray.index.first
64
+ # array.instances
65
+ # # => ServerArray#attributes[:instances]
66
+ # => [{:nickname => "web #1", :resource_uid => "i-12345", ...},
67
+ # {:nickname => "web #2", :resource_uid => "i-67890", ...}]
68
+ def instances
69
+ # first access
70
+ if self.attributes[:instances].nil?
71
+ self.attributes[:instances] = self.class.instances(self.id) rescue nil
72
+ end
73
+
74
+ self.attributes[:instances]
75
+ end
54
76
  end
@@ -39,6 +39,6 @@ require 'right_resource/macro'
39
39
  require 'right_resource/credential'
40
40
 
41
41
  module RightResource
42
- VERSION = '0.4.0'
42
+ VERSION = '0.4.2'
43
43
  API_VERSION = "1.0"
44
44
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightresource
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
4
+ hash: 11
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Satoshi Ohki
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-27 00:00:00 +09:00
18
+ date: 2011-10-01 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,12 +24,13 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 3
29
+ hash: 15
30
30
  segments:
31
+ - 1
31
32
  - 0
32
- version: "0"
33
+ version: "1.0"
33
34
  type: :runtime
34
35
  version_requirements: *id001
35
36
  - !ruby/object:Gem::Dependency
@@ -38,12 +39,13 @@ dependencies:
38
39
  requirement: &id002 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
- - - ">="
42
+ - - ~>
42
43
  - !ruby/object:Gem::Version
43
- hash: 3
44
+ hash: 15
44
45
  segments:
46
+ - 1
45
47
  - 0
46
- version: "0"
48
+ version: "1.0"
47
49
  type: :runtime
48
50
  version_requirements: *id002
49
51
  - !ruby/object:Gem::Dependency
@@ -52,12 +54,14 @@ dependencies:
52
54
  requirement: &id003 !ruby/object:Gem::Requirement
53
55
  none: false
54
56
  requirements:
55
- - - ">="
57
+ - - ~>
56
58
  - !ruby/object:Gem::Version
57
- hash: 3
59
+ hash: 27
58
60
  segments:
59
61
  - 0
60
- version: "0"
62
+ - 1
63
+ - 0
64
+ version: 0.1.0
61
65
  type: :runtime
62
66
  version_requirements: *id003
63
67
  description: |
@@ -115,6 +119,8 @@ rdoc_options:
115
119
  - RightResource API documentation
116
120
  - --main
117
121
  - README.rdoc
122
+ - --template
123
+ - direct
118
124
  require_paths:
119
125
  - lib
120
126
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -140,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
146
  requirements:
141
147
  - none
142
148
  rubyforge_project:
143
- rubygems_version: 1.3.7
149
+ rubygems_version: 1.6.2
144
150
  signing_key:
145
151
  specification_version: 3
146
152
  summary: "RightResource: RightScale Resource API wrapper"