private PSCustomIpPrefix CreateCustomIpPrefix() { var psModel = new PSCustomIpPrefix() { Name = this.Name, ResourceGroupName = this.ResourceGroupName, Location = this.Location, Cidr = this.Cidr, Zones = this.Zone?.ToList(), SignedMessage = this.SignedMessage, AuthorizationMessage = this.AuthorizationMessage, CustomIpPrefixParent = this.CustomIpPrefixParent }; var sdkModel = NetworkResourceManagerProfile.Mapper.Map <MNM.CustomIpPrefix>(psModel); sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Create new MasterCustomIpPrefix")) { this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); var customIpPrefix = this.GetCustomIpPrefix(this.ResourceGroupName, this.Name); return(customIpPrefix); } return(null); }
public override void Execute() { base.Execute(); if (this.IsParameterBound(c => c.ResourceId)) { var resourceInfo = new ResourceIdentifier(ResourceId); this.ResourceGroupName = resourceInfo.ResourceGroupName; this.Name = resourceInfo.ResourceName; } else if (this.IsParameterBound(c => c.InputObject)) { this.ResourceGroupName = InputObject.ResourceGroupName; this.Name = InputObject.Name; } var existingResourcePsModel = GetCustomIpPrefix(this.ResourceGroupName, this.Name); if (existingResourcePsModel == null) { throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound); } if ((Commission ? 1 : 0) + (Decommission ? 1 : 0) + (Provision ? 1 : 0) + (Deprovision ? 1 : 0) > 1) { throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.CommissioningStateConflict); } PSCustomIpPrefix customIpPrefixToUpdate = this.GetCustomIpPrefix(this.ResourceGroupName, this.Name); if (customIpPrefixToUpdate == null) { throw new PSArgumentException(Properties.Resources.ResourceNotFound, this.Name); } if (Commission) { customIpPrefixToUpdate.CommissionedState = "Commissioning"; } else if (Decommission) { customIpPrefixToUpdate.CommissionedState = "Decommissioning"; } else if (Provision) { customIpPrefixToUpdate.CommissionedState = "Provisioning"; } else if (Deprovision) { customIpPrefixToUpdate.CommissionedState = "Deprovisioning"; } if (this.Cidr != null) { customIpPrefixToUpdate.Cidr = this.Cidr; } var sdkModel = NetworkResourceManagerProfile.Mapper.Map <MNM.CustomIpPrefix>(customIpPrefixToUpdate); if (this.IsParameterBound(c => c.InputObject)) { sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.IsParameterBound(c => c.Tag) ? this.Tag : InputObject.Tag, validate: true); } else { sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); } if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Update existing CustomIpPrefix")) { // Execute the PUT MasterCustomIpPrefix Policy call this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); var customIpPrefix = this.GetCustomIpPrefix(this.ResourceGroupName, this.Name); WriteObject(customIpPrefix); } }