public override void Execute() { base.Execute(); ConfirmAction( Force.IsPresent, string.Format(Properties.Resources.OverwritingResource, Name), Properties.Resources.CreatingResourceMessage, Name, () => { var peering = this.ExpressRouteCrossConnection.Peerings.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase)); if (peering != null) { throw new ArgumentException("Peering with the specified name already exists"); } peering = new PSExpressRouteCrossConnectionPeering(); peering.Name = this.Name; peering.PeeringType = this.PeeringType; peering.PeerASN = this.PeerASN; peering.VlanId = this.VlanId; if (!string.IsNullOrEmpty(this.SharedKey)) { peering.SharedKey = this.SharedKey; } if (this.PeerAddressType == IPv6) { this.SetIpv6PeeringParameters(peering); } else { // Set IPv4 config even if no PeerAddresType has been specified for backward compatibility this.SetIpv4PeeringParameters(peering); } this.ConstructMicrosoftConfig(peering); this.ExpressRouteCrossConnection.Peerings.Add(peering); // Map to the sdk operation var crossConnectionModel = NetworkResourceManagerProfile.Mapper.Map <Management.Network.Models.ExpressRouteCrossConnection>(ExpressRouteCrossConnection); crossConnectionModel.Tags = TagsConversionHelper.CreateTagDictionary(ExpressRouteCrossConnection.Tag, validate: true); // Execute the Update ExpressRouteCrossConnection call ExpressRouteCrossConnectionClient.CreateOrUpdate(ExpressRouteCrossConnection.ResourceGroupName, ExpressRouteCrossConnection.Name, crossConnectionModel); var getExpressRouteCrossConnection = GetExpressRouteCrossConnection(ExpressRouteCrossConnection.ResourceGroupName, ExpressRouteCrossConnection.Name); WriteObject(getExpressRouteCrossConnection); }); }
public override void Execute() { base.Execute(); ConfirmAction( Force.IsPresent, string.Format(Properties.Resources.RemovingResource, Name), Properties.Resources.RemoveResourceMessage, Name, () => { var peering = this.ExpressRouteCrossConnection.Peerings.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase)); if (peering != null) { // When a PeerAddressType is specified, we need to check if the corresponding address family peering is present, else ignore // For example if the peering has only IPv4 properties set and the user tries to remove IPv6 address family peering, we can ignore the remove operation bool validateAddressFamilyPresent = true; if ((this.PeerAddressType == IPv4 && peering.PeeringType == MNM.ExpressRoutePeeringType.MicrosoftPeering && peering.MicrosoftPeeringConfig == null) || (this.PeerAddressType == IPv6 && peering.PeeringType == MNM.ExpressRoutePeeringType.MicrosoftPeering && (peering.Ipv6PeeringConfig == null || peering.Ipv6PeeringConfig.MicrosoftPeeringConfig == null))) { validateAddressFamilyPresent = false; } if (!validateAddressFamilyPresent) { // Peering config for specified address family is not present. No action return; } if (peering.MicrosoftPeeringConfig != null && peering.Ipv6PeeringConfig != null) { // Both IPv4 and IPv6 peering configs are present. Only nullify the config corresponding to the address family specified if (this.PeerAddressType == IPv4 || string.IsNullOrWhiteSpace(this.PeerAddressType)) { peering.PrimaryPeerAddressPrefix = null; peering.SecondaryPeerAddressPrefix = null; peering.MicrosoftPeeringConfig = null; } else if (this.PeerAddressType == IPv6) { peering.Ipv6PeeringConfig = null; } else if (this.PeerAddressType == All) { this.ExpressRouteCrossConnection.Peerings.Remove(peering); } } else { // Only one peering config exists. Removing that should result in the entire peering being removed this.ExpressRouteCrossConnection.Peerings.Remove(peering); } } // Map to the sdk operation var crossConnectionModel = NetworkResourceManagerProfile.Mapper.Map <Management.Network.Models.ExpressRouteCrossConnection>(ExpressRouteCrossConnection); crossConnectionModel.Tags = TagsConversionHelper.CreateTagDictionary(ExpressRouteCrossConnection.Tag, validate: true); // Execute the Update ExpressRouteCrossConnection call ExpressRouteCrossConnectionClient.CreateOrUpdate(ExpressRouteCrossConnection.ResourceGroupName, ExpressRouteCrossConnection.Name, crossConnectionModel); var getExpressRouteCrossConnection = GetExpressRouteCrossConnection(ExpressRouteCrossConnection.ResourceGroupName, ExpressRouteCrossConnection.Name); WriteObject(getExpressRouteCrossConnection); }); }
public override void Execute() { base.Execute(); if (ExpressRouteCrossConnection != null) { // If ExpressRouteCrossConnection object is provided ConfirmAction( Force.IsPresent, string.Format(Properties.Resources.OverwritingResource, ExpressRouteCrossConnection.Name), Properties.Resources.CreatingResourceMessage, ExpressRouteCrossConnection.Name, () => { var crossConnection = GetExistingExpressRouteCrossConnection(ExpressRouteCrossConnection.ResourceGroupName, ExpressRouteCrossConnection.Name); if (crossConnection == null) { throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound); } // Map to the sdk operation var crossConnectionModel = NetworkResourceManagerProfile.Mapper.Map <MNM.ExpressRouteCrossConnection>(ExpressRouteCrossConnection); crossConnectionModel.Tags = TagsConversionHelper.CreateTagDictionary(ExpressRouteCrossConnection.Tag, validate: true); // Execute the Update ExpressRouteCrossConnection call ExpressRouteCrossConnectionClient.CreateOrUpdate(ExpressRouteCrossConnection.ResourceGroupName, ExpressRouteCrossConnection.Name, crossConnectionModel); var getExpressRouteCircuit = GetExpressRouteCrossConnection(ExpressRouteCrossConnection.ResourceGroupName, ExpressRouteCrossConnection.Name); WriteObject(getExpressRouteCircuit); }); } else { // If individual parameters are provided ConfirmAction( Force.IsPresent, string.Format(Properties.Resources.OverwritingResource, Name), Properties.Resources.CreatingResourceMessage, Name, () => { var crossConnection = GetExistingExpressRouteCrossConnection(ResourceGroupName, Name); if (crossConnection == null) { throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound); } if (!string.IsNullOrWhiteSpace(ServiceProviderNotes)) { crossConnection.ServiceProviderNotes = ServiceProviderNotes; } if (!string.IsNullOrWhiteSpace(ServiceProviderProvisioningState)) { crossConnection.ServiceProviderProvisioningState = ServiceProviderProvisioningState; } if (Peerings != null && Peerings.Count > 0) { crossConnection.Peerings = Peerings; } // Map to the sdk operation var crossConnectionModel = NetworkResourceManagerProfile.Mapper.Map <MNM.ExpressRouteCrossConnection>(crossConnection); crossConnectionModel.Tags = TagsConversionHelper.CreateTagDictionary(crossConnection.Tag, validate: true); // Execute the Update ExpressRouteCrossConnection call ExpressRouteCrossConnectionClient.CreateOrUpdate(ResourceGroupName, Name, crossConnectionModel); var getExpressRouteCrossConnection = GetExpressRouteCrossConnection(ResourceGroupName, Name); WriteObject(getExpressRouteCrossConnection); }); } }