class Fog::Compute::HP::Server

Attributes

flavor_id[W]
image_id[W]
password[R]
private_key[W]
private_key_path[W]
public_key[W]
public_key_path[W]
username[W]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 36
def initialize(attributes = {})
  # assign these attributes first to prevent race condition with new_record?
  self.security_groups = attributes.delete(:security_groups)
  self.min_count = attributes.delete(:min_count)
  self.max_count = attributes.delete(:max_count)
  super
end

Public Instance Methods

change_password(admin_password) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 136
def change_password(admin_password)
  requires :id
  connection.change_password_server(id, admin_password)
  true
end
confirm_resize() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 166
def confirm_resize
  requires :id
  connection.confirm_resized_server(id)
  true
end
create_image(name, metadata={}) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 172
def create_image(name, metadata={})
  requires :id
  connection.create_image(id, name, metadata)
end
destroy() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 44
def destroy
  requires :id
  connection.delete_server(id)
  true
end
flavor_id() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 112
def flavor_id
  @flavor_id ||= (flavor.nil? ? nil : flavor["id"])
end
image_id() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 104
def image_id
  @image_id ||= (image.nil? ? nil : image["id"])
end
images() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 50
def images
  requires :id
  connection.images(:server => self)
end
key_pair() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 55
def key_pair
  requires :key_name

  connection.key_pairs.get(key_name)
end
key_pair=(new_keypair) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 61
def key_pair=(new_keypair)
  self.key_name = new_keypair && new_keypair.name
end
max_count=(new_max_count) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 124
def max_count=(new_max_count)
  @max_count = new_max_count
end
min_count=(new_min_count) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 120
def min_count=(new_min_count)
  @min_count = new_min_count
end
private_ip_address() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 65
def private_ip_address
  addr = addresses.nil? ? nil : addresses.fetch('private', []).first
  addr["addr"] if addr
end
private_key() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 75
def private_key
  @private_key ||= private_key_path && File.read(private_key_path)
end
private_key_path() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 70
def private_key_path
  @private_key_path ||= Fog.credentials[:private_key_path]
  @private_key_path &&= File.expand_path(@private_key_path)
end
public_ip_address() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 79
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('private', [])
    # 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
public_key() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 100
def public_key
  @public_key ||= public_key_path && File.read(public_key_path)
end
public_key_path() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 95
def public_key_path
  @public_key_path ||= Fog.credentials[:public_key_path]
  @public_key_path &&= File.expand_path(@public_key_path)
end
ready?() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 132
def ready?
  self.state == 'ACTIVE'
end
reboot(type = 'SOFT') click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 142
def reboot(type = 'SOFT')
  requires :id
  connection.reboot_server(id, type)
  true
end
rebuild(image_id, name, admin_pass=nil, metadata=nil, personality=nil) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 148
def rebuild(image_id, name, admin_pass=nil, metadata=nil, personality=nil)
  requires :id
  connection.rebuild_server(id, image_id, name, admin_pass, metadata, personality)
  true
end
resize(flavor_id) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 154
def resize(flavor_id)
  requires :id
  connection.resize_server(id, flavor_id)
  true
end
revert_resize() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 160
def revert_resize
  requires :id
  connection.revert_resized_server(id)
  true
end
save() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 177
def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
  requires :flavor_id, :image_id, :name
  options = {
    'metadata'    => metadata,
    'personality' => personality,
    'accessIPv4'  => accessIPv4,
    'accessIPv6'  => accessIPv6,
    'min_count'   => @min_count,
    'max_count'   => @max_count,
    'key_name'    => key_name,
    'security_groups' => @security_groups
  }
  options = options.reject {|key, value| value.nil?}
  data = connection.create_server(name, flavor_id, image_id, options)
  merge_attributes(data.body['server'])
  true
end
security_groups=(new_security_groups) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 128
def security_groups=(new_security_groups)
  @security_groups = new_security_groups
end
setup(credentials = {}) click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 196
def setup(credentials = {})
  requires :public_ip_address, :identity, :public_key, :username
  Fog::SSH.new(public_ip_address, username, credentials).run([
    %Q{mkdir .ssh},
    %Q{echo "#{public_key}" >> ~/.ssh/authorized_keys},
    %Q{passwd -l #{username}},
    %Q{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
    %Q{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
  ])
rescue Errno::ECONNREFUSED
  sleep(1)
  retry
end
username() click to toggle source
# File lib/fog/hp/models/compute/server.rb, line 210
def username
  @username ||= 'root'
end