Ejemplo n.º 1
0
        protected PublicIPAddress CreatePublicIP(string rgName)
        {
            // Create publicIP
            string publicIpName    = ComputeManagementTestUtilities.GenerateName("pip");
            string domainNameLabel = ComputeManagementTestUtilities.GenerateName("dn");

            var publicIp = new PublicIPAddress()
            {
                Location = m_location,
                Tags     = new Dictionary <string, string>()
                {
                    { "key", "value" }
                },
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = domainNameLabel
                }
            };

            var putPublicIpAddressResponse = m_NrpClient.PublicIPAddresses.CreateOrUpdate(rgName, publicIpName, publicIp);
            var getPublicIpAddressResponse = m_NrpClient.PublicIPAddresses.Get(rgName, publicIpName);

            return(getPublicIpAddressResponse);
        }
Ejemplo n.º 2
0
        protected PublicIPAddress CreatePublicIP(string publicIPAddressName, string resourceGroupName, string dnsName)
        {
            PublicIPAddress publicIPAddressParams = GeneratePublicIPAddressModel(publicIPAddressName, dnsName);
            PublicIPAddress publicIpAddress       = m_NrpClient.PublicIPAddresses.CreateOrUpdate(resourceGroupName, publicIPAddressName, publicIPAddressParams);

            return(publicIpAddress);
        }
        async Task <PublicIPAddress> SetupPublicIPAsync(ApiManagementTestBase testBase)
        {
            // put Public IP
            string publicIpName    = TestUtilities.GenerateName();
            string domainNameLabel = TestUtilities.GenerateName(testBase.rgName);

            var publicIp = new PublicIPAddress()
            {
                Location = testBase.location,
                Tags     = new Dictionary <string, string>()
                {
                    { "key", "value" }
                },
                PublicIPAllocationMethod = IPAllocationMethod.Static,
                PublicIPAddressVersion   = "IPv4",
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = domainNameLabel
                },
                Sku = new PublicIPAddressSku()
                {
                    Name = "Standard"
                }
            };
            var putPublicIPResponse = await testBase.networkClient.PublicIPAddresses.CreateOrUpdateAsync(testBase.rgName, publicIpName, publicIp);

            Assert.Equal("Succeeded", putPublicIPResponse.ProvisioningState);

            return(putPublicIPResponse);
        }
Ejemplo n.º 4
0
        public static PublicIPAddress CreateDefaultPublicIpAddress(string name, string resourceGroupName, string domainNameLabel, string location,
                                                                   NetworkManagementClient nrpClient)
        {
            var publicIp = new PublicIPAddress()
            {
                Location = location,
                Tags     = new Dictionary <string, string>()
                {
                    { "key", "value" }
                },
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = domainNameLabel
                }
            };

            // Put nic1PublicIpAddress
            var putPublicIpAddressResponse = nrpClient.PublicIPAddresses.CreateOrUpdate(resourceGroupName, name, publicIp);

            Assert.Equal("Succeeded", putPublicIpAddressResponse.ProvisioningState);
            var getPublicIpAddressResponse = nrpClient.PublicIPAddresses.Get(resourceGroupName, name);

            return(getPublicIpAddressResponse);
        }
        public async Task PublicIpAddressApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("csmrg");

            string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/publicIPAddresses");

            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            // Create the parameter for PUT PublicIPAddress
            string publicIpName    = Recording.GenerateAssetName("ipname");
            string domainNameLabel = Recording.GenerateAssetName("domain");

            PublicIPAddress publicIp = new PublicIPAddress()
            {
                Location = location,
                Tags     = { { "key", "value" } },
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = domainNameLabel
                }
            };

            // Put PublicIPAddress
            PublicIPAddressesCreateOrUpdateOperation putPublicIpAddressResponseOperation = await NetworkManagementClient.PublicIPAddresses.StartCreateOrUpdateAsync(resourceGroupName, publicIpName, publicIp);

            Response <PublicIPAddress> putPublicIpAddressResponse = await WaitForCompletionAsync(putPublicIpAddressResponseOperation);

            Assert.AreEqual("Succeeded", putPublicIpAddressResponse.Value.ProvisioningState.ToString());

            // Get PublicIPAddress
            Response <PublicIPAddress> getPublicIpAddressResponse = await NetworkManagementClient.PublicIPAddresses.GetAsync(resourceGroupName, publicIpName);

            Assert.AreEqual(4, getPublicIpAddressResponse.Value.IdleTimeoutInMinutes);
            Assert.NotNull(getPublicIpAddressResponse.Value.ResourceGuid);

            // Get List of PublicIPAddress
            AsyncPageable <PublicIPAddress> getPublicIpAddressListResponseAP = NetworkManagementClient.PublicIPAddresses.ListAsync(resourceGroupName);
            List <PublicIPAddress>          getPublicIpAddressListResponse   = await getPublicIpAddressListResponseAP.ToEnumerableAsync();

            Has.One.EqualTo(getPublicIpAddressListResponse);
            ArePublicIpAddressesEqual(getPublicIpAddressResponse, getPublicIpAddressListResponse.First());

            // Get List of PublicIPAddress in a subscription
            AsyncPageable <PublicIPAddress> getPublicIpAddressListSubscriptionResponseAP = NetworkManagementClient.PublicIPAddresses.ListAllAsync();
            List <PublicIPAddress>          getPublicIpAddressListSubscriptionResponse   = await getPublicIpAddressListSubscriptionResponseAP.ToEnumerableAsync();

            Assert.IsNotEmpty(getPublicIpAddressListSubscriptionResponse);

            // Delete PublicIPAddress
            PublicIPAddressesDeleteOperation deleteOperation = await NetworkManagementClient.PublicIPAddresses.StartDeleteAsync(resourceGroupName, publicIpName);

            await WaitForCompletionAsync(deleteOperation);

            // Get PublicIPAddress
            getPublicIpAddressListResponseAP = NetworkManagementClient.PublicIPAddresses.ListAsync(resourceGroupName);
            getPublicIpAddressListResponse   = await getPublicIpAddressListResponseAP.ToEnumerableAsync();

            Assert.IsEmpty(getPublicIpAddressListResponse);
        }
Ejemplo n.º 6
0
 public async Task TestSetUp()
 {
     var client = GetArmClient();
     _resourceGroup = await client.GetResourceGroup(_resourceGroupIdentifier).GetAsync();
     _network = await _resourceGroup.GetVirtualNetworks().GetAsync(_networkIdentifier.Name);
     _publicIPAddress = await _resourceGroup.GetPublicIPAddresses().GetAsync(_publicIPAddressIdentifier.Name);
 }
Ejemplo n.º 7
0
        public async Task <PublicIPAddress> CreateDefaultPublicIpAddress(string name, string resourceGroupName, string domainNameLabel, string location,
                                                                         NetworkManagementClient nrpClient)
        {
            PublicIPAddress publicIp = new PublicIPAddress()
            {
                Location = location,
                Tags     = new Dictionary <string, string>()
                {
                    { "key", "value" }
                },
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = domainNameLabel
                }
            };

            // Put nic1PublicIpAddress
            Operation <PublicIPAddress> putPublicIpAddressOperation = await nrpClient.PublicIPAddresses.StartCreateOrUpdateAsync(resourceGroupName, name, publicIp);

            Response <PublicIPAddress> putPublicIpAddressResponse = await WaitForCompletionAsync(putPublicIpAddressOperation);

            Assert.AreEqual("Succeeded", putPublicIpAddressResponse.Value.ProvisioningState.ToString());
            Response <PublicIPAddress> getPublicIpAddressResponse = await nrpClient.PublicIPAddresses.GetAsync(resourceGroupName, name);

            return(getPublicIpAddressResponse);
        }
Ejemplo n.º 8
0
 internal IPConfiguration(string id, string name, string etag, string privateIPAddress, IPAllocationMethod?privateIPAllocationMethod, Subnet subnet, PublicIPAddress publicIPAddress, ProvisioningState?provisioningState) : base(id)
 {
     Name                      = name;
     Etag                      = etag;
     PrivateIPAddress          = privateIPAddress;
     PrivateIPAllocationMethod = privateIPAllocationMethod;
     Subnet                    = subnet;
     PublicIPAddress           = publicIPAddress;
     ProvisioningState         = provisioningState;
 }
        public async Task VmssNetworkInterfaceApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

            string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Compute/virtualMachineScaleSets");

            string deploymentName = Recording.GenerateAssetName("vmss");
            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            await CreateVmss(ResourceManagementClient, resourceGroupName, deploymentName);

            string virtualMachineScaleSetName = "vmssip";
            AsyncPageable <PublicIPAddress> vmssListAllPageResultAP = NetworkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetPublicIPAddressesAsync(resourceGroupName, virtualMachineScaleSetName);
            List <PublicIPAddress>          vmssListAllPageResult   = await vmssListAllPageResultAP.ToEnumerableAsync();

            List <PublicIPAddress> vmssListAllResult = vmssListAllPageResult.ToList();
            PublicIPAddress        firstResult       = vmssListAllResult.First();

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

            string idItem  = firstResult.Id;
            string vmIndex = GetNameById(idItem, "virtualMachines");
            string nicName = GetNameById(idItem, "networkInterfaces");

            // Verify that NICs contain refernce to publicip, nsg and dns settings
            AsyncPageable <NetworkInterface> listNicPerVmssAP = NetworkManagementClient.NetworkInterfaces.ListVirtualMachineScaleSetNetworkInterfacesAsync(resourceGroupName, virtualMachineScaleSetName);
            List <NetworkInterface>          listNicPerVmss   = await listNicPerVmssAP.ToEnumerableAsync();

            Assert.NotNull(listNicPerVmss);

            foreach (NetworkInterface nic in listNicPerVmss)
            {
                VerifyVmssNicProperties(nic);
            }

            // Verify nics on a vm level
            AsyncPageable <NetworkInterface> listNicPerVmAP = NetworkManagementClient.NetworkInterfaces.ListVirtualMachineScaleSetVMNetworkInterfacesAsync(resourceGroupName, virtualMachineScaleSetName, vmIndex);
            List <NetworkInterface>          listNicPerVm   = await listNicPerVmAP.ToEnumerableAsync();

            Assert.NotNull(listNicPerVm);
            Has.One.EqualTo(listNicPerVm);

            foreach (NetworkInterface nic in listNicPerVm)
            {
                VerifyVmssNicProperties(nic);
            }

            // Verify getting individual nic
            Response <NetworkInterface> getNic = await NetworkManagementClient.NetworkInterfaces.GetVirtualMachineScaleSetNetworkInterfaceAsync(resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName);

            Assert.NotNull(getNic);
            VerifyVmssNicProperties(getNic);
        }
        public ArmBuilder <PublicIpAddress, PublicIPAddressData> Construct(Location location = null)
        {
            var ipAddress = new PublicIPAddress()
            {
                PublicIPAddressVersion   = IPVersion.IPv4.ToString(),
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                Location = location ?? DefaultLocation,
            };

            return(new ArmBuilder <PublicIpAddress, PublicIPAddressData>(this, new PublicIPAddressData(ipAddress)));
        }
        public static AzurePublicIpAddress ConstructIPAddress(this AzureResourceGroupBase resourceGroup)
        {
            var ipAddress = new PublicIPAddress()
            {
                PublicIPAddressVersion   = Azure.ResourceManager.Network.Models.IPVersion.IPv4.ToString(),
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                Location = resourceGroup.Location,
            };

            return(new AzurePublicIpAddress(resourceGroup, new PhPublicIPAddress(ipAddress)));
        }
 private static void ArePublicIpAddressesEqual(PublicIPAddress publicIpAddress1, PublicIPAddress publicIpAddress2)
 {
     Assert.Equal(publicIpAddress1.Name, publicIpAddress2.Name);
     Assert.Equal(publicIpAddress1.Location, publicIpAddress2.Location);
     Assert.Equal(publicIpAddress1.Id, publicIpAddress2.Id);
     Assert.Equal(publicIpAddress1.DnsSettings.DomainNameLabel, publicIpAddress2.DnsSettings.DomainNameLabel);
     Assert.Equal(publicIpAddress1.DnsSettings.Fqdn, publicIpAddress2.DnsSettings.Fqdn);
     Assert.Equal(publicIpAddress1.IdleTimeoutInMinutes, publicIpAddress2.IdleTimeoutInMinutes);
     Assert.Equal(publicIpAddress1.Tags.Count, publicIpAddress2.Tags.Count);
     Assert.Equal(publicIpAddress1.PublicIPAddressVersion, publicIpAddress2.PublicIPAddressVersion);
 }
        public PSPublicIpAddress ToPsPublicIpAddress(PublicIPAddress publicIp)
        {
            var psPublicIpAddress = Mapper.Map<PSPublicIpAddress>(publicIp);

            psPublicIpAddress.Tag = TagsConversionHelper.CreateTagHashtable(publicIp.Tags);

            if (string.IsNullOrEmpty(psPublicIpAddress.IpAddress))
            {
                psPublicIpAddress.IpAddress = "Not Assigned";
            }
            return psPublicIpAddress;
        }
        public PSPublicIpAddress ToPsPublicIpAddress(PublicIPAddress publicIp)
        {
            var psPublicIpAddress = Mapper.Map <PSPublicIpAddress>(publicIp);

            psPublicIpAddress.Tag = TagsConversionHelper.CreateTagHashtable(publicIp.Tags);

            if (string.IsNullOrEmpty(psPublicIpAddress.IpAddress))
            {
                psPublicIpAddress.IpAddress = "Not Assigned";
            }
            return(psPublicIpAddress);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Construct an object used to create a public IP address.
        /// </summary>
        /// <param name="location"> The location to create the network security group. </param>
        /// <returns> Object used to create a <see cref="PublicIpAddress"/>. </returns>
        public ArmBuilder <PublicIpAddress, PublicIPAddressData> Construct(LocationData location = null)
        {
            var parent    = GetParentResource <ResourceGroup, ResourceGroupOperations>();
            var ipAddress = new PublicIPAddress()
            {
                PublicIPAddressVersion   = IPVersion.IPv4.ToString(),
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                Location = location ?? parent.Data.Location,
            };

            return(new ArmBuilder <PublicIpAddress, PublicIPAddressData>(this, new PublicIPAddressData(ipAddress)));
        }
Ejemplo n.º 16
0
        public async Task TestSetUp()
        {
            var client = GetArmClient();
            var _      = await client.GetDefaultSubscriptionAsync(); // TODO: hack to avoid mismatch of recordings so we don't need to re-record for the change. Remove when you need to run live tests next time.

            _resourceGroup = await client.GetResourceGroup(_resourceGroupIdentifier).GetAsync();

            VirtualNetwork vnet = await _resourceGroup.GetVirtualNetworks().GetAsync(_subnetIdentifier.Parent.Name);

            _subnet = await vnet.GetSubnets().GetAsync(_subnetIdentifier.Name);

            _publicIPAddress = await _resourceGroup.GetPublicIPAddresses().GetAsync(_publicIPAddressIdentifier.Name);
        }
        public async Task GlobalSetUp()
        {
            Subscription subscription = await GlobalClient.GetDefaultSubscriptionAsync();

            var rgLro = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, SessionRecording.GenerateAssetName("FirewallRG-"), new ResourceGroupData(AzureLocation.WestUS2));

            ResourceGroup rg = rgLro.Value;

            _resourceGroupIdentifier = rg.Id;

            VirtualNetworkData vnetData = new VirtualNetworkData()
            {
                Location     = AzureLocation.WestUS2,
                AddressSpace = new AddressSpace()
                {
                    AddressPrefixes = { "10.20.0.0/16", }
                },
                Subnets =
                {
                    new SubnetData()
                    {
                        Name = "Default", AddressPrefix = "10.20.1.0/26",
                    },
                    new SubnetData()
                    {
                        Name = "AzureFirewallSubnet", AddressPrefix = "10.20.2.0/26",
                    },
                },
            };
            var vnetLro = await rg.GetVirtualNetworks().CreateOrUpdateAsync(true, SessionRecording.GenerateAssetName("vnet-"), vnetData);

            _network           = vnetLro.Value;
            _networkIdentifier = _network.Id;

            PublicIPAddressData ipData = new PublicIPAddressData()
            {
                Location = AzureLocation.WestUS2,
                PublicIPAllocationMethod = IPAllocationMethod.Static,
                Sku = new PublicIPAddressSku()
                {
                    Name = PublicIPAddressSkuName.Standard
                },
            };
            var ipLro = await rg.GetPublicIPAddresses().CreateOrUpdateAsync(true, SessionRecording.GenerateAssetName("publicIp-"), ipData);

            _publicIPAddress           = ipLro.Value;
            _publicIPAddressIdentifier = _publicIPAddress.Id;

            _firewallName = SessionRecording.GenerateAssetName("firewall-");
            await StopSessionRecordingAsync();
        }
 public static void PrintIPAddress(PublicIPAddress publicIPAddress)
 {
     Utilities.Log(new StringBuilder().Append("Public IP Address: ").Append(publicIPAddress.Id)
                   .Append("Name: ").Append(publicIPAddress.Name)
                   .Append("\n\tLocation: ").Append(publicIPAddress.Location)
                   .Append("\n\tTags: ").Append(FormatDictionary(publicIPAddress.Tags))
                   .Append("\n\tIP Address: ").Append(publicIPAddress.IpAddress)
                   .Append("\n\tLeaf domain label: ").Append(publicIPAddress.DnsSettings.DomainNameLabel)
                   .Append("\n\tFQDN: ").Append(publicIPAddress.DnsSettings.Fqdn)
                   .Append("\n\tReverse FQDN: ").Append(publicIPAddress.DnsSettings.ReverseFqdn)
                   .Append("\n\tIdle timeout (minutes): ").Append(publicIPAddress.IdleTimeoutInMinutes)
                   .Append("\n\tIP allocation method: ").Append(publicIPAddress.PublicIPAllocationMethod)
                   .ToString());
 }
Ejemplo n.º 19
0
        protected PublicIPAddress GeneratePublicIPAddressModel(string publicIPAddressName, string dnsName)
        {
            PublicIPAddress publicIPAddressParams = new PublicIPAddress(name: publicIPAddressName)
            {
                Location = m_location,
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = dnsName
                }
            };

            return(publicIPAddressParams);
        }
Ejemplo n.º 20
0
        public override bool Validate()
        {
            // TODO add these under a timeout
            try
            {
                // TODO Include test name in the logs
                logger.Info("Validations for Linux in progress...");

                var  token             = AzureHelper.GetAccessTokenAsync();
                var  credential        = new TokenCredentials(token.Result.AccessToken);
                bool ifCustomDataValid = true;

                PublicIPAddress ipAddress = AzureHelper.GetPublicAddressAsync(credential, groupName, subscriptionId, "myPublicIP").Result;

                using (var client = new SshClient(ipAddress.IpAddress, username, password))
                {
                    client.Connect();

                    SshCommand command = client.RunCommand("echo 'hello'");
                    logger.Info("Result of command 'x': " + command.Result);

                    if (!string.IsNullOrWhiteSpace(customData))
                    {
                        command           = client.RunCommand("echo '<PASSWORD>' | sudo -S cat /var/lib/waagent/CustomData");
                        ifCustomDataValid = command.Result.Contains(customData);
                    }

                    client.Disconnect();
                }

                if (!ifCustomDataValid)
                {
                    throw new ArgumentException("Incorrect custom data!!");
                }

                logger.Info("Validations for Linux...success!!");
            }
            catch (Exception e)
            {
                logger.Error(e);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 21
0
        public static void UseExistingPublicIP(this NetworkInterface nic, PublicIPAddress publicIp)
        {
            EnsureIpConfigrationsCollectionInitialized(nic);

            if (nic.IpConfigurations.Count == 0)
            {
                nic.IpConfigurations.Add(new NetworkInterfaceIPConfiguration()
                {
                    Name    = "Primary",
                    Primary = true,
                });
            }

            nic.IpConfigurations.First().PublicIPAddress = new PublicIPAddress()
            {
                Id = publicIp.Id
            };
        }
Ejemplo n.º 22
0
        public static NetworkInterface CreateNetworkInterface(SqlVirtualMachineTestContext context, VirtualNetwork virtualNetwork = null, NetworkSecurityGroup networkSecurityGroup = null)
        {
            // Create NIC
            MockClient client = context.client;
            ComputeManagementClient computeClient = client.computeClient;

            // Create virtual network
            string subnetName = context.generateResourceName();

            if (virtualNetwork == null)
            {
                virtualNetwork = CreateVirtualNetwork(context, subnetName: subnetName);
            }
            Subnet subnet = virtualNetwork.Subnets[0];

            // Create pbulic IP address
            PublicIPAddress publicIPAddress = CreatePublicIP(context);

            // Create Network security group
            if (networkSecurityGroup == null)
            {
                networkSecurityGroup = CreateNsg(context);
            }

            NetworkInterface nicParameters = new NetworkInterface()
            {
                Location         = context.location,
                IpConfigurations = new List <NetworkInterfaceIPConfiguration>()
                {
                    new NetworkInterfaceIPConfiguration()
                    {
                        Name   = context.generateResourceName(),
                        Subnet = subnet,
                        PrivateIPAllocationMethod = IPAllocationMethod.Dynamic,
                        PublicIPAddress           = publicIPAddress
                    }
                },
                NetworkSecurityGroup = networkSecurityGroup
            };
            string nicName = context.generateResourceName();

            client.networkClient.NetworkInterfaces.CreateOrUpdate(context.resourceGroup.Name, nicName, nicParameters);
            return(client.networkClient.NetworkInterfaces.Get(context.resourceGroup.Name, nicName));
        }
        public async Task VmssPublicIpAddressApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

            string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Compute/virtualMachineScaleSets");

            string deploymentName = Recording.GenerateAssetName("vmss");
            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            await CreateVmss(ResourceManagementClient, resourceGroupName, deploymentName);

            string virtualMachineScaleSetName = "vmssip";
            AsyncPageable <PublicIPAddress> vmssListAllPageResultAP = NetworkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetPublicIPAddressesAsync(resourceGroupName, virtualMachineScaleSetName);
            List <PublicIPAddress>          vmssListAllPageResult   = await vmssListAllPageResultAP.ToEnumerableAsync();

            List <PublicIPAddress> vmssListAllResult = vmssListAllPageResult.ToList();
            PublicIPAddress        firstResult       = vmssListAllResult.First();

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

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

            AsyncPageable <PublicIPAddress> vmssListPageResultAP = NetworkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetVMPublicIPAddressesAsync(
                resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName, ipConfigName);
            List <PublicIPAddress> vmssListPageResult = await vmssListPageResultAP.ToEnumerableAsync();

            List <PublicIPAddress> vmssListResult = vmssListPageResult.ToList();

            Has.One.EqualTo(vmssListResult);

            Response <PublicIPAddress> vmssGetResult = await NetworkManagementClient.PublicIPAddresses.GetVirtualMachineScaleSetPublicIPAddressAsync(
                resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName, ipConfigName, ipName);

            Assert.NotNull(vmssGetResult);
            Assert.AreEqual("Succeeded", vmssGetResult.Value.ProvisioningState.ToString());
            Assert.NotNull(vmssGetResult.Value.ResourceGuid);
        }
Ejemplo n.º 24
0
        protected PublicIPAddress CreatePublicIP(string rgName)
        {
            // Create publicIP
            string publicIpName    = "pip5913";
            string domainNameLabel = "dn5913";

            PublicIPAddress publicIp = null;

            try
            {
                publicIp = NetworkClient.PublicIPAddresses.Get(rgName, publicIpName);
            }
            catch { }

            if (publicIp == null)
            {
                publicIp = new PublicIPAddress()
                {
                    Location = DEFAULT_LOCATION,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "key", "value" }
                    },
                    PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                    DnsSettings = new PublicIPAddressDnsSettings()
                    {
                        DomainNameLabel = domainNameLabel
                    }
                };

                var putPublicIpAddressResponse = NetworkClient.PublicIPAddresses.CreateOrUpdate(rgName, publicIpName, publicIp);
                var getPublicIpAddressResponse = NetworkClient.PublicIPAddresses.Get(rgName, publicIpName);

                publicIp = getPublicIpAddressResponse;
            }

            return(publicIp);
        }
Ejemplo n.º 25
0
        public static PublicIPAddress CreatePublicIP(SqlVirtualMachineTestContext context, PublicIPAddress publicIp = null)
        {
            string publicIpName    = context.generateResourceName();
            string domainNameLabel = context.generateResourceName();

            if (publicIp == null)
            {
                publicIp = new PublicIPAddress()
                {
                    Location = context.location,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "key", "value" }
                    },
                    PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                    DnsSettings = new PublicIPAddressDnsSettings()
                    {
                        DomainNameLabel = domainNameLabel
                    }
                };
            }
            context.client.networkClient.PublicIPAddresses.CreateOrUpdate(context.resourceGroup.Name, publicIpName, publicIp);
            return(context.client.networkClient.PublicIPAddresses.Get(context.resourceGroup.Name, publicIpName));
        }
        public async Task CreateOrUpdate()
        {
            VirtualNetworkCollection virtualNetworkCollection = resourceGroup.GetVirtualNetworks();
            string vnetName = "myVnet";
            // Use the same location as the resource group
            VirtualNetworkData vnetInput = new VirtualNetworkData()
            {
                Location     = resourceGroup.Data.Location,
                AddressSpace = new AddressSpace()
                {
                    AddressPrefixes = { "10.0.0.0/16", }
                },
                DhcpOptions = new DhcpOptions()
                {
                    DnsServers = { "10.1.1.1", "10.1.2.4" }
                },
                Subnets = { new SubnetData()
                            {
                                Name = "mySubnet", AddressPrefix = "10.0.1.0/24"
                            } }
            };
            VirtualNetwork virtualNetwork = await virtualNetworkCollection.CreateOrUpdate(vnetName, vnetInput).WaitForCompletionAsync();

            #region Snippet:Managing_Networks_CreateANetworkInterface
            PublicIPAddressCollection publicIPAddressCollection = resourceGroup.GetPublicIPAddresses();
            string publicIPAddressName        = "myIPAddress";
            PublicIPAddressData publicIPInput = new PublicIPAddressData()
            {
                Location = resourceGroup.Data.Location,
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = "myDomain"
                }
            };
            PublicIPAddress publicIPAddress = await publicIPAddressCollection.CreateOrUpdate(publicIPAddressName, publicIPInput).WaitForCompletionAsync();

            NetworkInterfaceCollection networkInterfaceCollection = resourceGroup.GetNetworkInterfaces();
            string networkInterfaceName = "myNetworkInterface";
            NetworkInterfaceData networkInterfaceInput = new NetworkInterfaceData()
            {
                Location         = resourceGroup.Data.Location,
                IpConfigurations =
                {
                    new NetworkInterfaceIPConfiguration()
                    {
                        Name = "ipConfig",
                        PrivateIPAllocationMethod = IPAllocationMethod.Dynamic,
                        PublicIPAddress           = new PublicIPAddressData()
                        {
                            Id = publicIPAddress.Id
                        },
                        Subnet = new SubnetData()
                        {
                            // use the virtual network just created
                            Id = virtualNetwork.Data.Subnets[0].Id
                        }
                    }
                }
            };
            NetworkInterface networkInterface = await networkInterfaceCollection.CreateOrUpdate(networkInterfaceName, networkInterfaceInput).WaitForCompletionAsync();

            #endregion
        }
        public void PublicIpAddressApiTestWithIdletTimeoutAndReverseFqdn()
        {
            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);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);

                var location = ResourcesManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/publicIPAddresses");

                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                // Create the parameter for PUT PublicIPAddress
                string publicIpName    = TestUtilities.GenerateName();
                string domainNameLabel = TestUtilities.GenerateName();
                string reverseFqdn;

                var publicIp = new PublicIPAddress()
                {
                    Location = location,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "key", "value" }
                    },
                    PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                    DnsSettings = new PublicIPAddressDnsSettings()
                    {
                        DomainNameLabel = domainNameLabel,
                    },
                    IdleTimeoutInMinutes = 16,
                };

                // Put PublicIPAddress
                var putPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.CreateOrUpdate(resourceGroupName, publicIpName, publicIp);
                Assert.Equal("Succeeded", putPublicIpAddressResponse.ProvisioningState);

                // Get PublicIPAddress
                var getPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.Get(resourceGroupName, publicIpName);

                // Add Reverse FQDN
                reverseFqdn = getPublicIpAddressResponse.DnsSettings.Fqdn;
                getPublicIpAddressResponse.DnsSettings.ReverseFqdn = reverseFqdn;

                putPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.CreateOrUpdate(resourceGroupName, publicIpName, getPublicIpAddressResponse);
                Assert.Equal("Succeeded", putPublicIpAddressResponse.ProvisioningState);

                // Get PublicIPAddress
                getPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.Get(resourceGroupName, publicIpName);
                Assert.Equal(16, getPublicIpAddressResponse.IdleTimeoutInMinutes);
                Assert.Equal(reverseFqdn, getPublicIpAddressResponse.DnsSettings.ReverseFqdn);

                // Get List of PublicIPAddress
                var getPublicIpAddressListResponse = networkManagementClient.PublicIPAddresses.List(resourceGroupName);
                Assert.Single(getPublicIpAddressListResponse);
                ArePublicIpAddressesEqual(getPublicIpAddressResponse, getPublicIpAddressListResponse.First());

                // Get List of PublicIPAddress in a subscription
                var getPublicIpAddressListSubscriptionResponse = networkManagementClient.PublicIPAddresses.ListAll();
                Assert.NotEmpty(getPublicIpAddressListSubscriptionResponse);

                // Delete PublicIPAddress
                networkManagementClient.PublicIPAddresses.Delete(resourceGroupName, publicIpName);

                // Get PublicIPAddress
                getPublicIpAddressListResponse = networkManagementClient.PublicIPAddresses.List(resourceGroupName);
                Assert.Empty(getPublicIpAddressListResponse);
            }
        }
Ejemplo n.º 28
0
    public MyStack()
    {
        var tags = new InputMap <string> {
            { "resourceType", "Service Fabric" },
            { "clusterName", "thepulsf" }
        };

        // Create an Azure Resource Group
        var resourceGroup = new ResourceGroup("resourceGroup", new ResourceGroupArgs
        {
            ResourceGroupName = "apulsf",
            Location          = "SoutheastAsia",
            Tags = tags,
        });

        // Create a Storage Account for Log
        var storageAccountLog = new StorageAccount("saLog", new StorageAccountArgs
        {
            ResourceGroupName = resourceGroup.Name,
            AccountName       = "sflogstore",
            Location          = resourceGroup.Location,
            Sku = new SkuArgs
            {
                Name = "Standard_LRS",
                Tier = "Standard"
            },
            Kind = "StorageV2",
            Tags = tags,
        });
        // Create a Storage Account for Application Diagnostics
        var storageAccountAppDx = new StorageAccount("saAppDx", new StorageAccountArgs
        {
            ResourceGroupName = resourceGroup.Name,
            AccountName       = "sfappdxstore",
            Location          = resourceGroup.Location,
            Sku = new SkuArgs
            {
                Name = "Standard_LRS",
                Tier = "Standard"
            },
            Kind = "StorageV2",
            Tags = tags,
        });
        // Virtual Network
        var vnet = new VirtualNetwork("vnet", new VirtualNetworkArgs {
            ResourceGroupName  = resourceGroup.Name,
            VirtualNetworkName = "thevnet4sf",
            Location           = resourceGroup.Location,
            AddressSpace       = new nwin.AddressSpaceArgs {
                AddressPrefixes = "10.10.0.0/16",
            },
            Subnets =
            {
                new nwin.SubnetArgs {
                    Name          = "Subnet0",
                    AddressPrefix = "10.10.10.0/24",
                }
            },
            Tags = tags,
        });
        // Public IP Address
        var pubIpAddr = new PublicIPAddress("pubip4sf", new PublicIPAddressArgs {
            ResourceGroupName   = resourceGroup.Name,
            PublicIpAddressName = "thesfpubip",
            Location            = resourceGroup.Location,
            DnsSettings         = new nwin.PublicIPAddressDnsSettingsArgs {
                DomainNameLabel = "thepulsf",
            },
            PublicIPAllocationMethod = "Dynamic",
            Tags = tags,
        });

        // Load Balancer
        var loadBalancer = new LoadBalancer("lb", new LoadBalancerArgs {
            ResourceGroupName        = resourceGroup.Name,
            Location                 = resourceGroup.Location,
            LoadBalancerName         = "thepulsflb4set0",
            FrontendIPConfigurations = new nwin.FrontendIPConfigurationArgs {
                Name            = "lbipconfig",
                PublicIPAddress = new nwin.PublicIPAddressArgs {
                    Id = pubIpAddr.Id,
                },
            },
            Tags = tags,
        });
        var bepool0 = new lb.BackendAddressPool("bepool0", new lb.BackendAddressPoolArgs {
            Name = "bepool0",
            ResourceGroupName = resourceGroup.Name,
            LoadbalancerId    = loadBalancer.Id,
        });
        var lbPorts = new [] { 19000, 19080, 80, 443 };

        for (int i = 0; i < lbPorts.Length; i++)
        {
            var port = lbPorts[i];

            var probe = new lb.Probe($"lbProbe{i}", new lb.ProbeArgs {
                ResourceGroupName = resourceGroup.Name,
                LoadbalancerId    = loadBalancer.Id,
                Port = port,
                IntervalInSeconds = 5,
                NumberOfProbes    = 2,
                Protocol          = "tcp",
            });
            var rule = new lb.Rule($"lbRule{i}", new lb.RuleArgs {
                ResourceGroupName           = resourceGroup.Name,
                LoadbalancerId              = loadBalancer.Id,
                FrontendIpConfigurationName = "lbipconfig",
                FrontendPort         = port,
                BackendAddressPoolId = bepool0.Id,
                BackendPort          = port,
                IdleTimeoutInMinutes = 5,
                EnableFloatingIp     = false,
                Protocol             = "tcp",
            });
        }
        var lbNatPool = new lb.NatPool("lbNatPool", new lb.NatPoolArgs {
            ResourceGroupName           = resourceGroup.Name,
            LoadbalancerId              = loadBalancer.Id,
            FrontendIpConfigurationName = "lbipconfig",
            FrontendPortStart           = 3389,
            FrontendPortEnd             = 4500,
            BackendPort = 3389,
            Protocol    = "tcp",
        });

        var sfCluster = new Cluster("thesf", new ClusterArgs {
            ClusterName       = "thesf",
            ResourceGroupName = resourceGroup.Name,
            Location          = resourceGroup.Location,

            AddOnFeatures =
            {
                "DnsService",
                "BackupRestoreService"
            },
            Certificate = new sfi.CertificateDescriptionArgs {
                Thumbprint    = "4426C164D9E66C2C813DEEC0486F235C0E933212",
                X509StoreName = "My",
            },
            DiagnosticsStorageAccountConfig = new sfi.DiagnosticsStorageAccountConfigArgs {
                BlobEndpoint            = storageAccountLog.PrimaryEndpoints.Apply(it => it.Blob),
                ProtectedAccountKeyName = "StorageAccountKey1",
                QueueEndpoint           = storageAccountLog.PrimaryEndpoints.Apply(it => it.Queue),
                StorageAccountName      = storageAccountLog.Name,
                TableEndpoint           = storageAccountLog.PrimaryEndpoints.Apply(it => it.Table),
            },
            FabricSettings =
            {
                new sfi.SettingsSectionDescriptionArgs           {
                    Parameters =
                    {
                        new sfi.SettingsParameterDescriptionArgs {
                            Name  = "SecretEncryptionCertThumbprint",
                            Value = "4426C164D9E66C2C813DEEC0486F235C0E933212",
                        },
                        new sfi.SettingsParameterDescriptionArgs {
                            Name  = "SecretEncryptionCertX509StoreName",
                            Value = "My",
                        },
                    },
                    Name = "BackupRestoreService",
                },
                new sfi.SettingsSectionDescriptionArgs           {
                    Parameters =
                    {
                        new sfi.SettingsParameterDescriptionArgs {
                            Name  = "ClusterProtectionLevel",
                            Value = "EncryptAndSign",
                        },
                    },
                    Name = "Security",
                },
            },
            ManagementEndpoint = Output.Format($"https://{pubIpAddr.DnsSettings.Apply(it => it?.Fqdn)}:19080"),
            NodeTypes          =
            {
                new sfi.NodeTypeDescriptionArgs {
                    Name             = "Type925",
                    ApplicationPorts = new sfi.EndpointRangeDescriptionArgs{
                        StartPort = 20000,
                        EndPort   = 30000,
                    },
                    ClientConnectionEndpointPort = 19000,
                    DurabilityLevel = "Silver",
                    EphemeralPorts  = new sfi.EndpointRangeDescriptionArgs {
                        StartPort = 49152,
                        EndPort   = 65534,
                    },
                    HttpGatewayEndpointPort = 19080,
                    IsPrimary       = true,
                    VmInstanceCount = 5,
                },
            },
            ReliabilityLevel = "Silver",
            UpgradeMode      = "Automatic",
            VmImage          = "Windows",
        });


        Key1 = GetStorageKey(resourceGroup, storageAccountLog, 0);
        Key2 = GetStorageKey(resourceGroup, storageAccountLog, 1);
        Input <string> key1 = Key1;
        Input <string> key2 = Key2;

        var vmScaleSet = new VirtualMachineScaleSet("sfScaleSet", new VirtualMachineScaleSetArgs {
            ResourceGroupName = resourceGroup.Name,
            Location          = resourceGroup.Location,
            VmScaleSetName    = "sfScaleSet0",
            Sku = new cpi.SkuArgs {
                Name     = "Standard_D2s_v3",
                Capacity = 5,
                Tier     = "Standard",
            },
            Overprovision = false,
            UpgradePolicy = new cpi.UpgradePolicyArgs {
                Mode = "Automatic",
            },
            VirtualMachineProfile = new cpi.VirtualMachineScaleSetVMProfileArgs {
                ExtensionProfile = new cpi.VirtualMachineScaleSetExtensionProfileArgs {
                    Extensions =
                    {
                        new cpi.VirtualMachineScaleSetExtensionArgs                 {
                            Name = "Type925_ServiceFabricNode",
                            Type = "ServiceFabricNode",
                            TypeHandlerVersion      = "1.1",
                            AutoUpgradeMinorVersion = true,
                            // EnableAutomaticUpgrade = true,   // MUST NOT ENABLED
                            ProtectedSettings =
                            {
                                { "StorageAccountKey1", key1                                                        },
                                { "StorageAccountKey2", key2                                                        },
                            },
                            Publisher = "Microsoft.Azure.ServiceFabric",
                            Settings  =
                            {
                                // { "id", "thepulsf" },
                                // { "clusterId", "thepulsf" },
                                // { "clusterEndpoint", pubIpAddr.DnsSettings.Apply(it => it?.Fqdn) },
                                { "clusterEndpoint",    sfCluster.ClusterEndpoint                                             },
                                { "nodeTypeRef",        "Type925"                                                             },
                                { "dataPath",           @"D:\\SvcFab"                                                         },
                                { "durabilityLevel",    "Silver"                                                              },
                                { "enableParallelJobs", true                                                                  },
                                { "nicPrefixOverride",  "10.10.10.0/24"                                                       },
                                { "certificate",        new InputMap <string>
                                                                                      {
                                                                                          { "thumbprint",         "4426C164D9E66C2C813DEEC0486F235C0E933212"                            },
                                                                                          { "x509StoreName",      "My"                                                                  },
                                                                                      } },
                            },
                        },
                        new cpi.VirtualMachineScaleSetExtensionArgs                 {
                            Name = "VMDiagnosticsVmExt_Set0",
                            Type = "IaaSDiagnostics",
                            TypeHandlerVersion = "1.5",
                            ProtectedSettings  =
                            {
                                { "storageAccountName",     storageAccountAppDx.Name                                    },
                                { "storageAccountKey",      GetStorageKey(resourceGroup, storageAccountAppDx, 0)        },
                                { "storageAccountEndPoint", "https://core.windows.net/"                                 },
                            },
                            Publisher = "Microsoft.Azure.Diagnostics",
                            Settings  =
                            {
                                { "WadCfg",                              new InputMap <object>
                                                                                      {
                                                                                          { "DiagnosticMonitorConfiguration",      new InputMap <object>
                                                                                      {
                                                                                          { "overallQuotaInMB",                    "50000"                                                               },
                                                                                          { "EtwProviders",                        new InputMap <object>
                                                                                      {
                                                                                          { "EtwEventSourceProviderConfiguration", new InputList <InputMap <object> >
                                                                                      {
                                                                                          new InputMap <object>
                                                                                          {
                                                                                              { "provider",                            "Microsoft-ServiceFabric-Actors"                                      },
                                                                                              { "scheduledTransferKeywordFilter",      "1"                                                                   },
                                                                                              { "scheduledTransferPeriod",             "PT5M"                                                                },
                                                                                              { "DefaultEvents",                       new InputMap <string>
                                                                                      {
                                                                                          { "eventDestination",                    "ServiceFabricReliableActorEventTable"                                }
                                                                                      } },
                                                                                          },
                                                                                          new InputMap <object>
                                                                                          {
                                                                                              { "provider",                            "Microsoft-ServiceFabric-Services"                                    },
                                                                                              { "scheduledTransferPeriod",             "PT5M"                                                                },
                                                                                              { "DefaultEvents",                       new InputMap <string>
                                                                                      {
                                                                                          { "eventDestination",                    "ServiceFabricReliableServiceEventTable"                              }
                                                                                      } },
                                                                                          },
                                                                                      } },
                                                                                          { "EtwManifestProviderConfiguration",    new InputList <InputMap <object> >
                                                                                      {
                                                                                          new InputMap <object> {
                                                                                              { "provider",                            "cbd93bc2-71e5-4566-b3a7-595d8eeca6e8"                                },
                                                                                              { "scheduledTransferLogLevelFilter",     "Information"                                                         },
                                                                                              { "scheduledTransferKeywordFilter",      "4611686018427387904"                                                 },
                                                                                              { "scheduledTransferPeriod",             "PT5M"                                                                },
                                                                                              { "DefaultEvents",                       new InputMap <string>
                                                                                      {
                                                                                          { "eventDestination",                    "ServiceFabricSystemEventTable"                                       }
                                                                                      } },
                                                                                          }
                                                                                      } },
                                                                                      } },
                                                                                      } },
                                                                                      } },
                                { "StorageAccount",                      storageAccountAppDx.Name                                              },
                            },
                        },
                    },
                },
                NetworkProfile = new cpi.VirtualMachineScaleSetNetworkProfileArgs {
                    NetworkInterfaceConfigurations =
                    {
                        new cpi.VirtualMachineScaleSetNetworkConfigurationArgs    {
                            Name             = "nicSfSet-0",
                            IpConfigurations =
                            {
                                new cpi.VirtualMachineScaleSetIPConfigurationArgs {
                                    Name = "nicSfSet-0",
                                    LoadBalancerBackendAddressPools = new cpi.SubResourceArgs{
                                        Id = bepool0.Id
                                    },
                                    LoadBalancerInboundNatPools = new cpi.SubResourceArgs{
                                        Id = lbNatPool.Id
                                    },
                                    Subnet = new cpi.ApiEntityReferenceArgs       {
                                        Id = vnet.Subnets.First().Apply(it => it.Id ?? string.Empty),
                                    },
                                },
                            },
                            Primary = true,
                        },
                    },
                },
                OsProfile = new cpi.VirtualMachineScaleSetOSProfileArgs {
                    AdminUsername      = "******",
                    AdminPassword      = "******",
                    ComputerNamePrefix = "Type925",
                    Secrets            =
                    {
                        new cpi.VaultSecretGroupArgs         {
                            SourceVault = new cpi.SubResourceArgs{
                                Id = "/subscriptions/5fb1076d-8ce2-4bf8-90af-d53f1b8f8289/resourceGroups/prepkvault/providers/Microsoft.KeyVault/vaults/thekv4sf"
                            },
                            VaultCertificates =
                            {
                                new cpi.VaultCertificateArgs {
                                    CertificateStore = "My",
                                    CertificateUrl   = "https://thekv4sf.vault.azure.net/secrets/thesfcert/4379416a51dc4570bda6bc79a6fbfa59",
                                },
                            },
                        },
                    },
                },
                StorageProfile = new cpi.VirtualMachineScaleSetStorageProfileArgs {
                    ImageReference = new cpi.ImageReferenceArgs {
                        Publisher = "MicrosoftWindowsServer",
                        Offer     = "WindowsServer",
                        Sku       = "2019-Datacenter-with-Containers",
                        Version   = "latest",
                    },
                    OsDisk = new cpi.VirtualMachineScaleSetOSDiskArgs {
                        Caching      = "ReadOnly",
                        CreateOption = "FromImage",
                        ManagedDisk  = new cpi.VirtualMachineScaleSetManagedDiskParametersArgs {
                            StorageAccountType = "Standard_LRS",
                        },
                    },
                },
            },
        });

        // Export the primary key of> the Storage Account
        this.PrimaryStorageKey = Output.Tuple(resourceGroup.Name, storageAccountAppDx.Name).Apply(names =>
                                                                                                  Output.CreateSecret(GetStorageAccountKey(names.Item1, names.Item2, 0)));
    }
 /// <summary>
 /// Creates or updates a static or dynamic public IP address.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='publicIpAddressName'>
 /// The name of the public IP address.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create or update public IP address operation.
 /// </param>
 public static PublicIPAddress BeginCreateOrUpdate(this IPublicIPAddressesOperations operations, string resourceGroupName, string publicIpAddressName, PublicIPAddress parameters)
 {
     return(operations.BeginCreateOrUpdateAsync(resourceGroupName, publicIpAddressName, parameters).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Creates or updates a static or dynamic public IP address.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='publicIpAddressName'>
 /// The name of the public IP address.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create or update public IP address operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <PublicIPAddress> BeginCreateOrUpdateAsync(this IPublicIPAddressesOperations operations, string resourceGroupName, string publicIpAddressName, PublicIPAddress parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, publicIpAddressName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        public void MultiRole_CreateUpdateGetAndDeleteWithExtension_WorkerAndWebRole()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                EnsureClientsInitialized(context);

                // Create resource group
                var    rgName              = TestUtilities.GenerateName(TestPrefix);
                var    csName              = TestUtilities.GenerateName("cs");
                string cloudServiceName    = "TestCloudServiceMultiRole";
                string publicIPAddressName = TestUtilities.GenerateName("cspip");
                string vnetName            = TestUtilities.GenerateName("csvnet");
                string subnetName          = TestUtilities.GenerateName("subnet");
                string dnsName             = TestUtilities.GenerateName("dns");
                string lbName              = TestUtilities.GenerateName("lb");
                string lbfeName            = TestUtilities.GenerateName("lbfe");


                try
                {
                    CreateVirtualNetwork(rgName, vnetName, subnetName);
                    PublicIPAddress publicIPAddress = CreatePublicIP(publicIPAddressName, rgName, dnsName);


                    ///
                    /// Create: Create a multi-role CloudService with 2 WorkerRoles, 1 WebRole, and RDP Extension.
                    ///

                    string rdpExtensionPublicConfig = "<PublicConfig>" +
                                                      "<UserName>adminRdpTest</UserName>" +
                                                      "<Expiration>2021-10-27T23:59:59</Expiration>" +
                                                      "</PublicConfig>";
                    string rdpExtensionPrivateConfig = "<PrivateConfig>" +
                                                       "<Password>VsmrdpTest!</Password>" +
                                                       "</PrivateConfig>";

                    Extension rdpExtension = CreateExtension("RDPExtension", "Microsoft.Windows.Azure.Extensions", "RDP", "1.2.1", autoUpgrade: true,
                                                             publicConfig: rdpExtensionPublicConfig,
                                                             privateConfig: rdpExtensionPrivateConfig);
                    // Define Configurations
                    List <string> supportedRoleInstanceSizes = GetSupportedRoleInstanceSizes();
                    Dictionary <string, RoleConfiguration> roleNameToPropertiesMapping = new Dictionary <string, RoleConfiguration>
                    {
                        { "WorkerRole1", new RoleConfiguration {
                              InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[0]
                          } },
                        { "WorkerRole2", new RoleConfiguration {
                              InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[1]
                          } },
                        { "WebRole1", new RoleConfiguration {
                              InstanceCount = 2, RoleInstanceSize = supportedRoleInstanceSizes[3]
                          } }
                    };

                    // Generate the request
                    CloudService cloudService = GenerateCloudServiceWithNetworkProfile(
                        resourceGroupName: rgName,
                        serviceName: cloudServiceName,
                        cspkgSasUri: CreateCspkgSasUrl(rgName, MultiRole2Worker1WebRolesPackageSasUri),
                        roleNameToPropertiesMapping: roleNameToPropertiesMapping,
                        publicIPAddressName: publicIPAddressName,
                        vnetName: vnetName,
                        subnetName: subnetName,
                        lbName: lbName,
                        lbFrontendName: lbfeName);

                    cloudService.Properties.ExtensionProfile = new CloudServiceExtensionProfile()
                    {
                        Extensions = new List <Extension>()
                    };
                    cloudService.Properties.ExtensionProfile.Extensions.Add(rdpExtension);

                    CloudService getResponse = CreateCloudService_NoAsyncTracking(
                        rgName,
                        csName,
                        cloudService);

                    // Validate the response for multirole
                    ValidateGetAndListResponseForMultiRole(rgName, csName, cloudService, roleNameToPropertiesMapping);

                    ///
                    /// Update[1]: Delete RDP Extension, and Add Monitor Extension.
                    ///

                    Extension monitorExtension = CreateExtension("MonitoringExtension", "Microsoft.Azure.Security", "Monitoring", "3.1.0.0");
                    cloudService.Properties.ExtensionProfile = new CloudServiceExtensionProfile()
                    {
                        Extensions = new List <Extension>()
                    };
                    cloudService.Properties.ExtensionProfile.Extensions.Add(monitorExtension);

                    getResponse = CreateCloudService_NoAsyncTracking(
                        rgName,
                        csName,
                        cloudService);

                    // Send the request
                    ValidateGetAndListResponseForMultiRole(rgName, csName, cloudService, roleNameToPropertiesMapping);

                    ///
                    /// Update[2]: Delete Monitor Extension
                    ///

                    cloudService.Properties.ExtensionProfile = null;
                    getResponse = CreateCloudService_NoAsyncTracking(
                        rgName,
                        csName,
                        cloudService);

                    // Send the request
                    ValidateGetAndListResponseForMultiRole(rgName, csName, cloudService, roleNameToPropertiesMapping);

                    ///
                    /// Delete the CloudService
                    ///

                    m_CrpClient.CloudServices.Delete(rgName, csName);
                }
                finally
                {
                    // Fire and forget. No need to wait for RG deletion completion
                    try
                    {
                        m_ResourcesClient.ResourceGroups.BeginDelete(rgName);
                    }
                    catch (Exception e)
                    {
                        // Swallow this exception so that the original exception is thrown
                        Console.WriteLine(e);
                    }
                }
            }
        }
Ejemplo n.º 32
-1
        /// <summary>
        /// Create Virtual Network Interface Card, NIC
        /// </summary>
        /// <param name="credentials">Credentials to authorize application</param>
        /// <param name="subscriptionId">SubscriptionID that identifies subscription to create resoruce in</param>
        /// <param name="resourceGroup">Name of resource group</param>
        /// <param name="location">Location for resource</param>
        /// <param name="nicName">Internal name for NIC</param>
        /// <param name="nicIPConfigName">Internal name for NIC Configuration. Sample only provides one configuration, but could be extended to provide more</param>
        /// <param name="pip">Public IP Address to be assigned to NIC</param>
        /// <param name="subnet">Subnet to use for current configuration</param>
        /// <returns>Awaitable task</returns>
        private static Task<NetworkInterface> CreateNetworkInterfaceAsync(TokenCredentials credentials, string subscriptionId, string resourceGroup, string location, string nicName, string nicIPConfigName, PublicIPAddress pip, Subnet subnet)
        {
            Console.WriteLine("Creating Network Interface");
            var networkClient = new NetworkManagementClient(credentials) { SubscriptionId = subscriptionId };
            var createNicTask = networkClient.NetworkInterfaces.CreateOrUpdateAsync(resourceGroup, nicName,
                new NetworkInterface()
                {
                    Location = location,
                    IpConfigurations = new[] {
                        new NetworkInterfaceIPConfiguration
                        {
                            Name = nicIPConfigName,
                            PrivateIPAllocationMethod = "Dynamic",
                            PublicIPAddress = pip,
                            Subnet = subnet
                        }
                    }
                });

            return createNicTask;
        }