openstack_activeresource 0.2.1 → 0.3.0

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.
@@ -21,6 +21,7 @@ module OpenStack
21
21
 
22
22
  class Base < OpenStack::Common
23
23
 
24
+ # Get the Nova Compute endpoint assigned to OpenStack::Nova::Compute classes
24
25
  def self.site
25
26
  if self == OpenStack::Nova::Compute::Base
26
27
  Thread.current[:open_stack_nova_compute_site]
@@ -29,6 +30,7 @@ module OpenStack
29
30
  end
30
31
  end
31
32
 
33
+ # Set the Nova Compute endpoint for OpenStack::Nova::Compute classes
32
34
  def self.site=(site)
33
35
  super(site)
34
36
  Thread.current[:open_stack_nova_compute_site] = @site
@@ -19,7 +19,7 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
- class BaseDetail < Base
22
+ class BaseDetail < Base #:nodoc:
23
23
 
24
24
  # Overrides ActiveResource::Base::collection_path to add /details to resource path for servers and
25
25
  # to remove .<extension>
@@ -19,7 +19,17 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
+ # An OpenStack Floating Ip
23
+ #
24
+ # ==== Attributes
25
+ # * +name+ - The name of the flavor
26
+ # * +ram+ - Amount of RAM (MBytes)
27
+ # * +disk+ - Amount of storage (GBytes)
28
+ # * +vcpus+ - Virtual CPUs
29
+ # * +rxtx_factor+ - Traffic shaping (?)
30
+ # * +ephemeral_disk+ - Ephemeral storage amount (GByte)
22
31
  class Flavor < BaseDetail
32
+
23
33
  schema do
24
34
  attribute :name, :string
25
35
  attribute :ram, :integer
@@ -35,37 +45,55 @@ module OpenStack
35
45
  validates :disk, :presence => true, :numericality => {:greater_than_or_equal_to => 10, :only_integer => true}
36
46
  validates :ephemeral_disk, :presence => false, :numericality => {:greater_than_or_equal_to => 10, :only_integer => true}
37
47
 
48
+ # Returns a list of Flavor for a given name
49
+ #
50
+ # ==== Attributes
51
+ # * +name+ - A string
38
52
  def self.find_all_by_name(name)
39
53
  all.reject { |flavor| flavor.name != name }
40
54
  end
41
55
 
56
+ # Returns the first Flavor for a given name
57
+ #
58
+ # ==== Attributes
59
+ # * +name+ - A string
42
60
  def self.find_by_name(name)
43
- all.each { |flavor| return flavor if flavor.name == name }
44
-
45
- nil
61
+ all.detect { |flavor| flavor.name == name }
46
62
  end
47
63
 
64
+ # Returns a list of Flavor that can be used with the given constraints
65
+ #
66
+ # ==== Attributes
67
+ # * +constraints+ - Hash of constraints. Valid keys are: :ram, :vcpus, :disk
48
68
  def self.find_by_constraints(constraints = {})
49
69
  constraints = constraints.with_indifferent_access
50
- constraints[:ram] ||= -1.0/0.0
70
+ constraints[:ram] ||= -1.0/0.0
51
71
  constraints[:vcpus] ||= -1.0/0.0
52
- constraints[:disk] ||= -1.0/0.0
72
+ constraints[:disk] ||= -1.0/0.0
53
73
 
54
74
  all.select { |flavor| flavor.ram >= constraints[:ram] and flavor.vcpus >= constraints[:vcpus] and flavor.disk >= constraints[:disk] }
55
75
  end
56
76
 
77
+ # Returns a list of Flavor that can be used with the given Image
78
+ #
79
+ # ==== Attributes
80
+ # * +image+ - An OpenStack::Nova::Compute::Image instance or an Image id
57
81
  def self.applicable_for_image(image)
82
+ image_instance = image.is_a?(OpenStack::Nova::Compute::Image) ? image : Image.find(image)
83
+
58
84
  constraints = {}
59
- constraints[:ram] = image.min_ram if image.min_ram > 0
60
- constraints[:disk] = image.min_disk if image.min_disk > 0
85
+ constraints[:ram] = image.min_ram if image_instance.min_ram > 0
86
+ constraints[:disk] = image.min_disk if image_instance.min_disk > 0
61
87
 
62
88
  find_by_constraints constraints
63
89
  end
64
90
 
91
+ # Returns the amount of ephemeral disk
65
92
  def ephemeral_disk
66
93
  @attributes[:'OS-FLV-EXT-DATA:ephemeral'] || nil
67
94
  end
68
95
 
96
+ # Returns a human-friendly description for this Flavor
69
97
  def description
70
98
  "#{vcpus} vCPU - #{ram} MB RAM - #{disk} GB Disk"
71
99
  end
@@ -19,6 +19,13 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
+ # An OpenStack Floating Ip
23
+ #
24
+ # ==== Attributes
25
+ # * +ip+ - Floating IP(v4/v6) address
26
+ # * +fixed_ip+ - Fixed IP(v4/V6) address
27
+ # * +pool+ - The id of the pool this IP belongs to
28
+ # * +instance_id+ - Identifier of server this IPis assigned to (if any)
22
29
  class FloatingIp < Base
23
30
  self.collection_name = "os-floating-ips"
24
31
  self.element_name = "floating_ip"
@@ -30,9 +37,8 @@ module OpenStack
30
37
  attribute :instance_id, :string
31
38
  end
32
39
 
33
- # Overload ActiveRecord::encode method
34
- # Custom encoding to deal with openstack API
35
- def encode(options={})
40
+ # Overloads ActiveRecord::encode method
41
+ def encode(options={}) #:nodoc: Custom encoding to deal with openstack API
36
42
  to_encode = {}
37
43
  # Optional attributes (openstack will not accept empty attribute for update/create)
38
44
  to_encode[:pool] = pool if pool.present?
@@ -40,19 +46,32 @@ module OpenStack
40
46
  to_encode.send("to_#{self.class.format.extension}", options)
41
47
  end
42
48
 
49
+ # List of addresses for a given pool
50
+ #
51
+ # ==== Attributes
52
+ # * +pool+ - an instance of OpenStack::Nova::Compute::FloatingIpPool or a pool id
43
53
  def self.find_all_by_pool(pool)
44
- all.reject! { |floating_ip| floating_ip.pool != pool }
54
+ pool_id = pool.is_a?(OpenStack::Nova::Compute::FloatingIpPool) ? pool.id : pool
55
+ all.reject! { |floating_ip| floating_ip.pool != pool_id }
45
56
  end
46
57
 
58
+ # The OpenStack::Nova::Compute::Server instance this address belongs to (if any)
47
59
  def instance
48
- Server.find(instance_id) if instance_id
60
+ if instance_id
61
+ @instance ||= Server.find(instance_id)
62
+ end
49
63
  end
50
64
 
51
- # Assign the IP to a given server
52
- # Params:
53
- # ::server:: the server to assign the floating ip to
65
+ # Assign the IP to a server
66
+ #
67
+ # ==== Attributes:
68
+ # * +server+ - An instance of OpenStack::Nova::Compute::Server (or a server id) to assign the floating IP to
54
69
  def assign!(server)
55
- server.add_floating_ip(self)
70
+ server_instance = server.is_a?(OpenStack::Nova::Compute::Server) ? server : Server.find(server)
71
+ @instance = server_instance
72
+ self.instance_id = server_instance.id
73
+
74
+ server_instance.add_floating_ip(self)
56
75
  end
57
76
  end
58
77
 
@@ -19,6 +19,11 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
+ # An OpenStack Floating Ip Pool
23
+ #
24
+ # ==== Attributes
25
+ # * +id+ - Id of the pool
26
+ # * +name+ - Name of the pool
22
27
  class FloatingIpPool < Base
23
28
  self.collection_name = "os-floating-ip-pools"
24
29
  self.element_name = "floating_ip_pool"
@@ -19,10 +19,24 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
+ # An OpenStack Image
23
+ #
24
+ # ==== Attributes
25
+ # * +name+ - Name of this image
26
+ # * +tenant_id+ - Tenant id to which this image belongs to (if applicable)
27
+ # * +server_id+ - Server id to which this image belongs to (if applicable)
28
+ # * +user_id+ - User id to which this image belongs to (if applicable)
29
+ # * +status+ - Status of image (e.g. ACTIVE)
30
+ # * +progress+ - Progress of image
31
+ # * +min_disk+ - Minimal amount of storage needed by this image (GBytes)
32
+ # * +min_ram+ - Minimal amount of RAM needed by this image (MBytes)
33
+ # * +updated_at+ - Modification date
34
+ # * +created_at+ - Creation date
22
35
  class Image < BaseDetail
23
36
  schema do
24
37
  attribute :name, :string
25
38
  attribute :tenant_id, :string
39
+ attribute :server_id, :string
26
40
  attribute :user_id, :string
27
41
  attribute :status, :string
28
42
  attribute :progress, :string
@@ -32,7 +46,7 @@ module OpenStack
32
46
  attribute :created_at, :datetime
33
47
  end
34
48
 
35
- def initialize(attributes = {}, persisted = false)
49
+ def initialize(attributes = {}, persisted = false) # :notnew:
36
50
  attributes = attributes.with_indifferent_access
37
51
  new_attributes = {
38
52
  :id => attributes[:id],
@@ -42,6 +56,8 @@ module OpenStack
42
56
  :progress => attributes[:progress],
43
57
  :status => attributes[:status],
44
58
  :metadata => attributes[:metadata],
59
+ :user_id => attributes[:user_id],
60
+ :tenant_id => attributes[:tenant_id],
45
61
  :server_id => attributes[:server].present? ? attributes[:server][:id] : nil,
46
62
  :updated_at => attributes[:updated].present? ? DateTime.strptime(attributes[:updated], OpenStack::DATETIME_FORMAT) : nil,
47
63
  :created_at => attributes[:created].present? ? DateTime.strptime(attributes[:created], OpenStack::DATETIME_FORMAT) : nil
@@ -50,25 +66,39 @@ module OpenStack
50
66
  super(new_attributes, persisted)
51
67
  end
52
68
 
69
+ # Returns the list of Image instances with the specified name
70
+ #
71
+ # ==== Attributes
72
+ # * +name+ : A string
53
73
  def self.find_all_by_name(name)
54
74
  all.reject! { |image| image.name != name }
55
75
  end
56
76
 
77
+ # Returns the first Image instance with the specified name
78
+ #
79
+ # ==== Attributes
80
+ # * +name+ : A string
57
81
  def self.find_by_name(name)
58
- all.each { |image| return image if image.name == name }
59
-
60
- nil
82
+ all.detect { |image| image.name == name }
61
83
  end
62
84
 
85
+ # Returns the Server instance to which this image belongs to (if applicable)
63
86
  def server
64
87
  Server.find(server_id) if server_id.present?
65
88
  end
66
89
 
90
+ # Returns the type of image: image or snapshot
67
91
  def image_type
68
92
  metadata.image_type
69
93
  rescue NoMethodError
70
94
  'image'
71
95
  end
96
+
97
+ # True if this image is a snapshot
98
+ def snapshot?
99
+ image_type != 'image'
100
+ end
101
+
72
102
  end
73
103
 
74
104
  end
@@ -19,6 +19,13 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
+ # An OpenStack KeyPair
23
+ #
24
+ # ==== Attributes
25
+ # * +name+ - Bridge name for this network
26
+ # * +public_key+ - Public key
27
+ # * +private_key+ - Private key (write only)
28
+ # * +fingerprint+ - The fingerprint for this keypair
22
29
  class KeyPair < Base
23
30
  self.collection_name = "os-keypairs"
24
31
  self.element_name = "keypair"
@@ -30,18 +37,24 @@ module OpenStack
30
37
  attribute :fingerprint, :string
31
38
  end
32
39
 
33
- def id
40
+ def id #:nodoc:
34
41
  name
35
42
  end
36
43
 
44
+ # The list of keypair with a given name
45
+ #
46
+ # ==== Attributes
47
+ # * +name+ - A keypairs name
37
48
  def self.find_all_by_name(name)
38
49
  all.reject! { |key_pair| key_pair.name != name }
39
50
  end
40
51
 
52
+ # The first keypair with a given name
53
+ #
54
+ # ==== Attributes
55
+ # * +name+ - A keypair name
41
56
  def self.find_by_name(name)
42
- all.each { |key_pair| return key_pair if key_pair.name == name }
43
-
44
- nil
57
+ all.detect { |key_pair| key_pair.name == name }
45
58
  end
46
59
 
47
60
  end
@@ -19,6 +19,16 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
+ # An OpenStack Network (\*WARNING:* incomplete)
23
+ #
24
+ # ==== Attributes
25
+ # * +bridge+ - Bridge name for this network
26
+ # * +bridge_interface+ - Interface for this network
27
+ # * +cidr+ - CIDR used by this network
28
+ # * +label+ - Label for this network
29
+ # * +multi_host+ - True if this network is managed by more than one controller (false otherwise)
30
+ # * +vlan+ - Vlan ID (802.1q) used by this network
31
+ # * +project_id+ - Tenant id associated with this network (if any)
22
32
  class Network < Base
23
33
  self.collection_name = "os-networks"
24
34
 
@@ -19,6 +19,12 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
+ # An OpenStack Security Group
23
+ #
24
+ # ==== Attributes
25
+ # * +tenant_id+ - Tenant id for this security group
26
+ # * +name+ - Name of this security group
27
+ # * +description+ - Description of this security group
22
28
  class SecurityGroup < Base
23
29
  self.element_name = "security_group"
24
30
  self.collection_name = "os-security-groups"
@@ -34,6 +40,14 @@ module OpenStack
34
40
 
35
41
  end
36
42
 
43
+ # An OpenStack Security Group Rule
44
+ #
45
+ # ==== Attributes
46
+ # * +ip_protocol+ - Protocol: tcp, udp or icmp
47
+ # * +from_port+ - Initial port
48
+ # * +to_port+ - Final port
49
+ # * +parent_group_id+ - The security group this rule belongs to
50
+ # * +cidr+ - A cidr
37
51
  class SecurityGroup::Rule < Base
38
52
  self.element_name = "security_group_rule"
39
53
  self.collection_name = "os-security-group-rules"
@@ -60,7 +74,7 @@ module OpenStack
60
74
  validates_numericality_of :to_port, :greater_than_or_equal_to => :from_port, :if => Proc.new { |rule| rule.udp? or rule.tcp? }
61
75
 
62
76
 
63
- def initialize(attributes = {}, persisted = false)
77
+ def initialize(attributes = {}, persisted = false) #:notnew:
64
78
  attributes = attributes.with_indifferent_access
65
79
  new_attributes = {
66
80
  :id => attributes[:id],
@@ -74,8 +88,7 @@ module OpenStack
74
88
  end
75
89
 
76
90
  # Override ActiveRecord::encode method
77
- # Custom encoding to deal with openstack API
78
- def encode(options={})
91
+ def encode(options={}) #:nodoc: Custom encoding to deal with openstack API
79
92
  to_encode = {
80
93
  :security_group_rule => {
81
94
  :ip_protocol => ip_protocol,
@@ -88,23 +101,35 @@ module OpenStack
88
101
  to_encode.send("to_#{self.class.format.extension}", options)
89
102
  end
90
103
 
104
+ # Set the parent security group (if the rule is not persisted)
105
+ #
106
+ # ==== Attributes
107
+ # * +group+: An instance of OpenStack::Nova::Compute::SecurityGroup or a security group id
91
108
  def parent_group=(group)
92
- parent_group_id = group.id
109
+ unless persisted?
110
+ @parent_group = nil
111
+ self.parent_group_id = group.is_a?(OpenStack::Nova::Compute::SecurityGroup) ? group.id : group
112
+ end
93
113
  end
94
114
 
115
+ # Parent group for this rule
95
116
  def parent_group
96
- return nil if parent_group_id.nil?
97
- SecurityGroup.find(parent_group_id)
117
+ unless parent_group_id.nil?
118
+ @parent_group ||= SecurityGroup.find(parent_group_id)
119
+ end
98
120
  end
99
121
 
122
+ # True if this rule refers to ICMP
100
123
  def icmp?
101
124
  ip_protocol == 'icmp'
102
125
  end
103
126
 
127
+ # True if this rule refers to UDP
104
128
  def udp?
105
129
  ip_protocol == 'udp'
106
130
  end
107
131
 
132
+ # True if this rule refers to TCP
108
133
  def tcp?
109
134
  ip_protocol == 'tcp'
110
135
  end
@@ -19,6 +19,21 @@ module OpenStack
19
19
  module Nova
20
20
  module Compute
21
21
 
22
+ # An OpenStack Server
23
+ #
24
+ # ==== Attributes
25
+ # * +name+ - The name of the server
26
+ # * +status+ - Status of the server (see http://docs.openstack.org/api/openstack-compute/2/content/List_Servers-d1e2078.html)
27
+ # * +vm_state+ - Extended Instance Status
28
+ # * +task+ - If not +nil+, contains the task OpenStack is preforming on this server
29
+ # * +power_state+ - Server power state (0|1)
30
+ # * +tenant_id+ - Identifier of the tenant this server belongs to
31
+ # * +user_id+ - Identifier of the user that created this server
32
+ # * +image_id+ - Identifier of the image used to create this server
33
+ # * +flavor_id+ - Identifier of the flavor used to create this server
34
+ # * +key_pair_id+ - Identifier of the keypair used by this server
35
+ # * +updated_at+ - Last modification timestamp
36
+ # * +created_at+ - Creation timestamp
22
37
  class Server < BaseDetail
23
38
 
24
39
  schema do
@@ -41,13 +56,20 @@ module OpenStack
41
56
  validates :image, :presence => true
42
57
  validates :flavor, :presence => true
43
58
 
59
+ # Return the list of server for a given tenant
60
+ #
61
+ # ==== Attributes
62
+ # * +tenant+ - an OpenStack::Keystone::Admin::Tenant instance (or a tenant id)
63
+ #
64
+ # ==== Notes
65
+ # This method require an admin access
44
66
  def self.all_by_tenant(tenant)
45
67
  tenant_id = tenant.is_a?(OpenStack::Keystone::Admin::Tenant) ? tenant.id : tenant
46
68
 
47
69
  find(:all, :params => {:tenant_id => tenant_id})
48
70
  end
49
71
 
50
- def initialize(attributes = {}, persisted = false)
72
+ def initialize(attributes = {}, persisted = false) # :notnew:
51
73
  attributes = attributes.with_indifferent_access
52
74
  new_attributes = {
53
75
  :id => attributes[:id],
@@ -99,9 +121,9 @@ module OpenStack
99
121
  self
100
122
  end
101
123
 
102
- # Overload ActiveRecord::encode method
103
- # Custom encoding to deal with openstack API
104
- def encode(options={})
124
+ # Overloads ActiveRecord::encode method
125
+ def encode(options={}) #:nodoc:
126
+ # Custom encoding to deal with openstack API
105
127
  to_encode = {
106
128
  :server => {
107
129
  :name => name,
@@ -118,32 +140,61 @@ module OpenStack
118
140
  to_encode.send("to_#{self.class.format.extension}", options)
119
141
  end
120
142
 
121
- # Accessors
122
-
143
+ # The instance of OpenStack::Nova::Compute::Image used for this server
123
144
  def image
124
- Image.find(image_id) if image_id.present?
145
+ if image_id.present?
146
+ @image ||= Image.find(image_id)
147
+ end
125
148
  end
126
149
 
150
+ # Set the image for this server (if the server is not persisted)
151
+ #
152
+ # ==== Attributes
153
+ # * +image+ - An instance of OpenStack::Nova::Compute::Image or an image id
127
154
  def image=(image)
128
- self.image_id = image.id
155
+ unless persisted?
156
+ @image = nil # nullify @@image because the image id is changed
157
+ self.image_id = image.is_a?(OpenStack::Nova::Compute::Image) ? image.id : image
158
+ end
129
159
  end
130
160
 
161
+ # The instance of OpenStack::Nova::Compute::Flavor used for this server
131
162
  def flavor
132
- Flavor.find(flavor_id) if flavor_id.present?
163
+ if flavor_id.present?
164
+ @flavor ||= Flavor.find(flavor_id)
165
+ end
133
166
  end
134
167
 
168
+ # Set the flavor for this server (if the server is not persisted)
169
+ #
170
+ # ==== Attributes
171
+ # * +flavor+ - An instance of OpenStack::Nova::Compute::Flavor or a flavor id
135
172
  def flavor=(flavor)
136
- self.flavor_id = flavor.id
173
+ unless persisted?
174
+ @flavor = nil # nullify @flavor because the flavor id is changed
175
+ self.flavor_id = flavor.is_a?(OpenStack::Nova::Compute::Flavor) ? flavor.id : flavor
176
+ end
137
177
  end
138
178
 
179
+ # The instance of OpenStack::Nova::Compute::KeyPair used for this server (if any)
139
180
  def key_pair
140
- KeyPair.find(key_pair_id) if key_pair_id.present?
181
+ if key_pair_id.present?
182
+ @keypair ||= KeyPair.find(key_pair_id)
183
+ end
141
184
  end
142
185
 
186
+ # Set the keypair for this server (if the server is not persisted)
187
+ #
188
+ # ==== Attributes
189
+ # * +key_pair+ - An instance of OpenStack::Nova::Compute::KeyPair or a key-pair id
143
190
  def key_pair=(key_pair)
144
- self.key_pair_id = key_pair.name
191
+ unless persisted?
192
+ @keypair = nil # nullify @@keypair because the keypair id is changed
193
+ self.key_pair_id = key_pair.id
194
+ end
145
195
  end
146
196
 
197
+ # The array of OpenStack::Nova::Compute::SecurityGroup instances associated with this server
147
198
  def security_groups
148
199
  if persisted?
149
200
  get('os-security-groups').map { |sg| OpenStack::Nova::Compute::SecurityGroup.new(sg, true) }
@@ -152,14 +203,19 @@ module OpenStack
152
203
  end
153
204
  end
154
205
 
206
+ # Set security groups for this server
207
+ #
208
+ # ==== Attributes
209
+ # * +security_groups+ - Array of OpenStack::Nova::Compute::SecurityGroup instances
155
210
  def security_groups=(security_groups)
156
211
  return if persisted? # Do Nothing (it's a read-only attribute for OpenStack)
157
212
 
158
- security_group_ids = security_groups.map { |sg| sg.id }
213
+ self.security_group_ids = security_groups.map { |sg| sg.id }
159
214
 
160
215
  security_groups
161
216
  end
162
217
 
218
+ # Addresses hash associated to this server
163
219
  def addresses
164
220
  addresses = {}
165
221
  if persisted?
@@ -171,34 +227,50 @@ module OpenStack
171
227
  addresses
172
228
  end
173
229
 
174
- def addresses=(something)
175
- # Do Nothing (it's a read-only attribute for OpenStack)
230
+ def addresses=(something) # :nodoc: do Nothing (it's a read-only attribute for OpenStack)
231
+
176
232
  end
177
233
 
234
+ # The OpenStack::Nova::Compute::VolumeAttachment(s) for this server
235
+ #
236
+ # ==== Attributes
237
+ # * +scope+ - An ActiveResource find scope (default: :all)
178
238
  def volume_attachments(scope = :all)
179
239
  VolumeAttachment.find(scope, :params => {:server_id => self.id})
180
240
  end
181
241
 
182
- # Misc...
183
-
184
- # Return the list of attached volumes
242
+ # Array of OpenStack::Nova::Compute::Volume attached to this server
185
243
  def attached_volumes
186
244
  volume_attachments.present? ? volume_attachments.map { |va| va.volume } : []
187
245
  end
188
246
 
189
247
  # Attach a volume
248
+ #
249
+ # ==== Attributes
250
+ # * +volume+ - An OpenStack::Nova::Compute::Volume instance
251
+ # * +device_name+ - Name the device (from server perspective) (e.g. "/dev/vdc")
190
252
  def attach_volume!(volume, device_name)
191
253
  VolumeAttachment.create(:volume => volume, :device => device_name, :server => self)
192
254
  end
193
255
 
194
256
  # Refresh server status
257
+ # This method updates the following attributes:
258
+ # * progress
259
+ # * status
260
+ # * task
261
+ # * power_state
262
+ # * vm_state
195
263
  def refresh_status!
196
- updated = Server.find(self.id)
197
- self.progress = updated.progress
198
- self.status = updated.status
199
- self.task = updated.task
200
-
201
- self
264
+ if persisted?
265
+ updated = Server.find(self.id)
266
+ self.progress = updated.progress
267
+ self.status = updated.status
268
+ self.task = updated.task
269
+ self.power_state = updated.power_state
270
+ self.vm_state = updated.vm_state
271
+
272
+ self
273
+ end
202
274
  end
203
275
 
204
276
  SERVER_STATUSES = {
@@ -220,7 +292,7 @@ module OpenStack
220
292
  :VERIFY_RESIZE => I18n.t(:awaiting_verification, :scope => [:openstack, :status])
221
293
  }.with_indifferent_access
222
294
 
223
- # Returns an extended description for the server status
295
+ # Returns an extended (and localized) description for the server status
224
296
  def status_description
225
297
  SERVER_STATUSES[status]
226
298
  end
@@ -230,42 +302,45 @@ module OpenStack
230
302
  I18n.t(task, :scope => [:openstack, :tasks]) if task.present?
231
303
  end
232
304
 
233
- ## Actions
234
-
235
- # Assign a floating IP to the server.
236
- # Params:
237
- # +floating_ip+:: a FloatingIP to be attached to the server.
305
+ # Assign a floating IP to the server
306
+ #
307
+ # ==== Attributes
308
+ # * +floating_ip+ - a FloatingIP to be attached to the server.
238
309
  def add_floating_ip(floating_ip)
239
310
  post(:action, {}, {:addFloatingIp => {:address => floating_ip.ip}}.to_json)
240
311
  end
241
312
 
242
- # Reboot the server.
243
- # Params:
244
- # +type+:: type of reboot. Should be 'hard' or 'soft' (defaults to 'hard', may be nil)
313
+ # Reboot the server
314
+ #
315
+ # ==== Attributes
316
+ # * +type+ - type of reboot. Should be 'hard' or 'soft' (defaults to 'hard', may be nil)
245
317
  def reboot(type=:hard)
246
318
  post(:action, {}, {:reboot => {:type => type}}.to_json)
247
319
  end
248
320
 
249
- # Creates a new snapshot of server.
250
- # Params:
251
- # +name+:: name of the new snapshot image
252
- # +metadata+:: hash of metadata (may be nil)
321
+ # Creates a new snapshot of server
322
+ #
323
+ # ==== Attributes
324
+ # * +name+ - name of the new snapshot image
325
+ # * +metadata+ - hash of metadata (may be nil)
253
326
  def create_new_image(name, metadata={})
254
327
  post(:action, {}, {:createImage => {:name => name, :metadata => metadata}}.to_json)
255
328
  end
256
329
 
257
- # Gets the output from the console log for a server.
258
- # Params:
259
- # +length+:: numbers of lines to get (defaults to 50, may be nil)
330
+ # Gets the output from the console log for a server
331
+ #
332
+ # ==== Attributes
333
+ # * +length+ - numbers of lines to get (defaults to 50, may be nil)
260
334
  def console_output(length=50)
261
335
  response = post(:action, {}, {:'os-getConsoleOutput' => {:length => length}}.to_json)
262
336
 
263
337
  ActiveSupport::JSON.decode(response.body)['output']
264
338
  end
265
339
 
266
- # Accesses a VNC console for a specific server.
267
- # Params:
268
- # +length+:: numbers of lines to get (defaults to 50, may be nil)
340
+ # Accesses a VNC console for a specific server
341
+ #
342
+ # ==== Attributes
343
+ # * +length+ - numbers of lines to get (defaults to 50, may be nil)
269
344
  def vnc_console(type='novnc')
270
345
  response = post(:action, {}, {:'os-getVNCConsole' => {:type => type}}.to_json)
271
346