本文整理汇总了PHP中Scalr_Environment::cloudCredentials方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Environment::cloudCredentials方法的具体用法?PHP Scalr_Environment::cloudCredentials怎么用?PHP Scalr_Environment::cloudCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Environment
的用法示例。
在下文中一共展示了Scalr_Environment::cloudCredentials方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLocations
/**
* Gets the list of available locations
*
* @param \Scalr_Environment $environment
* @return \Scalr_Environment Returns the list of available locations looks like array(location => description)
*/
public function getLocations(\Scalr_Environment $environment = null)
{
$accountType = null;
if ($environment instanceof \Scalr_Environment) {
$accountType = $environment->cloudCredentials(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE];
}
return $this->getLocationsByAccountType($accountType);
}
示例2: xSaveCloudstackAction
public function xSaveCloudstackAction()
{
$pars = array();
$enabled = false;
$platform = $this->getParam('platform');
if ($this->getParam("{$platform}_is_enabled")) {
$enabled = true;
$pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL, 'string', 'API URL required', $platform);
$pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY, 'string', 'API key required', $platform);
$pars[Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY, 'string', 'Secret key required', $platform);
}
if (count($this->checkVarError)) {
$this->response->failure();
$this->response->data(array('errors' => $this->checkVarError));
} else {
if ($this->getParam("{$platform}_is_enabled")) {
$cs = new CloudStack($pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL], $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY], $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY], $platform);
$accounts = $cs->listAccounts();
foreach ($accounts as $account) {
foreach ($account->user as $user) {
if ($user->apikey == $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY]) {
$pars[Entity\CloudCredentialsProperty::CLOUDSTACK_ACCOUNT_NAME] = $user->account;
$pars[Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_NAME] = $user->domain;
$pars[Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_ID] = $user->domainid;
}
}
}
if (empty($pars[Entity\CloudCredentialsProperty::CLOUDSTACK_ACCOUNT_NAME])) {
throw new Exception("Cannot determine account name for provided keys");
}
}
$this->db->BeginTrans();
try {
$this->env->enablePlatform($platform, $enabled);
if ($enabled) {
$this->makeCloudCredentials($platform, $pars);
} else {
$this->env->cloudCredentials($platform)->properties->saveSettings([Entity\CloudCredentialsProperty::CLOUDSTACK_ACCOUNT_NAME => false, Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY => false, Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL => false, Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_ID => false, Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_NAME => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SHARED_IP => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SHARED_IP_ID => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SHARED_IP_INFO => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SZR_PORT_COUNTER => false]);
}
if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
$this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
}
$this->response->success('Environment saved');
$this->response->data(array('enabled' => $enabled));
} catch (Exception $e) {
$this->db->RollbackTrans();
throw new Exception(_('Failed to save ' . ucfirst($platform) . ' settings'));
}
$this->db->CommitTrans();
}
}
示例3: saveOpenstack
private function saveOpenstack()
{
$pars = array();
$enabled = false;
$platform = $this->getParam('platform');
$currentCloudCredentials = $this->env->cloudCredentials($platform);
$bNew = !$currentCloudCredentials->isEnabled();
if (!$bNew) {
$oldUrl = $currentCloudCredentials->properties[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL];
}
if ($this->getParam("{$platform}_is_enabled")) {
$enabled = true;
$pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL] = trim($this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL, 'string', 'KeyStone URL required', $platform));
$pars[Entity\CloudCredentialsProperty::OPENSTACK_SSL_VERIFYPEER] = trim($this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_SSL_VERIFYPEER, 'int', '', $platform));
$pars[Entity\CloudCredentialsProperty::OPENSTACK_USERNAME] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_USERNAME, 'string', 'Username required', $platform);
$pars[Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD, 'password', '', $platform, false);
$pars[Entity\CloudCredentialsProperty::OPENSTACK_API_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_API_KEY, 'string', '', $platform);
$pars[Entity\CloudCredentialsProperty::OPENSTACK_IDENTITY_VERSION] = OpenStackConfig::parseIdentityVersion($pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL]);
$pars[Entity\CloudCredentialsProperty::OPENSTACK_TENANT_NAME] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_TENANT_NAME, 'string', '', $platform);
$pars[Entity\CloudCredentialsProperty::OPENSTACK_DOMAIN_NAME] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_DOMAIN_NAME, 'string', '', $platform);
if (empty($this->checkVarError) && empty($pars[Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD]) && empty($pars[Entity\CloudCredentialsProperty::OPENSTACK_API_KEY])) {
$this->checkVarError['api_key'] = $this->checkVarError['password'] = 'Either API Key or password must be provided.';
}
}
/* @var $config Yaml */
$config = $this->env->getContainer()->config;
if (isset($platform) && $config->defined("scalr.{$platform}.use_proxy") && $config("scalr.{$platform}.use_proxy") && in_array($config('scalr.connections.proxy.use_on'), ['both', 'scalr'])) {
$proxySettings = $config('scalr.connections.proxy');
} else {
$proxySettings = null;
}
if (count($this->checkVarError)) {
$this->response->failure();
$this->response->data(array('errors' => $this->checkVarError));
} else {
if ($this->getParam($platform . "_is_enabled")) {
$os = new OpenStack(new OpenStackConfig($pars[Entity\CloudCredentialsProperty::OPENSTACK_USERNAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL], 'fake-region', $pars[Entity\CloudCredentialsProperty::OPENSTACK_API_KEY], null, null, $pars[Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD], $pars[Entity\CloudCredentialsProperty::OPENSTACK_TENANT_NAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_DOMAIN_NAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_IDENTITY_VERSION], $proxySettings));
//It throws an exception on failure
$zones = $os->listZones();
$zone = array_shift($zones);
$os = new OpenStack(new OpenStackConfig($pars[Entity\CloudCredentialsProperty::OPENSTACK_USERNAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL], $zone->name, $pars[Entity\CloudCredentialsProperty::OPENSTACK_API_KEY], null, null, $pars[Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD], $pars[Entity\CloudCredentialsProperty::OPENSTACK_TENANT_NAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_DOMAIN_NAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_IDENTITY_VERSION], $proxySettings));
// Check SG Extension
$pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_SECURITYGROUPS_ENABLED] = (int) $os->servers->isExtensionSupported(ServersExtension::securityGroups());
// Check Floating Ips Extension
$pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_FLOATING_IPS_ENABLED] = (int) $os->servers->isExtensionSupported(ServersExtension::floatingIps());
// Check Cinder Extension
$pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_CINDER_ENABLED] = (int) $os->hasService('volume');
// Check Swift Extension
$pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_SWIFT_ENABLED] = (int) $os->hasService('object-store');
// Check LBaas Extension
$pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_LBAAS_ENABLED] = !in_array($platform, array(SERVER_PLATFORMS::RACKSPACENG_US, SERVER_PLATFORMS::RACKSPACENG_UK)) && $os->hasService('network') ? (int) $os->network->isExtensionSupported('lbaas') : 0;
}
$this->db->BeginTrans();
try {
$this->env->enablePlatform($platform, $enabled);
if ($enabled) {
$this->makeCloudCredentials($platform, $pars);
if ($this->getContainer()->analytics->enabled && ($bNew || $oldUrl !== $pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL])) {
$this->getContainer()->analytics->notifications->onCloudAdd($platform, $this->env, $this->user);
}
}
if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
$this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
}
$this->response->success('Cloud credentials have been ' . ($enabled ? 'saved' : 'removed from Scalr'));
$this->response->data(array('enabled' => $enabled));
} catch (Exception $e) {
$this->db->RollbackTrans();
throw new Exception(_('Failed to save ' . ucfirst($platform) . ' settings'));
}
$this->db->CommitTrans();
}
}
示例4: getEndpointUrl
/**
* Gets endpoint url for private cloud
*
* @param \Scalr_Environment $env The scalr environment object
* @param string $group optional The group name
* @return string Returns endpoint url for cloudstack.
*/
public function getEndpointUrl(\Scalr_Environment $env, $group = null)
{
return $env->cloudCredentials($this->platform)->properties[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL];
}
示例5: 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__));
}
$collection = $this->getCachedInstanceTypes(\SERVER_PLATFORMS::AZURE, '', $cloudLocation);
if ($collection === false || $collection->count() == 0) {
$instanceTypesResult = $env->azure()->compute->location->getInstanceTypesList($env->cloudCredentials(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;
}
示例6: GetAsyncOperationStatus
/**
*
* @param \Scalr_Environment $environment
* @param string $operationId
* @param string $cloudLocation
* @param string $scope
* @return Google_Service_Compute_Operation $operation
*/
public function GetAsyncOperationStatus(\Scalr_Environment $environment, $operationId, $cloudLocation, $scope = 'zones')
{
$projectName = $environment->cloudCredentials(SERVER_PLATFORMS::GCE)->properties[Entity\CloudCredentialsProperty::GCE_PROJECT_ID];
$gce = $this->getClient($environment);
if ($scope == 'zones') {
$operation = $gce->zoneOperations->get($projectName, $cloudLocation, $operationId);
} elseif ($scope == 'regions') {
$operation = $gce->regionOperations->get($projectName, $cloudLocation, $operationId);
}
return $operation;
}
示例7: getUrl
/**
* Gets a normalized url for an each platform
*
* @param string $platform Cloud platform
* @return string Returns url
*/
public function getUrl($platform)
{
if (!isset($this->aUrl[$platform])) {
if ($platform == \SERVER_PLATFORMS::EC2 || $platform == \SERVER_PLATFORMS::GCE || $platform == \SERVER_PLATFORMS::AZURE) {
$value = '';
} else {
if (PlatformFactory::isOpenstack($platform)) {
$value = CloudLocation::normalizeUrl($this->env->cloudCredentials($platform)->properties[CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL]);
} else {
if (PlatformFactory::isCloudstack($platform)) {
$value = CloudLocation::normalizeUrl($this->env->cloudCredentials($platform)->properties[CloudCredentialsProperty::CLOUDSTACK_API_URL]);
}
}
}
$this->aUrl[$platform] = $value;
}
return $this->aUrl[$platform];
}
示例8: getSubscriptionsList
/**
* Get list of all user subscriptions.
*
* @return SubscriptionList List of subscription objects
*/
public function getSubscriptionsList()
{
$result = null;
$path = '/subscriptions';
$step = $this->environment->cloudCredentials(\SERVER_PLATFORMS::AZURE)->properties[CloudCredentialsProperty::AZURE_AUTH_STEP];
if ($step == 3) {
$token = $this->getClientToken(Azure::URL_MANAGEMENT_WINDOWS);
}
if (empty($token) && $step != 3) {
$token = $this->getAccessToken();
}
$headers = ['Authorization' => 'Bearer ' . $token->token];
$request = $this->getClient()->prepareRequest($path, 'GET', self::SUBSCRIPTION_API_VERSION, self::URL_MANAGEMENT_WINDOWS, [], [], $headers);
$response = $this->getClient()->call($request);
if (!$response->hasError()) {
$resultArray = $response->getResult();
$result = new SubscriptionList();
foreach ($resultArray as $array) {
$result->append(SubscriptionData::initArray($array));
}
}
return $result;
}
示例9: hasCloudPrices
/**
* {@inheritdoc}
* @see \Scalr\Modules\PlatformModuleInterface::hasCloudPrices()
*/
public function hasCloudPrices(\Scalr_Environment $env)
{
if (!$this->container->analytics->enabled) {
return false;
}
if (in_array($env->cloudCredentials(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE], [Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_GOV_CLOUD, Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_CN_CLOUD])) {
$locations = $this->getLocations($env);
$cloudLocation = key($locations);
}
return $this->container->analytics->prices->hasPriceForUrl(\SERVER_PLATFORMS::EC2, '', isset($cloudLocation) ? $cloudLocation : null);
}
示例10: getImageInfo
/**
* {@inheritdoc}
* @see PlatformModuleInterface::getImageInfo()
*/
public function getImageInfo(\Scalr_Environment $environment, $cloudLocation, $imageId)
{
$ccProps = $environment->cloudCredentials("{$cloudLocation}." . SERVER_PLATFORMS::RACKSPACE)->properties;
$client = \Scalr_Service_Cloud_Rackspace::newRackspaceCS($ccProps[Entity\CloudCredentialsProperty::RACKSPACE_USERNAME], $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_API_KEY], $cloudLocation);
$snap = $client->getImageDetails($imageId);
return $snap ? ["name" => $snap->image->name] : [];
}