Class: Fog::Compute::HPV2::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::HPV2::Server
- Defined in:
- lib/fog/hp/models/compute_v2/server.rb
Instance Attribute Summary collapse
- #network_name ⇒ Object
-
#password ⇒ Object
readonly
Returns the value of attribute password.
- #private_key ⇒ Object
- #private_key_path ⇒ Object
- #public_key ⇒ Object
- #public_key_path ⇒ Object
- #username ⇒ Object
Instance Method Summary collapse
- #add_security_group(sg_name) ⇒ Object
- #block_device_mapping=(new_block_device_mapping) ⇒ Object
- #console_output(num_lines) ⇒ Object
-
#create_image(name, metadata = {}) ⇒ Object
def revert_resize requires :id service.revert_resized_server(id) true end.
- #destroy ⇒ Object
- #flavor ⇒ Object
- #image ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
- #key_pair ⇒ Object
- #key_pair=(new_keypair) ⇒ Object
- #max_count=(new_max_count) ⇒ Object
- #metadata ⇒ Object
- #metadata=(new_metadata = {}) ⇒ Object
- #min_count=(new_min_count) ⇒ Object
-
#network_names ⇒ Object
derive the network names from the addresses hash.
- #networks=(new_networks) ⇒ Object
- #private_ip_address ⇒ Object
- #private_ip_addresses ⇒ Object
- #public_ip_address ⇒ Object
- #public_ip_addresses ⇒ Object
- #ready? ⇒ Boolean
- #reboot(type = 'SOFT') ⇒ Object
- #rebuild(image_id, name, options = {}) ⇒ Object
- #remove_security_group(sg_name) ⇒ Object
- #save ⇒ Object
- #setup(credentials = {}) ⇒ Object
- #update_name(new_name) ⇒ Object
- #user_data=(ascii_userdata) ⇒ Object
- #vnc_console_url(type = 'novnc') ⇒ Object
- #volume_attachments ⇒ Object
- #windows_password ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
45 46 47 48 49 50 51 52 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 45 def initialize(attributes = {}) # assign these attributes first to prevent race condition with new_record? self.min_count = attributes.delete(:min_count) self.max_count = attributes.delete(:max_count) self.block_device_mapping = attributes.delete(:block_device_mapping) self.networks = attributes.delete(:networks) super end |
Instance Attribute Details
#network_name ⇒ Object
103 104 105 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 103 def network_name @network_name ||= get_first_network_with_public_ip end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
40 41 42 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 40 def password @password end |
#private_key ⇒ Object
131 132 133 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 131 def private_key @private_key ||= private_key_path && File.read(private_key_path) end |
#private_key_path ⇒ Object
126 127 128 129 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 126 def private_key_path @private_key_path ||= Fog.credentials[:private_key_path] @private_key_path &&= File.(@private_key_path) end |
#public_key ⇒ Object
159 160 161 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 159 def public_key @public_key ||= public_key_path && File.read(public_key_path) end |
#public_key_path ⇒ Object
154 155 156 157 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 154 def public_key_path @public_key_path ||= Fog.credentials[:public_key_path] @public_key_path &&= File.(@public_key_path) end |
#username ⇒ Object
312 313 314 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 312 def username @username ||= 'ubuntu' end |
Instance Method Details
#add_security_group(sg_name) ⇒ Object
254 255 256 257 258 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 254 def add_security_group(sg_name) requires :id service.add_security_group(id, sg_name) true end |
#block_device_mapping=(new_block_device_mapping) ⇒ Object
181 182 183 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 181 def block_device_mapping=(new_block_device_mapping) @block_device_mapping = new_block_device_mapping end |
#console_output(num_lines) ⇒ Object
73 74 75 76 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 73 def console_output(num_lines) requires :id service.get_console_output(id, num_lines) end |
#create_image(name, metadata = {}) ⇒ Object
def revert_resize
requires :id
service.revert_resized_server(id)
true
end
def confirm_resize
requires :id
service.confirm_resized_server(id)
true
end
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 228 def create_image(name, = {}) requires :id response = service.create_image(id, name, ) begin image_id = response.headers["Location"].match(/\/([^\/]+$)/)[1] Fog::Compute::HPV2::Image.new(:collection => service.images, :service => service, :id => image_id) rescue nil end end |
#destroy ⇒ Object
87 88 89 90 91 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 87 def destroy requires :id service.delete_server(id) true end |
#flavor ⇒ Object
163 164 165 166 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 163 def flavor requires :flavor_id @flavor ||= service.flavors.get(flavor_id) end |
#image ⇒ Object
168 169 170 171 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 168 def image requires :image_id @image ||= service.images.get(image_id) end |
#key_pair ⇒ Object
93 94 95 96 97 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 93 def key_pair requires :key_name service.key_pairs.get(key_name) end |
#key_pair=(new_keypair) ⇒ Object
99 100 101 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 99 def key_pair=(new_keypair) self.key_name = new_keypair && new_keypair.name end |
#max_count=(new_max_count) ⇒ Object
177 178 179 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 177 def max_count=(new_max_count) @max_count = new_max_count end |
#metadata ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 54 def ||= begin Fog::Compute::HPV2::Metadata.new({ :service => service, :parent => self }) end end |
#metadata=(new_metadata = {}) ⇒ Object
63 64 65 66 67 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 63 def (={}) = [] .each_pair {|k,v| << {'key' => k, 'value' => v} } .load() end |
#min_count=(new_min_count) ⇒ Object
173 174 175 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 173 def min_count=(new_min_count) @min_count = new_min_count end |
#network_names ⇒ Object
derive the network names from the addresses hash
108 109 110 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 108 def network_names self.addresses.keys unless self.addresses.nil? end |
#networks=(new_networks) ⇒ Object
185 186 187 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 185 def networks=(new_networks) @networks = new_networks end |
#private_ip_address ⇒ Object
122 123 124 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 122 def private_ip_address private_ip_addresses.first if private_ip_addresses end |
#private_ip_addresses ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 112 def private_ip_addresses return nil if addresses.nil? addr = [] addresses.each { |key, value| ipaddr = value.first addr << ipaddr["addr"] unless ipaddr.nil? } addr end |
#public_ip_address ⇒ Object
150 151 152 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 150 def public_ip_address public_ip_addresses.first if public_ip_addresses end |
#public_ip_addresses ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 135 def public_ip_addresses return nil if addresses.nil? addr = [] addresses.each { |key, value| if value.count > 1 value = value.dup value.delete_at(0) value.each { |ipaddr| addr << ipaddr["addr"] } end } addr end |
#ready? ⇒ Boolean
189 190 191 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 189 def ready? self.state == 'ACTIVE' end |
#reboot(type = 'SOFT') ⇒ Object
198 199 200 201 202 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 198 def reboot(type = 'SOFT') requires :id service.reboot_server(id, type) true end |
#rebuild(image_id, name, options = {}) ⇒ Object
204 205 206 207 208 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 204 def rebuild(image_id, name, ={}) requires :id service.rebuild_server(id, image_id, name, ) true end |
#remove_security_group(sg_name) ⇒ Object
260 261 262 263 264 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 260 def remove_security_group(sg_name) requires :id service.remove_security_group(id, sg_name) true end |
#save ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 266 def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? requires :flavor_id, :name = {} .each { || .store(.key, .value) } = { 'metadata' => , 'personality' => personality, 'accessIPv4' => accessIPv4, 'accessIPv6' => accessIPv6, 'min_count' => @min_count, 'max_count' => @max_count, 'key_name' => key_name, 'security_groups' => security_groups, 'config_drive' => config_drive, 'user_data' => user_data_encoded, 'availability_zone' => availability_zone, 'networks' => @networks } = .reject {|key, value| value.nil?} # either create a regular server or a persistent server based on input if image_id # create a regular server using the image data = service.create_server(name, flavor_id, image_id, ) elsif image_id.nil? && !@block_device_mapping.nil? && !@block_device_mapping.empty? # create a persistent server using the bootable volume in the block_device_mapping data = service.create_persistent_server(name, flavor_id, @block_device_mapping, ) end merge_attributes(data.body['server']) true end |
#setup(credentials = {}) ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 298 def setup(credentials = {}) requires :ssh_ip_address, :identity, :public_key, :username Fog::SSH.new(ssh_ip_address, username, credentials).run([ %{mkdir .ssh}, %{echo "#{public_key}" >> ~/.ssh/authorized_keys}, %{passwd -l #{username}}, %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json}, %{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json} ]) rescue Errno::ECONNREFUSED sleep(1) retry end |
#update_name(new_name) ⇒ Object
248 249 250 251 252 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 248 def update_name(new_name) requires :id service.update_server(id, :name => new_name) true end |
#user_data=(ascii_userdata) ⇒ Object
69 70 71 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 69 def user_data=(ascii_userdata) self.user_data_encoded = [ascii_userdata].pack('m') # same as Base64.encode64 end |
#vnc_console_url(type = 'novnc') ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 78 def vnc_console_url(type='novnc') requires :id if resp = service.get_vnc_console(id, type).body resp['console']['url'] else nil end end |
#volume_attachments ⇒ Object
239 240 241 242 243 244 245 246 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 239 def ||= begin Fog::Compute::HPV2::VolumeAttachments.new({ :service => service, :server => self }) end end |
#windows_password ⇒ Object
193 194 195 196 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 193 def windows_password requires :id service.get_windows_password(id) end |