private PSPublicIpPrefix CreatePublicIpPrefix() { var publicIpPrefix = new PSPublicIpPrefix(); publicIpPrefix.Name = this.Name; publicIpPrefix.Location = this.Location; publicIpPrefix.PublicIpAddressVersion = MNM.IPVersion.IPv4; if (!string.IsNullOrEmpty(this.IpAddressVersion)) { publicIpPrefix.PublicIpAddressVersion = this.IpAddressVersion; } if (publicIpPrefix.PublicIpAddressVersion == MNM.IPVersion.IPv6 && (this.PrefixLength < 117 || this.PrefixLength > 127)) { throw new ArgumentException(string.Format(Properties.Resources.InvalidIPv6IPPrefixLength, this.PrefixLength)); } else if (publicIpPrefix.PublicIpAddressVersion == MNM.IPVersion.IPv4 && (this.PrefixLength < 21 || this.PrefixLength > 31)) { throw new ArgumentException(string.Format(Properties.Resources.InvalidIPv4IPPrefixLength, this.PrefixLength)); } publicIpPrefix.Zones = this.Zone?.ToList(); publicIpPrefix.PrefixLength = this.PrefixLength; publicIpPrefix.Sku = new PSPublicIpPrefixSku(); publicIpPrefix.Sku.Name = MNM.PublicIPAddressSkuName.Standard; publicIpPrefix.Sku.Tier = MNM.PublicIPAddressSkuTier.Regional; if (!string.IsNullOrEmpty(this.Sku)) { publicIpPrefix.Sku.Name = this.Sku; } if (!string.IsNullOrEmpty(this.Tier)) { publicIpPrefix.Sku.Tier = this.Tier; } if (this.IpTag != null && this.IpTag.Length > 0) { publicIpPrefix.IpTags = this.IpTag?.ToList(); } publicIpPrefix.CustomIpPrefix = this.CustomIpPrefix; var theModel = NetworkResourceManagerProfile.Mapper.Map <MNM.PublicIPPrefix>(publicIpPrefix); theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); if (this.ShouldProcess(this.Name, $"Creating a new PublicIpPrefix in ResourceGroup {this.ResourceGroupName} with Name {this.Name}")) { this.PublicIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, theModel); var getPublicIpPrefix = this.GetPublicIpPrefix(this.ResourceGroupName, this.Name); return(getPublicIpPrefix); } return(null); }
private PSPublicIpPrefix CreatePublicIpPrefix() { var publicIpPrefix = new PSPublicIpPrefix(); publicIpPrefix.Name = this.Name; publicIpPrefix.Location = this.Location; publicIpPrefix.PublicIpAddressVersion = MNM.IPVersion.IPv4; if (!string.IsNullOrEmpty(this.IpAddressVersion)) { publicIpPrefix.PublicIpAddressVersion = this.IpAddressVersion; } publicIpPrefix.Zones = this.Zone?.ToList(); publicIpPrefix.PrefixLength = this.PrefixLength; publicIpPrefix.Sku = new PSPublicIpPrefixSku(); publicIpPrefix.Sku.Name = MNM.PublicIPAddressSkuName.Standard; if (!string.IsNullOrEmpty(this.Sku)) { publicIpPrefix.Sku.Name = this.Sku; } if (this.IpTag != null && this.IpTag.Length > 0) { publicIpPrefix.IpTags = this.IpTag?.ToList(); } var theModel = NetworkResourceManagerProfile.Mapper.Map <MNM.PublicIPPrefix>(publicIpPrefix); theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); if (this.ShouldProcess(this.Name, $"Creating a new PublicIpPrefix in ResourceGroup {this.ResourceGroupName} with Name {this.Name}")) { this.PublicIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, theModel); var getPublicIpPrefix = this.GetPublicIpPrefix(this.ResourceGroupName, this.Name); return(getPublicIpPrefix); } return(null); }