コード例 #1
0
        public override void ExecuteCmdlet()
        {
            if (string.IsNullOrEmpty(AccessType))
            {
                AzureDedicatedCircuitStats stats = new AzureDedicatedCircuitStats
                {
                    PrimaryBytesIn    = (ulong)0,
                    PrimaryBytesOut   = (ulong)0,
                    SecondaryBytesIn  = (ulong)0,
                    SecondaryBytesOut = (ulong)0
                };
                stats = compute(stats, ServiceKey, BgpPeeringAccessType.Private);
                stats = compute(stats, ServiceKey, BgpPeeringAccessType.Public);
                stats = compute(stats, ServiceKey, BgpPeeringAccessType.Microsoft);

                WriteObject(stats);
            }
            BgpPeeringAccessType type;

            if (BgpPeeringAccessType.TryParse(AccessType, true, out type))
            {
                var stats = ExpressRouteClient.GetAzureDedicatedCircuitStatsInfo(ServiceKey, type);
                WriteObject(stats);
            }
        }
コード例 #2
0
        private AzureDedicatedCircuitStats compute(AzureDedicatedCircuitStats stats, Guid key, BgpPeeringAccessType type)
        {
            var tempstats = ExpressRouteClient.GetAzureDedicatedCircuitStatsInfo(key, type);

            stats.PrimaryBytesIn    += tempstats.PrimaryBytesIn;
            stats.PrimaryBytesOut   += tempstats.PrimaryBytesOut;
            stats.SecondaryBytesIn  += tempstats.SecondaryBytesIn;
            stats.SecondaryBytesOut += tempstats.SecondaryBytesOut;
            return(stats);
        }
コード例 #3
0
 private AzureDedicatedCircuitStats compute(AzureDedicatedCircuitStats stats, Guid key, BgpPeeringAccessType type)
 {
     try
     {
         AzureBgpPeering peering = ExpressRouteClient.GetAzureBGPPeering(ServiceKey, type);
         if (peering != null)
         {
             var tempstats = ExpressRouteClient.GetAzureDedicatedCircuitStatsInfo(key, type);
             stats.PrimaryBytesIn    += tempstats.PrimaryBytesIn;
             stats.PrimaryBytesOut   += tempstats.PrimaryBytesOut;
             stats.SecondaryBytesIn  += tempstats.SecondaryBytesIn;
             stats.SecondaryBytesOut += tempstats.SecondaryBytesOut;
         }
         return(stats);
     }
     catch
     {
         // The cirucit might not have corresponding peering
         return(stats);
     }
 }
        /// <summary>
        /// The Get Dedicated Circuit Stats operation retrieves the
        /// bytesin/bytesout of the dedicated circuit on primary/secondary
        /// devices for specified peering type.
        /// </summary>
        /// <param name='serviceKey'>
        /// Required. The service key representing the circuit.
        /// </param>
        /// <param name='accessType'>
        /// Required. Whether the peering is private or public or microsoft.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Get DedicatedCircuitPeeringStats operation response.
        /// </returns>
        public async Task <DedicatedCircuitPeeringStatsGetResponse> GetAsync(string serviceKey, BgpPeeringAccessType accessType, CancellationToken cancellationToken)
        {
            // Validate
            if (serviceKey == null)
            {
                throw new ArgumentNullException("serviceKey");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

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

            // Construct URL
            string url = "";

            url = url + "/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/services/networking/dedicatedcircuits/";
            url = url + Uri.EscapeDataString(serviceKey);
            url = url + "/bgppeerings/";
            url = url + Uri.EscapeDataString(ExpressRouteManagementClient.BgpPeeringAccessTypeToString(accessType));
            url = url + "/stats";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=1.0");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // 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;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

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

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

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

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

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    DedicatedCircuitPeeringStatsGetResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new DedicatedCircuitPeeringStatsGetResponse();
                        XDocument responseDoc = XDocument.Parse(responseContent);

                        XElement dedicatedCircuitPeeringStatsElement = responseDoc.Element(XName.Get("DedicatedCircuitPeeringStats", "http://schemas.microsoft.com/windowsazure"));
                        if (dedicatedCircuitPeeringStatsElement != null)
                        {
                            AzureDedicatedCircuitStats dedicatedCircuitStatsInstance = new AzureDedicatedCircuitStats();
                            result.DedicatedCircuitStats = dedicatedCircuitStatsInstance;

                            XElement primaryBytesInElement = dedicatedCircuitPeeringStatsElement.Element(XName.Get("PrimaryBytesIn", "http://schemas.microsoft.com/windowsazure"));
                            if (primaryBytesInElement != null)
                            {
                                ulong primaryBytesInInstance = ulong.Parse(primaryBytesInElement.Value, CultureInfo.InvariantCulture);
                                dedicatedCircuitStatsInstance.PrimaryBytesIn = primaryBytesInInstance;
                            }

                            XElement primaryBytesOutElement = dedicatedCircuitPeeringStatsElement.Element(XName.Get("PrimaryBytesOut", "http://schemas.microsoft.com/windowsazure"));
                            if (primaryBytesOutElement != null)
                            {
                                ulong primaryBytesOutInstance = ulong.Parse(primaryBytesOutElement.Value, CultureInfo.InvariantCulture);
                                dedicatedCircuitStatsInstance.PrimaryBytesOut = primaryBytesOutInstance;
                            }

                            XElement secondaryBytesInElement = dedicatedCircuitPeeringStatsElement.Element(XName.Get("SecondaryBytesIn", "http://schemas.microsoft.com/windowsazure"));
                            if (secondaryBytesInElement != null)
                            {
                                ulong secondaryBytesInInstance = ulong.Parse(secondaryBytesInElement.Value, CultureInfo.InvariantCulture);
                                dedicatedCircuitStatsInstance.SecondaryBytesIn = secondaryBytesInInstance;
                            }

                            XElement secondaryBytesOutElement = dedicatedCircuitPeeringStatsElement.Element(XName.Get("SecondaryBytesOut", "http://schemas.microsoft.com/windowsazure"));
                            if (secondaryBytesOutElement != null)
                            {
                                ulong secondaryBytesOutInstance = ulong.Parse(secondaryBytesOutElement.Value, CultureInfo.InvariantCulture);
                                dedicatedCircuitStatsInstance.SecondaryBytesOut = secondaryBytesOutInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }