示例#1
0
 /**
  * Create an availability set for virtual machines.
  *
  * @param string $subscriptionId    Subscription Id
  * @param string $resourceGroupName Name of Resource Group for new Availability Set
  * @param array|CreateAvailabilitySet|AvailabilitySetData $requestData    Request data object or array
  *
  * @return AvailabilitySetData Object with response
  */
 public function create($subscriptionId, $resourceGroupName, $requestData)
 {
     $result = null;
     if (!$requestData instanceof CreateAvailabilitySet && !$requestData instanceof AvailabilitySetData) {
         $requestData = CreateAvailabilitySet::initArray($requestData);
     }
     $path = '/subscriptions/' . $subscriptionId . '/resourceGroups/' . $resourceGroupName . ComputeService::ENDPOINT_MICROSOFT_COMPUTE . '/availabilitySets/' . $requestData->name;
     if (empty($requestData->id)) {
         $requestData->id = $path;
     }
     $request = $this->getClient()->prepareRequest($path, 'PUT', $this->getApiVersion(), $this->getServiceUrl(), [], $requestData->toArray());
     $response = $this->getClient()->call($request);
     if (!$response->hasError()) {
         $result = AvailabilitySetData::initArray($response->getResult());
     }
     return $result;
 }
示例#2
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();
 }