Ejemplo n.º 1
0
        /// <summary>
        /// Creates an empty VNET to add address ranges and subnets
        /// </summary>
        public string AddSubnetToAddressRange(string networkName, string addressRange, string subnetName)
        {
            var networkResponse = GetAvailableVirtualNetworks();
            var vNetSpecific    = networkResponse.FirstOrDefault(vnet => vnet.Name == networkName);
            var subnetAddress   = VirtualNetworkingUtils.NextAvailableSubnet(addressRange, vNetSpecific);

            if (subnetAddress == null)
            {
                throw new FluentManagementException("there is no space in the selected address range to create a new subnet", "VirtualNetworkClient");
            }
            var subnetTag = new SubnetTag()
            {
                NetworkName        = networkName,
                AddressPrefix      = addressRange,
                SubnetAddressRange = subnetAddress,
                SubnetName         = subnetName
            };
            string xml     = AddXmlSubnetToExistingNetworkingDefinition(subnetTag);
            var    command = new SetVirtualNetworkConfigCommand(xml)
            {
                SubscriptionId = SubscriptionId,
                Certificate    = ManagementCertificate
            };

            command.Execute();
            return(xml);
        }
Ejemplo n.º 2
0
        private string AddXmlSubnetToExistingNetworkingDefinition(SubnetTag tag)
        {
            var xml          = GetAllNetworkingConfig();
            var document     = XDocument.Parse(xml);
            var virtualSites = document.Element(Namespace + "NetworkConfiguration")
                               .Element(Namespace + "VirtualNetworkConfiguration")
                               .Element(Namespace + "VirtualNetworkSites")
                               .Elements(Namespace + "VirtualNetworkSite")
                               .FirstOrDefault(site => site.Attributes("name").FirstOrDefault().Value == tag.NetworkName);
            var addedSubnetTag = new XElement(Namespace + "Subnet",
                                              new XAttribute("name", tag.SubnetName),
                                              new XElement(Namespace + "AddressPrefix", tag.SubnetAddressRange)
                                              );

            if (virtualSites.Element(Namespace + "Subnets") == null)
            {
                virtualSites.Add(new XElement(Namespace + "Subnets"));
            }
            virtualSites.Element(Namespace + "Subnets").Add(addedSubnetTag);
            return(document.ToStringFullXmlDeclaration());
        }
 /// <summary>
 /// Creates an empty VNET to add address ranges and subnets 
 /// </summary>
 public string AddSubnetToAddressRange(string networkName, string addressRange, string subnetName)
 {
     var networkResponse = GetAvailableVirtualNetworks();
     var vNetSpecific = networkResponse.FirstOrDefault(vnet => vnet.Name == networkName);
     var subnetAddress = VirtualNetworkingUtils.NextAvailableSubnet(addressRange, vNetSpecific);
     if (subnetAddress == null)
     {
         throw new FluentManagementException("there is no space in the selected address range to create a new subnet", "VirtualNetworkClient");
     }
     var subnetTag = new SubnetTag()
     {
         NetworkName = networkName,
         AddressPrefix = addressRange,
         SubnetAddressRange = subnetAddress,
         SubnetName = subnetName
     };
     string xml = AddXmlSubnetToExistingNetworkingDefinition(subnetTag);
     var command = new SetVirtualNetworkConfigCommand(xml)
     {
         SubscriptionId = SubscriptionId,
         Certificate = ManagementCertificate
     };
     command.Execute();
     return xml;
 }
 private string AddXmlSubnetToExistingNetworkingDefinition(SubnetTag tag)
 {
     var xml = GetAllNetworkingConfig();
     var document = XDocument.Parse(xml);
     var virtualSites = document.Element(Namespace + "NetworkConfiguration")
         .Element(Namespace + "VirtualNetworkConfiguration")
         .Element(Namespace + "VirtualNetworkSites")
         .Elements(Namespace + "VirtualNetworkSite")
         .FirstOrDefault(site => site.Attributes("name").FirstOrDefault().Value == tag.NetworkName);
     var addedSubnetTag = new XElement(Namespace + "Subnet",
         new XAttribute("name", tag.SubnetName),
         new XElement(Namespace + "AddressPrefix", tag.SubnetAddressRange)
         );
     if (virtualSites.Element(Namespace + "Subnets") == null)
     {
         virtualSites.Add(new XElement(Namespace + "Subnets"));
     }
     virtualSites.Element(Namespace + "Subnets").Add(addedSubnetTag);
     return document.ToStringFullXmlDeclaration();
 }