public override void Execute() { base.Execute(); if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource)) { if (this.NetworkSecurityGroup != null) { this.NetworkSecurityGroupId = this.NetworkSecurityGroup.Id; } if (this.RouteTable != null) { this.RouteTableId = this.RouteTable.Id; } } var subnet = new PSSubnet(); subnet.Name = this.Name; subnet.AddressPrefix = this.AddressPrefix?.ToList(); if (!string.IsNullOrEmpty(this.NetworkSecurityGroupId)) { subnet.NetworkSecurityGroup = new PSNetworkSecurityGroup(); subnet.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId; } if (!string.IsNullOrEmpty(this.RouteTableId)) { subnet.RouteTable = new PSRouteTable(); subnet.RouteTable.Id = this.RouteTableId; } if (this.ServiceEndpoint != null) { subnet.ServiceEndpoints = new List <PSServiceEndpoint>(); foreach (var item in this.ServiceEndpoint) { var service = new PSServiceEndpoint(); service.Service = item; subnet.ServiceEndpoints.Add(service); } } if (this.ServiceEndpointPolicy != null) { subnet.ServiceEndpointPolicies = this.ServiceEndpointPolicy?.ToList(); } if (this.Delegation != null) { subnet.Delegations = this.Delegation?.ToList(); } WriteObject(subnet); }
public override void Execute() { base.Execute(); // Verify if the subnet exists in the VirtualNetwork var subnet = this.VirtualNetwork.Subnets.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase)); if (subnet != null) { throw new ArgumentException("Subnet with the specified name already exists"); } if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource)) { if (this.NetworkSecurityGroup != null) { this.NetworkSecurityGroupId = this.NetworkSecurityGroup.Id; } if (this.RouteTable != null) { this.RouteTableId = this.RouteTable.Id; } } subnet = new PSSubnet(); subnet.Name = this.Name; subnet.AddressPrefix = this.AddressPrefix; if (!string.IsNullOrEmpty(this.NetworkSecurityGroupId)) { subnet.NetworkSecurityGroup = new PSNetworkSecurityGroup(); subnet.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId; } if (!string.IsNullOrEmpty(this.RouteTableId)) { subnet.RouteTable = new PSRouteTable(); subnet.RouteTable.Id = this.RouteTableId; } if (this.ServiceEndpoint != null) { subnet.ServiceEndpoints = new List <PSServiceEndpoint>(); foreach (var item in this.ServiceEndpoint) { var service = new PSServiceEndpoint(); service.Service = item; subnet.ServiceEndpoints.Add(service); } } this.VirtualNetwork.Subnets.Add(subnet); WriteObject(this.VirtualNetwork); }
public override void Execute() { base.Execute(); // Verify if the subnet exists in the VirtualNetwork var subnet = this.VirtualNetwork.Subnets.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, StringComparison.CurrentCultureIgnoreCase)); if (subnet == null) { throw new ArgumentException("Subnet with the specified name does not exist"); } if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource)) { if (this.NetworkSecurityGroup != null) { this.NetworkSecurityGroupId = this.NetworkSecurityGroup.Id; } else if (this.MyInvocation.BoundParameters.ContainsKey("NetworkSecurityGroup")) { this.NetworkSecurityGroupId = null; } if (this.RouteTable != null) { this.RouteTableId = this.RouteTable.Id; } else if (this.MyInvocation.BoundParameters.ContainsKey("RouteTable")) { this.RouteTableId = null; } } subnet.AddressPrefix = this.AddressPrefix?.ToList(); if (this.IpAllocation != null) { foreach (var allocation in this.IpAllocation) { subnet.IpAllocations.Add(allocation); } } if (!string.IsNullOrEmpty(this.NetworkSecurityGroupId)) { subnet.NetworkSecurityGroup = new PSNetworkSecurityGroup(); subnet.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId; } else if (this.MyInvocation.BoundParameters.ContainsKey("NetworkSecurityGroup") || this.MyInvocation.BoundParameters.ContainsKey("NetworkSecurityGroupId")) { subnet.NetworkSecurityGroup = null; } if (!string.IsNullOrEmpty(this.RouteTableId)) { subnet.RouteTable = new PSRouteTable(); subnet.RouteTable.Id = this.RouteTableId; } else if (this.MyInvocation.BoundParameters.ContainsKey("RouteTable") || this.MyInvocation.BoundParameters.ContainsKey("RouteTableId")) { subnet.RouteTable = null; } if (this.ServiceEndpoint != null) { subnet.ServiceEndpoints = new List <PSServiceEndpoint>(); foreach (var item in this.ServiceEndpoint) { var service = new PSServiceEndpoint(); service.Service = item; subnet.ServiceEndpoints.Add(service); } } else { subnet.ServiceEndpoints = null; } if (this.ServiceEndpointPolicy != null) { subnet.ServiceEndpointPolicies = this.ServiceEndpointPolicy?.ToList(); } else { subnet.ServiceEndpointPolicies = null; } if (this.Delegation != null) { subnet.Delegations = this.Delegation?.ToList(); } else { subnet.Delegations = null; } if (!string.IsNullOrEmpty(this.PrivateEndpointNetworkPoliciesFlag)) { subnet.PrivateEndpointNetworkPolicies = this.PrivateEndpointNetworkPoliciesFlag; } if (!string.IsNullOrEmpty(this.PrivateLinkServiceNetworkPoliciesFlag)) { subnet.PrivateLinkServiceNetworkPolicies = this.PrivateLinkServiceNetworkPoliciesFlag; } WriteObject(this.VirtualNetwork); }