/** * @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(); }
/** * Gets Security Rules list * * @param array|SecurityRuleList $securityRules * @return SecurityRuleList */ private function getRuleList($securityRules) { if (!$securityRules instanceof SecurityRuleList) { $securityRuleList = new SecurityRuleList(); foreach ($securityRules as $securityRule) { if (!$securityRule instanceof SecurityRuleData) { $securityRuleData = SecurityRuleData::initArray($securityRule); } else { $securityRuleData = $securityRule; } $securityRuleList->append($securityRuleData); } } else { $securityRuleList = $securityRules; } return $securityRuleList; }
/** * Gets default security rule's info in a security group. * * @param string $subscriptionId Subscription Id * @param string $resourceGroupName Name of Resource Group * @param string $securityGroupName Name of Security Group * @param string $securityRuleName Name of Security Rule * * @return SecurityRuleData Object with response */ public function getInfoDefault($subscriptionId, $resourceGroupName, $securityGroupName, $securityRuleName) { $result = null; $path = '/subscriptions/' . $subscriptionId . '/resourceGroups/' . $resourceGroupName . NetworkService::ENDPOINT_MICROSOFT_NETWORK . '/networkSecurityGroups/' . $securityGroupName . '/defaultSecurityRules/' . $securityRuleName; $request = $this->getClient()->prepareRequest($path, 'GET', $this->getApiVersion()); $response = $this->getClient()->call($request); if (!$response->hasError()) { $result = SecurityRuleData::initArray($response->getResult()); } return $result; }