本文整理汇总了PHP中Scalr_Environment::azure方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Environment::azure方法的具体用法?PHP Scalr_Environment::azure怎么用?PHP Scalr_Environment::azure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Environment
的用法示例。
在下文中一共展示了Scalr_Environment::azure方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Set test names for objects
*/
protected function setUp()
{
parent::setUp();
if ($this->isSkipFunctionalTests()) {
$this->markTestSkipped();
}
$testEnvId = \Scalr::config('scalr.phpunit.envid');
try {
$this->testEnv = \Scalr_Environment::init()->loadById($testEnvId);
} catch (Exception $e) {
$this->markTestSkipped('Test Environment does not exist.');
}
if (!$this->testEnv || !$this->testEnv->isPlatformEnabled(\SERVER_PLATFORMS::AZURE)) {
$this->markTestSkipped('Azure platform is not enabled.');
}
$this->azure = $this->testEnv->azure();
$this->subscriptionId = $this->azure->getEnvironment()->cloudCredentials(SERVER_PLATFORMS::AZURE)->properties[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID];
$this->resourceGroupName = 'test3-resource-group-' . $this->getInstallationId();
$this->availabilitySetName = 'test3-availability-set-' . $this->getInstallationId();
$this->vmName = 'test3-virtual-machine-' . $this->getInstallationId();
$this->vnName = 'test3-virtual-network-' . $this->getInstallationId();
$this->nicName = 'test3-network-interface' . $this->getInstallationId();
$this->publicIpName = 'myPublicIP3';
$this->storageName = 'teststorage3' . $this->getInstallationId();
$this->sgName = 'test3-security-group' . $this->getInstallationId();
}
示例2: saveAzure
private function saveAzure()
{
if (Scalr::isHostedScalr() && !$this->request->getHeaderVar('Interface-Beta')) {
$this->response->failure('Azure support available only for Scalr Enterprise Edition.');
return;
}
$enabled = false;
$currentCloudCredentials = $this->env->keychain(SERVER_PLATFORMS::AZURE);
if (empty($currentCloudCredentials->id)) {
$currentCloudCredentials = $this->makeCloudCredentials(SERVER_PLATFORMS::AZURE, [], Entity\CloudCredentials::STATUS_DISABLED);
}
/* @var $ccProps Scalr\Model\Collections\SettingsCollection */
$ccProps = $currentCloudCredentials->properties;
if ($this->getParam('azure.is_enabled')) {
$enabled = true;
$tenantName = $this->checkVar(Entity\CloudCredentialsProperty::AZURE_TENANT_NAME, 'string', "Azure Tenant name is required", SERVER_PLATFORMS::AZURE);
$ccProps->saveSettings([Entity\CloudCredentialsProperty::AZURE_AUTH_STEP => 0]);
if (!count($this->checkVarError)) {
$oldTenantName = $ccProps[Entity\CloudCredentialsProperty::AZURE_TENANT_NAME];
$ccProps->saveSettings([Entity\CloudCredentialsProperty::AZURE_TENANT_NAME => $tenantName]);
$azure = $this->env->azure();
$ccProps->saveSettings([Entity\CloudCredentialsProperty::AZURE_AUTH_STEP => 1]);
$authorizationCode = $ccProps[Entity\CloudCredentialsProperty::AZURE_AUTH_CODE];
$accessToken = $ccProps[Entity\CloudCredentialsProperty::AZURE_ACCESS_TOKEN];
if (empty($authorizationCode) && empty($accessToken) || $oldTenantName != $ccProps[Entity\CloudCredentialsProperty::AZURE_TENANT_NAME]) {
$ccProps->saveSettings([Entity\CloudCredentialsProperty::AZURE_AUTH_CODE => false, Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID => false]);
$location = $azure->getAuthorizationCodeLocation();
$this->response->data(['authLocation' => $location]);
return;
}
$ccProps->saveSettings([Entity\CloudCredentialsProperty::AZURE_AUTH_STEP => 0]);
$subscriptionId = trim($this->checkVar(Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID, 'string', "Azure Subscription id is required", SERVER_PLATFORMS::AZURE));
$params[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID] = $subscriptionId;
if (!count($this->checkVarError)) {
$oldSubscriptionId = $ccProps[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID];
if ($subscriptionId != $oldSubscriptionId) {
$azure->getClientToken();
$objectId = $azure->getAppObjectId();
$params[Entity\CloudCredentialsProperty::AZURE_CLIENT_OBJECT_ID] = $objectId;
$contributorRoleId = $azure->getContributorRoleId($subscriptionId);
$params[Entity\CloudCredentialsProperty::AZURE_CONTRIBUTOR_ID] = $contributorRoleId;
$roleAssignment = $azure->getContributorRoleAssignmentInfo($subscriptionId, $objectId, $contributorRoleId);
if (empty($roleAssignment)) {
$roleAssignmentId = \Scalr::GenerateUID();
$azure->assignContributorRoleToApp($subscriptionId, $roleAssignmentId, $objectId, $contributorRoleId);
} else {
$roleAssignmentId = $roleAssignment->name;
}
$params[Entity\CloudCredentialsProperty::AZURE_ROLE_ASSIGNMENT_ID] = $roleAssignmentId;
$ccProps->saveSettings([Entity\CloudCredentialsProperty::AZURE_CLIENT_TOKEN => false, Entity\CloudCredentialsProperty::AZURE_CLIENT_TOKEN_EXPIRE => false]);
$azure->getClientToken(Azure::URL_CORE_WINDOWS);
$ccProps->saveSettings($params);
$providersList = $azure->getProvidersList($subscriptionId);
$requiredProviders = ProviderData::getRequiredProviders();
foreach ($providersList as $providerData) {
/* @var $providerData ProviderData */
if (in_array($providerData->namespace, $requiredProviders) && $providerData->registrationState == ProviderData::REGISTRATION_STATE_NOT_REGISTERED) {
$registerResponse = $azure->registerSubscription($subscriptionId, $providerData->namespace);
}
}
if (!empty($registerResponse)) {
do {
sleep(5);
$provider = $azure->getLocationsList($registerResponse->namespace);
} while ($provider->registrationState != ProviderData::REGISTRATION_STATE_REGISTERED);
}
}
$ccProps[Entity\CloudCredentialsProperty::AZURE_AUTH_STEP] = 3;
} else {
$this->response->failure();
$this->response->data(['errors' => $this->checkVarError]);
return;
}
} else {
$this->response->failure();
$this->response->data(['errors' => $this->checkVarError]);
return;
}
}
$this->db->BeginTrans();
try {
$this->env->enablePlatform(SERVER_PLATFORMS::AZURE, $enabled);
if ($enabled) {
$currentCloudCredentials->status = Entity\CloudCredentials::STATUS_ENABLED;
$currentCloudCredentials->save();
}
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(['enabled' => $enabled]);
} catch (Exception $e) {
$this->db->RollbackTrans();
throw new Exception(_("Failed to save Azure settings: {$e->getMessage()}"));
}
$this->db->CommitTrans();
}
示例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__));
}
$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;
}