openstack-compute 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.8
1
+ 1.1.9
@@ -55,6 +55,7 @@ module Compute
55
55
  response = @connection.req('POST', @base_url, :data => json)
56
56
  @metadata = JSON.parse(response.body)['metadata']
57
57
  else
58
+ keys = [keys] unless keys.is_a? Array
58
59
  keys.each { |key|
59
60
  next if not @metadata.has_key?(key)
60
61
  json = JSON.generate(:meta => { key => @metadata[key] })
@@ -69,6 +70,7 @@ module Compute
69
70
  @metadata = JSON.parse(response.body)['metadata']
70
71
  else
71
72
  @metadata = {} if @metadata == nil
73
+ keys = [keys] unless keys.is_a? Array
72
74
  keys.each { |key|
73
75
  response = @connection.req('GET', "#{@base_url}/#{key}")
74
76
  next if response.code == "404"
@@ -80,12 +82,14 @@ module Compute
80
82
 
81
83
  def delete(keys)
82
84
  return if @metadata.nil?
85
+ keys = [keys] unless keys.is_a? Array
83
86
  keys.each { |key|
84
87
  @metadata.delete(key)
85
88
  }
86
89
  end
87
90
 
88
91
  def delete!(keys)
92
+ keys = [keys] unless keys.is_a? Array
89
93
  keys.each { |key|
90
94
  @connection.req('DELETE', "#{@base_url}/#{key}")
91
95
  @metadata.delete(key) if not @metadata.nil?
@@ -15,6 +15,8 @@ module Compute
15
15
  attr_reader :image
16
16
  attr_reader :flavor
17
17
  attr_reader :metadata
18
+ attr_reader :created
19
+ attr_reader :updated
18
20
  attr_accessor :adminPass
19
21
 
20
22
  # This class is the representation of a single Server object. The constructor finds the server identified by the specified
@@ -61,10 +63,38 @@ module Compute
61
63
  @hostId = data["hostId"]
62
64
  @image = data["image"]
63
65
  @flavor = data["flavor"]
66
+ @created = DateTime.strptime(data["created"]).to_time
67
+ @updated = DateTime.strptime(data["updated"]).to_time
64
68
  true
65
69
  end
66
70
  alias :refresh :populate
67
71
 
72
+ # Sends an API request to suspend this server.
73
+ #
74
+ # Returns true if the API call succeeds.
75
+ #
76
+ # >> server.suspend
77
+ # => true
78
+ def suspend
79
+ data = JSON.generate(:suspend => nil)
80
+ response = @connection.req('POST', "/servers/#{@id}/action", :data => data)
81
+ OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
82
+ true
83
+ end
84
+
85
+ # Sends an API request to resume this server.
86
+ #
87
+ # Returns true if the API call succeeds.
88
+ #
89
+ # >> server.suspend
90
+ # => true
91
+ def resume
92
+ data = JSON.generate(:resume => nil)
93
+ response = @connection.req('POST', "/servers/#{@id}/action", :data => data)
94
+ OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
95
+ true
96
+ end
97
+
68
98
  # Sends an API request to reboot this server. Takes an optional argument for the type of reboot, which can be "SOFT" (graceful shutdown)
69
99
  # or "HARD" (power cycle). The hard reboot is also triggered by server.reboot!, so that may be a better way to call it.
70
100
  #
@@ -74,7 +104,7 @@ module Compute
74
104
  # => true
75
105
  def reboot(type="SOFT")
76
106
  data = JSON.generate(:reboot => {:type => type})
77
- response = @connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
107
+ response = @connection.req('POST', "/servers/#{@id}/action", :data => data)
78
108
  OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
79
109
  true
80
110
  end
@@ -101,7 +131,7 @@ module Compute
101
131
  # => "MyServer"
102
132
  def update(options)
103
133
  data = JSON.generate(:server => options)
104
- response = @connection.csreq("PUT",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
134
+ response = @connection.req('PUT', "/servers/#{@id}", :data => data)
105
135
  OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
106
136
  # If we rename the instance, repopulate the object
107
137
  self.populate if options[:name]
@@ -115,7 +145,7 @@ module Compute
115
145
  # >> server.delete!
116
146
  # => true
117
147
  def delete!
118
- response = @connection.csreq("DELETE",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}",@svrmgmtport,@svrmgmtscheme)
148
+ response = @connection.req('DELETE', "/servers/#{@id}")
119
149
  OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
120
150
  true
121
151
  end
@@ -171,7 +201,7 @@ module Compute
171
201
  # =>
172
202
  def create_image(options)
173
203
  data = JSON.generate(:createImage => options)
174
- response = @connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
204
+ response = @connection.req('POST', "/servers/#{@id}/action", :data => data)
175
205
  OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
176
206
  image_id = response["Location"].scan(/.*\/(.*)/).flatten
177
207
  OpenStack::Compute::Image.new(@connection, image_id)
@@ -186,7 +216,7 @@ module Compute
186
216
  # => true
187
217
  def resize!(flavorRef)
188
218
  data = JSON.generate(:resize => {:flavorRef => flavorRef})
189
- response = @connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
219
+ response = @connection.req('POST', "/servers/#{@id}/action", :data => data)
190
220
  OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
191
221
  self.populate
192
222
  true
@@ -201,7 +231,7 @@ module Compute
201
231
  def confirm_resize!
202
232
  # If the resize bug gets figured out, should put a check here to make sure that it's in the proper state for this.
203
233
  data = JSON.generate(:confirmResize => nil)
204
- response = @connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
234
+ response = @connection.req('POST', "/servers/#{@id}/action", :data => data)
205
235
  OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
206
236
  self.populate
207
237
  true
@@ -217,7 +247,7 @@ module Compute
217
247
  def revert_resize!
218
248
  # If the resize bug gets figured out, should put a check here to make sure that it's in the proper state for this.
219
249
  data = JSON.generate(:revertResize => nil)
220
- response = @connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data)
250
+ response = @connection.req('POST', "/servers/#{@id}/action", :data => data)
221
251
  OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/)
222
252
  self.populate
223
253
  true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstack-compute
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 8
10
- version: 1.1.8
9
+ - 9
10
+ version: 1.1.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Prince
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-16 00:00:00 Z
18
+ date: 2012-06-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json