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::AutoScaling::Policy, 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::ElasticBeanstalk::Application, AWS::ElasticBeanstalk::Environment, AWS::ElasticBeanstalk::Event, AWS::ElasticBeanstalk::Template, AWS::ElasticBeanstalk::Version, AWS::Elasticache::Cluster, AWS::Elasticache::ParameterGroup, AWS::Elasticache::SecurityGroup, AWS::Glacier::Archive, AWS::Glacier::Job, AWS::Glacier::Vault, AWS::IAM::AccessKey, AWS::IAM::Policy, AWS::IAM::User, AWS::RDS::Parameter, AWS::RDS::ParameterGroup, AWS::RDS::SecurityGroup, AWS::RDS::Server, AWS::RDS::Snapshot, AWS::RDS::SubnetGroup, CDN::AWS::Distribution, CDN::AWS::Invalidation, CDN::AWS::StreamingDistribution, Compute::AWS::Address, Compute::AWS::DhcpOption, Compute::AWS::Flavor, Compute::AWS::Image, Compute::AWS::InternetGateway, Compute::AWS::KeyPair, Compute::AWS::NetworkInterface, Compute::AWS::SecurityGroup, Compute::AWS::Snapshot, Compute::AWS::Subnet, Compute::AWS::Tag, Compute::AWS::VPC, Compute::AWS::Volume, Compute::Bluebox::Flavor, Compute::Bluebox::Image, Compute::Bluebox::Location, Compute::Brightbox::Account, Compute::Brightbox::ApiClient, Compute::Brightbox::Application, 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::Cloudstack::Address, Compute::Cloudstack::Flavor, Compute::Cloudstack::Image, Compute::Cloudstack::Job, Compute::Cloudstack::SecurityGroup, Compute::Cloudstack::SecurityGroupRule, Compute::Cloudstack::Volume, Compute::Cloudstack::Zone, Compute::GoGrid::Image, Compute::GoGrid::Password, Compute::HP::Address, Compute::HP::Flavor, Compute::HP::Image, Compute::HP::KeyPair, Compute::HP::SecurityGroup, Compute::IBM::Address, Compute::IBM::Image, Compute::IBM::InstanceType, Compute::IBM::Key, Compute::IBM::Location, Compute::IBM::Vlan, Compute::Joyent::Flavor, Compute::Joyent::Image, Compute::Joyent::Key, Compute::Joyent::Snapshot, Compute::Libvirt::Interface, Compute::Libvirt::Network, Compute::Libvirt::Nic, Compute::Libvirt::Node, Compute::Libvirt::Pool, 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::Address, Compute::OpenStack::Flavor, Compute::OpenStack::Host, Compute::OpenStack::Image, Compute::OpenStack::KeyPair, Compute::OpenStack::Metadatum, Compute::OpenStack::Network, Compute::OpenStack::SecurityGroup, Compute::OpenStack::Snapshot, Compute::OpenStack::Tenant, Compute::OpenStack::Volume, Compute::Ovirt::Cluster, Compute::Ovirt::Interface, Compute::Ovirt::Template, Compute::Ovirt::Volume, Compute::Rackspace::Flavor, Compute::Rackspace::Image, Compute::RackspaceV2::Attachment, Compute::RackspaceV2::Flavor, Compute::RackspaceV2::Image, Compute::Server, Compute::Serverlove::Image, Compute::Serverlove::Server, 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::StorageController, Compute::Voxel::Image, Compute::Vsphere::Cluster, Compute::Vsphere::Datacenter, Compute::Vsphere::Datastore, Compute::Vsphere::Folder, Compute::Vsphere::Interface, Compute::Vsphere::Network, Compute::Vsphere::ResourcePool, Compute::Vsphere::Template, Compute::Vsphere::Volume, Compute::XenServer::GuestMetrics, Compute::XenServer::Host, Compute::XenServer::Network, Compute::XenServer::PBD, Compute::XenServer::PIF, Compute::XenServer::Pool, Compute::XenServer::StorageRepository, Compute::XenServer::VBD, Compute::XenServer::VDI, Compute::XenServer::VIF, Compute::XenServer::VbdMetrics, 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::Zerigo::Record, DNS::Zerigo::Zone, Ecloud::Model, Glesys::Compute::Ip, Glesys::Compute::Template, Identity::OpenStack::Role, Identity::OpenStack::Tenant, Identity::OpenStack::User, Image::OpenStack::Image, Network::OpenStack::Network, Network::OpenStack::Port, Network::OpenStack::Subnet, Rackspace::BlockStorage::Snapshot, Rackspace::BlockStorage::Volume, Rackspace::BlockStorage::VolumeType, Rackspace::Databases::Database, Rackspace::Databases::Flavor, Rackspace::Databases::Instance, Rackspace::Databases::User, Rackspace::Identity::Credential, Rackspace::Identity::Role, Rackspace::Identity::Tenant, Rackspace::Identity::User, Rackspace::LoadBalancers::AccessRule, Rackspace::LoadBalancers::LoadBalancer, Rackspace::LoadBalancers::Node, Rackspace::LoadBalancers::VirtualIp, Storage::AWS::Directory, Storage::AWS::File, Storage::AWS::Version, Storage::Atmos::Directory, Storage::Atmos::File, Storage::Google::Directory, Storage::Google::File, Storage::HP::Directory, Storage::HP::File, Storage::IBM::Offering, Storage::IBM::Volume, Storage::Local::Directory, Storage::Local::File, Storage::Rackspace::Directory, Storage::Rackspace::File, Terremark::Shared::Address, Terremark::Shared::Image, Terremark::Shared::InternetService, Terremark::Shared::Network, Terremark::Shared::NodeService, Terremark::Shared::Server, Terremark::Shared::Task, Terremark::Shared::Vdc, Vcloud::Model, Volume::OpenStack::Volume

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

#symbolize_keys(hash) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/fog/core/model.rb', line 44

def symbolize_keys(hash)
  return nil if hash.nil?
  hash.inject({}) do |options, (key, value)|
    options[(key.to_sym rescue key) || key] = value
    options
  end
end

#to_json(options = {}) ⇒ Object



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

def to_json(options = {})
  Fog::JSON.encode(attributes)
end

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/core/model.rb', line 52

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