/// <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); }
/// <summary> /// Removes a subnet from the network configuration /// </summary> public void RemoveSubnet(string networkName, string subnetName) { var networkResponse = GetAllNetworkingConfig(); var document = XDocument.Parse(networkResponse); var networks = document.Descendants(Namespaces.NetworkingConfig + "VirtualNetworkSite"); var vnet = networks.FirstOrDefault(network => network.Attribute("name").Value == networkName); if (vnet == null) { throw new FluentManagementException("VirtualNetworkClient", "Virtual Network not found"); } var subnets = vnet.Descendants(Namespaces.NetworkingConfig + "Subnet"); var subnet = subnets.FirstOrDefault(element => element.Attribute("name").Value == subnetName); if (subnet == null) { throw new FluentManagementException("VirtualNetworkClient", "Subnet not found"); } subnet.Remove(); var command = new SetVirtualNetworkConfigCommand(document.ToStringFullXmlDeclaration()) { SubscriptionId = SubscriptionId, Certificate = ManagementCertificate }; command.Execute(); }