|
| 1 | +/************************************************************************************************************ |
| 2 | + * This software is distributed under a GNU Lesser License by Elastacloud Limited and it is free to * |
| 3 | + * modify and distribute providing the terms of the license are followed. From the root of the source the * |
| 4 | + * license can be found in /Resources/license.txt * |
| 5 | + * * |
| 6 | + * Web at: www.elastacloud.com * |
| 7 | + |
| 8 | + ************************************************************************************************************/ |
| 9 | + |
| 10 | +using System.Collections.Generic; |
| 11 | +using System.IO; |
| 12 | +using System.Linq; |
| 13 | +using System.Net; |
| 14 | +using System.Xml.Linq; |
| 15 | +using Elastacloud.AzureManagement.Fluent.Commands.Parsers; |
| 16 | +using Elastacloud.AzureManagement.Fluent.Commands.Services; |
| 17 | +using Elastacloud.AzureManagement.Fluent.Helpers; |
| 18 | +using Elastacloud.AzureManagement.Fluent.Types.VirtualNetworks; |
| 19 | + |
| 20 | +namespace Elastacloud.AzureManagement.Fluent.Commands.VirtualNetworks |
| 21 | +{ |
| 22 | + /// <summary> |
| 23 | + /// Registers a virtual machine image for either Linux or Windowss |
| 24 | + /// </summary> |
| 25 | + public class GetVirtualNetworkAndSubnetsFromCloudServiceCommand : ServiceCommand |
| 26 | + { |
| 27 | + // https://management.core.windows.net/<subscription-id>/services/networking/<virtual-network-name> |
| 28 | + /// <summary> |
| 29 | + /// Lists all images that are registered in your subscriptions |
| 30 | + /// </summary> |
| 31 | + internal GetVirtualNetworkAndSubnetsFromCloudServiceCommand(string cloudService) |
| 32 | + { |
| 33 | + AdditionalHeaders["x-ms-version"] = "2012-03-01"; |
| 34 | + OperationId = "hostedservices"; |
| 35 | + ServiceType = "services"; |
| 36 | + HttpCommand = cloudService + "/deploymentslots/Production"; |
| 37 | + HttpVerb = HttpVerbGet; |
| 38 | + NetworkDetails = new CloudServiceNetworking(); |
| 39 | + } |
| 40 | + |
| 41 | + public CloudServiceNetworking NetworkDetails { get; private set; } |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Initially used via a response callback for commands which expect a async response |
| 45 | + /// </summary> |
| 46 | + /// <param name="webResponse">the HttpWebResponse that will be sent back to the user from the request</param> |
| 47 | + protected override void ResponseCallback(HttpWebResponse webResponse) |
| 48 | + { |
| 49 | + XDocument document; |
| 50 | + |
| 51 | + using (var reader = new StreamReader(webResponse.GetResponseStream())) |
| 52 | + { |
| 53 | + document = XDocument.Parse(reader.ReadToEnd()); |
| 54 | + } |
| 55 | + var root = document.Descendants(Namespaces.NsWindowsAzure + "SubnetName"); |
| 56 | + NetworkDetails.Subnets = root.Select(subnet => subnet.Value).Distinct().ToList(); |
| 57 | + var networkNode = document.Descendants(Namespaces.NsWindowsAzure + "VirtualNetworkName").FirstOrDefault(); |
| 58 | + NetworkDetails.VirtualNetworkName = networkNode == null ? null : networkNode.Value; |
| 59 | + |
| 60 | + SitAndWait.Set(); |
| 61 | + } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// returns the name of the command |
| 65 | + /// </summary> |
| 66 | + public override string ToString() |
| 67 | + { |
| 68 | + return "GetVirtualNetworkAndSubnetsFromCloudServiceCommand"; |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments