Sha256: b5c09df7b92ec26e0b99c90e20723288328008867203f378fe834eedbc9b7da6

Contents?: true

Size: 1.47 KB

Versions: 32

Compression:

Stored size: 1.47 KB

Contents

module Rudy::AWS
  module EC2
    
    class Zone < Storable
      
      field :name
      field :region
      field :state  
      
      def to_s(titles=false)
        [@name.bright, @region, @state].join '; '
      end

    end
    
    module Zones
      include Rudy::AWS::EC2  # important! include,
      extend self             # then extend
      
      def list(*names)
        zones = list_as_hash(names)
        zones &&= zones.values
        zones
      end
      
      def list_as_hash(*names)
        names = names.flatten
        zlist = @@ec2.describe_availability_zones(:zone_name => names)
        return unless zlist['availabilityZoneInfo'].is_a?(Hash)
        zones = {}
        zlist['availabilityZoneInfo']['item'].each do |zhash| 
          zon = Zones.from_hash(zhash)
          zones[zon.name] = zon
        end
        zones = nil if zones.empty?
        zones
      end

      def self.from_hash(h)
        zone = Rudy::AWS::EC2::Zone.new
        zone.name = h['zoneName']
        zone.region = h['regionName']
        zone.state = h['zoneState']
        zone
      end
      
      def any?
        zones = list || []
        !zones.empty?
      end
      
      def get(name)
        zones = list(name) || []
        return if zones.empty?
        zones.first
      end
      
      def zone?(name)
        begin
          kp = get(name)
          kp.is_a?(Rudy::AWS::EC2::Zone)
        rescue => ex
          false
        end
      end
      
    end
    
  end
end


Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
solutious-rudy-0.9.2 lib/rudy/aws/ec2/zone.rb
solutious-rudy-0.9.3 lib/rudy/aws/ec2/zone.rb
solutious-rudy-0.9.4 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.020 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.019 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.018 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.017 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.016 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.015 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.014 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.013 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.012 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.011 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.010 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.009 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.008 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.007 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.006 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.005 lib/rudy/aws/ec2/zone.rb
rudy-0.9.8.004 lib/rudy/aws/ec2/zone.rb