示例#1
0
        public void VmssPublicIpAddressApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1, true);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);

                var    location          = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Compute/virtualMachineScaleSets");
                string resourceGroupName = TestUtilities.GenerateName();
                string deploymentName    = TestUtilities.GenerateName("vmss");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                DeploymentUpdate.CreateVmss(resourcesClient, resourceGroupName, deploymentName);

                string virtualMachineScaleSetName = "vmssip";
                var    vmssListAllPageResult      = networkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetPublicIPAddresses(resourceGroupName, virtualMachineScaleSetName);
                var    vmssListAllResult          = vmssListAllPageResult.ToList();
                var    firstResult = vmssListAllResult.First();

                Assert.NotNull(vmssListAllResult);
                Assert.Equal("Succeeded", firstResult.ProvisioningState);
                Assert.NotNull(firstResult.ResourceGuid);

                var idItem       = firstResult.Id;
                var vmIndex      = GetNameById(idItem, "virtualMachines");
                var nicName      = GetNameById(idItem, "networkInterfaces");
                var ipConfigName = GetNameById(idItem, "ipConfigurations");
                var ipName       = GetNameById(idItem, "publicIPAddresses");

                var vmssListPageResult = networkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetVMPublicIPAddresses(
                    resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName, ipConfigName);
                var vmssListResult = vmssListPageResult.ToList();

                Assert.Single(vmssListResult);

                var vmssGetResult = networkManagementClient.PublicIPAddresses.GetVirtualMachineScaleSetPublicIPAddress(
                    resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName, ipConfigName, ipName);

                Assert.NotNull(vmssGetResult);
                Assert.Equal("Succeeded", vmssGetResult.ProvisioningState);
                Assert.NotNull(vmssGetResult.ResourceGuid);

                resourcesClient.ResourceGroups.Delete(resourceGroupName);
            }
        }
        public void VmssNetworkInterfaceApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1, true);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);

                var    location          = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Compute/virtualMachineScaleSets");
                string resourceGroupName = TestUtilities.GenerateName();
                string deploymentName    = TestUtilities.GenerateName("vmss");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                DeploymentUpdate.CreateVmss(resourcesClient, resourceGroupName, deploymentName);

                string virtualMachineScaleSetName = "vmssip";
                var    vmssListAllPageResult      = networkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetPublicIPAddresses(resourceGroupName, virtualMachineScaleSetName);
                var    vmssListAllResult          = vmssListAllPageResult.ToList();
                var    firstResult = vmssListAllResult.First();

                Assert.NotNull(vmssListAllResult);
                Assert.Equal("Succeeded", firstResult.ProvisioningState);
                Assert.NotNull(firstResult.ResourceGuid);

                var idItem       = firstResult.Id;
                var vmIndex      = GetNameById(idItem, "virtualMachines");
                var nicName      = GetNameById(idItem, "networkInterfaces");
                var ipConfigName = GetNameById(idItem, "ipConfigurations");
                var ipName       = GetNameById(idItem, "publicIPAddresses");

                // Verify that NICs contain refernce to publicip, nsg and dns settings
                var listNicPerVmss = networkManagementClient.NetworkInterfaces.ListVirtualMachineScaleSetNetworkInterfaces(resourceGroupName, virtualMachineScaleSetName).ToList();
                Assert.NotNull(listNicPerVmss);

                foreach (var nic in listNicPerVmss)
                {
                    this.VerifyVmssNicProperties(nic);
                }

                // Verify nics on a vm level
                var listNicPerVm = networkManagementClient.NetworkInterfaces.ListVirtualMachineScaleSetVMNetworkInterfaces(resourceGroupName, virtualMachineScaleSetName, vmIndex).ToList();
                Assert.NotNull(listNicPerVm);
                Assert.Single(listNicPerVm);

                foreach (var nic in listNicPerVm)
                {
                    this.VerifyVmssNicProperties(nic);
                }

                // Verify getting individual nic
                var getNic = networkManagementClient.NetworkInterfaces.GetVirtualMachineScaleSetNetworkInterface(resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName);
                Assert.NotNull(getNic);
                this.VerifyVmssNicProperties(getNic);

                resourcesClient.ResourceGroups.Delete(resourceGroupName);
            }
        }