Beispiel #1
0
    def subnets(self, subnet_cfg):
        """Build subnets defined in config."""
        sizes = sorted([x['size'] for x in subnet_cfg.values()])
        cidrs = allocate(self.evpc.cidr_block, sizes)

        azones = self.evpc.azones

        subnets = {}
        for size, cidr in zip(sizes, cidrs):
            subnets.setdefault(size, []).append(cidr)

        for name, sn in subnet_cfg.items():
            longname = '{}-{}'.format(self.evpc.name, name)
            az_letter = sn.get('availability_zone', None)
            if az_letter is not None:
                az_name = self.evpc.region_name + az_letter
            else:
                az_index = int(name.split('-')[-1]) - 1
                az_name = azones[az_index]

            cidr = subnets[sn['size']].pop()
            self.log.emit('creating subnet {} in {}'.format(cidr, az_name))
            subnet = self.evpc.create_subnet(CidrBlock=str(cidr),
                                             AvailabilityZone=az_name)
            self.log.emit('tagging subnet (Name:{})'.format(longname), 'debug')
            update_tags(
                subnet,
                Name=longname,
                description=sn.get('description', ''),
            )
            # Modifying the subnet's public IP addressing behavior.
            if sn.get('public', False) == True:
                subnet.map_public_ip_on_launch = True
Beispiel #2
0
    def subnets(self, subnet_cfg):
        """Build subnets defined in config."""
        sizes = sorted([x['size'] for x in subnet_cfg.values()])
        cidrs = allocate(self.evpc.cidr_block, sizes)

        azones = self.evpc.azones

        subnets = {}
        for size, cidr in zip(sizes, cidrs):
            subnets.setdefault(size, []).append(cidr)

        for name, sn in subnet_cfg.items():
            longname = '{}-{}'.format(self.evpc.name, name)
            az_letter = sn.get('availability_zone', None)
            if az_letter is not None:
                az_name = self.evpc.region_name + az_letter
            else:
                az_index = int(name.split('-')[-1]) - 1
                az_name = azones[az_index]

            cidr = subnets[sn['size']].pop()
            self.log.emit('creating subnet {} in {}'.format(cidr, az_name))
            subnet = self.evpc.create_subnet(
                          CidrBlock = str(cidr),
                          AvailabilityZone = az_name
            )
            self.log.emit('tagging subnet (Name:{})'.format(longname), 'debug')
            update_tags(
                subnet,
                Name = longname,
                description = sn.get('description', ''),
            )
            # Modifying the subnet's public IP addressing behavior.
            if sn.get('public', False) == True:
                subnet.map_public_ip_on_launch = True
 def test_allocate_many_subnets(self):
     desired_allocations = ['10.0.6.0/26', '10.0.6.64/26',
                            '10.0.6.128/26', '10.0.6.192/27',
                            '10.0.6.224/28', '10.0.6.240/28']
     allocations = map(str, allocate('10.0.6.0/24', [26,26,26,27,28,28]))
     self.assertEqual(len(allocations), 6)
     self.assertListEqual(allocations, desired_allocations)
 def test_allocate_many_subnets_2(self):
     desired_allocations = [
         '10.0.6.0/26', '10.0.6.64/26', '10.0.6.128/27', '10.0.6.160/27',
         '10.0.6.192/27', '10.0.6.224/28'
     ]
     allocations = map(str, allocate('10.0.6.0/24',
                                     [26, 26, 27, 27, 27, 28]))
     self.assertEqual(len(allocations), 6)
     self.assertListEqual(allocations, desired_allocations)
Beispiel #5
0
 def test_allocate_many_subnets(self):
     desired_allocations = [
         "10.0.6.0/26",
         "10.0.6.64/26",
         "10.0.6.128/26",
         "10.0.6.192/27",
         "10.0.6.224/28",
         "10.0.6.240/28",
     ]
     allocations = map(str, allocate("10.0.6.0/24",
                                     [26, 26, 26, 27, 28, 28]))
     self.assertEqual(len(allocations), 6)
     self.assertListEqual(allocations, desired_allocations)
Beispiel #6
0
    def subnets(self, subnet_cfg):
        """Build subnets defined in config."""
        sizes = sorted([x['size'] for x in subnet_cfg.values()])
        cidrs = allocate(self.evpc.cidr_block, sizes)

        azones = self.evpc.azones

        subnets = {}
        for size, cidr in zip(sizes, cidrs):
            subnets.setdefault(size, []).append(cidr)

        for sn_name in sorted(subnet_cfg):
            sn = subnet_cfg[sn_name]
            longname = '{}-{}'.format(self.evpc.name, sn_name)
            az_letter = sn.get('availability_zone', None)
            if az_letter is not None:
                az_name = self.evpc.region_name + az_letter
            else:
                az_index = int(sn_name.split('-')[-1]) - 1
                az_name = azones[az_index]

            cidr = subnets[sn['size']].pop(0)
            self.log.emit('creating subnet {} in {}'.format(cidr, az_name))
            subnet = self.evpc.create_subnet(CidrBlock=str(cidr),
                                             AvailabilityZone=az_name)
            self.log.emit('tagging subnet (Name:{})'.format(longname), 'debug')
            update_tags(
                subnet,
                Name=longname,
                description=sn.get('description', ''),
            )

            if sn.get('public', False) == True:
                # Modify the subnet's public IP addressing behavior.
                msg_mod = 'modifying subnet to map public IPs on instance launch ({})'
                self.log.emit(msg_mod.format(longname))
                self.boto.ec2_client.modify_subnet_attribute(
                    SubnetId=subnet.id,
                    MapPublicIpOnLaunch={'Value': True},
                )
Beispiel #7
0
 def test_allocate_returns_desired_network_list(self):
     desired_allocations = ["10.0.6.0/26", "10.0.6.64/29", "10.0.6.72/29"]
     allocations = map(str, allocate("10.0.6.0/24", [26, 29, 29]))
     self.assertListEqual(allocations, desired_allocations)
     self.assertEqual(len(allocations), 3)
Beispiel #8
0
 def test_allocate_too_many_subnets_exception_2(self):
     with self.assertRaises(Exception):
         allocate("10.0.6.0/24", [26, 26, 26, 27, 28, 28, 28])
Beispiel #9
0
 def test_allocate_sizes_sorted(self):
     desired_allocations = ["10.0.6.0/26", "10.0.6.64/29", "10.0.6.72/29"]
     allocations = map(str, allocate("10.0.6.0/24", [29, 26, 29]))
     self.assertListEqual(allocations, desired_allocations)
     self.assertEqual(len(allocations), 3)
 def test_allocate_sizes_sorted(self):
     desired_allocations = ['10.0.6.0/26', '10.0.6.64/29', '10.0.6.72/29']
     allocations = map(str, allocate('10.0.6.0/24', [29, 26, 29]))
     self.assertListEqual(allocations, desired_allocations)
     self.assertEqual(len(allocations), 3)
 def test_allocate_returns_desired_network_list(self):
     desired_allocations = ['10.0.6.0/26', '10.0.6.64/29', '10.0.6.72/29']
     allocations = map(str, allocate('10.0.6.0/24', [26,29,29]))
     self.assertListEqual(allocations, desired_allocations)
     self.assertEqual(len(allocations), 3)
 def test_allocate_too_many_subnets_exception_2(self):
     with self.assertRaises(Exception):
         allocate('10.0.6.0/24', [26,26,26,27,28,28,28])
 def test_allocate_sizes_sorted(self):
     desired_allocations = ['10.0.6.0/26', '10.0.6.64/29', '10.0.6.72/29']
     allocations = map(str, allocate('10.0.6.0/24', [29,26,29]))
     self.assertListEqual(allocations, desired_allocations)
     self.assertEqual(len(allocations), 3)