Class: Reyes::FakeAws
- Inherits:
-
Object
- Object
- Reyes::FakeAws
- Includes:
- Chalk::Log
- Defined in:
- lib/reyes/fake_aws.rb
Instance Method Summary collapse
- #addresses_for_security_group(region, security_group_id) ⇒ Object
-
#ec2_classic_cidr_blocks ⇒ Object
We could actually calculate this data, but it makes assigning security group rules a little bit trickier, so these will be generated statically from config.
- #excluded_group_names ⇒ Object
-
#foreign_groups_by_name(group_name, vpc_id) ⇒ Hash<Hash>
Look up remote security group data.
-
#initialize(data, assert_version = true) ⇒ FakeAws
constructor
A new instance of FakeAws.
- #instance(region, instance_id) ⇒ Object
- #metadata ⇒ Object
- #region_data(region) ⇒ Object
-
#remote_cidr_blocks(self_vpc_id) ⇒ Array<String>
Return all EC2 classic and VPC CIDR blocks that are not in ‘self_vpc_id`.
- #security_group(region, security_group_id) ⇒ Object
- #security_group_ids_for_instance(region, instance_id) ⇒ Object
- #security_group_members(region, security_group_id) ⇒ Object
- #security_groups_for_instance(region, instance_id) ⇒ Object
- #vpc_ids ⇒ Object
- #vpcs ⇒ Object
- #vpcs_except(vpc_id) ⇒ Object
Constructor Details
#initialize(data, assert_version = true) ⇒ FakeAws
Returns a new instance of FakeAws.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/reyes/fake_aws.rb', line 9 def initialize(data, assert_version=true) @data = data log.info("Initialized FakeAws with metadata: #{.inspect}") version = ['format_version'] if version != Reyes::JSON_FORMAT_VERSION msg = "JSON format_version #{version.inspect} " \ "differs from our version #{Reyes::JSON_FORMAT_VERSION}" log.error('WARNING: ' + msg) if assert_version raise Error.new(msg) end end end |
Instance Method Details
#addresses_for_security_group(region, security_group_id) ⇒ Object
50 51 52 53 54 |
# File 'lib/reyes/fake_aws.rb', line 50 def addresses_for_security_group(region, security_group_id) security_group_members(region, security_group_id).map do |instance_id| instance(region, instance_id).fetch('private_ip_address') end end |
#ec2_classic_cidr_blocks ⇒ Object
We could actually calculate this data, but it makes assigning security group rules a little bit trickier, so these will be generated statically from config.
110 111 112 |
# File 'lib/reyes/fake_aws.rb', line 110 def ec2_classic_cidr_blocks @data.fetch('classic_cidr_blocks') end |
#excluded_group_names ⇒ Object
129 130 131 |
# File 'lib/reyes/fake_aws.rb', line 129 def excluded_group_names @data.fetch('excluded_group_names') end |
#foreign_groups_by_name(group_name, vpc_id) ⇒ Hash<Hash>
Look up remote security group data. If ‘vpc_id` is nil, all VPC security groups will be returned. If `vpc_id` is given, all EC2 classic and all VPC security groups that aren’t in the given VPC will be returned.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/reyes/fake_aws.rb', line 71 def foreign_groups_by_name(group_name, vpc_id) vpc_set = vpc_ids.to_set groups = {} @data.fetch('security_groups_by_name').fetch(group_name).each do |g| group_vpc_id = g.fetch('vpc') # skip local groups that are not foreign # (groups with same VPC ID / VPCness) next if group_vpc_id == vpc_id # skip VPC groups that are not listed in our config next if group_vpc_id && !vpc_set.include?(group_vpc_id) groups[g.fetch('group_id')] = security_group(g.fetch('region'), g.fetch('group_id')) end groups end |
#instance(region, instance_id) ⇒ Object
28 29 30 |
# File 'lib/reyes/fake_aws.rb', line 28 def instance(region, instance_id) region_data(region).fetch('instances').fetch(instance_id) end |
#metadata ⇒ Object
125 126 127 |
# File 'lib/reyes/fake_aws.rb', line 125 def @data.fetch('metadata') end |
#region_data(region) ⇒ Object
24 25 26 |
# File 'lib/reyes/fake_aws.rb', line 24 def region_data(region) @data.fetch('regions').fetch(region) end |
#remote_cidr_blocks(self_vpc_id) ⇒ Array<String>
Return all EC2 classic and VPC CIDR blocks that are not in ‘self_vpc_id`.
120 121 122 123 |
# File 'lib/reyes/fake_aws.rb', line 120 def remote_cidr_blocks(self_vpc_id) nets = vpcs_except(self_vpc_id).map {|v, data| data.fetch('cidr_block') } return nets + ec2_classic_cidr_blocks end |
#security_group(region, security_group_id) ⇒ Object
32 33 34 |
# File 'lib/reyes/fake_aws.rb', line 32 def security_group(region, security_group_id) region_data(region).fetch('security_groups').fetch(security_group_id) end |
#security_group_ids_for_instance(region, instance_id) ⇒ Object
36 37 38 |
# File 'lib/reyes/fake_aws.rb', line 36 def security_group_ids_for_instance(region, instance_id) instance(region, instance_id).fetch('security_groups') end |
#security_group_members(region, security_group_id) ⇒ Object
56 57 58 |
# File 'lib/reyes/fake_aws.rb', line 56 def security_group_members(region, security_group_id) security_group(region, security_group_id).fetch('instances') end |
#security_groups_for_instance(region, instance_id) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/reyes/fake_aws.rb', line 40 def security_groups_for_instance(region, instance_id) data = {} security_group_ids_for_instance(region, instance_id).each do |sg_id| data[sg_id] = security_group(region, sg_id) end data end |
#vpc_ids ⇒ Object
103 104 105 |
# File 'lib/reyes/fake_aws.rb', line 103 def vpc_ids @data.fetch('vpcs').keys end |
#vpcs ⇒ Object
92 93 94 |
# File 'lib/reyes/fake_aws.rb', line 92 def vpcs @data.fetch('vpcs') end |
#vpcs_except(vpc_id) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/reyes/fake_aws.rb', line 96 def vpcs_except(vpc_id) unless vpc_id.is_a?(String) raise ArgumentError.new("#{vpc_id.inspect} must be a String") end vpcs.find_all {|v, _| v != vpc_id } end |