Scalr\Modules\Platforms\Ec2\Ec2PlatformModule::listSubnets PHP Method

listSubnets() public method

public listSubnets ( Scalr_Environment $env, $cloudLocation, $vpcId, $extended = true, $subnetId = null )
$env Scalr_Environment
    public function listSubnets(\Scalr_Environment $env, $cloudLocation, $vpcId, $extended = true, $subnetId = null)
    {
        $aws = $env->aws($cloudLocation);
        if ($extended) {
            $routingTables = $this->getRoutingTables($aws->ec2, $vpcId);
        }
        $filter = array(array('name' => SubnetFilterNameType::vpcId(), 'value' => $vpcId));
        $subnets = $aws->ec2->subnet->describe($subnetId, $filter);
        $retval = array();
        /* @var $subnet \Scalr\Service\Aws\Ec2\DataType\SubnetData  */
        foreach ($subnets as $subnet) {
            $item = array('id' => $subnet->subnetId, 'description' => "{$subnet->subnetId} ({$subnet->cidrBlock} in {$subnet->availabilityZone})", 'cidr' => $subnet->cidrBlock, 'availability_zone' => $subnet->availabilityZone, 'ips_left' => $subnet->availableIpAddressCount);
            foreach ($subnet->tagSet as $tag) {
                if ($tag->key == 'Name') {
                    $item['name'] = $tag->value;
                }
            }
            if ($extended) {
                foreach ($routingTables as $table) {
                    if (in_array($subnet->subnetId, $table['subnets'])) {
                        $item['type'] = $table['type'];
                    }
                    if ($table['main']) {
                        $mainTableType = $table['type'];
                    }
                }
            }
            if (empty($item['type'])) {
                $item['type'] = $mainTableType;
            }
            $retval[] = $item;
        }
        return $subnetId ? $retval[0] : $retval;
    }