def __init__(self, spec, location, name, number_subnets): super(AzureVirtualNetwork, self).__init__(spec) self.name = name self.resource_group = GetResourceGroup() self.location = location self.args = ['--vnet-name', self.name] self.address_index = 0 self.regional_index = AzureVirtualNetwork._regional_network_count self.address_spaces = [] for zone_num in range(number_subnets): self.address_spaces.append( network.GetCidrBlock(self.regional_index, zone_num)) self.is_created = False
def __init__(self, region, vpc_id=None, regional_network_index=0): super(AwsVpc, self).__init__(vpc_id is not None) self.region = region self.regional_network_index = regional_network_index self.cidr = network.GetCidrBlock(self.regional_network_index, 0, 16) self.id = vpc_id # Subnets are assigned per-AZ. # _subnet_index tracks the next unused 10.x.y.0/24 block. self._subnet_index = 0 # Lock protecting _subnet_index self._subnet_index_lock = threading.Lock() self.default_security_group_id = None if self.id: self._SetSecurityGroupId() self._endpoints = [ aws_vpc_endpoint.CreateEndpointService(service, self) for service in set(FLAGS.aws_endpoint) ]
def NextSubnetCidrBlock(self): """Returns the next available /24 CIDR block in this VPC. Each VPC has a 10.0.0.0/16 CIDR block. Each subnet is assigned a /24 within this allocation. Calls to this method return the next unused /24. Returns: A string representing the next available /24 block, in CIDR notation. Raises: ValueError: when no additional subnets can be created. """ with self._subnet_index_lock: if self._subnet_index >= (1 << 8) - 1: raise ValueError('Exceeded subnet limit ({0}).'.format( self._subnet_index)) cidr = network.GetCidrBlock(self.regional_network_index, self._subnet_index) self._subnet_index += 1 return cidr
def __init__(self, region, vpc_id=None): self.region = region self.internet_gateway = AwsInternetGateway(region, vpc_id) self.route_table = None self.created = False # Locks to ensure that a single thread creates / deletes the instance. self._create_lock = threading.Lock() # Tracks the number of AwsNetworks using this _AwsRegionalNetwork. # Incremented by Create(); decremented by Delete(); # When a Delete() call decrements _reference_count to 0, the RegionalNetwork # is destroyed. self._reference_count = 0 self._reference_count_lock = threading.Lock() # Each regional network needs unique cidr_block for VPC peering. with _AwsRegionalNetwork._regional_network_lock: self.vpc = AwsVpc(self.region, vpc_id, _AwsRegionalNetwork._regional_network_count) self.cidr_block = network.GetCidrBlock( _AwsRegionalNetwork._regional_network_count) _AwsRegionalNetwork._regional_network_count += 1