Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the Subnet class.
 /// </summary>
 /// <param name="id">Resource ID.</param>
 /// <param name="addressPrefix">The address prefix for the
 /// subnet.</param>
 /// <param name="addressPrefixes">List of address prefixes for the
 /// subnet.</param>
 /// <param name="networkSecurityGroup">The reference to the
 /// NetworkSecurityGroup resource.</param>
 /// <param name="routeTable">The reference to the RouteTable
 /// resource.</param>
 /// <param name="natGateway">Nat gateway associated with this
 /// subnet.</param>
 /// <param name="serviceEndpoints">An array of service
 /// endpoints.</param>
 /// <param name="serviceEndpointPolicies">An array of service endpoint
 /// policies.</param>
 /// <param name="privateEndpoints">An array of references to private
 /// endpoints.</param>
 /// <param name="ipConfigurations">An array of references to the
 /// network interface IP configurations using subnet.</param>
 /// <param name="ipConfigurationProfiles">Array of IP configuration
 /// profiles which reference this subnet.</param>
 /// <param name="ipAllocations">Array of IpAllocation which reference
 /// this subnet.</param>
 /// <param name="resourceNavigationLinks">An array of references to the
 /// external resources using subnet.</param>
 /// <param name="serviceAssociationLinks">An array of references to
 /// services injecting into this subnet.</param>
 /// <param name="delegations">An array of references to the delegations
 /// on the subnet.</param>
 /// <param name="purpose">A read-only string identifying the intention
 /// of use for this subnet based on delegations and other user-defined
 /// properties.</param>
 /// <param name="provisioningState">The provisioning state of the
 /// subnet resource. Possible values include: 'Succeeded', 'Updating',
 /// 'Deleting', 'Failed'</param>
 /// <param name="privateEndpointNetworkPolicies">Enable or Disable
 /// apply network policies on private end point in the subnet.</param>
 /// <param name="privateLinkServiceNetworkPolicies">Enable or Disable
 /// apply network policies on private link service in the
 /// subnet.</param>
 /// <param name="name">The name of the resource that is unique within a
 /// resource group. This name can be used to access the
 /// resource.</param>
 /// <param name="etag">A unique read-only string that changes whenever
 /// the resource is updated.</param>
 public Subnet(string id = default(string), string addressPrefix = default(string), IList <string> addressPrefixes = default(IList <string>), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), RouteTable routeTable = default(RouteTable), SubResource natGateway = default(SubResource), IList <ServiceEndpointPropertiesFormat> serviceEndpoints = default(IList <ServiceEndpointPropertiesFormat>), IList <ServiceEndpointPolicy> serviceEndpointPolicies = default(IList <ServiceEndpointPolicy>), IList <PrivateEndpoint> privateEndpoints = default(IList <PrivateEndpoint>), IList <IPConfiguration> ipConfigurations = default(IList <IPConfiguration>), IList <IPConfigurationProfile> ipConfigurationProfiles = default(IList <IPConfigurationProfile>), IList <SubResource> ipAllocations = default(IList <SubResource>), IList <ResourceNavigationLink> resourceNavigationLinks = default(IList <ResourceNavigationLink>), IList <ServiceAssociationLink> serviceAssociationLinks = default(IList <ServiceAssociationLink>), IList <Delegation> delegations = default(IList <Delegation>), string purpose = default(string), string provisioningState = default(string), string privateEndpointNetworkPolicies = default(string), string privateLinkServiceNetworkPolicies = default(string), string name = default(string), string etag = default(string))
     : base(id)
 {
     AddressPrefix           = addressPrefix;
     AddressPrefixes         = addressPrefixes;
     NetworkSecurityGroup    = networkSecurityGroup;
     RouteTable              = routeTable;
     NatGateway              = natGateway;
     ServiceEndpoints        = serviceEndpoints;
     ServiceEndpointPolicies = serviceEndpointPolicies;
     PrivateEndpoints        = privateEndpoints;
     IpConfigurations        = ipConfigurations;
     IpConfigurationProfiles = ipConfigurationProfiles;
     IpAllocations           = ipAllocations;
     ResourceNavigationLinks = resourceNavigationLinks;
     ServiceAssociationLinks = serviceAssociationLinks;
     Delegations             = delegations;
     Purpose           = purpose;
     ProvisioningState = provisioningState;
     PrivateEndpointNetworkPolicies    = privateEndpointNetworkPolicies;
     PrivateLinkServiceNetworkPolicies = privateLinkServiceNetworkPolicies;
     Name = name;
     Etag = etag;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the NetworkInterface class.
 /// </summary>
 /// <param name="id">Resource ID.</param>
 /// <param name="name">Resource name.</param>
 /// <param name="type">Resource type.</param>
 /// <param name="location">Resource location.</param>
 /// <param name="tags">Resource tags.</param>
 /// <param name="extendedLocation">The extended location of the network
 /// interface.</param>
 /// <param name="virtualMachine">The reference to a virtual
 /// machine.</param>
 /// <param name="networkSecurityGroup">The reference to the
 /// NetworkSecurityGroup resource.</param>
 /// <param name="privateEndpoint">A reference to the private endpoint
 /// to which the network interface is linked.</param>
 /// <param name="ipConfigurations">A list of IPConfigurations of the
 /// network interface.</param>
 /// <param name="tapConfigurations">A list of TapConfigurations of the
 /// network interface.</param>
 /// <param name="dnsSettings">The DNS settings in network
 /// interface.</param>
 /// <param name="macAddress">The MAC address of the network
 /// interface.</param>
 /// <param name="primary">Whether this is a primary network interface
 /// on a virtual machine.</param>
 /// <param name="vnetEncryptionSupported">Whether the virtual machine
 /// this nic is attached to supports encryption.</param>
 /// <param name="enableAcceleratedNetworking">If the network interface
 /// is accelerated networking enabled.</param>
 /// <param name="enableIPForwarding">Indicates whether IP forwarding is
 /// enabled on this network interface.</param>
 /// <param name="hostedWorkloads">A list of references to linked
 /// BareMetal resources.</param>
 /// <param name="dscpConfiguration">A reference to the dscp
 /// configuration to which the network interface is linked.</param>
 /// <param name="resourceGuid">The resource GUID property of the
 /// network interface resource.</param>
 /// <param name="provisioningState">The provisioning state of the
 /// network interface resource. Possible values include: 'Succeeded',
 /// 'Updating', 'Deleting', 'Failed'</param>
 /// <param name="workloadType">WorkloadType of the NetworkInterface for
 /// BareMetal resources</param>
 /// <param name="nicType">Type of Network Interface resource. Possible
 /// values include: 'Standard', 'Elastic'</param>
 /// <param name="privateLinkService">Privatelinkservice of the network
 /// interface resource.</param>
 /// <param name="migrationPhase">Migration phase of Network Interface
 /// resource. Possible values include: 'None', 'Prepare', 'Commit',
 /// 'Abort', 'Committed'</param>
 /// <param name="etag">A unique read-only string that changes whenever
 /// the resource is updated.</param>
 public NetworkInterface(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), ExtendedLocation extendedLocation = default(ExtendedLocation), SubResource virtualMachine = default(SubResource), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), PrivateEndpoint privateEndpoint = default(PrivateEndpoint), IList <NetworkInterfaceIPConfiguration> ipConfigurations = default(IList <NetworkInterfaceIPConfiguration>), IList <NetworkInterfaceTapConfiguration> tapConfigurations = default(IList <NetworkInterfaceTapConfiguration>), NetworkInterfaceDnsSettings dnsSettings = default(NetworkInterfaceDnsSettings), string macAddress = default(string), bool?primary = default(bool?), bool?vnetEncryptionSupported = default(bool?), bool?enableAcceleratedNetworking = default(bool?), bool?enableIPForwarding = default(bool?), IList <string> hostedWorkloads = default(IList <string>), SubResource dscpConfiguration = default(SubResource), string resourceGuid = default(string), string provisioningState = default(string), string workloadType = default(string), string nicType = default(string), PrivateLinkService privateLinkService = default(PrivateLinkService), string migrationPhase = default(string), string etag = default(string))
     : base(id, name, type, location, tags)
 {
     ExtendedLocation     = extendedLocation;
     VirtualMachine       = virtualMachine;
     NetworkSecurityGroup = networkSecurityGroup;
     PrivateEndpoint      = privateEndpoint;
     IpConfigurations     = ipConfigurations;
     TapConfigurations    = tapConfigurations;
     DnsSettings          = dnsSettings;
     MacAddress           = macAddress;
     Primary = primary;
     VnetEncryptionSupported     = vnetEncryptionSupported;
     EnableAcceleratedNetworking = enableAcceleratedNetworking;
     EnableIPForwarding          = enableIPForwarding;
     HostedWorkloads             = hostedWorkloads;
     DscpConfiguration           = dscpConfiguration;
     ResourceGuid       = resourceGuid;
     ProvisioningState  = provisioningState;
     WorkloadType       = workloadType;
     NicType            = nicType;
     PrivateLinkService = privateLinkService;
     MigrationPhase     = migrationPhase;
     Etag = etag;
     CustomInit();
 }
        public PSNetworkSecurityGroup ToPsNetworkSecurityGroup(NetworkSecurityGroup nsg)
        {
            var psNsg = Mapper.Map<PSNetworkSecurityGroup>(nsg);

            psNsg.Tag = TagsConversionHelper.CreateTagHashtable(nsg.Tags);

            return psNsg;
        }
 /// <summary>
 /// The Put NetworkSecurityGroup operation creates/updates a network
 /// security groupin the specified resource group.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Network.INetworkSecurityGroupOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='networkSecurityGroupName'>
 /// Required. The name of the network security group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the create/update Network Security
 /// Group operation
 /// </param>
 /// <returns>
 /// Response for PUT NetworkSecurityGroups Api servive call
 /// </returns>
 public static NetworkSecurityGroupPutResponse BeginCreateOrUpdating(this INetworkSecurityGroupOperations operations, string resourceGroupName, string networkSecurityGroupName, NetworkSecurityGroup parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((INetworkSecurityGroupOperations)s).BeginCreateOrUpdatingAsync(resourceGroupName, networkSecurityGroupName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the Subnet class.
 /// </summary>
 public Subnet(string name = default(string), string etag = default(string), string addressPrefix = default(string), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), RouteTable routeTable = default(RouteTable), IList <IPConfiguration> ipConfigurations = default(IList <IPConfiguration>), string provisioningState = default(string))
 {
     Name                 = name;
     Etag                 = etag;
     AddressPrefix        = addressPrefix;
     NetworkSecurityGroup = networkSecurityGroup;
     RouteTable           = routeTable;
     IpConfigurations     = ipConfigurations;
     ProvisioningState    = provisioningState;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the Subnet class.
 /// </summary>
 public Subnet(string id = default(string), string addressPrefix = default(string), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), RouteTable routeTable = default(RouteTable), IList <IPConfiguration> ipConfigurations = default(IList <IPConfiguration>), IList <ResourceNavigationLink> resourceNavigationLinks = default(IList <ResourceNavigationLink>), string provisioningState = default(string), string name = default(string), string etag = default(string))
     : base(id)
 {
     AddressPrefix           = addressPrefix;
     NetworkSecurityGroup    = networkSecurityGroup;
     RouteTable              = routeTable;
     IpConfigurations        = ipConfigurations;
     ResourceNavigationLinks = resourceNavigationLinks;
     ProvisioningState       = provisioningState;
     Name = name;
     Etag = etag;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the NetworkInterface class.
 /// </summary>
 public NetworkInterface(string etag = default(string), SubResource virtualMachine = default(SubResource), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), IList <NetworkInterfaceIPConfiguration> ipConfigurations = default(IList <NetworkInterfaceIPConfiguration>), NetworkInterfaceDnsSettings dnsSettings = default(NetworkInterfaceDnsSettings), string macAddress = default(string), bool?primary = default(bool?), bool?enableIPForwarding = default(bool?), string resourceGuid = default(string), string provisioningState = default(string))
 {
     Etag                 = etag;
     VirtualMachine       = virtualMachine;
     NetworkSecurityGroup = networkSecurityGroup;
     IpConfigurations     = ipConfigurations;
     DnsSettings          = dnsSettings;
     MacAddress           = macAddress;
     Primary              = primary;
     EnableIPForwarding   = enableIPForwarding;
     ResourceGuid         = resourceGuid;
     ProvisioningState    = provisioningState;
 }
Exemplo n.º 8
0
        public void UsageTest()
        {
            var handler = new RecordedDelegatingHandler {StatusCodeToReturn = HttpStatusCode.OK};

            using (var context = UndoContext.Current)
            {
                context.Start();
                var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler);
                var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler);

                var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkSecurityGroups");
                
                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                    new ResourceGroup
                    {
                        Location = location
                    });

                string networkSecurityGroupName = TestUtilities.GenerateName();

                var networkSecurityGroup = new NetworkSecurityGroup()
                {
                    Location = location,
                };

                // Put Nsg
                var putNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup);
                Assert.Equal(HttpStatusCode.OK, putNsgResponse.StatusCode);
                Assert.Equal("Succeeded", putNsgResponse.Status);

                var getNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, getNsgResponse.StatusCode);

                // Query for usages
                var usagesResponse = networkResourceProviderClient.Usages.List(getNsgResponse.NetworkSecurityGroup.Location.Replace(" ", string.Empty));
                Assert.True(usagesResponse.StatusCode == HttpStatusCode.OK);

                // Verify that the strings are populated
                Assert.NotNull(usagesResponse.Usages);
                Assert.True(usagesResponse.Usages.Any());

                foreach (var usage in usagesResponse.Usages)
                {
                    Assert.True(usage.Limit > 0);
                    Assert.NotNull(usage.Name);
                    Assert.True(!string.IsNullOrEmpty(usage.Name.LocalizedValue));
                    Assert.True(!string.IsNullOrEmpty(usage.Name.Value));
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the NetworkInterface class.
 /// </summary>
 public NetworkInterface(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), SubResource virtualMachine = default(SubResource), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), IList <NetworkInterfaceIPConfiguration> ipConfigurations = default(IList <NetworkInterfaceIPConfiguration>), NetworkInterfaceDnsSettings dnsSettings = default(NetworkInterfaceDnsSettings), string macAddress = default(string), bool?primary = default(bool?), bool?enableIPForwarding = default(bool?), string resourceGuid = default(string), string provisioningState = default(string), string etag = default(string))
     : base(id, name, type, location, tags)
 {
     VirtualMachine       = virtualMachine;
     NetworkSecurityGroup = networkSecurityGroup;
     IpConfigurations     = ipConfigurations;
     DnsSettings          = dnsSettings;
     MacAddress           = macAddress;
     Primary            = primary;
     EnableIPForwarding = enableIPForwarding;
     ResourceGuid       = resourceGuid;
     ProvisioningState  = provisioningState;
     Etag = etag;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the NetworkInterface class.
 /// </summary>
 /// <param name="id">Resource ID.</param>
 /// <param name="name">Resource name.</param>
 /// <param name="type">Resource type.</param>
 /// <param name="location">Resource location.</param>
 /// <param name="tags">Resource tags.</param>
 /// <param name="virtualMachine">The reference of a virtual
 /// machine.</param>
 /// <param name="networkSecurityGroup">The reference of the
 /// NetworkSecurityGroup resource.</param>
 /// <param name="privateEndpoint">A reference to the private endpoint
 /// to which the network interface is linked.</param>
 /// <param name="ipConfigurations">A list of IPConfigurations of the
 /// network interface.</param>
 /// <param name="tapConfigurations">A list of TapConfigurations of the
 /// network interface.</param>
 /// <param name="dnsSettings">The DNS settings in network
 /// interface.</param>
 /// <param name="macAddress">The MAC address of the network
 /// interface.</param>
 /// <param name="primary">Whether this is a primary network interface
 /// on a virtual machine.</param>
 /// <param name="enableAcceleratedNetworking">If the network interface
 /// is accelerated networking enabled.</param>
 /// <param name="enableIPForwarding">Indicates whether IP forwarding is
 /// enabled on this network interface.</param>
 /// <param name="hostedWorkloads">A list of references to linked
 /// BareMetal resources.</param>
 /// <param name="resourceGuid">The resource GUID property of the
 /// network interface resource.</param>
 /// <param name="provisioningState">The provisioning state of the
 /// network interface resource. Possible values include: 'Succeeded',
 /// 'Updating', 'Deleting', 'Failed'</param>
 /// <param name="etag">A unique read-only string that changes whenever
 /// the resource is updated.</param>
 public NetworkInterface(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), SubResource virtualMachine = default(SubResource), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), PrivateEndpoint privateEndpoint = default(PrivateEndpoint), IList <NetworkInterfaceIPConfiguration> ipConfigurations = default(IList <NetworkInterfaceIPConfiguration>), IList <NetworkInterfaceTapConfiguration> tapConfigurations = default(IList <NetworkInterfaceTapConfiguration>), NetworkInterfaceDnsSettings dnsSettings = default(NetworkInterfaceDnsSettings), string macAddress = default(string), bool?primary = default(bool?), bool?enableAcceleratedNetworking = default(bool?), bool?enableIPForwarding = default(bool?), IList <string> hostedWorkloads = default(IList <string>), string resourceGuid = default(string), string provisioningState = default(string), string etag = default(string))
     : base(id, name, type, location, tags)
 {
     VirtualMachine       = virtualMachine;
     NetworkSecurityGroup = networkSecurityGroup;
     PrivateEndpoint      = privateEndpoint;
     IpConfigurations     = ipConfigurations;
     TapConfigurations    = tapConfigurations;
     DnsSettings          = dnsSettings;
     MacAddress           = macAddress;
     Primary = primary;
     EnableAcceleratedNetworking = enableAcceleratedNetworking;
     EnableIPForwarding          = enableIPForwarding;
     HostedWorkloads             = hostedWorkloads;
     ResourceGuid      = resourceGuid;
     ProvisioningState = provisioningState;
     Etag = etag;
     CustomInit();
 }
 /// <summary>
 /// The Put NetworkSecurityGroup operation creates/updates a network
 /// security groupin the specified resource group.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Network.INetworkSecurityGroupOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='networkSecurityGroupName'>
 /// Required. The name of the network security group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the create/update Network Security
 /// Group operation
 /// </param>
 /// <returns>
 /// Response for PUT NetworkSecurityGroups Api servive call
 /// </returns>
 public static Task<NetworkSecurityGroupPutResponse> BeginCreateOrUpdatingAsync(this INetworkSecurityGroupOperations operations, string resourceGroupName, string networkSecurityGroupName, NetworkSecurityGroup parameters)
 {
     return operations.BeginCreateOrUpdatingAsync(resourceGroupName, networkSecurityGroupName, parameters, CancellationToken.None);
 }
        public void NetworkSecurityGroupApiTest()
        {
            var handler = new RecordedDelegatingHandler {StatusCodeToReturn = HttpStatusCode.OK};

            using (var context = UndoContext.Current)
            {
                context.Start();
                var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler);
                var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler);

                var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkSecurityGroups");
                
                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                    new ResourceGroup
                    {
                        Location = location
                    });

                string networkSecurityGroupName = TestUtilities.GenerateName();

                var networkSecurityGroup = new NetworkSecurityGroup()
                {
                    Location = location,
                };

                // Put Nsg
                var putNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup);
                Assert.Equal(HttpStatusCode.OK, putNsgResponse.StatusCode);
                Assert.Equal("Succeeded", putNsgResponse.Status);

                // Get NSG
                var getNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, getNsgResponse.StatusCode);
                Assert.Equal(networkSecurityGroupName, getNsgResponse.NetworkSecurityGroup.Name);
                Assert.NotNull(getNsgResponse.NetworkSecurityGroup.ResourceGuid);
                Assert.Equal(6, getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules.Count);
                Assert.Equal("AllowVnetInBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].Name);
                Assert.Equal("AllowAzureLoadBalancerInBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[1].Name);
                Assert.Equal("DenyAllInBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[2].Name);
                Assert.Equal("AllowVnetOutBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[3].Name);
                Assert.Equal("AllowInternetOutBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[4].Name);
                Assert.Equal("DenyAllOutBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[5].Name);

                // Verify a default security rule
                Assert.Equal(SecurityRuleAccess.Allow, getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].Access);
                Assert.Equal("Allow inbound traffic from all VMs in VNET", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].Description);
                Assert.Equal("VirtualNetwork", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].DestinationAddressPrefix);
                Assert.Equal("*", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].DestinationPortRange);
                Assert.Equal(SecurityRuleDirection.Inbound, getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].Direction);
                Assert.Equal(65000, getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].Priority);
                Assert.Equal(SecurityRuleProtocol.All, getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].Protocol);
                Assert.Equal("Succeeded", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].ProvisioningState);
                Assert.Equal("VirtualNetwork", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].SourceAddressPrefix);
                Assert.Equal("*", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].SourcePortRange);

                // List NSG
                var listNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listNsgResponse.StatusCode);
                Assert.Equal(1, listNsgResponse.NetworkSecurityGroups.Count);
                Assert.Equal(networkSecurityGroupName, listNsgResponse.NetworkSecurityGroups[0].Name);
                Assert.Equal(6, listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules.Count);
                Assert.Equal("AllowVnetInBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[0].Name);
                Assert.Equal("AllowAzureLoadBalancerInBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[1].Name);
                Assert.Equal("DenyAllInBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[2].Name);
                Assert.Equal("AllowVnetOutBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[3].Name);
                Assert.Equal("AllowInternetOutBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[4].Name);
                Assert.Equal("DenyAllOutBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[5].Name);
                Assert.Equal(getNsgResponse.NetworkSecurityGroup.Etag, listNsgResponse.NetworkSecurityGroups[0].Etag);

                // List NSG in a subscription
                var listNsgSubsciptionResponse = networkResourceProviderClient.NetworkSecurityGroups.ListAll();
                Assert.Equal(HttpStatusCode.OK, listNsgSubsciptionResponse.StatusCode);
                Assert.Equal(1, listNsgSubsciptionResponse.NetworkSecurityGroups.Count);
                Assert.Equal(networkSecurityGroupName, listNsgSubsciptionResponse.NetworkSecurityGroups[0].Name);
                Assert.Equal(6, listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules.Count);
                Assert.Equal("AllowVnetInBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[0].Name);
                Assert.Equal("AllowAzureLoadBalancerInBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[1].Name);
                Assert.Equal("DenyAllInBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[2].Name);
                Assert.Equal("AllowVnetOutBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[3].Name);
                Assert.Equal("AllowInternetOutBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[4].Name);
                Assert.Equal("DenyAllOutBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[5].Name);
                Assert.Equal(getNsgResponse.NetworkSecurityGroup.Etag, listNsgSubsciptionResponse.NetworkSecurityGroups[0].Etag);

                // Delete NSG
                var deleteResponse = networkResourceProviderClient.NetworkSecurityGroups.Delete(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);

                // List NSG
                listNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listNsgResponse.StatusCode);
                Assert.Equal(0, listNsgResponse.NetworkSecurityGroups.Count);
            }
        }
        public void NetworkSecurityGroupWithRulesApiTest()
        {
            var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };

            using (var context = UndoContext.Current)
            {
                context.Start();
                var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler);
                var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler);

                var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkSecurityGroups");
                
                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                    new ResourceGroup
                    {
                        Location = location
                    });

                string networkSecurityGroupName = TestUtilities.GenerateName();
                string securityRule1 = TestUtilities.GenerateName();
                string securityRule2 = TestUtilities.GenerateName();

                string destinationPortRange = "123-3500";

                var networkSecurityGroup = new NetworkSecurityGroup()
                {
                    Location = location,
                    SecurityRules = new List<SecurityRule>()
                                    {
                                        new SecurityRule()
                                            {
                                                Name = securityRule1,
                                                Access = SecurityRuleAccess.Allow,
                                                Description = "Test security rule",
                                                DestinationAddressPrefix = "*",
                                                DestinationPortRange = destinationPortRange,
                                                Direction = SecurityRuleDirection.Inbound,
                                                Priority = 500,
                                                Protocol = SecurityRuleProtocol.Tcp,
                                                SourceAddressPrefix = "*",
                                                SourcePortRange = "655"
                                            }
                                    }
                };

                // Put Nsg
                var putNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup);
                Assert.Equal(HttpStatusCode.OK, putNsgResponse.StatusCode);
                Assert.Equal("Succeeded", putNsgResponse.Status);

                // Get NSG
                var getNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, getNsgResponse.StatusCode);
                Assert.Equal(networkSecurityGroupName, getNsgResponse.NetworkSecurityGroup.Name);
                Assert.Equal(6, getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules.Count);
                Assert.Equal("AllowVnetInBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[0].Name);
                Assert.Equal("AllowAzureLoadBalancerInBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[1].Name);
                Assert.Equal("DenyAllInBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[2].Name);
                Assert.Equal("AllowVnetOutBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[3].Name);
                Assert.Equal("AllowInternetOutBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[4].Name);
                Assert.Equal("DenyAllOutBound", getNsgResponse.NetworkSecurityGroup.DefaultSecurityRules[5].Name);

                // Verify the security rule
                Assert.Equal(SecurityRuleAccess.Allow, getNsgResponse.NetworkSecurityGroup.SecurityRules[0].Access);
                Assert.Equal("Test security rule", getNsgResponse.NetworkSecurityGroup.SecurityRules[0].Description);
                Assert.Equal("*", getNsgResponse.NetworkSecurityGroup.SecurityRules[0].DestinationAddressPrefix);
                Assert.Equal(destinationPortRange, getNsgResponse.NetworkSecurityGroup.SecurityRules[0].DestinationPortRange);
                Assert.Equal(SecurityRuleDirection.Inbound, getNsgResponse.NetworkSecurityGroup.SecurityRules[0].Direction);
                Assert.Equal(500, getNsgResponse.NetworkSecurityGroup.SecurityRules[0].Priority);
                Assert.Equal(SecurityRuleProtocol.Tcp, getNsgResponse.NetworkSecurityGroup.SecurityRules[0].Protocol);
                Assert.Equal("Succeeded", getNsgResponse.NetworkSecurityGroup.SecurityRules[0].ProvisioningState);
                Assert.Equal("*", getNsgResponse.NetworkSecurityGroup.SecurityRules[0].SourceAddressPrefix);
                Assert.Equal("655", getNsgResponse.NetworkSecurityGroup.SecurityRules[0].SourcePortRange);

                // List NSG
                var listNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listNsgResponse.StatusCode);
                Assert.Equal(1, listNsgResponse.NetworkSecurityGroups.Count);
                Assert.Equal(networkSecurityGroupName, listNsgResponse.NetworkSecurityGroups[0].Name);
                Assert.Equal(6, listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules.Count);
                Assert.Equal("AllowVnetInBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[0].Name);
                Assert.Equal("AllowAzureLoadBalancerInBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[1].Name);
                Assert.Equal("DenyAllInBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[2].Name);
                Assert.Equal("AllowVnetOutBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[3].Name);
                Assert.Equal("AllowInternetOutBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[4].Name);
                Assert.Equal("DenyAllOutBound", listNsgResponse.NetworkSecurityGroups[0].DefaultSecurityRules[5].Name);
                Assert.Equal(getNsgResponse.NetworkSecurityGroup.Etag, listNsgResponse.NetworkSecurityGroups[0].Etag);

                // List NSG in a subscription
                var listNsgSubsciptionResponse = networkResourceProviderClient.NetworkSecurityGroups.ListAll();
                Assert.Equal(HttpStatusCode.OK, listNsgSubsciptionResponse.StatusCode);
                Assert.Equal(1, listNsgSubsciptionResponse.NetworkSecurityGroups.Count);
                Assert.Equal(networkSecurityGroupName, listNsgSubsciptionResponse.NetworkSecurityGroups[0].Name);
                Assert.Equal(6, listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules.Count);
                Assert.Equal("AllowVnetInBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[0].Name);
                Assert.Equal("AllowAzureLoadBalancerInBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[1].Name);
                Assert.Equal("DenyAllInBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[2].Name);
                Assert.Equal("AllowVnetOutBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[3].Name);
                Assert.Equal("AllowInternetOutBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[4].Name);
                Assert.Equal("DenyAllOutBound", listNsgSubsciptionResponse.NetworkSecurityGroups[0].DefaultSecurityRules[5].Name);
                Assert.Equal(getNsgResponse.NetworkSecurityGroup.Etag, listNsgSubsciptionResponse.NetworkSecurityGroups[0].Etag);

                // Add a new security rule
                var SecurityRule = new SecurityRule()
                                              {
                                                  Name = securityRule2,
                                                  Access = SecurityRuleAccess.Deny,
                                                  Description = "Test outbound security rule",
                                                  DestinationAddressPrefix = "*",
                                                  DestinationPortRange = destinationPortRange,
                                                  Direction = SecurityRuleDirection.Outbound,
                                                  Priority = 501,
                                                  Protocol = SecurityRuleProtocol.Udp,
                                                  SourceAddressPrefix = "*",
                                                  SourcePortRange = "656",
                                              };

                networkSecurityGroup.SecurityRules.Add(SecurityRule);

                putNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup);
                Assert.Equal(HttpStatusCode.OK, putNsgResponse.StatusCode);
                Assert.Equal("Succeeded", putNsgResponse.Status);

                // Get NSG
                getNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, getNsgResponse.StatusCode);

                // Verify the security rule
                Assert.Equal(SecurityRuleAccess.Deny, getNsgResponse.NetworkSecurityGroup.SecurityRules[1].Access);
                Assert.Equal("Test outbound security rule", getNsgResponse.NetworkSecurityGroup.SecurityRules[1].Description);
                Assert.Equal("*", getNsgResponse.NetworkSecurityGroup.SecurityRules[1].DestinationAddressPrefix);
                Assert.Equal(destinationPortRange, getNsgResponse.NetworkSecurityGroup.SecurityRules[1].DestinationPortRange);
                Assert.Equal(SecurityRuleDirection.Outbound, getNsgResponse.NetworkSecurityGroup.SecurityRules[1].Direction);
                Assert.Equal(501, getNsgResponse.NetworkSecurityGroup.SecurityRules[1].Priority);
                Assert.Equal(SecurityRuleProtocol.Udp, getNsgResponse.NetworkSecurityGroup.SecurityRules[1].Protocol);
                Assert.Equal("Succeeded", getNsgResponse.NetworkSecurityGroup.SecurityRules[1].ProvisioningState);
                Assert.Equal("*", getNsgResponse.NetworkSecurityGroup.SecurityRules[1].SourceAddressPrefix);
                Assert.Equal("656", getNsgResponse.NetworkSecurityGroup.SecurityRules[1].SourcePortRange);

                // Delete NSG
                var deleteResponse = networkResourceProviderClient.NetworkSecurityGroups.Delete(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);

                // List NSG
                listNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listNsgResponse.StatusCode);
                Assert.Equal(0, listNsgResponse.NetworkSecurityGroups.Count);
            }
        }
Exemplo n.º 14
0
        public void SecurityRuleWithRulesApiTest()
        {
            var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };

            using (var context = UndoContext.Current)
            {
                context.Start();
                var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler);
                var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler);

                var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkSecurityGroups");
                
                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                    new ResourceGroup
                    {
                        Location = location
                    });

                string networkSecurityGroupName = TestUtilities.GenerateName();
                string securityRule1 = TestUtilities.GenerateName();
                string securityRule2 = TestUtilities.GenerateName();

                string destinationPortRange = "123-3500";

                var networkSecurityGroup = new NetworkSecurityGroup()
                {
                    Location = location,
                    SecurityRules = new List<SecurityRule>()
                                            {
                                                new SecurityRule()
                                                    {
                                                        Name = securityRule1,
                                                        Access = SecurityRuleAccess.Allow,
                                                        Description = "Test security rule",
                                                        DestinationAddressPrefix = "*",
                                                        DestinationPortRange = destinationPortRange,
                                                        Direction = SecurityRuleDirection.Inbound,
                                                        Priority = 500,
                                                        Protocol = SecurityRuleProtocol.Tcp,
                                                        SourceAddressPrefix = "*",
                                                        SourcePortRange = "655"
                                                    }
                                            }
                };

                // Put Nsg
                var putNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup);
                Assert.Equal(HttpStatusCode.OK, putNsgResponse.StatusCode);
                Assert.Equal("Succeeded", putNsgResponse.Status);

                // Get NSG
                var getNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, getNsgResponse.StatusCode);
                Assert.Equal(networkSecurityGroupName, getNsgResponse.NetworkSecurityGroup.Name);

                // Get SecurityRule
                var getSecurityRuleResponse = networkResourceProviderClient.SecurityRules.Get(resourceGroupName, networkSecurityGroupName, securityRule1);
                Assert.Equal(HttpStatusCode.OK, getSecurityRuleResponse.StatusCode);
                Assert.Equal(securityRule1, getSecurityRuleResponse.SecurityRule.Name);

                this.CompareSecurityRule(getNsgResponse.NetworkSecurityGroup.SecurityRules[0], getSecurityRuleResponse.SecurityRule);

                // Add a new security rule
                var SecurityRule = new SecurityRule()
                                   {
                                       Name = securityRule2,
                                       Access = SecurityRuleAccess.Deny,
                                       Description = "Test outbound security rule",
                                       DestinationAddressPrefix = "*",
                                       DestinationPortRange = destinationPortRange,
                                       Direction = SecurityRuleDirection.Outbound,
                                       Priority = 501,
                                       Protocol = SecurityRuleProtocol.Udp,
                                       SourceAddressPrefix = "*",
                                       SourcePortRange = "656",
                                   };

                var putSecurityRuleResponse = networkResourceProviderClient.SecurityRules.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, securityRule2, SecurityRule);
                Assert.Equal(HttpStatusCode.OK, putSecurityRuleResponse.StatusCode);
                Assert.Equal("Succeeded", putSecurityRuleResponse.Status);

                // Get NSG
                getNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, getNsgResponse.StatusCode);

                // Get the SecurityRule2
                var getSecurityRule2Response = networkResourceProviderClient.SecurityRules.Get(resourceGroupName, networkSecurityGroupName, securityRule2);
                Assert.Equal(HttpStatusCode.OK, getSecurityRule2Response.StatusCode);
                Assert.Equal(securityRule2, getSecurityRule2Response.SecurityRule.Name);

                // Verify the security rule
                Assert.Equal(SecurityRuleAccess.Deny, getSecurityRule2Response.SecurityRule.Access);
                Assert.Equal("Test outbound security rule", getSecurityRule2Response.SecurityRule.Description);
                Assert.Equal("*", getSecurityRule2Response.SecurityRule.DestinationAddressPrefix);
                Assert.Equal(destinationPortRange, getSecurityRule2Response.SecurityRule.DestinationPortRange);
                Assert.Equal(SecurityRuleDirection.Outbound, getSecurityRule2Response.SecurityRule.Direction);
                Assert.Equal(501, getSecurityRule2Response.SecurityRule.Priority);
                Assert.Equal(SecurityRuleProtocol.Udp, getSecurityRule2Response.SecurityRule.Protocol);
                Assert.Equal("Succeeded", getSecurityRule2Response.SecurityRule.ProvisioningState);
                Assert.Equal("*", getSecurityRule2Response.SecurityRule.SourceAddressPrefix);
                Assert.Equal("656", getSecurityRule2Response.SecurityRule.SourcePortRange);

                this.CompareSecurityRule(getNsgResponse.NetworkSecurityGroup.SecurityRules[1], getSecurityRule2Response.SecurityRule);

                // List all SecurityRules
                var getsecurityRules = networkResourceProviderClient.SecurityRules.List(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, getsecurityRules.StatusCode);

                Assert.Equal(2, getsecurityRules.SecurityRules.Count);
                this.CompareSecurityRule(getNsgResponse.NetworkSecurityGroup.SecurityRules[0], getsecurityRules.SecurityRules[0]);
                this.CompareSecurityRule(getNsgResponse.NetworkSecurityGroup.SecurityRules[1], getsecurityRules.SecurityRules[1]);

                // Delete a SecurityRule
                var deleteSecurityRuleResponse = networkResourceProviderClient.SecurityRules.Delete(resourceGroupName, networkSecurityGroupName, securityRule2);
                Assert.Equal(HttpStatusCode.OK, deleteSecurityRuleResponse.StatusCode);

                getsecurityRules = networkResourceProviderClient.SecurityRules.List(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, getsecurityRules.StatusCode);

                Assert.Equal(1, getsecurityRules.SecurityRules.Count);

               // Delete NSG
                var deleteResponse = networkResourceProviderClient.NetworkSecurityGroups.Delete(resourceGroupName, networkSecurityGroupName);
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);

                // List NSG
                var listNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listNsgResponse.StatusCode);
                Assert.Equal(0, listNsgResponse.NetworkSecurityGroups.Count);
            }
        }
Exemplo n.º 15
0
        public void CreateVirtualNetwork(string ruleName, string[] sourceAddresses, int[] destPorts)
        {
            azureLogin.Authenticate();
            using (var networkClient = new NetworkResourceProviderClient(azureLogin.Credentials))
            {
                var subnetName = demo.Network + "_sub";
                var netSecName = demo.Network + "_sec";

                var nsg = new NetworkSecurityGroup()
                {
                    Name = netSecName,
                    Location = demo.Location,
                    SecurityRules = new List<SecurityRule>(),
                };
                
                var prio = 0;
                foreach (var sourceAddress in sourceAddresses)
                {
                    foreach (var destPort in destPorts)
                    {
                        prio += 100;
                        nsg.SecurityRules.Add(new SecurityRule()
                        {
                            Name = ruleName + "_" + destPort + "_" + sourceAddress,
                            Access = "Allow",
                            Direction = "Inbound",
                            Protocol = "Tcp",
                            SourceAddressPrefix = sourceAddress,
                            SourcePortRange = "*",
                            DestinationAddressPrefix = "*",
                            DestinationPortRange = destPort > 0 ? destPort.ToString() : "*",
                            Priority = prio,
                        });
                    }
                }

                HandleResult("Create Network Security Group", 
                    () => networkClient.NetworkSecurityGroups.CreateOrUpdate(demo.Group, netSecName, nsg));

                var vn = new VirtualNetwork()
                {
                    Location = demo.Location,
                    AddressSpace = new AddressSpace()
                    {
                        AddressPrefixes = new List<string> { demo.AddressSpace },
                    },
                    Subnets = new List<Subnet>()
                    {
                        new Subnet()
                        {
                            Name = subnetName,
                            AddressPrefix = demo.AddressSpace,
                            NetworkSecurityGroup = GetNetwokSecurityGroupId(demo.Network),
                        }
                    },
                };
                HandleResult("Create Virtual Network", 
                    () => networkClient.VirtualNetworks.CreateOrUpdate(demo.Group, demo.Network, vn));
            }
        }