# 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
# File lib/fog/hp/models/compute/server.rb, line 157 def block_device_mapping=(new_block_device_mapping) @block_device_mapping = new_block_device_mapping end
# File lib/fog/hp/models/compute/server.rb, line 165 def change_password(admin_password) requires :id service.change_password_server(id, admin_password) true end
# File lib/fog/hp/models/compute/server.rb, line 200 def confirm_resize requires :id service.confirm_resized_server(id) true end
# File lib/fog/hp/models/compute/server.rb, line 50 def console_output(num_lines) requires :id service.get_console_output(id, num_lines) end
# File lib/fog/hp/models/compute/server.rb, line 206 def create_image(name, metadata={}) requires :id service.create_image(id, name, metadata) end
# File lib/fog/hp/models/compute/server.rb, line 74 def destroy requires :id service.delete_server(id) true end
# File lib/fog/hp/models/compute/server.rb, line 141 def flavor_id @flavor_id ||= (flavor.nil? ? nil : flavor["id"]) end
# File lib/fog/hp/models/compute/server.rb, line 133 def image_id @image_id ||= (image.nil? ? nil : image["id"]) end
# File lib/fog/hp/models/compute/server.rb, line 80 def key_pair requires :key_name service.key_pairs.get(key_name) end
# File lib/fog/hp/models/compute/server.rb, line 86 def key_pair=(new_keypair) self.key_name = new_keypair && new_keypair.name end
# File lib/fog/hp/models/compute/server.rb, line 153 def max_count=(new_max_count) @max_count = new_max_count end
# File lib/fog/hp/models/compute/server.rb, line 55 def metadata @metadata ||= begin Fog::Compute::HP::Metadata.new({ :service => service, :parent => self }) end end
# File lib/fog/hp/models/compute/server.rb, line 64 def metadata=(new_metadata={}) metas = [] new_metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} } metadata.load(metas) end
# File lib/fog/hp/models/compute/server.rb, line 149 def min_count=(new_min_count) @min_count = new_min_count end
# File lib/fog/hp/models/compute/server.rb, line 90 def network_name @network_name ||= "private" end
# File lib/fog/hp/models/compute/server.rb, line 94 def private_ip_address addr = addresses.nil? ? nil : addresses.fetch(network_name, []).first addr["addr"] if addr end
# File lib/fog/hp/models/compute/server.rb, line 104 def private_key @private_key ||= private_key_path && File.read(private_key_path) end
# File lib/fog/hp/models/compute/server.rb, line 99 def private_key_path @private_key_path ||= Fog.credentials[:private_key_path] @private_key_path &&= File.expand_path(@private_key_path) end
# File lib/fog/hp/models/compute/server.rb, line 108 def public_ip_address # FIX: Both the private and public ips are bundled under "private" network name # So hack to get to the public ip address if !addresses.nil? addr = addresses.fetch(network_name, []) # if we have more than 1 address, then the return the second address which is public if addr.count > 1 addr[1]["addr"] else nil end else nil end end
# File lib/fog/hp/models/compute/server.rb, line 129 def public_key @public_key ||= public_key_path && File.read(public_key_path) end
# File lib/fog/hp/models/compute/server.rb, line 124 def public_key_path @public_key_path ||= Fog.credentials[:public_key_path] @public_key_path &&= File.expand_path(@public_key_path) end
# File lib/fog/hp/models/compute/server.rb, line 161 def ready? self.state == 'ACTIVE' end
# File lib/fog/hp/models/compute/server.rb, line 176 def reboot(type = 'SOFT') requires :id service.reboot_server(id, type) true end
# File lib/fog/hp/models/compute/server.rb, line 182 def rebuild(image_id, name, admin_pass=nil, metadata=nil, personality=nil) requires :id service.rebuild_server(id, image_id, name, admin_pass, metadata, personality) true end
# File lib/fog/hp/models/compute/server.rb, line 188 def resize(flavor_id) requires :id service.resize_server(id, flavor_id) true end
# File lib/fog/hp/models/compute/server.rb, line 194 def revert_resize requires :id service.revert_resized_server(id) true end
# File lib/fog/hp/models/compute/server.rb, line 218 def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? requires :flavor_id, :name meta_hash = {} metadata.each { |meta| meta_hash.store(meta.key, meta.value) } options = { 'metadata' => meta_hash, '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 } options = options.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, options) 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, options) end merge_attributes(data.body['server']) true end
# File lib/fog/hp/models/compute/server.rb, line 248 def setup(credentials = {}) requires :public_ip_address, :identity, :public_key, :username Fog::SSH.new(public_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
# File lib/fog/hp/models/compute/server.rb, line 70 def user_data=(ascii_userdata) self.user_data_encoded = [ascii_userdata].pack('m') # same as Base64.encode64 end
# File lib/fog/hp/models/compute/server.rb, line 262 def username @username ||= 'root' end
Generated with the Darkfish Rdoc Generator 2.