protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            var slotType = string.IsNullOrEmpty(this.Slot) ?
                           DeploymentSlot.Production :
                           (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);


            string deploymentName = this.ComputeClient.Deployments.GetBySlot(
                this.ServiceName,
                slotType).Name;

            ExecuteClientActionNewSM(
                null,
                CommandRuntime.ToString(),
                () =>
            {
                var parameters = new NetworkReservedIPMobilityParameters
                {
                    ServiceName    = this.ServiceName,
                    DeploymentName = deploymentName
                };

                return(this.NetworkClient.ReservedIPs.Associate(this.ReservedIPName, parameters));
            });
        }
예제 #2
0
        public void AssociateReservedIP(
            string usWestLocStr,
            string location,
            string storageAccountName,
            ref bool storageAccountCreated,
            string serviceName,
            string deploymentName,
            string reserveIpName,
            ref bool hostedServiceCreated,
            ref bool reserveIpCreated)
        {
            if (this.ManagementClient.Locations.List().Any(
                    c => string.Equals(c.Name, usWestLocStr, StringComparison.OrdinalIgnoreCase)))
            {
                location = usWestLocStr;
            }

            this.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);

            this.CreateHostedService(location, serviceName, out hostedServiceCreated);

            this.CreatePaaSDeployment(storageAccountName, serviceName, deploymentName, NetworkTestConstants.OneWebOneWorkerPkgFilePath, "OneWebOneWorker.cscfg", true);

            NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
            {
                Name     = reserveIpName,
                Location = location,
                Label    = "SampleReserveIPLabel",
            };

            OperationStatusResponse reserveIpCreate = this.NetworkClient.ReservedIPs.Create(reservedIpCreatePars);

            Assert.True(reserveIpCreate.StatusCode == HttpStatusCode.OK);
            reserveIpCreated = true;

            NetworkReservedIPGetResponse reserveIpCreationResponse =
                this.NetworkClient.ReservedIPs.Get(reserveIpName);

            Assert.True(reserveIpCreationResponse.StatusCode == HttpStatusCode.OK);


            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
            {
                ServiceName    = serviceName,
                DeploymentName = deploymentName
            };
            OperationStatusResponse responseAssociateRip = this.NetworkClient.ReservedIPs.Associate(reserveIpName, pars);

            Assert.True(responseAssociateRip.StatusCode == HttpStatusCode.OK);

            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                this.NetworkClient.ReservedIPs.Get(reserveIpName);

            Assert.True(receivedReservedIpFromRdfe.StatusCode == HttpStatusCode.OK);

            Assert.True(serviceName == receivedReservedIpFromRdfe.ServiceName);
            Assert.True(receivedReservedIpFromRdfe.InUse == true);
            Assert.True(deploymentName == receivedReservedIpFromRdfe.DeploymentName);
        }
예제 #3
0
        private static void AssociateReservedIP(ManagementClient managementClient, string usWestLocStr, string location,
                                                StorageManagementClient storageClient, string storageAccountName, ref bool storageAccountCreated,
                                                ComputeManagementClient computeClient, string serviceName, string deploymentName, string reserveIpName,
                                                NetworkTestBase _testFixture, ref bool hostedServiceCreated, ref bool reserveIpCreated)
        {
            if (managementClient.Locations.List().Any(
                    c => string.Equals(c.Name, usWestLocStr, StringComparison.OrdinalIgnoreCase)))
            {
                location = usWestLocStr;
            }

            CreateStorageAccount(location, storageClient, storageAccountName, out storageAccountCreated);

            CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);

            CreatePaaSDeployment(storageAccountName, computeClient, serviceName, deploymentName);

            NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
            {
                Name     = reserveIpName,
                Location = "uswest",
                Label    = "SampleReserveIPLabel"
            };

            OperationStatusResponse reserveIpCreate = _testFixture.NetworkClient.ReservedIPs.Create(reservedIpCreatePars);

            Assert.True(reserveIpCreate.StatusCode == HttpStatusCode.OK);
            reserveIpCreated = true;

            NetworkReservedIPGetResponse reserveIpCreationResponse =
                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

            Assert.True(reserveIpCreationResponse.StatusCode == HttpStatusCode.OK);


            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
            {
                ServiceName    = serviceName,
                DeploymentName = deploymentName
            };
            OperationStatusResponse responseAssociateRip = _testFixture.NetworkClient.ReservedIPs.Associate(reserveIpName, pars);

            Assert.True(responseAssociateRip.StatusCode == HttpStatusCode.OK);

            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

            Assert.True(receivedReservedIpFromRdfe.StatusCode == HttpStatusCode.OK);

            Assert.True(serviceName == receivedReservedIpFromRdfe.ServiceName);
            Assert.True(receivedReservedIpFromRdfe.InUse == true);
            Assert.True(deploymentName == receivedReservedIpFromRdfe.DeploymentName);
        }
예제 #4
0
        private static void DisassociateReservedIP(NetworkTestBase _testFixture, string reserveIpName, string serviceName, string deploymentName)
        {
            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
            {
                ServiceName    = serviceName,
                DeploymentName = deploymentName
            };
            OperationStatusResponse responseDisassociateRip = _testFixture.NetworkClient.ReservedIPs.Disassociate(reserveIpName, pars);

            Assert.True(responseDisassociateRip.StatusCode == HttpStatusCode.OK);

            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

            Assert.True(receivedReservedIpFromRdfe.StatusCode == HttpStatusCode.OK);

            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.ServiceName));
            Assert.True(receivedReservedIpFromRdfe.InUse == false);
            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.DeploymentName));
        }
 /// <summary>
 /// The Associate Reserved IP operation associates a Reserved IP with a
 /// service.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IReservedIPOperations.
 /// </param>
 /// <param name='reservedIpName'>
 /// Required. The name of the reserved IP.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to associate Reserved IP.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static Task <OperationStatusResponse> AssociateAsync(this IReservedIPOperations operations, string reservedIpName, NetworkReservedIPMobilityParameters parameters)
 {
     return(operations.AssociateAsync(reservedIpName, parameters, CancellationToken.None));
 }
 /// <summary>
 /// The Associate Reserved IP operation associates a Reserved IP with a
 /// service.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IReservedIPOperations.
 /// </param>
 /// <param name='reservedIpName'>
 /// Required. The name of the reserved IP.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to associate Reserved IP.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static OperationStatusResponse Associate(this IReservedIPOperations operations, string reservedIpName, NetworkReservedIPMobilityParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IReservedIPOperations)s).AssociateAsync(reservedIpName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
예제 #7
0
        public void TestAssociateDisassociateOnMultivipIaaSDeployment()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    bool   hostedServiceCreated  = false;
                    bool   storageAccountCreated = false;
                    string storageAccountName    = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName           = AZT.TestUtilities.GenerateName("testser");
                    string deploymentName        = AZT.TestUtilities.GenerateName("dep");

                    ComputeManagementClient computeClient    = _testFixture.GetComputeManagementClient();
                    ManagementClient        managementClient = _testFixture.ManagementClient;
                    StorageManagementClient storageClient    = _testFixture.GetStorageManagementClient();
                    List <string>           createdRips      = new List <string>();

                    try
                    {
                        string location = Utilities.GetTestLocation(managementClient);
                        Assert.True(!string.IsNullOrEmpty(location));

                        // Create hosted service
                        Utilities.CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);
                        Assert.True(hostedServiceCreated);

                        // Create storage account
                        storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                        Utilities.CreateStorageAccount(location, storageClient, storageAccountName,
                                                       out storageAccountCreated);
                        Assert.True(storageAccountCreated);


                        List <string> vipNames = new List <string>()
                        {
                            AZT.TestUtilities.GenerateName("VipA"),
                            AZT.TestUtilities.GenerateName("VipB"),
                            AZT.TestUtilities.GenerateName("VipC"),
                            AZT.TestUtilities.GenerateName("VipD"),
                            AZT.TestUtilities.GenerateName("VipE")
                        };

                        List <string> reservedIPNames = new List <string>()
                        {
                            AZT.TestUtilities.GenerateName("RipA"),
                            AZT.TestUtilities.GenerateName("RipB"),
                            AZT.TestUtilities.GenerateName("RipC"),
                            AZT.TestUtilities.GenerateName("RipD"),
                            AZT.TestUtilities.GenerateName("RipE")
                        };

                        CreateMultivipDeploymentAndAssertSuccess(_testFixture.NetworkClient, computeClient,
                                                                 vipNames, serviceName, deploymentName, storageAccountName, location);

                        // Associate 5 reserved IPs
                        for (int i = 0; i < 5; i++)
                        {
                            string reserveIpName = reservedIPNames[i];
                            string vipName       = vipNames[i];
                            NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
                            {
                                Name     = reserveIpName,
                                Location = location,
                                Label    = "SampleReserveIPLabel"
                            };

                            OperationStatusResponse reserveIpCreate = _testFixture.NetworkClient.ReservedIPs.Create(reservedIpCreatePars);
                            Assert.True(reserveIpCreate.StatusCode == HttpStatusCode.OK);
                            createdRips.Add(reserveIpName);

                            NetworkReservedIPGetResponse reserveIpCreationResponse =
                                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

                            Assert.True(reserveIpCreationResponse.StatusCode == HttpStatusCode.OK);

                            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
                            {
                                ServiceName    = serviceName,
                                DeploymentName = deploymentName,
                                VirtualIPName  = vipName
                            };
                            OperationStatusResponse responseAssociateRip = _testFixture.NetworkClient.ReservedIPs.Associate(reserveIpName, pars);
                            Assert.True(responseAssociateRip.StatusCode == HttpStatusCode.OK);
                            DeploymentGetResponse deploymentResponse =
                                computeClient.Deployments.GetByName(serviceName: serviceName,
                                                                    deploymentName: deploymentName);

                            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

                            Assert.True(receivedReservedIpFromRdfe.StatusCode == HttpStatusCode.OK);

                            Assert.True(serviceName == receivedReservedIpFromRdfe.ServiceName);
                            Assert.True(receivedReservedIpFromRdfe.InUse == true);
                            Assert.True(deploymentName == receivedReservedIpFromRdfe.DeploymentName);
                            Assert.True(reserveIpName == receivedReservedIpFromRdfe.Name);
                            Assert.True(vipName == receivedReservedIpFromRdfe.VirtualIPName);
                            var vipAssociated = deploymentResponse.VirtualIPAddresses.FirstOrDefault(vip => vip.Name == vipName);
                            Assert.NotNull(vipAssociated);
                            Assert.True(vipAssociated.ReservedIPName == reserveIpName);
                        }

                        // Disassociate the associated IPs
                        for (int i = 0; i < 5; i++)
                        {
                            string reserveIpName = reservedIPNames[i];
                            string vipName       = vipNames[i];

                            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
                            {
                                ServiceName    = serviceName,
                                DeploymentName = deploymentName,
                                VirtualIPName  = vipName
                            };

                            OperationStatusResponse responseDisassociateRip = _testFixture.NetworkClient.ReservedIPs.Disassociate(reserveIpName, pars);
                            Assert.True(responseDisassociateRip.StatusCode == HttpStatusCode.OK);
                            DeploymentGetResponse deploymentResponse =
                                computeClient.Deployments.GetByName(serviceName: serviceName,
                                                                    deploymentName: deploymentName);

                            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

                            Assert.True(receivedReservedIpFromRdfe.StatusCode == HttpStatusCode.OK);

                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.ServiceName));
                            Assert.True(receivedReservedIpFromRdfe.InUse == false);
                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.DeploymentName));
                            Assert.True(reserveIpName == receivedReservedIpFromRdfe.Name);
                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.VirtualIPName));
                            var vipAssociated = deploymentResponse.VirtualIPAddresses.FirstOrDefault(vip => vip.Name == vipName);
                            Assert.NotNull(vipAssociated);
                            Assert.True(string.IsNullOrEmpty(vipAssociated.ReservedIPName));
                        }
                    }
                    finally
                    {
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (createdRips.Any())
                        {
                            foreach (var rip in createdRips)
                            {
                                // Clean up created Reserved IPs
                                _testFixture.NetworkClient.ReservedIPs.Delete(rip);
                            }
                        }
                    }
                }
            }
        }