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.
43 44 45 46 47 48 49 50 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 43 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
101 102 103 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 101 def network_name @network_name ||= get_first_network_with_public_ip end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
38 39 40 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 38 def password @password end |
#private_key ⇒ Object
129 130 131 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 129 def private_key @private_key ||= private_key_path && File.read(private_key_path) end |
#private_key_path ⇒ Object
124 125 126 127 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 124 def private_key_path @private_key_path ||= Fog.credentials[:private_key_path] @private_key_path &&= File.(@private_key_path) end |
#public_key ⇒ Object
157 158 159 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 157 def public_key @public_key ||= public_key_path && File.read(public_key_path) end |
#public_key_path ⇒ Object
152 153 154 155 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 152 def public_key_path @public_key_path ||= Fog.credentials[:public_key_path] @public_key_path &&= File.(@public_key_path) end |
#username ⇒ Object
310 311 312 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 310 def username @username ||= 'ubuntu' end |
Instance Method Details
#add_security_group(sg_name) ⇒ Object
252 253 254 255 256 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 252 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
179 180 181 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 179 def block_device_mapping=(new_block_device_mapping) @block_device_mapping = new_block_device_mapping end |
#console_output(num_lines) ⇒ Object
71 72 73 74 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 71 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
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 226 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
85 86 87 88 89 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 85 def destroy requires :id service.delete_server(id) true end |
#flavor ⇒ Object
161 162 163 164 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 161 def flavor requires :flavor_id @flavor ||= service.flavors.get(flavor_id) end |
#image ⇒ Object
166 167 168 169 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 166 def image requires :image_id @image ||= service.images.get(image_id) end |
#key_pair ⇒ Object
91 92 93 94 95 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 91 def key_pair requires :key_name service.key_pairs.get(key_name) end |
#key_pair=(new_keypair) ⇒ Object
97 98 99 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 97 def key_pair=(new_keypair) self.key_name = new_keypair && new_keypair.name end |
#max_count=(new_max_count) ⇒ Object
175 176 177 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 175 def max_count=(new_max_count) @max_count = new_max_count end |
#metadata ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 52 def @metadata ||= begin Fog::Compute::HPV2::Metadata.new({ :service => service, :parent => self }) end end |
#metadata=(new_metadata = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 61 def (={}) = [] .each_pair {|k,v| << {'key' => k, 'value' => v} } .load() end |
#min_count=(new_min_count) ⇒ Object
171 172 173 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 171 def min_count=(new_min_count) @min_count = new_min_count end |
#network_names ⇒ Object
derive the network names from the addresses hash
106 107 108 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 106 def network_names self.addresses.keys unless self.addresses.nil? end |
#networks=(new_networks) ⇒ Object
183 184 185 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 183 def networks=(new_networks) @networks = new_networks end |
#private_ip_address ⇒ Object
120 121 122 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 120 def private_ip_address private_ip_addresses.first if private_ip_addresses end |
#private_ip_addresses ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 110 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
148 149 150 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 148 def public_ip_address public_ip_addresses.first if public_ip_addresses end |
#public_ip_addresses ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 133 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
187 188 189 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 187 def ready? self.state == 'ACTIVE' end |
#reboot(type = 'SOFT') ⇒ Object
196 197 198 199 200 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 196 def reboot(type = 'SOFT') requires :id service.reboot_server(id, type) true end |
#rebuild(image_id, name, options = {}) ⇒ Object
202 203 204 205 206 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 202 def rebuild(image_id, name, ={}) requires :id service.rebuild_server(id, image_id, name, ) true end |
#remove_security_group(sg_name) ⇒ Object
258 259 260 261 262 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 258 def remove_security_group(sg_name) requires :id service.remove_security_group(id, sg_name) true end |
#save ⇒ Object
264 265 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 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 264 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
296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 296 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.json} ]) rescue Errno::ECONNREFUSED sleep(1) retry end |
#update_name(new_name) ⇒ Object
246 247 248 249 250 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 246 def update_name(new_name) requires :id service.update_server(id, :name => new_name) true end |
#user_data=(ascii_userdata) ⇒ Object
67 68 69 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 67 def user_data=(ascii_userdata) self.user_data_encoded = [ascii_userdata].pack('m') # same as Base64.encode64 end |
#vnc_console_url(type = 'novnc') ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 76 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
237 238 239 240 241 242 243 244 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 237 def @volume_attachments ||= begin Fog::Compute::HPV2::VolumeAttachments.new({ :service => service, :server => self }) end end |
#windows_password ⇒ Object
191 192 193 194 |
# File 'lib/fog/hp/models/compute_v2/server.rb', line 191 def windows_password requires :id service.get_windows_password(id) end |