public static PublicIpAddress CreateDefaultPublicIpAddress(string name, string resourceGroupName, string domainNameLabel, string location,
                                                                   NetworkResourceProviderClient 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(HttpStatusCode.OK, putPublicIpAddressResponse.StatusCode);
            Assert.Equal("Succeeded", putPublicIpAddressResponse.Status);
            var getPublicIpAddressResponse = nrpClient.PublicIpAddresses.Get(resourceGroupName, name);

            return(getPublicIpAddressResponse.PublicIpAddress);
        }
        protected PublicIpAddressGetResponse CreatePublicIP(string rgName)
        {
            // Create publicIP
            string publicIpName    = TestUtilities.GenerateName();
            string domainNameLabel = TestUtilities.GenerateName();

            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);
        }
Exemple #3
0
 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);
 }
        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);
        }
Exemple #5
0
        public override void Register(PhotonServerPeer peer)
        {
            var registerSubServerOperation =
                new RegisterSubServerData()
            {
                GameServerAddress = PublicIpAddress.ToString(),
                TcpPort           = TcpPort,
                UdpPort           = UdpPort,
                ServerId          = ServerId,
                ServerType        = ServerType,
                ApplicationName   = ApplicationName
            };

            peer.SendOperationRequest(new OperationRequest((byte)ServerOperationCode.RegisterSubServer,
                                                           new RegisterSubServer()
            {
                RegisterSubServerOperation = SerializeUtil.Serialize(registerSubServerOperation)
            }), new SendParameters());
        }
Exemple #6
0
        public override void Register(PhotonServerPeer peer)
        {
            var registerSubServerOperation = new RegisterSubServerData()
            {
                GameServerAddress = PublicIpAddress.ToString(),
                TcpPort           = TcpPort,
                UdpPort           = UdpPort,
                ServerId          = ServerId,
                ServerType        = ServerType,
                ApplicationName   = ApplicationName
            };
            XmlSerializer mySerializer = new XmlSerializer(typeof(RegisterSubServerData));
            StringWriter  outString    = new StringWriter();

            mySerializer.Serialize(outString, registerSubServerOperation);

            peer.SendOperationRequest(
                new OperationRequest((byte)ServerOperationCode.RegisterSubServer,
                                     new RegisterSubServer()
            {
                RegisterSubServerOperation = outString.ToString()
            }), new SendParameters());
        }
        public void NetworkInterfaceApiTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();
                var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler);
                var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler);

                var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkInterfaces");

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

                // Create publicIP
                string publicIpName    = TestUtilities.GenerateName();
                string domainNameLabel = TestUtilities.GenerateName();

                var publicIp = new PublicIpAddress()
                {
                    Location = location,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "key", "value" }
                    },
                    PublicIpAllocationMethod = IpAllocationMethod.Dynamic,
                    DnsSettings = new PublicIpAddressDnsSettings()
                    {
                        DomainNameLabel = domainNameLabel
                    }
                };

                // Put PublicIpAddress
                var putPublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.CreateOrUpdate(resourceGroupName, publicIpName, publicIp);
                Assert.Equal(HttpStatusCode.OK, putPublicIpAddressResponse.StatusCode);
                Assert.Equal("Succeeded", putPublicIpAddressResponse.Status);
                var getPublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.Get(resourceGroupName, publicIpName);

                // Create Vnet
                // Populate parameter for Put Vnet
                string vnetName   = TestUtilities.GenerateName();
                string subnetName = TestUtilities.GenerateName();

                var vnet = new VirtualNetwork()
                {
                    Location = location,

                    AddressSpace = new AddressSpace()
                    {
                        AddressPrefixes = new List <string>()
                        {
                            "10.0.0.0/16",
                        }
                    },
                    DhcpOptions = new DhcpOptions()
                    {
                        DnsServers = new List <string>()
                        {
                            "10.1.1.1",
                            "10.1.2.4"
                        }
                    },
                    Subnets = new List <Subnet>()
                    {
                        new Subnet()
                        {
                            Name          = subnetName,
                            AddressPrefix = "10.0.0.0/24",
                        }
                    }
                };

                var putVnetResponse = networkResourceProviderClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, vnetName, vnet);
                Assert.Equal(HttpStatusCode.OK, putVnetResponse.StatusCode);

                var getSubnetResponse = networkResourceProviderClient.Subnets.Get(resourceGroupName, vnetName, subnetName);

                // Create Nic
                string nicName      = TestUtilities.GenerateName();
                string ipConfigName = TestUtilities.GenerateName();

                var nicParameters = new NetworkInterface()
                {
                    Location = location,
                    Name     = nicName,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "key", "value" }
                    },
                    IpConfigurations = new List <NetworkInterfaceIpConfiguration>()
                    {
                        new NetworkInterfaceIpConfiguration()
                        {
                            Name = ipConfigName,
                            PrivateIpAllocationMethod = IpAllocationMethod.Dynamic,
                            PublicIpAddress           = new ResourceId()
                            {
                                Id = getPublicIpAddressResponse.PublicIpAddress.Id
                            },
                            Subnet = new ResourceId()
                            {
                                Id = getSubnetResponse.Subnet.Id
                            }
                        }
                    }
                };

                // Test NIC apis
                var putNicResponse = networkResourceProviderClient.NetworkInterfaces.CreateOrUpdate(resourceGroupName, nicName, nicParameters);
                Assert.Equal(HttpStatusCode.OK, putNicResponse.StatusCode);

                var getNicResponse = networkResourceProviderClient.NetworkInterfaces.Get(resourceGroupName, nicName);
                Assert.Equal(getNicResponse.NetworkInterface.Name, nicName);
                Assert.Equal(getNicResponse.NetworkInterface.ProvisioningState, Microsoft.Azure.Management.Resources.Models.ProvisioningState.Succeeded);
                Assert.Null(getNicResponse.NetworkInterface.VirtualMachine);
                Assert.Null(getNicResponse.NetworkInterface.MacAddress);
                Assert.Equal(1, getNicResponse.NetworkInterface.IpConfigurations.Count);
                Assert.Equal(ipConfigName, getNicResponse.NetworkInterface.IpConfigurations[0].Name);
                Assert.Equal(getPublicIpAddressResponse.PublicIpAddress.Id, getNicResponse.NetworkInterface.IpConfigurations[0].PublicIpAddress.Id);
                Assert.Equal(getSubnetResponse.Subnet.Id, getNicResponse.NetworkInterface.IpConfigurations[0].Subnet.Id);

                // Get all Nics
                var getListNicResponse = networkResourceProviderClient.NetworkInterfaces.List(resourceGroupName);
                Assert.Equal(1, getListNicResponse.NetworkInterfaces.Count);
                Assert.Equal(getNicResponse.NetworkInterface.Name, getListNicResponse.NetworkInterfaces[0].Name);
                Assert.Equal(getNicResponse.NetworkInterface.Etag, getListNicResponse.NetworkInterfaces[0].Etag);
                Assert.Equal(getNicResponse.NetworkInterface.IpConfigurations[0].Etag, getListNicResponse.NetworkInterfaces[0].IpConfigurations[0].Etag);

                // Get all Nics in subscription
                var listNicSubscription = networkResourceProviderClient.NetworkInterfaces.ListAll();
                Assert.Equal(1, getListNicResponse.NetworkInterfaces.Count);
                Assert.Equal(getNicResponse.NetworkInterface.Name, listNicSubscription.NetworkInterfaces[0].Name);
                Assert.Equal(getNicResponse.NetworkInterface.Etag, listNicSubscription.NetworkInterfaces[0].Etag);
                Assert.Equal(listNicSubscription.NetworkInterfaces[0].IpConfigurations[0].Etag, getListNicResponse.NetworkInterfaces[0].IpConfigurations[0].Etag);

                // Delete Nic
                var deleteNicResponse = networkResourceProviderClient.NetworkInterfaces.Delete(resourceGroupName, nicName);
                Assert.Equal(HttpStatusCode.OK, deleteNicResponse.StatusCode);

                getListNicResponse = networkResourceProviderClient.NetworkInterfaces.List(resourceGroupName);
                Assert.Equal(0, getListNicResponse.NetworkInterfaces.Count);

                // Delete PublicIpAddress
                var deletePublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.Delete(resourceGroupName, publicIpName);
                Assert.Equal(HttpStatusCode.OK, deletePublicIpAddressResponse.StatusCode);

                // Delete VirtualNetwork
                var deleteVnetResponse = networkResourceProviderClient.VirtualNetworks.Delete(resourceGroupName, vnetName);
                Assert.Equal(HttpStatusCode.OK, deleteVnetResponse.StatusCode);
            }
        }
Exemple #8
0
        public void PublicIpAddressApiTestWithIdletTimeoutAndReverseFqdn()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();
                var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler);
                var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler);

                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 = networkResourceProviderClient.PublicIpAddresses.CreateOrUpdate(resourceGroupName, publicIpName, publicIp);
                Assert.Equal(HttpStatusCode.OK, putPublicIpAddressResponse.StatusCode);
                Assert.Equal("Succeeded", putPublicIpAddressResponse.Status);

                // Get PublicIpAddress
                var getPublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.Get(resourceGroupName, publicIpName);
                Assert.Equal(HttpStatusCode.OK, getPublicIpAddressResponse.StatusCode);

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

                putPublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.CreateOrUpdate(resourceGroupName, publicIpName, getPublicIpAddressResponse.PublicIpAddress);
                Assert.Equal(HttpStatusCode.OK, putPublicIpAddressResponse.StatusCode);
                Assert.Equal("Succeeded", putPublicIpAddressResponse.Status);

                // Get PublicIpAddress
                getPublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.Get(resourceGroupName, publicIpName);
                Assert.Equal(HttpStatusCode.OK, getPublicIpAddressResponse.StatusCode);
                Assert.Equal(16, getPublicIpAddressResponse.PublicIpAddress.IdleTimeoutInMinutes);
                Assert.Equal(reverseFqdn, getPublicIpAddressResponse.PublicIpAddress.DnsSettings.ReverseFqdn);

                // Get List of PublicIpAddress
                var getPublicIpAddressListResponse = networkResourceProviderClient.PublicIpAddresses.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, getPublicIpAddressListResponse.StatusCode);
                Assert.Equal(1, getPublicIpAddressListResponse.PublicIpAddresses.Count);
                ArePublicIpAddressesEqual(getPublicIpAddressResponse.PublicIpAddress, getPublicIpAddressListResponse.PublicIpAddresses[0]);

                // Get List of PublicIpAddress in a subscription
                var getPublicIpAddressListSubscriptionResponse = networkResourceProviderClient.PublicIpAddresses.ListAll();
                Assert.Equal(HttpStatusCode.OK, getPublicIpAddressListSubscriptionResponse.StatusCode);
                Assert.Equal(1, getPublicIpAddressListSubscriptionResponse.PublicIpAddresses.Count);
                ArePublicIpAddressesEqual(getPublicIpAddressResponse.PublicIpAddress, getPublicIpAddressListSubscriptionResponse.PublicIpAddresses[0]);

                // Delete PublicIpAddress
                var deletePublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.Delete(resourceGroupName, publicIpName);
                Assert.Equal(HttpStatusCode.OK, deletePublicIpAddressResponse.StatusCode);

                // Get PublicIpAddress
                getPublicIpAddressListResponse = networkResourceProviderClient.PublicIpAddresses.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, getPublicIpAddressListResponse.StatusCode);
                Assert.Equal(0, getPublicIpAddressListResponse.PublicIpAddresses.Count);
            }
        }
        protected NetworkInterfaceGetResponse CreateNIC(string rgName, Subnet subnet, PublicIpAddress publicIPaddress, string nicname = null)
        {
            // Create Nic
            nicname = nicname ?? TestUtilities.GenerateName();
            string ipConfigName = TestUtilities.GenerateName();

            var nicParameters = new NetworkInterface()
            {
                Location = m_location,
                Name     = nicname,
                Tags     = new Dictionary <string, string>()
                {
                    { "key", "value" }
                },
                IpConfigurations = new List <NetworkInterfaceIpConfiguration>()
                {
                    new NetworkInterfaceIpConfiguration()
                    {
                        Name = ipConfigName,
                        PrivateIpAllocationMethod = IpAllocationMethod.Dynamic,
                        Subnet = subnet,
                    }
                }
            };

            if (publicIPaddress != null)
            {
                nicParameters.IpConfigurations[0].PublicIpAddress = new ResourceId {
                    Id = publicIPaddress.Id
                };
            }

            var putNicResponse = m_NrpClient.NetworkInterfaces.CreateOrUpdate(rgName, nicname, nicParameters);
            var getNicResponse = m_NrpClient.NetworkInterfaces.Get(rgName, nicname);

            return(getNicResponse);
        }
 /// <summary>
 /// The Put PublicIPAddress operation creates/updates a stable/dynamic
 /// PublicIP address
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Network.IPublicIpAddressOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='publicIpAddressName'>
 /// Required. The name of the publicIpAddress.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the create/update PublicIPAddress
 /// operation
 /// </param>
 /// <returns>
 /// Response for PutPublicIpAddress Api servive call
 /// </returns>
 public static Task <PublicIpAddressPutResponse> BeginCreateOrUpdatingAsync(this IPublicIpAddressOperations operations, string resourceGroupName, string publicIpAddressName, PublicIpAddress parameters)
 {
     return(operations.BeginCreateOrUpdatingAsync(resourceGroupName, publicIpAddressName, parameters, CancellationToken.None));
 }
 /// <summary>
 /// The Put PublicIPAddress operation creates/updates a stable/dynamic
 /// PublicIP address
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Network.IPublicIpAddressOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='publicIpAddressName'>
 /// Required. The name of the publicIpAddress.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the create/update PublicIPAddress
 /// operation
 /// </param>
 /// <returns>
 /// Response for PutPublicIpAddress Api servive call
 /// </returns>
 public static PublicIpAddressPutResponse BeginCreateOrUpdating(this IPublicIpAddressOperations operations, string resourceGroupName, string publicIpAddressName, PublicIpAddress parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IPublicIpAddressOperations)s).BeginCreateOrUpdatingAsync(resourceGroupName, publicIpAddressName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemple #12
0
 private bool ValidateBaseResourceTenant(PublicIpAddress tenant)
 {
     return(tenant != null &&
            tenant.SubscriptionId == null &&
            tenant.TenantResourceUri != null);
 }