Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// Gets the available virtual networks in the correct order binding the address ranges to the subnets
        /// </summary>
        public IEnumerable <VirtualNetworkingUtils.VirtualNetwork> GetAvailableVirtualNetworks(string location)
        {
            var command = new ListVirtualNetworksCommand()
            {
                SubscriptionId = SubscriptionId,
                Certificate    = ManagementCertificate
            };

            command.Execute();
            List <VirtualNetworkSite> virtualNetworks = command.VirtualNetworks;

            if (location != null)
            {
                virtualNetworks = command.VirtualNetworks.Where(network => network.Location == location).ToList();
            }

            return(VirtualNetworkingUtils.ConvertVNetToHierarchicalModel(virtualNetworks));
        }