Scalr\Modules\Platforms\Azure\AzurePlatformModule::getImageInfo PHP Method

getImageInfo() public method

See also: PlatformModuleInterface::getImageInfo()
public getImageInfo ( Scalr_Environment $environment, $cloudLocation, $imageId )
$environment Scalr_Environment
    public function getImageInfo(\Scalr_Environment $environment, $cloudLocation, $imageId)
    {
        //Example of the correct imageid: Canonical/UbuntuServer/12.04.5-LTS/latest
        // Format: Publisher/Offering/Sku/Version/IsPaid
        $imageDetails = explode("/", $imageId);
        // Azure Marketplace is not tied to location.
        $cloudLocation = 'eastus';
        $info = ['name' => $imageId];
        if (count($imageDetails) >= 4) {
            $subscriptionId = $environment->keychain(SERVER_PLATFORMS::AZURE)->properties[CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID];
            $azure = $environment->azure();
            try {
                $offers = $azure->compute->location->getOffersList($subscriptionId, $cloudLocation, $imageDetails[0]);
                foreach ($offers as $offer) {
                    /* @var $offer OfferData */
                    if ($offer->name == $imageDetails[1]) {
                        $skus = $azure->compute->location->getSkusList($subscriptionId, $cloudLocation, $imageDetails[0], $imageDetails[1]);
                        foreach ($skus as $sku) {
                            /* @var $sku SkuData */
                            if ($sku->name == $imageDetails[2]) {
                                if (isset($imageDetails[3])) {
                                    if ($imageDetails[3] == 'latest') {
                                        return $info;
                                    }
                                    $versions = $azure->compute->location->getVersionsList($subscriptionId, $cloudLocation, $imageDetails[0], $imageDetails[1], $imageDetails[2]);
                                    foreach ($versions as $version) {
                                        /* @var $version VersionData */
                                        if ($version->name == $imageDetails[3]) {
                                            return $info;
                                        }
                                    }
                                } else {
                                    return $info;
                                }
                            }
                        }
                    }
                }
            } catch (\Exception $e) {
            }
        }
        return [];
    }