Example #1
0
 public static function setupScalrAgent(\DBServer $dbServer)
 {
     $baseurl = \Scalr::config('scalr.endpoint.scheme') . "://" . \Scalr::config('scalr.endpoint.host');
     $env = $dbServer->GetEnvironmentObject();
     $azure = $env->azure();
     $branch = $dbServer->getScalarizrRepository()['repository'];
     $develRepos = \Scalr::getContainer()->config->get('scalr.scalarizr_update.devel_repos');
     $scmBranch = $dbServer->GetFarmRoleObject()->GetSetting('user-data.scm_branch');
     if ($scmBranch != '' && $develRepos) {
         $branch = $dbServer->GetFarmRoleObject()->GetSetting('base.devel_repository');
         $scmBranch = "{$scmBranch}/";
     } else {
         $scmBranch = '';
     }
     if ($dbServer->osType == 'linux') {
         $extensionProperties = new ResourceExtensionProperties('Microsoft.OSTCExtensions', 'CustomScriptForLinux', '1.2');
         $extensionProperties->setSettings(['commandToExecute' => "bash -c 'curl -k -L \"{$baseurl}/public/linux/{$branch}/azure/{$scmBranch}install_scalarizr.sh\" | bash && service scalr-upd-client start'"]);
     } else {
         $extensionProperties = new ResourceExtensionProperties('Microsoft.Compute', 'CustomScriptExtension', '1.4');
         $extensionProperties->setSettings(["commandToExecute" => "powershell -NoProfile -ExecutionPolicy Bypass -Command \"iex ((new-object net.webclient).DownloadString('{$baseurl}/public/windows/{$branch}/{$scmBranch}install_scalarizr.ps1')); start-service ScalrUpdClient\""]);
     }
     $createExtension = new CreateResourceExtension('scalarizr', $dbServer->cloudLocation, $extensionProperties);
     try {
         $response = $azure->compute->resourceExtension->create($env->keychain(SERVER_PLATFORMS::AZURE)->properties[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID], $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::RESOURCE_GROUP), $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::SERVER_NAME), $createExtension);
         \Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->info(new \FarmLogMessage($dbServer, sprintf(_("Created azure resource extension to install and launch scalr agent"))));
         $dbServer->SetProperty(\AZURE_SERVER_PROPERTIES::SZR_EXTENSION_DEPLOYED, 1);
     } catch (\Exception $e) {
         \Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->fatal(new \FarmLogMessage($dbServer, sprintf(_("Unable to create azure resource extension to install and launch scalr agent: %s"), $e->getMessage())));
     }
 }
Example #2
0
 /**
  * Sets properties
  *
  * @param   array|ResourceExtensionProperties $properties
  * @return  CreateResourceExtension
  */
 public function setProperties($properties = null)
 {
     if (!$properties instanceof ResourceExtensionProperties) {
         $properties = ResourceExtensionProperties::initArray($properties);
     }
     return $this->__call(__FUNCTION__, [$properties]);
 }
Example #3
0
 /**
  * @test
  * @functional
  */
 public function testAzureFunctional()
 {
     $region = 'westus';
     $containerName = 'vhds';
     $osDiskName = 'osdisk1';
     $providers = $this->azure->getProvidersList($this->subscriptionId);
     $this->assertNotEmpty($providers);
     foreach ($providers as $provider) {
         /* @var $provider ProviderData */
         $this->assertNotEmpty($provider->namespace);
         $this->assertNotEmpty($provider->registrationState);
     }
     $provider = $this->azure->getLocationsList(ProviderData::RESOURCE_PROVIDER_COMPUTE);
     $this->assertNotEmpty($provider->namespace);
     $this->deleteAllTestObjects();
     $createResGroup = $this->azure->resourceManager->resourceGroup->create($this->subscriptionId, $this->resourceGroupName, $region);
     $this->assertNotEmpty($createResGroup);
     $request = new CreateAvailabilitySet($this->availabilitySetName, $region);
     $request->tags = ['key' => 'value'];
     $request->setProperties(['platformUpdateDomainCount' => 5, 'platformFaultDomainCount' => 3]);
     $createAs = $this->azure->compute->availabilitySet->create($this->subscriptionId, $this->resourceGroupName, $request);
     $this->assertNotEmpty($createAs);
     $virtualNetworkProperties = new VirtualNetworkProperties([['name' => 'mysubnet1', 'properties' => ["addressPrefix" => "10.1.0.0/24"]]]);
     $virtualNetworkProperties->addressSpace = ["addressPrefixes" => ["10.1.0.0/16", "10.2.0.0/16"]];
     $createVirtualNetwork = new CreateVirtualNetwork($this->vnName, $region, $virtualNetworkProperties);
     $vnResponse = $this->azure->network->virtualNetwork->create($this->subscriptionId, $this->resourceGroupName, $createVirtualNetwork);
     $this->assertNotEmpty($vnResponse);
     $createPublicIpAddress = new CreatePublicIpAddress($region, ["publicIPAllocationMethod" => 'Dynamic', 'settings' => ['domainNameLabel' => 'scalrtestlabel67']]);
     $nicIpAddressResponse = $this->azure->network->publicIPAddress->create($this->subscriptionId, $this->resourceGroupName, $this->publicIpName, $createPublicIpAddress);
     $this->assertNotEmpty($nicIpAddressResponse);
     $ipConfigProperties = new IpConfigurationProperties(["id" => "/subscriptions/" . $this->subscriptionId . "/resourceGroups/" . $this->resourceGroupName . "/providers/Microsoft.Network/virtualNetworks/" . $this->vnName . "/subnets/mysubnet1"], "Dynamic");
     $ipConfigProperties->publicIPAddress = ["id" => "/subscriptions/" . $this->subscriptionId . "/resourceGroups/" . $this->resourceGroupName . "/providers/Microsoft.Network/publicIPAddresses/" . $this->publicIpName];
     $nicProperties = new InterfaceProperties([new InterfaceIpConfigurationsData('ipconfig1', $ipConfigProperties)]);
     $createSecurityRule = new CreateSecurityRule('Tcp', '23-45', '46-56', '*', '*', 'Allow', 123, 'Inbound');
     $ruleData = new SecurityRuleData();
     $ruleData->name = 'rule_name';
     $ruleData->setProperties($createSecurityRule);
     $securityGroupProperties = new SecurityGroupProperties();
     $securityGroupProperties->setSecurityRules([$ruleData]);
     $createSecurityGroup = new CreateSecurityGroup($region);
     $createSecurityGroup->setProperties($securityGroupProperties);
     $sgResponse = $this->azure->network->securityGroup->create($this->subscriptionId, $this->resourceGroupName, $this->sgName, $createSecurityGroup);
     $this->assertNotEmpty($sgResponse);
     $secGroupId = "/subscriptions/" . $this->subscriptionId . "/resourceGroups/" . $this->resourceGroupName . "/providers/Microsoft.Network/networkSecurityGroups/" . $this->sgName;
     $nicProperties->setNetworkSecurityGroup(['id' => $secGroupId]);
     $createNic = new CreateInterface($region, $nicProperties);
     $nicResponse = $this->azure->network->interface->create($this->subscriptionId, $this->resourceGroupName, $this->nicName, $createNic);
     $this->assertNotEmpty($nicResponse);
     $nicInfo = $this->azure->network->interface->getInfo($this->subscriptionId, $this->resourceGroupName, $this->nicName);
     $this->assertNotEmpty($nicInfo);
     $disassociate = $this->azure->network->publicIPAddress->disassociate($this->subscriptionId, $this->resourceGroupName, $this->nicName, $this->publicIpName);
     $this->assertTrue($disassociate);
     $associate = $this->azure->network->publicIPAddress->associate($this->subscriptionId, $this->resourceGroupName, $this->nicName, $this->publicIpName);
     $this->assertTrue($associate);
     $createStorage = new AccountData($region, ['accountType' => 'Standard_LRS']);
     $storageResponse = $this->azure->storage->account->create($this->subscriptionId, $this->resourceGroupName, $this->storageName, $createStorage);
     $this->assertNotEmpty($storageResponse);
     $networkProfile = ["networkInterfaces" => [["id" => "/subscriptions/" . $this->subscriptionId . "/resourceGroups/" . $this->resourceGroupName . "/providers/Microsoft.Network/networkInterfaces/" . $this->nicName]]];
     $osProfile = new OsProfile('vladtest34', 'Tex6-HBU*7');
     $osProfile->computerName = 'testscalr';
     $vhd = ['uri' => 'https://' . $this->storageName . '.blob.core.windows.net/' . $containerName . '/' . $osDiskName . '.vhd'];
     $storageProfile = new StorageProfile(new OsDisk($osDiskName, $vhd, 'FromImage'));
     $publishers = $this->azure->compute->location->getPublishersList($this->subscriptionId, $region);
     $this->assertNotEmpty($publishers);
     $offers = null;
     foreach ($publishers as $publisher) {
         $this->assertObjectHasAttribute('name', $publisher);
         $offers = $this->azure->compute->location->getOffersList($this->subscriptionId, $region, $publisher->name);
         if (!empty($offers)) {
             break;
         }
     }
     $this->assertNotNull($offers);
     $offer = reset($offers);
     $this->assertObjectHasAttribute('name', $offer);
     $skus = $this->azure->compute->location->getSkusList($this->subscriptionId, $region, $publisher->name, $offer->name);
     $this->assertNotEmpty($skus);
     $sku = reset($skus);
     $this->assertObjectHasAttribute('name', $sku);
     $versions = $this->azure->compute->location->getVersionsList($this->subscriptionId, $region, $publisher->name, $offer->name, $sku->name);
     $this->assertNotEmpty($versions);
     $version = reset($versions);
     $this->assertObjectHasAttribute('name', $version);
     $storageProfile->setImageReference(['publisher' => 'Canonical', 'offer' => 'UbuntuServer', 'sku' => '14.04.2-LTS', 'version' => 'latest']);
     $vmProperties = new VirtualMachineProperties(["vmSize" => "Standard_A0"], $networkProfile, $storageProfile, $osProfile);
     //$this->azure->getClient()->setDebug();
     $vmRequest = new CreateVirtualMachine($this->vmName, $region, $vmProperties);
     $createVm = $this->azure->compute->virtualMachine->create($this->subscriptionId, $this->resourceGroupName, $vmRequest);
     $this->assertNotEmpty($createVm);
     $modelInfo = $this->azure->compute->virtualMachine->getModelViewInfo($this->subscriptionId, $this->resourceGroupName, $this->vmName, true);
     $this->assertNotEmpty($modelInfo);
     $extensionProperties = new ResourceExtensionProperties('Microsoft.OSTCExtensions', 'CustomScriptForLinux', '1.2');
     // for Windows use "new ResourceExtensionProperties('Microsoft.Compute', 'CustomScriptExtension', '1.0')"
     $extensionProperties->setSettings(['fileUris' => ["http://tru4.scalr.com/public/installScalarizr?osType=linux&repo=latest&platform=azure"], 'commandToExecute' => 'bash -c "cat installScalarizr | bash && service scalr-upd-client start"']);
     $createExtension = new CreateResourceExtension('scalarizr', $region, $extensionProperties);
     $this->azure->compute->resourceExtension->create($this->subscriptionId, $this->resourceGroupName, $this->vmName, $createExtension);
     $this->deleteAllTestObjects();
 }