class Fog::Compute::Slicehost::Server

Attributes

'root-password='[RW]
password[RW]
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/slicehost/models/compute/server.rb, line 25
def initialize(attributes={})
  self.flavor_id  ||= 1  # 256 server
  self.image_id   ||= 49 # Ubuntu 10.04 LTS 64bit
  super
end

Public Instance Methods

destroy() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 31
def destroy
  requires :id
  connection.delete_slice(id)
  true
end
flavor() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 37
def flavor
  requires :flavor_id
  connection.flavors.get(flavor_id)
end
image() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 42
def image
  requires :image_id
  connection.images.get(image_id)
end
private_ip_address() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 47
def private_ip_address
  nil
end
private_key() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 56
def private_key
  @private_key ||= private_key_path && File.read(private_key_path)
end
private_key_path() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 51
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/slicehost/models/compute/server.rb, line 60
def public_ip_address
  addresses.first
end
public_key() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 69
def public_key
  @public_key ||= public_key_path && File.read(public_key_path)
end
public_key_path() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 64
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/slicehost/models/compute/server.rb, line 73
def ready?
  self.state == 'active'
end
reboot(type = 'SOFT') click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 77
def reboot(type = 'SOFT')
  requires :id
  connection.reboot_slice(id, type)
  true
end
save() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 83
def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
  requires :flavor_id, :image_id, :name

  data = connection.create_slice(flavor_id, image_id, name)
  merge_attributes(data.body)
  true
end
setup(credentials = {}) click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 92
def setup(credentials = {})
  requires :addresses, :identity, :public_key, :username
  Fog::SSH.new(addresses.first, 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}
  ])
rescue Errno::ECONNREFUSED
  sleep(1)
  retry
end
username() click to toggle source
# File lib/fog/slicehost/models/compute/server.rb, line 105
def username
  @username ||= 'root'
end