private PSBastion CreateBastion() { var bastion = new PSBastion() { Name = this.Name, ResourceGroupName = this.ResourceGroupName, Location = this.VirtualNetwork.Location, }; bastion.Sku = new PSBastionSku(); bastion.ScaleUnit = 2; if (!String.IsNullOrEmpty(this.Sku) || !String.IsNullOrWhiteSpace(this.Sku)) { bastion.Sku.Name = this.Sku; } if (this.ScaleUnit.HasValue) { if (bastion.Sku.Name.Equals(MNM.BastionHostSkuName.Standard)) { if (this.ScaleUnit >= 2 && this.ScaleUnit <= 50) { bastion.ScaleUnit = this.ScaleUnit; } else { throw new ArgumentException("Please select scale units value between 2 and 50"); } } else if (bastion.Sku.Name.Equals(MNM.BastionHostSkuName.Basic) && this.ScaleUnit != 2) { throw new ArgumentException("Scale Units cannot be updated with Basic Sku"); } } if (this.VirtualNetwork != null) { bastion.Allocate(this.VirtualNetwork, this.PublicIpAddress); } //// Map to the sdk object var BastionModel = NetworkResourceManagerProfile.Mapper.Map <MNM.BastionHost>(bastion); BastionModel.ScaleUnits = bastion.ScaleUnit; BastionModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); //// Execute the Create bastion call this.BastionClient.CreateOrUpdate(this.ResourceGroupName, this.Name, BastionModel); return(this.GetBastion(this.ResourceGroupName, this.Name)); }
public List <PSBastion> ListBastions(string resourceGroupName) { var bastions = ShouldListBySubscription(resourceGroupName, null) ? this.BastionClient.List() : //// List by sub id this.BastionClient.ListByResourceGroup(resourceGroupName); //// List by RG name List <PSBastion> bastionsToReturn = new List <PSBastion>(); if (bastions != null) { foreach (MNM.BastionHost bastion in bastions) { PSBastion bastionToReturn = ToPsBastion(bastion); bastionToReturn.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(bastion.Id); bastionsToReturn.Add(bastionToReturn); } } return(bastionsToReturn); }
private PSBastion CreateBastion() { var bastion = new PSBastion() { Name = this.Name, ResourceGroupName = this.ResourceGroupName, Location = this.VirtualNetwork.Location }; if (this.VirtualNetwork != null) { bastion.Allocate(this.VirtualNetwork, this.PublicIpAddress); } //// Map to the sdk object var BastionModel = NetworkResourceManagerProfile.Mapper.Map <MNM.BastionHost>(bastion); BastionModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); //// Execute the Create bastion call this.BastionClient.CreateOrUpdate(this.ResourceGroupName, this.Name, BastionModel); return(this.GetBastion(this.ResourceGroupName, this.Name)); }
public override void Execute() { base.Execute(); ConfirmAction(Force.IsPresent, string.Format(Properties.Resources.OverwritingResource, InputObject.Name), Properties.Resources.SettingResourceMessage, InputObject.Name, () => { if (!this.IsResourcePresent(this.InputObject.ResourceGroupName, this.InputObject.Name)) { throw new ArgumentException(Properties.Resources.ResourceNotFound); } PSBastion getBastionHost = this.GetBastion(this.InputObject.ResourceGroupName, this.InputObject.Name); // If Sku parameter is present if (!String.IsNullOrEmpty(this.Sku) || !String.IsNullOrWhiteSpace(this.Sku)) { // Check if InputObject Sku is being downgraded if (this.InputObject.Sku.Name.Equals(MNM.BastionHostSkuName.Standard) && this.Sku.Equals(MNM.BastionHostSkuName.Basic)) { throw new ArgumentException("Downgrading Sku is not allowed"); } this.InputObject.Sku = new PSBastionSku(this.Sku); } // If Sku parameter is not present else { // Check if getBastionHost Sku is being downgraded from InputObject by setting InputObject.Sku.Name = "Basic" if (getBastionHost.Sku.Name.Equals(MNM.BastionHostSkuName.Standard) && this.InputObject.Sku.Name.Equals(MNM.BastionHostSkuName.Basic)) { throw new ArgumentException("Downgrading Sku is not allowed"); } this.InputObject.Sku = new PSBastionSku(getBastionHost.Sku.Name); } if (this.ScaleUnit.HasValue) { if (this.InputObject.Sku.Name.Equals(MNM.BastionHostSkuName.Standard)) { if (this.ScaleUnit >= 2 && this.ScaleUnit <= 50) { this.InputObject.ScaleUnit = this.ScaleUnit; } else { throw new ArgumentException("Please select scale units value between 2 and 50"); } } else if (this.InputObject.Sku.Name.Equals(MNM.BastionHostSkuName.Basic)) { throw new ArgumentException("Scale Units cannot be updated with Basic Sku"); } } else { if (this.InputObject.ScaleUnit < 2 || this.InputObject.ScaleUnit > 50) { throw new ArgumentException("Please select scale units value between 2 and 50"); } } MNM.BastionHost bastionHostModel = NetworkResourceManagerProfile.Mapper.Map <MNM.BastionHost>(this.InputObject); bastionHostModel.ScaleUnits = this.InputObject.ScaleUnit; bastionHostModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); this.BastionClient.CreateOrUpdate(this.InputObject.ResourceGroupName, this.InputObject.Name, bastionHostModel); getBastionHost = this.GetBastion(this.InputObject.ResourceGroupName, this.InputObject.Name); WriteObject(getBastionHost); }); }