Class: Fog::Compute::HP::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::HP::Server
- Defined in:
- lib/fog/hp/models/compute/server.rb
Instance Attribute Summary collapse
- #flavor_id ⇒ Object
- #image_id ⇒ Object
- #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
- #block_device_mapping=(new_block_device_mapping) ⇒ Object
- #change_password(admin_password) ⇒ Object
- #confirm_resize ⇒ Object
- #console_output(num_lines) ⇒ Object
- #create_image(name, metadata = {}) ⇒ Object
- #destroy ⇒ 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
- #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, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
- #resize(flavor_id) ⇒ Object
- #revert_resize ⇒ Object
- #save ⇒ Object
- #setup(credentials = {}) ⇒ 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.
42 43 44 45 46 47 48 |
# File 'lib/fog/hp/models/compute/server.rb', line 42 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) super end |
Instance Attribute Details
#flavor_id ⇒ Object
162 163 164 |
# File 'lib/fog/hp/models/compute/server.rb', line 162 def flavor_id @flavor_id ||= (flavor.nil? ? nil : flavor["id"]) end |
#image_id ⇒ Object
154 155 156 |
# File 'lib/fog/hp/models/compute/server.rb', line 154 def image_id @image_id ||= (image.nil? ? nil : image["id"]) end |
#network_name ⇒ Object
99 100 101 |
# File 'lib/fog/hp/models/compute/server.rb', line 99 def network_name @network_name ||= "private" end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
37 38 39 |
# File 'lib/fog/hp/models/compute/server.rb', line 37 def password @password end |
#private_key ⇒ Object
122 123 124 |
# File 'lib/fog/hp/models/compute/server.rb', line 122 def private_key @private_key ||= private_key_path && File.read(private_key_path) end |
#private_key_path ⇒ Object
117 118 119 120 |
# File 'lib/fog/hp/models/compute/server.rb', line 117 def private_key_path @private_key_path ||= Fog.credentials[:private_key_path] @private_key_path &&= File.(@private_key_path) end |
#public_key ⇒ Object
150 151 152 |
# File 'lib/fog/hp/models/compute/server.rb', line 150 def public_key @public_key ||= public_key_path && File.read(public_key_path) end |
#public_key_path ⇒ Object
145 146 147 148 |
# File 'lib/fog/hp/models/compute/server.rb', line 145 def public_key_path @public_key_path ||= Fog.credentials[:public_key_path] @public_key_path &&= File.(@public_key_path) end |
#username ⇒ Object
283 284 285 |
# File 'lib/fog/hp/models/compute/server.rb', line 283 def username @username ||= 'root' end |
Instance Method Details
#block_device_mapping=(new_block_device_mapping) ⇒ Object
178 179 180 |
# File 'lib/fog/hp/models/compute/server.rb', line 178 def block_device_mapping=(new_block_device_mapping) @block_device_mapping = new_block_device_mapping end |
#change_password(admin_password) ⇒ Object
186 187 188 189 190 |
# File 'lib/fog/hp/models/compute/server.rb', line 186 def change_password(admin_password) requires :id service.change_password_server(id, admin_password) true end |
#confirm_resize ⇒ Object
221 222 223 224 225 |
# File 'lib/fog/hp/models/compute/server.rb', line 221 def confirm_resize requires :id service.confirm_resized_server(id) true end |
#console_output(num_lines) ⇒ Object
69 70 71 72 |
# File 'lib/fog/hp/models/compute/server.rb', line 69 def console_output(num_lines) requires :id service.get_console_output(id, num_lines) end |
#create_image(name, metadata = {}) ⇒ Object
227 228 229 230 |
# File 'lib/fog/hp/models/compute/server.rb', line 227 def create_image(name, ={}) requires :id service.create_image(id, name, ) end |
#destroy ⇒ Object
83 84 85 86 87 |
# File 'lib/fog/hp/models/compute/server.rb', line 83 def destroy requires :id service.delete_server(id) true end |
#key_pair ⇒ Object
89 90 91 92 93 |
# File 'lib/fog/hp/models/compute/server.rb', line 89 def key_pair requires :key_name service.key_pairs.get(key_name) end |
#key_pair=(new_keypair) ⇒ Object
95 96 97 |
# File 'lib/fog/hp/models/compute/server.rb', line 95 def key_pair=(new_keypair) self.key_name = new_keypair && new_keypair.name end |
#max_count=(new_max_count) ⇒ Object
174 175 176 |
# File 'lib/fog/hp/models/compute/server.rb', line 174 def max_count=(new_max_count) @max_count = new_max_count end |
#metadata ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/fog/hp/models/compute/server.rb', line 50 def @metadata ||= begin Fog::Compute::HP::Metadata.new({ :service => service, :parent => self }) end end |
#metadata=(new_metadata = {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/fog/hp/models/compute/server.rb', line 59 def (={}) = [] .each_pair {|k,v| << {"key" => k, "value" => v} } .load() end |
#min_count=(new_min_count) ⇒ Object
170 171 172 |
# File 'lib/fog/hp/models/compute/server.rb', line 170 def min_count=(new_min_count) @min_count = new_min_count end |
#private_ip_address ⇒ Object
113 114 115 |
# File 'lib/fog/hp/models/compute/server.rb', line 113 def private_ip_address private_ip_addresses.first end |
#private_ip_addresses ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/fog/hp/models/compute/server.rb', line 103 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
141 142 143 |
# File 'lib/fog/hp/models/compute/server.rb', line 141 def public_ip_address public_ip_addresses.first end |
#public_ip_addresses ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/fog/hp/models/compute/server.rb', line 126 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
182 183 184 |
# File 'lib/fog/hp/models/compute/server.rb', line 182 def ready? self.state == 'ACTIVE' end |
#reboot(type = 'SOFT') ⇒ Object
197 198 199 200 201 |
# File 'lib/fog/hp/models/compute/server.rb', line 197 def reboot(type = 'SOFT') requires :id service.reboot_server(id, type) true end |
#rebuild(image_id, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
203 204 205 206 207 |
# File 'lib/fog/hp/models/compute/server.rb', line 203 def rebuild(image_id, name, admin_pass=nil, =nil, personality=nil) requires :id service.rebuild_server(id, image_id, name, admin_pass, , personality) true end |
#resize(flavor_id) ⇒ Object
209 210 211 212 213 |
# File 'lib/fog/hp/models/compute/server.rb', line 209 def resize(flavor_id) requires :id service.resize_server(id, flavor_id) true end |
#revert_resize ⇒ Object
215 216 217 218 219 |
# File 'lib/fog/hp/models/compute/server.rb', line 215 def revert_resize requires :id service.revert_resized_server(id) true end |
#save ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/fog/hp/models/compute/server.rb', line 239 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 } = .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
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/fog/hp/models/compute/server.rb', line 269 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 |
#user_data=(ascii_userdata) ⇒ Object
65 66 67 |
# File 'lib/fog/hp/models/compute/server.rb', line 65 def user_data=(ascii_userdata) self.user_data_encoded = [ascii_userdata].pack('m') # same as Base64.encode64 end |
#vnc_console_url(type = 'novnc') ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/fog/hp/models/compute/server.rb', line 74 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
232 233 234 235 236 237 |
# File 'lib/fog/hp/models/compute/server.rb', line 232 def requires :id if vols = service.list_server_volumes(id).body vols["volumeAttachments"] end end |
#windows_password ⇒ Object
192 193 194 195 |
# File 'lib/fog/hp/models/compute/server.rb', line 192 def windows_password() requires :id service.get_windows_password(id) end |