Sha256: 9d00ba67d93e3654f4257e24e6c395e863cba845e9233b098a1cc3bada2f7a84

Contents?: true

Size: 1.3 KB

Versions: 31

Compression:

Stored size: 1.3 KB

Contents

# Provides access to default network settings for a vpc: subnets and security_group
# If no @vpc_id is provided to the initializer then the default vpc is used.
class Ufo::Network
  class Fetch
    include Ufo::AwsService
    extend Memoist

    def initialize(vpc_id)
      @vpc_id = vpc_id
    end

    def vpc_id
      return @vpc_id if @vpc_id

      resp = ec2.describe_vpcs(filters: [
        {name: "isDefault", values: ["true"]}
      ])
      default_vpc = resp.vpcs.first
      if default_vpc
        default_vpc.vpc_id
      else
        puts "A default vpc was not found in this AWS account and region.".color(:red)
        puts "Because there is no default vpc, please specify the --vpc-id option.  More info: http://ufoships.com/reference/ufo-init/"
        exit 1
      end
    end
    memoize :vpc_id

    # all subnets
    def subnet_ids
      resp = ec2.describe_subnets(filters: [
        {name: "vpc-id", values: [vpc_id]}
      ])
      resp.subnets.map(&:subnet_id).sort
    end
    memoize :subnet_ids

    # default security group
    def security_group_id
      resp = ec2.describe_security_groups(filters: [
        {name: "vpc-id", values: [vpc_id]},
        {name: "group-name", values: ["default"]}
      ])
      resp.security_groups.first.group_id
    end
    memoize :security_group_id
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ufo-5.0.7 lib/ufo/network/fetch.rb
ufo-5.0.6 lib/ufo/network/fetch.rb
ufo-5.0.5 lib/ufo/network/fetch.rb
ufo-5.0.4 lib/ufo/network/fetch.rb
ufo-5.0.3 lib/ufo/network/fetch.rb
ufo-5.0.2 lib/ufo/network/fetch.rb
ufo-5.0.1 lib/ufo/network/fetch.rb
ufo-5.0.0 lib/ufo/network/fetch.rb
ufo-4.6.3 lib/ufo/network/fetch.rb
ufo-4.6.2 lib/ufo/network/fetch.rb
ufo-4.6.1 lib/ufo/network/fetch.rb
ufo-4.6.0 lib/ufo/network/fetch.rb
ufo-4.5.11 lib/ufo/network/fetch.rb
ufo-4.5.10 lib/ufo/network/fetch.rb
ufo-4.5.9 lib/ufo/network/fetch.rb
ufo-4.5.8 lib/ufo/network/fetch.rb
ufo-4.5.7 lib/ufo/network/fetch.rb
ufo-4.5.6 lib/ufo/network/fetch.rb
ufo-4.5.5 lib/ufo/network/fetch.rb
ufo-4.5.4 lib/ufo/network/fetch.rb