Class: Fog::Model

Inherits:
Object
  • Object
show all
Extended by:
Attributes::ClassMethods
Includes:
Attributes::InstanceMethods
Defined in:
lib/fog/core/model.rb

Direct Known Subclasses

AWS::AutoScaling::Activity, AWS::AutoScaling::Configuration, AWS::AutoScaling::Group, AWS::AutoScaling::Instance, AWS::CloudWatch::Alarm, AWS::CloudWatch::AlarmDatum, AWS::CloudWatch::AlarmHistory, AWS::CloudWatch::Metric, AWS::CloudWatch::MetricStatistic, AWS::ELB::Listener, AWS::ELB::LoadBalancer, AWS::ELB::Policy, AWS::Elasticache::Cluster, AWS::Elasticache::ParameterGroup, AWS::Elasticache::SecurityGroup, AWS::RDS::Parameter, AWS::RDS::ParameterGroup, AWS::RDS::SecurityGroup, AWS::RDS::Server, AWS::RDS::Snapshot, Compute::AWS::Address, Compute::AWS::Flavor, Compute::AWS::Image, Compute::AWS::KeyPair, Compute::AWS::SecurityGroup, Compute::AWS::Snapshot, Compute::AWS::SpotRequest, Compute::AWS::Tag, Compute::AWS::Volume, Compute::Bluebox::Flavor, Compute::Bluebox::Image, Compute::Bluebox::Location, Compute::Brightbox::Account, Compute::Brightbox::CloudIp, Compute::Brightbox::FirewallPolicy, Compute::Brightbox::FirewallRule, Compute::Brightbox::Flavor, Compute::Brightbox::Image, Compute::Brightbox::LoadBalancer, Compute::Brightbox::ServerGroup, Compute::Brightbox::User, Compute::Brightbox::Zone, Compute::Clodo::Image, Compute::Clodo::Server, Compute::GoGrid::Image, Compute::GoGrid::Password, Compute::Joyent::Flavor, Compute::Joyent::Image, Compute::Joyent::Key, Compute::Joyent::Snapshot, Compute::Libvirt::Interface, Compute::Libvirt::Network, Compute::Libvirt::Node, Compute::Libvirt::Pool, Compute::Libvirt::Server, Compute::Libvirt::Volume, Compute::Linode::DataCenter, Compute::Linode::Disk, Compute::Linode::Flavor, Compute::Linode::Image, Compute::Linode::Ip, Compute::Linode::Kernel, Compute::Linode::StackScript, Compute::Ninefold::Address, Compute::Ninefold::Flavor, Compute::Ninefold::Image, Compute::Ninefold::IpForwardingRule, Compute::OpenStack::Flavor, Compute::OpenStack::Image, Compute::OpenStack::Meta, Compute::Ovirt::Cluster, Compute::Ovirt::Template, Compute::Rackspace::Flavor, Compute::Rackspace::Image, Compute::Server, Compute::Slicehost::Flavor, Compute::Slicehost::Image, Compute::StormOnDemand::Balancer, Compute::StormOnDemand::Config, Compute::StormOnDemand::Image, Compute::StormOnDemand::PrivateIp, Compute::StormOnDemand::Stat, Compute::StormOnDemand::Template, Compute::VirtualBox::Medium, Compute::VirtualBox::MediumFormat, Compute::VirtualBox::NATEngine, Compute::VirtualBox::NATRedirect, Compute::VirtualBox::NetworkAdapter, Compute::VirtualBox::Server, Compute::VirtualBox::StorageController, Compute::Vmfusion::Server, Compute::Voxel::Image, DNS::AWS::Record, DNS::AWS::Zone, DNS::Bluebox::Record, DNS::Bluebox::Zone, DNS::DNSMadeEasy::Record, DNS::DNSMadeEasy::Zone, DNS::DNSimple::Record, DNS::DNSimple::Zone, DNS::Dynect::Record, DNS::Dynect::Zone, DNS::Linode::Record, DNS::Linode::Zone, DNS::Rackspace::Record, DNS::Rackspace::Zone, DNS::Slicehost::Record, DNS::Slicehost::Zone, DNS::Zerigo::Record, DNS::Zerigo::Zone, Ecloud::Model, Glesys::Compute::Ip, Glesys::Compute::Template, Rackspace::LoadBalancers::AccessRule, Rackspace::LoadBalancers::LoadBalancer, Rackspace::LoadBalancers::Node, Rackspace::LoadBalancers::VirtualIp, Storage::AWS::Directory, Storage::AWS::File, Storage::AWS::Version, Storage::Google::Directory, Storage::Google::File, Storage::Local::Directory, Storage::Local::File, Storage::Ninefold::Directory, Storage::Ninefold::File, Storage::Rackspace::Directory, Storage::Rackspace::File, Terremark::Shared::Address, Terremark::Shared::Network, Terremark::Shared::Server, Terremark::Shared::Task, Terremark::Shared::Vdc, Vcloud::Model

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attributes::ClassMethods

_load, aliases, attribute, attributes, identity, ignore_attributes, ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

#initialize(new_attributes = {}) ⇒ Model

Returns a new instance of Model.



9
10
11
# File 'lib/fog/core/model.rb', line 9

def initialize(new_attributes = {})
  merge_attributes(new_attributes)
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



7
8
9
# File 'lib/fog/core/model.rb', line 7

def collection
  @collection
end

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/fog/core/model.rb', line 7

def connection
  @connection
end

Instance Method Details

#inspectObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/core/model.rb', line 13

def inspect
  Thread.current[:formatador] ||= Formatador.new
  data = "#{Thread.current[:formatador].indentation}<#{self.class.name}"
  Thread.current[:formatador].indent do
    unless self.class.attributes.empty?
      data << "\n#{Thread.current[:formatador].indentation}"
      data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
    end
  end
  data << "\n#{Thread.current[:formatador].indentation}>"
  data
end

#reloadObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/core/model.rb', line 26

def reload
  requires :identity

  return unless data = begin
    collection.get(identity)
  rescue Excon::Errors::SocketError
    nil
  end

  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#to_json(options = {}) ⇒ Object



40
41
42
43
# File 'lib/fog/core/model.rb', line 40

def to_json(options = {})
  require 'multi_json'
  MultiJson.encode(attributes)
end

#wait_for(timeout = Fog.timeout, interval = 1, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/core/model.rb', line 45

def wait_for(timeout=Fog.timeout, interval=1, &block)
  reload
  retries = 3
  Fog.wait_for(timeout, interval) do
    if reload
      retries = 3
    elsif retries > 0
      retries -= 1
      sleep(1)
    elsif retries == 0
      raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} went away.")
    end
    instance_eval(&block)
  end
end