cloudstack() public method

This method ensures that cloudstack instance is always from the current environment scope
public cloudstack ( string $platform = 'cloudstack', string $apiUrl = null, string $apiKey = null, string $secretKey = null ) : CloudStack
$platform string Platform name
$apiUrl string The endpoint name url
$apiKey string Api key
$secretKey string Secret key
return Scalr\Service\CloudStack\CloudStack Returns cloudstack instance from DI container
Exemplo n.º 1
0
 /**
  * {@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 = array();
     $cs = $env->cloudstack($this->platform);
     $products = $cs->listAvailableProductTypes();
     if (count($products) > 0) {
         foreach ($products as $product) {
             $ret[(string) $product->serviceofferingid] = (string) $product->serviceofferingdesc;
         }
     }
     return $ret;
 }
 public function GetServersList(\Scalr_Environment $environment, $region, $skipCache = false)
 {
     if (!$region) {
         return array();
     }
     if (!$this->instancesListCache[$environment->id][$region] || $skipCache) {
         $cs = $environment->cloudstack($this->platform);
         try {
             $results = $cs->instance->describe(array('zoneid' => $region));
         } catch (\Exception $e) {
             throw new \Exception(sprintf("Cannot get list of servers for platform {$this->platform}: %s", $e->getMessage()));
         }
         if (count($results) > 0) {
             foreach ($results as $item) {
                 $this->instancesListCache[$environment->id][$region][$item->id] = $item->state;
             }
         }
     }
     return $this->instancesListCache[$environment->id][$region];
 }
 /**
  * {@inheritdoc}
  * @see PlatformModuleInterface::getImageInfo()
  */
 public function getImageInfo(\Scalr_Environment $environment, $cloudLocation, $imageId)
 {
     $snap = $environment->cloudstack($this->platform)->template->describe(["templatefilter" => "executable", "id" => $imageId, "zoneid" => $cloudLocation]);
     return $snap && isset($snap[0]) ? ["name" => $snap[0]->name, "size" => ceil($snap[0]->size / pow(1024, 3))] : [];
 }
Exemplo n.º 4
0
 /**
  * {@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 = $env->cloudCredentials($this->platform)->properties[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL];
     $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;
 }
Exemplo n.º 5
0
 /**
  * {@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 = array();
     $client = $env->cloudstack($this->platform);
     foreach ($client->listServiceOfferings() as $offering) {
         if (!$details) {
             $ret[(string) $offering->id] = (string) $offering->name;
         } else {
             $ret[(string) $offering->id] = array('name' => (string) $offering->name, 'ram' => (string) $offering->memory, 'vcpus' => (string) $offering->cpunumber, 'disk' => "", 'type' => strtoupper((string) $offering->storagetype));
         }
     }
     return $ret;
 }