Class: Fog::Model

Inherits:
Object
  • Object
show all
Extended by:
Attributes::ClassMethods
Includes:
Attributes::InstanceMethods, Core::DeprecatedConnectionAccessors
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::DataPipeline::Pipeline, 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::Role, AWS::IAM::User, AWS::RDS::Parameter, AWS::RDS::ParameterGroup, AWS::RDS::SecurityGroup, AWS::RDS::Server, AWS::RDS::Snapshot, AWS::RDS::SubnetGroup, Account::StormOnDemand::Token, Billing::StormOnDemand::Invoice, Billing::StormOnDemand::Payment, Bluebox::BLB::LbApplication, Bluebox::BLB::LbBackend, Bluebox::BLB::LbService, CDN::AWS::Distribution, CDN::AWS::Invalidation, CDN::AWS::StreamingDistribution, CloudSigma::CloudsigmaModel, 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::CloudSigma::LibVolume, Compute::CloudSigma::MountPoint, Compute::CloudSigma::ObjRef, Compute::Cloudstack::Address, Compute::Cloudstack::DiskOffering, Compute::Cloudstack::Flavor, Compute::Cloudstack::Image, Compute::Cloudstack::Job, Compute::Cloudstack::SecurityGroup, Compute::Cloudstack::SecurityGroupRule, Compute::Cloudstack::Snapshot, Compute::Cloudstack::Volume, Compute::Cloudstack::Zone, Compute::DigitalOcean::Flavor, Compute::DigitalOcean::Image, Compute::DigitalOcean::Region, Compute::DigitalOcean::SshKey, Compute::Glesys::Ip, Compute::Glesys::Template, Compute::GoGrid::Image, Compute::GoGrid::Password, Compute::Google::Flavor, Compute::Google::Image, Compute::HP::Address, Compute::HP::Flavor, Compute::HP::Image, Compute::HP::KeyPair, Compute::HP::Meta, 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::Network, 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::Quota, Compute::Ovirt::Template, Compute::Ovirt::Volume, Compute::Rackspace::Flavor, Compute::Rackspace::Image, Compute::RackspaceV2::Attachment, Compute::RackspaceV2::Flavor, Compute::RackspaceV2::Image, Compute::RackspaceV2::Metadatum, Compute::RackspaceV2::Network, Compute::Server, Compute::Serverlove::Image, Compute::Serverlove::Server, Compute::StormOnDemand::Config, Compute::StormOnDemand::Image, Compute::StormOnDemand::Notification, Compute::StormOnDemand::Product, Compute::StormOnDemand::Template, Compute::Voxel::Image, Compute::Vsphere::Cluster, Compute::Vsphere::Customfield, Compute::Vsphere::Customvalue, 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::HostCpu, Compute::XenServer::HostMetrics, 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::VLAN, 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::Dreamhost::Record, DNS::Dreamhost::Zone, DNS::Dynect::Record, DNS::Dynect::Zone, DNS::Linode::Record, DNS::Linode::Zone, DNS::Rackspace::Record, DNS::Rackspace::Zone, DNS::StormOnDemand::Domain, DNS::StormOnDemand::Record, DNS::StormOnDemand::Reverse, DNS::StormOnDemand::Zone, DNS::Zerigo::Record, DNS::Zerigo::Zone, Ecloud::Model, HP::BlockStorage::Snapshot, HP::BlockStorage::Volume, Identity::OpenStack::Ec2Credential, Identity::OpenStack::Role, Identity::OpenStack::Tenant, Identity::OpenStack::User, Image::OpenStack::Image, Fog::Monitoring::StormOnDemand::Bandwidth, Fog::Monitoring::StormOnDemand::Load, Fog::Monitoring::StormOnDemand::MonitorService, Network::OpenStack::FloatingIp, Network::OpenStack::LbHealthMonitor, Network::OpenStack::LbMember, Network::OpenStack::LbPool, Network::OpenStack::LbVip, Network::OpenStack::Network, Network::OpenStack::Port, Network::OpenStack::Router, Network::OpenStack::Subnet, Network::StormOnDemand::Balancer, Network::StormOnDemand::Firewall, Network::StormOnDemand::NetworkIP, Network::StormOnDemand::Pool, Network::StormOnDemand::PrivateIp, Network::StormOnDemand::Ruleset, Network::StormOnDemand::Zone, 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::ServiceCatalog, 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::HP::SharedDirectory, Storage::HP::SharedFile, Storage::IBM::Offering, Storage::IBM::Volume, Storage::InternetArchive::Directory, Storage::InternetArchive::File, Storage::Local::Directory, Storage::Local::File, Storage::OpenStack::Directory, Storage::OpenStack::File, Storage::Rackspace::Account, Storage::Rackspace::Directory, Storage::Rackspace::File, Storage::StormOnDemand::Cluster, Storage::StormOnDemand::Volume, Support::StormOnDemand::Alert, Support::StormOnDemand::Ticket, Terremark::Shared::Address, Terremark::Shared::Image, Terremark::Shared::InternetService, Terremark::Shared::Network, Terremark::Shared::NodeService, Terremark::Shared::Server, Terremark::Shared::Task, Terremark::Shared::Vdc, VPN::StormOnDemand::Vpn, 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 Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

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

Constructor Details

#initialize(new_attributes = {}) ⇒ Model

Returns a new instance of Model.



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

def initialize(new_attributes = {})
  # TODO Remove compatibility with old connection option
  @service = new_attributes.delete(:service)
  if @service.nil? && new_attributes[:connection]
    Fog::Logger.deprecation("Passing :connection option is deprecated, use :service instead [light_black](#{caller.first})[/]")
    @service = new_attributes[:connection]
  end
  merge_attributes(new_attributes)
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



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

def collection
  @collection
end

#serviceObject (readonly)

Returns the value of attribute service.



11
12
13
# File 'lib/fog/core/model.rb', line 11

def service
  @service
end

Instance Method Details

#inspectObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/core/model.rb', line 23

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



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/core/model.rb', line 36

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



54
55
56
57
58
59
60
# File 'lib/fog/core/model.rb', line 54

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



50
51
52
# File 'lib/fog/core/model.rb', line 50

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

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/core/model.rb', line 62

def wait_for(timeout=Fog.timeout, interval=1, &block)
  reload_has_succeeded = false
  duration = Fog.wait_for(timeout, interval) do # Note that duration = false if it times out
    if reload
      reload_has_succeeded = true
      instance_eval(&block)
    else
      false
    end
  end
  if reload_has_succeeded
    return duration # false if timeout; otherwise {:duration => elapsed time }
  else
    raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} not present.")
  end
end