Пример #1
0
        public async Task CreateStorageAccountTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var storageNamePrefix      = Environment.GetEnvironmentVariable("AZURE_STORAGENAME_PREFIX");
            var storageAccountName     = string.Format("{0}{1}", storageNamePrefix, new Random().Next(0, 99));
            var storageAccountSku      = Profile2018Storage.Models.SkuName.StandardLRS;
            var credentials            = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var storageController  = new StorageController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE STORAGE ACCOUNT
            var storageAccount = await storageController.CreateStorageAccount(storageAccountName, resourceGroupName, location, storageAccountSku);

            // VALIDATION
            Assert.Equal("OK", storageAccount.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(storageAccount.Body);
            Assert.Equal("Succeeded", storageAccount.Body.ProvisioningState.ToString(), ignoreCase: true);
        }
Пример #2
0
        public async Task CreateLinuxVirtualMachineTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var vmName             = Environment.GetEnvironmentVariable("AZURE_VM_NAME");
            var vnetName           = Environment.GetEnvironmentVariable("AZURE_VNET_NAME");
            var subnetNames        = Environment.GetEnvironmentVariable("AZURE_SUBNET_NAMES");
            var subnetAddresses    = Environment.GetEnvironmentVariable("AZURE_SUBNET_ADDRESSES");
            var vnetAddresses      = Environment.GetEnvironmentVariable("AZURE_VNET_ADDRESSES");
            var ipName             = Environment.GetEnvironmentVariable("AZURE_IP_NAME");
            var nicName            = Environment.GetEnvironmentVariable("AZURE_NIC_NAME");
            var storageNamePrefix  = Environment.GetEnvironmentVariable("AZURE_STORAGENAME_PREFIX");
            var storageEndpoint    = Environment.GetEnvironmentVariable("AZURE_STORAGE_ENDPOINT");
            var storageAccountName = string.Format("{0}{1}", storageNamePrefix, new Random().Next(0, 99));
            var storageAccountSku  = Profile2018Storage.Models.SkuName.StandardLRS;
            var credentials        = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var networkController  = new NetworkController(new Uri(baseUriString), credentials, subscriptionId);
            var storageController  = new StorageController(new Uri(baseUriString), credentials, subscriptionId);
            var computerController = new ComputeController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE VNET
            var vnetAddressSpaces = vnetAddresses.Split(';');
            var subNames          = subnetNames.Split(';');
            var suAddresses       = subnetAddresses.Split(';');
            var subnets           = new Dictionary <string, string>();

            for (int i = 0; i < subNames.Length; i++)
            {
                subnets.Add(subNames[i], suAddresses[i]);
            }

            var vnet = await networkController.CreateVirtualNetwork(vnetName, vnetAddressSpaces, resourceGroupName, location, subnets);

            // CREATE VNET VALIDATION
            Assert.Equal("OK", vnet.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vnet.Body);

            // CREATE IP
            var ip = await networkController.CreatePublicIpAddress(ipName, resourceGroupName, location);

            // CREATE IP VALIDATION
            Assert.Equal("OK", ip.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(ip.Body);

            // CREATE NIC
            var nic = await networkController.CreateNetworkInterface(nicName, resourceGroupName, vnetName, subNames[0], ipName, location);

            // CREATE NIC VALIDATION
            Assert.Equal("OK", nic.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(nic.Body);
            Assert.Equal("Succeeded", nic.Body.ProvisioningState, ignoreCase: true);

            // CREATE STORAGE ACCOUNT
            var storageAccount = await storageController.CreateStorageAccount(storageAccountName, resourceGroupName, location, storageAccountSku);

            // STORAGE ACCOUNT VALIDATION
            Assert.Equal("OK", storageAccount.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(storageAccount.Body);
            Assert.Equal("Succeeded", storageAccount.Body.ProvisioningState.ToString(), ignoreCase: true);

            // CREATE VM
            var vm = await computerController.CreateVirtialMachine(resourceGroupName, vmName, storageAccountName, storageEndpoint, nic.Body.Id, location);

            // VALIDATION
            Assert.Equal("OK", vm.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vm.Body);
            Assert.Equal("Succeeded", vm.Body.ProvisioningState.ToString(), ignoreCase: true);
        }