Example #1
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::getInstanceTypes()
  */
 public function getInstanceTypes(\Scalr_Environment $env = null, $cloudLocation = null, $details = false)
 {
     if (!$env instanceof \Scalr_Environment || empty($cloudLocation)) {
         throw new \InvalidArgumentException(sprintf("Method %s requires both environment object and cloudLocation to be specified.", __METHOD__));
     }
     $gceClient = $this->getClient($env);
     $projectId = $env->keychain(SERVER_PLATFORMS::GCE)->properties[Entity\CloudCredentialsProperty::GCE_PROJECT_ID];
     $ret = [];
     $detailed = [];
     //Trying to retrieve instance types from the cache
     $collection = $this->getCachedInstanceTypes(\SERVER_PLATFORMS::GCE, '', $cloudLocation);
     if ($collection === false || $collection->count() == 0) {
         //No cache. Fetching data from the cloud
         $types = $gceClient->machineTypes->listMachineTypes($projectId, $cloudLocation);
         foreach ($types->items as $item) {
             $isEphemeral = substr($item->name, -2) == '-d';
             if (!$isEphemeral) {
                 $detailed[(string) $item->name] = ['name' => (string) $item->name, 'description' => (string) $item->description, 'ram' => (string) $item->memoryMb, 'vcpus' => (string) $item->guestCpus, 'disk' => (string) $item->imageSpaceGb, 'type' => "HDD"];
                 if (!$details) {
                     $ret[(string) $item->name] = "{$item->name} ({$item->description})";
                 } else {
                     $ret[(string) $item->name] = $detailed[(string) $item->name];
                 }
             }
         }
         //Refreshes/creates a cache
         CloudLocation::updateInstanceTypes(\SERVER_PLATFORMS::GCE, '', $cloudLocation, $detailed);
     } else {
         //Takes data from cache
         foreach ($collection as $cloudInstanceType) {
             /* @var $cloudInstanceType \Scalr\Model\Entity\CloudInstanceType */
             if (!$details) {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->name . "(" . $cloudInstanceType->options->description . ")";
             } else {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->getProperties();
             }
         }
     }
     return $ret;
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::getInstanceTypes()
  */
 public function getInstanceTypes(\Scalr_Environment $env = null, $cloudLocation = null, $details = false)
 {
     if (!$env instanceof \Scalr_Environment) {
         throw new \InvalidArgumentException(sprintf("Method %s requires environment to be specified.", __METHOD__));
     }
     $ret = [];
     $detailed = [];
     //Trying to retrieve instance types from the cache
     $url = $this->getConfigVariable(static::API_URL, $env);
     $collection = $this->getCachedInstanceTypes($this->platform, $url, $cloudLocation ?: '');
     if ($collection === false || $collection->count() == 0) {
         //No cache. Fetching data from the cloud
         $client = $env->cloudstack($this->platform);
         foreach ($client->listServiceOfferings() as $offering) {
             $detailed[(string) $offering->id] = array('name' => (string) $offering->name, 'ram' => (string) $offering->memory, 'vcpus' => (string) $offering->cpunumber, 'disk' => "", 'type' => strtoupper((string) $offering->storagetype));
             if (!$details) {
                 $ret[(string) $offering->id] = (string) $offering->name;
             } else {
                 $ret[(string) $offering->id] = $detailed[(string) $offering->id];
             }
         }
         //Refreshes/creates a cache
         CloudLocation::updateInstanceTypes($this->platform, $url, $cloudLocation ?: '', $detailed);
     } else {
         //Takes data from cache
         foreach ($collection as $cloudInstanceType) {
             /* @var $cloudInstanceType \Scalr\Model\Entity\CloudInstanceType */
             if (!$details) {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->name;
             } else {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->getProperties();
             }
         }
     }
     return $ret;
 }
Example #3
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::getInstanceTypes()
  */
 public function getInstanceTypes(\Scalr_Environment $env = null, $cloudLocation = null, $details = false)
 {
     if (!$env instanceof \Scalr_Environment || empty($cloudLocation)) {
         throw new \InvalidArgumentException(sprintf("Method %s requires both environment object and cloudLocation to be specified.", __METHOD__));
     }
     $collection = $this->getCachedInstanceTypes(\SERVER_PLATFORMS::AZURE, '', $cloudLocation);
     if ($collection === false || $collection->count() == 0) {
         $instanceTypesResult = $env->azure()->compute->location->getInstanceTypesList($env->keychain(SERVER_PLATFORMS::AZURE)->properties[CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID], $cloudLocation);
         $ret = [];
         foreach ($instanceTypesResult as $instanceType) {
             $detailed[$instanceType->name] = ['name' => $instanceType->name, 'ram' => $instanceType->memoryInMB, 'vcpus' => $instanceType->numberOfCores, 'disk' => $instanceType->resourceDiskSizeInMB / 1024, 'type' => '', 'maxdatadiskcount' => $instanceType->maxDataDiskCount, 'rootdevicesize' => $instanceType->osDiskSizeInMB / 1024];
             if (!$details) {
                 $ret[$instanceType->name] = array($instanceType->name => $instanceType->name);
             } else {
                 $ret[$instanceType->name] = $detailed[$instanceType->name];
             }
         }
         CloudLocation::updateInstanceTypes(\SERVER_PLATFORMS::AZURE, '', $cloudLocation, $detailed);
     } else {
         //Takes data from cache
         foreach ($collection as $cloudInstanceType) {
             /* @var $cloudInstanceType \Scalr\Model\Entity\CloudInstanceType */
             if (!$details) {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->name;
             } else {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->getProperties();
             }
         }
     }
     return $ret;
 }
Example #4
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::getInstanceTypes()
  */
 public function getInstanceTypes(\Scalr_Environment $env = null, $cloudLocation = null, $details = false)
 {
     if (!$env instanceof \Scalr_Environment || empty($cloudLocation)) {
         throw new \InvalidArgumentException(sprintf("Method %s requires both environment object and cloudLocation to be specified.", __METHOD__));
     }
     $ret = [];
     $detailed = [];
     //Trying to retrieve instance types from the cache
     $url = $env->cloudCredentials($this->platform)->properties[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL];
     $collection = $this->getCachedInstanceTypes($this->platform, $url, $cloudLocation);
     if ($collection === false || $collection->count() == 0) {
         //No cache. Fetching data from the cloud
         $client = $env->openstack($this->platform, $cloudLocation);
         foreach ($client->servers->listFlavors() as $flavor) {
             $detailed[(string) $flavor->id] = array('name' => (string) $flavor->name, 'ram' => (string) $flavor->ram, 'vcpus' => (string) $flavor->vcpus, 'disk' => (string) $flavor->disk, 'type' => 'HDD');
             if (!$details) {
                 $ret[(string) $flavor->id] = (string) $flavor->name;
             } else {
                 $ret[(string) $flavor->id] = $detailed[(string) $flavor->id];
             }
         }
         //Refreshes/creates a cache
         CloudLocation::updateInstanceTypes($this->platform, $url, $cloudLocation, $detailed);
     } else {
         //Takes data from cache
         foreach ($collection as $cloudInstanceType) {
             /* @var $cloudInstanceType \Scalr\Model\Entity\CloudInstanceType */
             if (!$details) {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->name;
             } else {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->getProperties();
             }
         }
     }
     return $ret;
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::getInstanceTypes()
  */
 public function getInstanceTypes(\Scalr_Environment $env = null, $cloudLocation = null, $details = false)
 {
     if (!$env instanceof \Scalr_Environment || empty($cloudLocation)) {
         throw new \InvalidArgumentException(sprintf("Method %s requires both environment object and cloudLocation to be specified.", __METHOD__));
     }
     $ret = [];
     $detailed = [];
     //Trying to retrieve instance types from the cache
     $url = $this->getConfigVariable(static::EC2_URL, $env, false, $cloudLocation);
     $collection = $this->getCachedInstanceTypes(\SERVER_PLATFORMS::EUCALYPTUS, $url, $cloudLocation);
     if ($collection === false || $collection->count() == 0) {
         //No cache. Fetching data from the cloud
         $client = $env->eucalyptus($cloudLocation);
         foreach ($client->describeInstanceTypes() as $item) {
             $detailed[(string) $item->name] = ['name' => (string) $item->name, 'ram' => (string) $item->memory, 'vcpus' => (string) $item->cpu, 'disk' => (string) $item->disk, 'type' => 'hdd'];
             if (!$details) {
                 $ret[(string) $item->name] = sprintf("%s (CPUs: %d DISK: %d RAM: %d)", $item->name, $item->cpu, $item->disk, $item->memory);
             } else {
                 $ret[(string) $item->name] = $detailed[(string) $item->name];
             }
         }
         //Refreshes/creates a cache
         CloudLocation::updateInstanceTypes(\SERVER_PLATFORMS::EUCALYPTUS, $url, $cloudLocation, $detailed);
     } else {
         //Takes data from cache
         foreach ($collection as $cloudInstanceType) {
             /* @var $cloudInstanceType \Scalr\Model\Entity\CloudInstanceType */
             if (!$details) {
                 $ret[$cloudInstanceType->instanceTypeId] = sprintf("%s (CPUs: %d DISK: %d RAM: %d)", $cloudInstanceType->name, $cloudInstanceType->cpu, $cloudInstanceType->disk, $cloudInstanceType->ram);
             } else {
                 $ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->getProperties();
             }
         }
     }
     return $ret;
 }