# 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
# 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
# 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
# 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
# File lib/fog/ibm/models/compute/server.rb, line 88 def destroy requires :id service.delete_instance(id).body['success'] end
# 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
Expires the instance immediately
# File lib/fog/ibm/models/compute/server.rb, line 156 def expire! expire_at(Time.now + 5) end
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
# File lib/fog/ibm/models/compute/server.rb, line 139 def expires_at Time.at(attributes[:expires_at].to_f / 1000) end
# File lib/fog/ibm/models/compute/server.rb, line 160 def image requires :image_id service.images.get(image_id) end
# File lib/fog/ibm/models/compute/server.rb, line 135 def launched_at Time.at(attributes[:launched_at].to_f / 1000) end
# File lib/fog/ibm/models/compute/server.rb, line 165 def location requires :location_id service.locations.get(location_id) end
# File lib/fog/ibm/models/compute/server.rb, line 170 def public_hostname primary_ip ? primary_ip['hostname'] : nil end
# File lib/fog/ibm/models/compute/server.rb, line 174 def public_ip_address primary_ip ? primary_ip['ip'] : nil end
# File lib/fog/ibm/models/compute/server.rb, line 79 def ready? state == "Active" end
# File lib/fog/ibm/models/compute/server.rb, line 83 def reboot requires :id service.modify_instance(id, 'state' => 'restart').body['success'] end
# 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
# 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
# File lib/fog/ibm/models/compute/server.rb, line 75 def state STATES[attributes[:state]] end
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
Generated with the Darkfish Rdoc Generator 2.