Class/Module Index [+]

Quicksearch

Fog::Compute::IBM::Server

Constants

STATES

Public Class Methods

new(new_attributes={}) click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 51
def initialize(new_attributes={})
  super(new_attributes)
  self.name ||= 'fog-instance'
  self.image_id ||= '20010001'
  self.location_id ||= '41'
  self.instance_type ||= 'COP32.1/2048/60'
  self.key_name ||= 'fog'
end

Public Instance Methods

addresses() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 112
def addresses
  addys = secondary_ip.map {|ip| Fog::Compute[:ibm].addresses.new(ip) }
  # Set an ID, in case someone tries to save
  addys << service.addresses.new(attributes[:primary_ip].merge(
    :id => "0",
    :location => location_id,
    :state => 3
  ))
  addys
end
allocate_ip(wait_for_ready=true) click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 103
def allocate_ip(wait_for_ready=true)
  requires :location_id
  new_ip = service.addresses.new(:location => location_id)
  new_ip.save
  new_ip.wait_for(Fog::IBM.timeout) { ready? } if wait_for_ready
  secondary_ip << new_ip
  new_ip
end
attach(volume_id) click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 123
def attach(volume_id)
  requires :id
  data = service.modify_instance(id, {'type' => 'attach', 'storageID' => volume_id})
  data.body
end
create_image(opts={}) click to toggle source
Alias for: to_image
destroy() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 88
def destroy
  requires :id
  service.delete_instance(id).body['success']
end
detach(volume_id) click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 129
def detach(volume_id)
  requires :id
  data = service.modify_instance(id, {'type' => 'detach', 'storageID' => volume_id})
  data.body
end
expire!() click to toggle source

Expires the instance immediately

# File lib/fog/ibm/models/compute/server.rb, line 156
def expire!
  expire_at(Time.now + 5)
end
expire_at(time) click to toggle source

Sets expiration time - Pass an instance of Time.

# File lib/fog/ibm/models/compute/server.rb, line 144
def expire_at(time)
  expiry_time = (time.tv_sec * 1000).to_i
  data = service.modify_instance(id, 'expirationTime' => expiry_time)
  if data.body['expirationTime'] == expiry_time
    attributes[:expires_at] = expiry_time
    true
  else
    false
  end
end
expires_at() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 139
def expires_at
  Time.at(attributes[:expires_at].to_f / 1000)
end
image() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 160
def image
  requires :image_id
  service.images.get(image_id)
end
launched_at() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 135
def launched_at
  Time.at(attributes[:launched_at].to_f / 1000)
end
location() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 165
def location
  requires :location_id
  service.locations.get(location_id)
end
public_hostname() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 170
def public_hostname
  primary_ip ? primary_ip['hostname'] : nil
end
public_ip_address() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 174
def public_ip_address
  primary_ip ? primary_ip['ip'] : nil
end
ready?() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 79
def ready?
  state == "Active"
end
reboot() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 83
def reboot
  requires :id
  service.modify_instance(id, 'state' => 'restart').body['success']
end
rename(name) click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 93
def rename(name)
  requires :id
  if service.modify_instance(id, 'name' => name).body["success"]
    attributes[:name] = name
  else
    return false
  end
  true
end
save() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 60
def save
  requires :name, :image_id, :instance_type, :location_id
  data = service.create_instance(name, image_id, instance_type, location_id,
                                    :key_name => key_name,
                                    :vlan_id => vlan_id,
                                    :secondary_ip => secondary_ip)
  data.body['instances'].each do |iattrs|
    if iattrs['name'] == name
      merge_attributes(iattrs)
      return true
    end
  end
  false
end
state() click to toggle source
# File lib/fog/ibm/models/compute/server.rb, line 75
def state
  STATES[attributes[:state]]
end
to_image(opts={}) click to toggle source

Creates an image from the current instance if name isn't passed then we'll take the current name and timestamp it

# File lib/fog/ibm/models/compute/server.rb, line 180
def to_image(opts={})
 options = {
   :name => name + " as of " + Time.now.strftime("%Y-%m-%d %H:%M"),
   :description => ""
 }.merge(opts)
 service.create_image(id, options[:name], options[:description]).body
end
Also aliased as: create_image

[Validate]

Generated with the Darkfish Rdoc Generator 2.