protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();
            string deploymentName = string.Empty;

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


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

            ExecuteClientActionNewSM(
                null,
                CommandRuntime.ToString(),
                () =>
            {
                var parameters = new NetworkReservedIPCreateParameters
                {
                    Name           = this.ReservedIPName,
                    Label          = this.Label,
                    Location       = this.Location,
                    ServiceName    = this.ServiceName,
                    DeploymentName = deploymentName,
                    VirtualIPName  = this.VirtualIPName
                };

                return(this.NetworkClient.ReservedIPs.Create(parameters));
            });
        }
Example #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);
        }
        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);
        }
Example #4
0
        public void TestReserveIPWithIPTagsNegative()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    var    managementClient      = _testFixture.ManagementClient;
                    bool   storageAccountCreated = false;
                    string storageAccountName    = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string reserveIpName         = HttpMockServer.GetAssetName("res", "testresIPtagNegative").ToLower();
                    string location = managementClient.GetDefaultLocation("Storage", "Compute");

                    // Create an IPTag Value that doesn't exist
                    IPTag iptag = new IPTag();
                    iptag.IPTagType = "FirstPartyUsage";
                    iptag.Value     = "MyVip";
                    List <IPTag> iptags = new List <IPTag>();
                    iptags.Add(iptag);

                    try
                    {
                        _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);

                        NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
                        {
                            Name     = reserveIpName,
                            Label    = "TestResTagNegLabel",
                            Location = location,
                            IPTags   = iptags
                        };

                        OperationStatusResponse reserveIpCreate = _testFixture.NetworkClient.ReservedIPs.Create(reservedIpCreatePars);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("TestReserveIPWithIPTagsNegative test did not succeed with error being ," + ex.Message);
                        Assert.NotNull(ex);
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                    }
                }
            }
        }
        public void ExecuteCommand()
        {
            var parameters = new NetworkReservedIPCreateParameters
            {
                Name           = ReservedIPName,
                Label          = Label,
                AffinityGroup  = AffinityGroup,
                ServiceName    = ServiceName,
                DeploymentName = DeploymentName
            };

            ExecuteClientActionNewSM(null,
                                     CommandRuntime.ToString(),
                                     () => NetworkClient.ReservedIPs.Create(parameters));
        }
        public void ExecuteCommand()
        {
            var parameters = new NetworkReservedIPCreateParameters
            {
                Name = ReservedIPName,
                Label = Label,
                AffinityGroup = AffinityGroup,
                ServiceName = ServiceName,
                DeploymentName = DeploymentName
            };

            ExecuteClientActionNewSM(null,
                CommandRuntime.ToString(),
                () => NetworkClient.ReservedIPs.Create(parameters));
        }
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            ExecuteClientActionNewSM(
                null,
                CommandRuntime.ToString(),
                () =>
                {
                    var parameters = new NetworkReservedIPCreateParameters
                    {
                        Name           = this.ReservedIPName,
                        Label          = this.Label,
                        Location       = this.Location
                    };

                    return this.NetworkClient.ReservedIPs.Create(parameters);
                });
        }
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            ExecuteClientActionNewSM(
                null,
                CommandRuntime.ToString(),
                () =>
            {
                var parameters = new NetworkReservedIPCreateParameters
                {
                    Name     = this.ReservedIPName,
                    Label    = this.Label,
                    Location = this.Location
                };

                return(this.NetworkClient.ReservedIPs.Create(parameters));
            });
        }
        /// <summary>
        /// Preview Only. The Begin Creating Reserved IP operation creates a
        /// reserved IP from your the subscription.
        /// </summary>
        /// <param name='parameters'>
        /// Required. Parameters supplied to the Begin Creating Reserved IP
        /// operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </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 async System.Threading.Tasks.Task <OperationStatusResponse> BeginCreatingAsync(NetworkReservedIPCreateParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("parameters", parameters);
                Tracing.Enter(invocationId, this, "BeginCreatingAsync", tracingParameters);
            }

            // Construct URL
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            string url     = "/" + this.Client.Credentials.SubscriptionId.Trim() + "/services/networking/reservedips";

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Post;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2013-11-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Serialize Request
                string    requestContent = null;
                XDocument requestDoc     = new XDocument();

                XElement reservedIPElement = new XElement(XName.Get("ReservedIP", "http://schemas.microsoft.com/windowsazure"));
                requestDoc.Add(reservedIPElement);

                if (parameters.Name != null)
                {
                    XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                    nameElement.Value = parameters.Name;
                    reservedIPElement.Add(nameElement);
                }

                if (parameters.Label != null)
                {
                    XElement labelElement = new XElement(XName.Get("Label", "http://schemas.microsoft.com/windowsazure"));
                    labelElement.Value = parameters.Label;
                    reservedIPElement.Add(labelElement);
                }

                if (parameters.AffinityGroup != null)
                {
                    XElement affinityGroupElement = new XElement(XName.Get("AffinityGroup", "http://schemas.microsoft.com/windowsazure"));
                    affinityGroupElement.Value = parameters.AffinityGroup;
                    reservedIPElement.Add(affinityGroupElement);
                }

                if (parameters.ServiceName != null)
                {
                    XElement serviceNameElement = new XElement(XName.Get("ServiceName", "http://schemas.microsoft.com/windowsazure"));
                    serviceNameElement.Value = parameters.ServiceName;
                    reservedIPElement.Add(serviceNameElement);
                }

                if (parameters.DeploymentName != null)
                {
                    XElement deploymentNameElement = new XElement(XName.Get("DeploymentName", "http://schemas.microsoft.com/windowsazure"));
                    deploymentNameElement.Value = parameters.DeploymentName;
                    reservedIPElement.Add(deploymentNameElement);
                }

                requestContent      = requestDoc.ToString();
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml");

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.Accepted)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    OperationStatusResponse result = null;
                    result            = new OperationStatusResponse();
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Example #10
0
 /// <summary>
 /// Preview Only. The Begin Creating Reserved IP operation creates a
 /// reserved IP from your the subscription.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IReservedIPOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Creating Reserved IP
 /// operation.
 /// </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> BeginCreatingAsync(this IReservedIPOperations operations, NetworkReservedIPCreateParameters parameters)
 {
     return(operations.BeginCreatingAsync(parameters, CancellationToken.None));
 }
        /// <summary>
        /// The Create Reserved IP operation creates a reserved IP from your
        /// the subscription.
        /// </summary>
        /// <param name='parameters'>
        /// Required. Parameters supplied to the Create Reserved IP operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </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 async System.Threading.Tasks.Task <OperationStatusResponse> CreateAsync(NetworkReservedIPCreateParameters parameters, CancellationToken cancellationToken)
        {
            NetworkManagementClient client = this.Client;
            bool   shouldTrace             = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId            = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("parameters", parameters);
                Tracing.Enter(invocationId, this, "CreateAsync", tracingParameters);
            }
            try
            {
                if (shouldTrace)
                {
                    client = this.Client.WithHandler(new ClientRequestTrackingHandler(invocationId));
                }

                cancellationToken.ThrowIfCancellationRequested();
                OperationStatusResponse response = await client.ReservedIPs.BeginCreatingAsync(parameters, cancellationToken).ConfigureAwait(false);

                if (response.Status == OperationStatus.Succeeded)
                {
                    return(response);
                }
                cancellationToken.ThrowIfCancellationRequested();
                OperationStatusResponse result = await client.GetOperationStatusAsync(response.RequestId, cancellationToken).ConfigureAwait(false);

                int delayInSeconds = 30;
                while ((result.Status != OperationStatus.InProgress) == false)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    await TaskEx.Delay(delayInSeconds * 1000, cancellationToken).ConfigureAwait(false);

                    cancellationToken.ThrowIfCancellationRequested();
                    result = await client.GetOperationStatusAsync(response.RequestId, cancellationToken).ConfigureAwait(false);

                    delayInSeconds = 30;
                }

                if (shouldTrace)
                {
                    Tracing.Exit(invocationId, result);
                }

                if (result.Status != OperationStatus.Succeeded)
                {
                    if (result.Error != null)
                    {
                        CloudException ex = new CloudException(result.Error.Code + " : " + result.Error.Message);
                        ex.ErrorCode    = result.Error.Code;
                        ex.ErrorMessage = result.Error.Message;
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }
                    else
                    {
                        CloudException ex = new CloudException("");
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }
                }

                return(result);
            }
            finally
            {
                if (client != null && shouldTrace)
                {
                    client.Dispose();
                }
            }
        }
Example #12
0
        public void TestReserveIPWithIPTagsSimple()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    var    managementClient      = _testFixture.ManagementClient;
                    bool   storageAccountCreated = false;
                    string storageAccountName    = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string reserveIpName         = HttpMockServer.GetAssetName("res", "testresIPtag").ToLower();
                    string location          = "West Central US";
                    bool   reservedIpCreated = false;

                    IPTag iptag = new IPTag();
                    iptag.IPTagType = "FirstPartyUsage";
                    iptag.Value     = "/tagTypes/SystemService/operators/Microsoft/platforms/Azure/services/Microsoft.AzureAD";
                    List <IPTag> iptags = new List <IPTag>();
                    iptags.Add(iptag);

                    try
                    {
                        _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);

                        NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
                        {
                            Name     = reserveIpName,
                            Label    = "TestResTagLabel",
                            Location = location,
                            IPTags   = iptags
                        };

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

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

                        Assert.True(reserveIpCreationResponse.StatusCode == HttpStatusCode.OK);
                        Assert.True(reserveIpCreationResponse.IPTags.Count == iptags.Count);

                        foreach (var iptag1 in iptags)
                        {
                            Assert.True(reserveIpCreationResponse.IPTags.Any(x => x.IPTagType == iptag1.IPTagType && x.Value == iptag1.Value));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("TestReserveIPWithIPTagsSimple test did not succeed with error being ," + ex.Message);
                        throw;
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (reservedIpCreated)
                        {
                            _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName);
                        }
                    }
                }
            }
        }
Example #13
0
 /// <summary>
 /// Preview Only. The Begin Creating Reserved IP operation creates a
 /// reserved IP from your the subscription.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IReservedIPOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Creating Reserved IP
 /// operation.
 /// </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 BeginCreating(this IReservedIPOperations operations, NetworkReservedIPCreateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IReservedIPOperations)s).BeginCreatingAsync(parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Example #14
0
        /// <summary>
        /// The Create Reserved IP operation creates a reserved IP from your
        /// the subscription.
        /// </summary>
        /// <param name='parameters'>
        /// Required. Parameters supplied to the Create Reserved IP operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </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 async Task <OperationStatusResponse> CreateAsync(NetworkReservedIPCreateParameters parameters, CancellationToken cancellationToken)
        {
            NetworkManagementClient client = this.Client;
            bool   shouldTrace             = TracingAdapter.IsEnabled;
            string invocationId            = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("parameters", parameters);
                TracingAdapter.Enter(invocationId, this, "CreateAsync", tracingParameters);
            }

            cancellationToken.ThrowIfCancellationRequested();
            OperationStatusResponse response = await client.ReservedIPs.BeginCreatingAsync(parameters, cancellationToken).ConfigureAwait(false);

            if (response.Status == OperationStatus.Succeeded)
            {
                return(response);
            }
            cancellationToken.ThrowIfCancellationRequested();
            OperationStatusResponse result = await client.GetOperationStatusAsync(response.RequestId, cancellationToken).ConfigureAwait(false);

            int delayInSeconds = 30;

            if (client.LongRunningOperationInitialTimeout >= 0)
            {
                delayInSeconds = client.LongRunningOperationInitialTimeout;
            }
            while ((result.Status != OperationStatus.InProgress) == false)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await TaskEx.Delay(delayInSeconds * 1000, cancellationToken).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();
                result = await client.GetOperationStatusAsync(response.RequestId, cancellationToken).ConfigureAwait(false);

                delayInSeconds = 30;
                if (client.LongRunningOperationRetryTimeout >= 0)
                {
                    delayInSeconds = client.LongRunningOperationRetryTimeout;
                }
            }

            if (shouldTrace)
            {
                TracingAdapter.Exit(invocationId, result);
            }

            if (result.Status != OperationStatus.Succeeded)
            {
                if (result.Error != null)
                {
                    CloudException ex = new CloudException(result.Error.Code + " : " + result.Error.Message);
                    ex.Error         = new CloudError();
                    ex.Error.Code    = result.Error.Code;
                    ex.Error.Message = result.Error.Message;
                    if (shouldTrace)
                    {
                        TracingAdapter.Error(invocationId, ex);
                    }
                    throw ex;
                }
                else
                {
                    CloudException ex = new CloudException("");
                    if (shouldTrace)
                    {
                        TracingAdapter.Error(invocationId, ex);
                    }
                    throw ex;
                }
            }

            return(result);
        }
 /// <summary>
 /// Preview Only. The Create Reserved IP operation creates a reserved
 /// IP from your the subscription.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.VirtualNetworks.IReservedIPOperations.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create Virtual Machine Image operation.
 /// </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 VirtualNetworkOperationStatusResponse BeginCreating(this IReservedIPOperations operations, NetworkReservedIPCreateParameters parameters)
 {
     try
     {
         return(operations.BeginCreatingAsync(parameters).Result);
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
 /// <summary>
 /// The Create Reserved IP operation creates a reserved IP from your
 /// the subscription.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.VirtualNetworks.IReservedIPOperations.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create Virtual Machine Image operation.
 /// </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 <VirtualNetworkOperationStatusResponse> CreateAsync(this IReservedIPOperations operations, NetworkReservedIPCreateParameters parameters)
 {
     return(operations.CreateAsync(parameters, CancellationToken.None));
 }
Example #17
0
        public void TestReservingExistingDeploymentIP()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    var    managementClient      = _testFixture.ManagementClient;
                    bool   storageAccountCreated = false;
                    bool   hostedServiceCreated  = false;
                    string storageAccountName    = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName           = AZT.TestUtilities.GenerateName("testser");
                    string deploymentName        = string.Format("{0}Prd", serviceName);
                    string reserveIpName         = HttpMockServer.GetAssetName("res", "testres").ToLower();
                    string location          = managementClient.GetDefaultLocation("Storage", "Compute");
                    bool   reservedIpCreated = false;
                    try
                    {
                        _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);

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

                        var deployment = _testFixture.CreatePaaSDeployment(storageAccountName, serviceName, deploymentName, NetworkTestConstants.OneWebOneWorkerPkgFilePath, "OneWebOneWorker.cscfg", startDeployment: true);

                        NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
                        {
                            Name           = reserveIpName,
                            Label          = "TestLabel",
                            DeploymentName = deploymentName,
                            ServiceName    = serviceName,
                            Location       = location
                        };

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

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


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

                        Assert.True(reserveIpCreationResponse.ServiceName == serviceName);
                        Assert.True(reserveIpCreationResponse.DeploymentName == deploymentName);
                        Assert.True(reserveIpCreationResponse.InUse == true);
                        Assert.True(reserveIpCreationResponse.Address == deployment.VirtualIPAddresses[0].Address);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            _testFixture.ComputeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (reservedIpCreated)
                        {
                            _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName);
                        }
                    }
                }
            }
        }
Example #18
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);
                            }
                        }
                    }
                }
            }
        }