本文整理汇总了PHP中Scalr_Environment::openstack方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Environment::openstack方法的具体用法?PHP Scalr_Environment::openstack怎么用?PHP Scalr_Environment::openstack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Environment
的用法示例。
在下文中一共展示了Scalr_Environment::openstack方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLocations
/**
* {@inheritdoc}
* @see \Scalr\Modules\PlatformModuleInterface::getLocations()
*/
public function getLocations(\Scalr_Environment $environment = null)
{
if ($environment === null || !$environment->isPlatformEnabled($this->platform)) {
return array();
}
try {
$client = $environment->openstack($this->platform, "fakeRegion");
foreach ($client->listZones() as $zone) {
$retval[$zone->name] = ucfirst($this->platform) . " / {$zone->name}";
}
} catch (\Exception $e) {
return array();
}
return $retval;
}
示例2: getLocations
/**
* {@inheritdoc}
* @see \Scalr\Modules\Platforms\Openstack\OpenstackPlatformModule::getLocations()
*/
public function getLocations(\Scalr_Environment $environment = null)
{
if (!$environment) {
return array('ORD' => 'Rackspace US / ORD', 'DFW' => 'Rackspace US / DFW', 'IAD' => 'Rackspace US / IAD', 'SYD' => 'Rackspace US / SYD');
} else {
try {
$client = $environment->openstack($this->platform, "fakeRegion");
$zones = $client->listZones();
$endpoints = $client->getConfig()->getAuthToken()->getRegionEndpoints();
foreach ($zones as $zone) {
if (isset($endpoints['compute'][$zone->name])) {
$retval[$zone->name] = "Rackspace US / {$zone->name}";
}
}
} catch (\Exception $e) {
return array();
}
return $retval;
}
}
示例3: getInstanceTypes
/**
* {@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 = array();
$client = $env->openstack($this->platform, $cloudLocation);
foreach ($client->servers->listFlavors() as $flavor) {
if (!$details) {
$ret[(string) $flavor->id] = (string) $flavor->name;
} else {
$ret[(string) $flavor->id] = array('name' => (string) $flavor->name, 'ram' => (string) $flavor->ram, 'vcpus' => (string) $flavor->vcpus, 'disk' => (string) $flavor->disk, 'type' => 'HDD');
}
}
return $ret;
}
示例4: getInstanceTypes
/**
* {@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;
}
示例5: getOsClient
/**
* @return \Scalr\Service\OpenStack\OpenStack
*/
public function getOsClient(Scalr_Environment $environment, $cloudLocation)
{
return $environment->openstack($this->platform, $cloudLocation);
}
示例6: getImageInfo
/**
* {@inheritdoc}
* @see PlatformModuleInterface::getImageInfo()
*/
public function getImageInfo(\Scalr_Environment $environment, $cloudLocation, $imageId)
{
$snap = $environment->openstack($this->platform, $cloudLocation)->servers->getImage($imageId);
return $snap ? ["name" => $snap->name, "size" => $snap->metadata->instance_type_root_gb] : [];
}