public PSVirtualHub CreateOrUpdateVirtualHub(string resourceGroupName, string virtualHubName, PSVirtualHub virtualHub, Hashtable tags, Dictionary <string, List <string> > customHeaders = null) { var virtualHubModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualHub>(virtualHub); virtualHubModel.Location = virtualHub.Location; virtualHubModel.Tags = TagsConversionHelper.CreateTagDictionary(tags, validate: true); MNM.VirtualHub virtualHubCreatedOrUpdated; if (customHeaders == null) { virtualHubCreatedOrUpdated = this.VirtualHubClient.CreateOrUpdate(resourceGroupName, virtualHubName, virtualHubModel); } else { // Execute the create call and pass the custom headers. using (var _result = this.VirtualHubClient.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, virtualHubName, virtualHubModel, customHeaders).GetAwaiter().GetResult()) { virtualHubCreatedOrUpdated = _result.Body; } } PSVirtualHub hubToReturn = this.ToPsVirtualHub(virtualHubCreatedOrUpdated); hubToReturn.ResourceGroupName = resourceGroupName; return(hubToReturn); }
public PSVirtualHub CreateOrUpdateVirtualHub(string resourceGroupName, string virtualHubName, PSVirtualHub virtualHub, Hashtable tags, Dictionary <string, List <string> > customHeaders = null) { var psHubVnetConnections = virtualHub.VirtualNetworkConnections; virtualHub.VirtualNetworkConnections = null; var virtualHubModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualHub>(virtualHub); virtualHubModel.Location = virtualHub.Location; virtualHubModel.Tags = TagsConversionHelper.CreateTagDictionary(tags, validate: true); MNM.VirtualHub virtualHubCreatedOrUpdated; if (customHeaders == null) { virtualHubCreatedOrUpdated = this.VirtualHubClient.CreateOrUpdate(resourceGroupName, virtualHubName, virtualHubModel); } else { // Execute the create call and pass the custom headers. using (var _result = this.VirtualHubClient.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, virtualHubName, virtualHubModel, customHeaders).GetAwaiter().GetResult()) { virtualHubCreatedOrUpdated = _result.Body; } } PSVirtualHub hubToReturn = this.ToPsVirtualHub(virtualHubCreatedOrUpdated); hubToReturn.ResourceGroupName = resourceGroupName; if (psHubVnetConnections == null) { return(hubToReturn); } // Crud operation on the vnet connections hubToReturn.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>(); foreach (var psConnection in psHubVnetConnections) { var hubVnetConnnection = NetworkResourceManagerProfile.Mapper.Map <MNM.HubVirtualNetworkConnection>(psConnection); // get auth headers for cross-tenant hubvnet conn List <string> resourceIds = new List <string>(); resourceIds.Add(psConnection.RemoteVirtualNetwork.Id); var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds); Dictionary <string, List <string> > auxAuthHeader = null; if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0) { auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary); } var psConnectionReturn = this.HubVnetConnectionCmdlet.CreateOrUpdateHubVirtualNetworkConnection(resourceGroupName, virtualHubName, psConnection.Name, hubVnetConnnection, customHeaders); hubToReturn.VirtualNetworkConnections.Add(psConnectionReturn); } return(hubToReturn); }
public override void Execute() { // Resolve the parameters if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(this.VirtualHub.Id); this.ResourceGroupName = parsedResourceId.ResourceGroupName; this.HubName = parsedResourceId.ResourceName; } if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubRouteTableObject, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = parsedResourceId.ResourceGroupName; this.HubName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last(); this.Name = parsedResourceId.ResourceName; } if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubRouteTableResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = parsedResourceId.ResourceGroupName; this.HubName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last(); this.Name = parsedResourceId.ResourceName; } //// Get the virtual hub - this will throw not found if the resource is invalid PSVirtualHub parentVirtualHub = this.GetVirtualHub(this.ResourceGroupName, this.HubName); if (parentVirtualHub == null) { throw new PSArgumentException(Properties.Resources.ParentVirtualHubNotFound); } var routeTableToRemove = parentVirtualHub.RouteTables.FirstOrDefault(routeTable => routeTable.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase)); if (routeTableToRemove != null) { base.Execute(); ConfirmAction( Force.IsPresent, string.Format(Properties.Resources.RemovingResource, Name), Properties.Resources.RemoveResourceMessage, this.Name, () => { parentVirtualHub.RouteTables.Remove(routeTableToRemove); this.CreateOrUpdateVirtualHub(this.ResourceGroupName, this.HubName, parentVirtualHub, parentVirtualHub.Tag); if (PassThru) { WriteObject(true); } }); } }
public override void Execute() { base.Execute(); //// Resolve the VirtualHub if (ParameterSetName.Equals(CortexParameterSetNames.ByHubVirtualNetworkConnectionObject, StringComparison.OrdinalIgnoreCase)) { this.ResourceId = this.InputObject.Id; if (string.IsNullOrWhiteSpace(this.ResourceId)) { throw new PSArgumentException(Properties.Resources.HubVnetConnectionNotFound); } var parsedResourceId = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = parsedResourceId.ResourceGroupName; this.ParentResourceName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last(); this.Name = parsedResourceId.ResourceName; } else if (ParameterSetName.Equals(CortexParameterSetNames.ByHubVirtualNetworkConnectionResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = parsedResourceId.ResourceGroupName; this.ParentResourceName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last(); this.Name = parsedResourceId.ResourceName; } //// Get the virtual hub - this will throw not found if the resource is invalid PSVirtualHub parentVirtualHub = this.GetVirtualHub(this.ResourceGroupName, this.ParentResourceName); var connectionToModify = parentVirtualHub.VirtualNetworkConnections.FirstOrDefault(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase)); if (connectionToModify == null) { throw new PSArgumentException(Properties.Resources.HubVnetConnectionNotFound); } if (this.EnableInternetSecurity.HasValue) { connectionToModify.EnableInternetSecurity = this.EnableInternetSecurity.Value; } ConfirmAction( Properties.Resources.SettingResourceMessage, this.Name, () => { this.CreateOrUpdateVirtualHub(this.ResourceGroupName, this.ParentResourceName, parentVirtualHub, parentVirtualHub.Tag); var updatedVirtualHub = this.GetVirtualHub(this.ResourceGroupName, this.ParentResourceName); WriteObject(updatedVirtualHub.VirtualNetworkConnections.FirstOrDefault(hubConnection => hubConnection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase))); }); }
public PSVirtualHub CreateOrUpdateVirtualHub(string resourceGroupName, string virtualHubName, PSVirtualHub virtualHub, Hashtable tags) { var virtualHubModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualHub>(virtualHub); virtualHubModel.Location = virtualHub.Location; virtualHubModel.Tags = TagsConversionHelper.CreateTagDictionary(tags, validate: true); var virtualHubCreatedOrUpdated = this.VirtualHubClient.CreateOrUpdate(resourceGroupName, virtualHubName, virtualHubModel); PSVirtualHub hubToReturn = this.ToPsVirtualHub(virtualHubCreatedOrUpdated); hubToReturn.ResourceGroupName = resourceGroupName; return(hubToReturn); }
public override void Execute() { base.Execute(); PSVirtualHub virtualHub = null; if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase)) { var inputVirtualHub = this.InputObject; this.ResourceGroupName = inputVirtualHub.ResourceGroupName; this.Name = inputVirtualHub.Name; } else { if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(ResourceId); this.Name = parsedResourceId.ResourceName; this.ResourceGroupName = parsedResourceId.ResourceGroupName; } } // always do an explicit Get and use this object to trigger a Put if needed. virtualHub = this.GetVirtualHub(this.ResourceGroupName, this.Name); if (virtualHub == null) { throw new PSArgumentException(Properties.Resources.VirtualHubToUpdateNotFound); } if (string.Equals(virtualHub.RoutingState, MNM.RoutingState.Provisioned.ToString(), StringComparison.InvariantCultureIgnoreCase)) { WriteVerbose($"The virtual hub routing state is already Provisioned. Nothing to do."); WriteObject(virtualHub); return; } // trigger the Put on the VirtualHub ConfirmAction( Properties.Resources.SettingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); WriteObject(this.CreateOrUpdateVirtualHub( this.ResourceGroupName, this.Name, virtualHub, null)); }); }
public List <PSVirtualHub> ListVirtualHubs(string resourceGroupName) { var virtualHubs = ShouldListBySubscription(resourceGroupName, null) ? this.VirtualHubClient.List() : //// List by SubId this.VirtualHubClient.ListByResourceGroup(resourceGroupName); //// List by RG Name List <PSVirtualHub> hubsToReturn = new List <PSVirtualHub>(); if (virtualHubs != null) { foreach (MNM.VirtualHub virtualHub in virtualHubs) { PSVirtualHub virtualHubToReturn = ToPsVirtualHub(virtualHub); virtualHubToReturn.ResourceGroupName = resourceGroupName; hubsToReturn.Add(virtualHubToReturn); } } return(hubsToReturn); }
public PSVirtualHub GetVirtualHub(string resourceGroupName, string name) { try { //// The following code will throw if resource is not found MNM.VirtualHub virtualHub = this.VirtualHubClient.Get(resourceGroupName, name); PSVirtualHub psVirtualHub = ToPsVirtualHub(virtualHub); psVirtualHub.ResourceGroupName = resourceGroupName; return(psVirtualHub); } catch (Exception ex) { if (ex is Microsoft.Azure.Management.Network.Models.ErrorException || ex is Rest.Azure.CloudException) { return(null); } throw; } }
public PSVirtualHub GetVirtualHub(string resourceGroupName, string name) { MNM.VirtualHub virtualHub = null; PSVirtualHub psVirtualHub = null; try { //// The following code will throw if resource is not found virtualHub = this.VirtualHubClient.Get(resourceGroupName, name); psVirtualHub = ToPsVirtualHub(virtualHub); psVirtualHub.ResourceGroupName = resourceGroupName; } catch (Microsoft.Azure.Management.Network.Models.ErrorException) { // Resource is not present return(psVirtualHub); } return(psVirtualHub); }
public List <PSVirtualHub> ListVirtualHubs(string resourceGroupName) { var virtualHubs = ShouldListBySubscription(resourceGroupName, null) ? this.VirtualHubClient.List() : //// List by SubId this.VirtualHubClient.ListByResourceGroup(resourceGroupName); //// List by RG Name List <PSVirtualHub> hubsToReturn = new List <PSVirtualHub>(); if (virtualHubs != null) { foreach (MNM.VirtualHub virtualHub in virtualHubs) { PSVirtualHub virtualHubToReturn = ToPsVirtualHub(virtualHub); virtualHubToReturn.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(virtualHub.Id); virtualHubToReturn.VirtualNetworkConnections = this.HubVnetConnectionCmdlet.ListHubVnetConnections(resourceGroupName, virtualHub.Name); hubsToReturn.Add(virtualHubToReturn); } } return(hubsToReturn); }
public override void Execute() { base.Execute(); PSVirtualHub virtualHubToUpdate = null; Dictionary <string, List <string> > auxAuthHeader = null; if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase)) { virtualHubToUpdate = this.InputObject; this.ResourceGroupName = virtualHubToUpdate.ResourceGroupName; this.Name = virtualHubToUpdate.Name; } else { if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(ResourceId); this.Name = parsedResourceId.ResourceName; this.ResourceGroupName = parsedResourceId.ResourceGroupName; } virtualHubToUpdate = this.GetVirtualHub(this.ResourceGroupName, this.Name); } if (virtualHubToUpdate == null) { throw new PSArgumentException(Properties.Resources.VirtualHubToUpdateNotFound); } //// Update address prefix, if specified if (!string.IsNullOrWhiteSpace(this.AddressPrefix)) { virtualHubToUpdate.AddressPrefix = this.AddressPrefix; } //// HubVirtualNetworkConnections List <PSHubVirtualNetworkConnection> hubVnetConnectionList = null; if (this.HubVnetConnection != null) { // Simulate behavior of old API to clear all existing connections not in new request and then add new ones if (virtualHubToUpdate.VirtualNetworkConnections != null) { foreach (var connection in virtualHubToUpdate.VirtualNetworkConnections) { if (!this.HubVnetConnection.Any(conn => conn.Name == connection.Name)) { this.HubVnetConnectionCmdlet.HubVirtualNetworkConnectionsClient.Delete(this.ResourceGroupName, this.Name, connection.Name); } } } virtualHubToUpdate.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>(); virtualHubToUpdate.VirtualNetworkConnections.AddRange(this.HubVnetConnection); } else { // optimization to avoid unnecessary put on hubvnet connections hubVnetConnectionList = virtualHubToUpdate.VirtualNetworkConnections; virtualHubToUpdate.VirtualNetworkConnections = null; } //// VirtualHubRouteTable if (this.RouteTable != null) { virtualHubToUpdate.RouteTable = this.RouteTable; } if (!string.IsNullOrWhiteSpace(this.Sku)) { virtualHubToUpdate.Sku = this.Sku; } if (!string.IsNullOrWhiteSpace(this.PreferredRoutingGateway)) { virtualHubToUpdate.PreferredRoutingGateway = this.PreferredRoutingGateway; } //// Update the virtual hub ConfirmAction( Properties.Resources.SettingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); var hubToReturn = this.CreateOrUpdateVirtualHub( this.ResourceGroupName, this.Name, virtualHubToUpdate, this.Tag, auxAuthHeader); if (hubVnetConnectionList != null) { // patch back the hubvnet connection for backward compatibility hubToReturn.VirtualNetworkConnections = hubVnetConnectionList; } WriteObject(hubToReturn); }); }
public override void Execute() { base.Execute(); PSVirtualHub virtualHubToUpdate = null; if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase)) { virtualHubToUpdate = this.InputObject; this.ResourceGroupName = virtualHubToUpdate.ResourceGroupName; this.Name = virtualHubToUpdate.Name; } else { if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(ResourceId); this.Name = parsedResourceId.ResourceName; this.ResourceGroupName = parsedResourceId.ResourceGroupName; } virtualHubToUpdate = this.GetVirtualHub(this.ResourceGroupName, this.Name); } if (virtualHubToUpdate == null) { throw new PSArgumentException(Properties.Resources.VirtualHubToUpdateNotFound); } //// Update address prefix, if specified if (!string.IsNullOrWhiteSpace(this.AddressPrefix)) { virtualHubToUpdate.AddressPrefix = this.AddressPrefix; } //// HubVirtualNetworkConnections if (this.HubVnetConnection != null) { virtualHubToUpdate.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>(); virtualHubToUpdate.VirtualNetworkConnections.AddRange(this.HubVnetConnection); } //// VirtualHubRouteTable if (this.RouteTable != null) { virtualHubToUpdate.RouteTable = this.RouteTable; } //// Update the virtual hub ConfirmAction( Properties.Resources.SettingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); WriteObject(this.CreateOrUpdateVirtualHub( this.ResourceGroupName, this.Name, virtualHubToUpdate, this.Tag)); }); }
public override void Execute() { base.Execute(); if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualHubObject)) { this.ResourceGroupName = this.ParentObject.ResourceGroupName; this.ParentResourceName = this.ParentObject.Name; } else if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualHubResourceId)) { var parsedResourceId = new ResourceIdentifier(this.ParentResourceId); this.ResourceGroupName = parsedResourceId.ResourceGroupName; this.ParentResourceName = parsedResourceId.ResourceName; } if (this.IsHubVnetConnectionPresent(this.ResourceGroupName, this.ParentResourceName, this.Name)) { throw new PSArgumentException(string.Format(Properties.Resources.ChildResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName, this.ParentResourceName)); } //// Get the virtual hub - this will throw not found if the resource does not exist PSVirtualHub parentVirtualHub = this.GetVirtualHub(this.ResourceGroupName, this.ParentResourceName); if (parentVirtualHub == null) { throw new PSArgumentException(Properties.Resources.ParentVirtualHubNotFound); } PSHubVirtualNetworkConnection hubVnetConnection = new PSHubVirtualNetworkConnection(); hubVnetConnection.Name = this.Name; hubVnetConnection.EnableInternetSecurity = this.EnableInternetSecurity.IsPresent; //// Resolve the remote virtual network //// Let's not try to resolve this since this can be in other RG/Sub/Location if (ParameterSetName.Contains(CortexParameterSetNames.ByRemoteVirtualNetworkObject)) { hubVnetConnection.RemoteVirtualNetwork = new PSResourceId() { Id = this.RemoteVirtualNetwork.Id }; } else if (ParameterSetName.Contains(CortexParameterSetNames.ByRemoteVirtualNetworkResourceId)) { hubVnetConnection.RemoteVirtualNetwork = new PSResourceId() { Id = this.RemoteVirtualNetworkId }; } if (parentVirtualHub.VirtualNetworkConnections == null) { parentVirtualHub.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>(); } parentVirtualHub.VirtualNetworkConnections.Add(hubVnetConnection); ConfirmAction( Properties.Resources.CreatingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); this.CreateOrUpdateVirtualHub(this.ResourceGroupName, this.ParentResourceName, parentVirtualHub, parentVirtualHub.Tag); var createdVirtualHub = this.GetVirtualHub(this.ResourceGroupName, this.ParentResourceName); WriteObject(createdVirtualHub.VirtualNetworkConnections.FirstOrDefault(hubConnection => hubConnection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase))); }); }
public override void Execute() { base.Execute(); PSVirtualHub virtualHubToUpdate = null; Dictionary <string, List <string> > auxAuthHeader = null; if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase)) { virtualHubToUpdate = this.InputObject; this.ResourceGroupName = virtualHubToUpdate.ResourceGroupName; this.Name = virtualHubToUpdate.Name; } else { if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(ResourceId); this.Name = parsedResourceId.ResourceName; this.ResourceGroupName = parsedResourceId.ResourceGroupName; } virtualHubToUpdate = this.GetVirtualHub(this.ResourceGroupName, this.Name); } if (virtualHubToUpdate == null) { throw new PSArgumentException(Properties.Resources.VirtualHubToUpdateNotFound); } //// Update address prefix, if specified if (!string.IsNullOrWhiteSpace(this.AddressPrefix)) { virtualHubToUpdate.AddressPrefix = this.AddressPrefix; } //// HubVirtualNetworkConnections if (this.HubVnetConnection != null) { virtualHubToUpdate.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>(); virtualHubToUpdate.VirtualNetworkConnections.AddRange(this.HubVnetConnection); // get auth headers for cross-tenant hubvnet conn List <string> resourceIds = new List <string>(); foreach (var connection in this.HubVnetConnection) { resourceIds.Add(connection.RemoteVirtualNetwork.Id); } var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds); if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0) { auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary); } } //// VirtualHubRouteTable if (this.RouteTable != null) { virtualHubToUpdate.RouteTable = this.RouteTable; } if (!string.IsNullOrWhiteSpace(this.Sku)) { virtualHubToUpdate.Sku = this.Sku; } //// Update the virtual hub ConfirmAction( Properties.Resources.SettingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); WriteObject(this.CreateOrUpdateVirtualHub( this.ResourceGroupName, this.Name, virtualHubToUpdate, this.Tag, auxAuthHeader)); }); }
public override void Execute() { base.Execute(); Dictionary <string, List <string> > auxAuthHeader = null; if (this.IsVirtualHubPresent(this.ResourceGroupName, this.Name)) { throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName)); } string virtualWanRGName = null; string virtualWanName = null; //// Resolve the virtual wan if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanObject, StringComparison.OrdinalIgnoreCase)) { virtualWanRGName = this.VirtualWan.ResourceGroupName; virtualWanName = this.VirtualWan.Name; } else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedWanResourceId = new ResourceIdentifier(this.VirtualWanId); virtualWanName = parsedWanResourceId.ResourceName; virtualWanRGName = parsedWanResourceId.ResourceGroupName; } if (string.IsNullOrWhiteSpace(virtualWanRGName) || string.IsNullOrWhiteSpace(virtualWanName)) { throw new PSArgumentException(Properties.Resources.VirtualWanReferenceNeededForVirtualHub); } PSVirtualWan resolvedVirtualWan = new VirtualWanBaseCmdlet().GetVirtualWan(virtualWanRGName, virtualWanName); ConfirmAction( Properties.Resources.CreatingResourceMessage, Name, () => { WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); PSVirtualHub virtualHub = new PSVirtualHub { ResourceGroupName = this.ResourceGroupName, Name = this.Name, VirtualWan = new PSResourceId() { Id = resolvedVirtualWan.Id }, AddressPrefix = this.AddressPrefix, Location = this.Location }; virtualHub.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>(); if (this.HubVnetConnection != null) { virtualHub.VirtualNetworkConnections.AddRange(this.HubVnetConnection); // get auth headers for cross-tenant hubvnet conn List <string> resourceIds = new List <string>(); foreach (var connection in this.HubVnetConnection) { resourceIds.Add(connection.RemoteVirtualNetwork.Id); } var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds); if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0) { auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary); } } virtualHub.RouteTable = this.RouteTable; virtualHub.RouteTables = new List <PSVirtualHubRouteTable>(); if (string.IsNullOrWhiteSpace(this.Sku)) { virtualHub.Sku = "Standard"; } WriteObject(this.CreateOrUpdateVirtualHub( this.ResourceGroupName, this.Name, virtualHub, this.Tag, auxAuthHeader)); }); }
public bool IsVirtualHubPresent(string resourceGroupName, string name) { PSVirtualHub psVirtualHub = GetVirtualHub(resourceGroupName, name); return(psVirtualHub == null ? false : true); }
public override void Execute() { base.Execute(); if (this.IsVirtualHubPresent(this.ResourceGroupName, this.Name)) { throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName)); } string virtualWanRGName = null; string virtualWanName = null; //// Resolve the virtual wan if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanObject, StringComparison.OrdinalIgnoreCase)) { virtualWanRGName = this.VirtualWan.ResourceGroupName; virtualWanName = this.VirtualWan.Name; } else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedWanResourceId = new ResourceIdentifier(this.VirtualWanId); virtualWanName = parsedWanResourceId.ResourceName; virtualWanRGName = parsedWanResourceId.ResourceGroupName; } if (string.IsNullOrWhiteSpace(virtualWanRGName) || string.IsNullOrWhiteSpace(virtualWanName)) { throw new PSArgumentException(Properties.Resources.VirtualWanReferenceNeededForVirtualHub); } PSVirtualWan resolvedVirtualWan = new VirtualWanBaseCmdlet().GetVirtualWan(virtualWanRGName, virtualWanName); ConfirmAction( Properties.Resources.CreatingResourceMessage, Name, () => { WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); PSVirtualHub virtualHub = new PSVirtualHub { ResourceGroupName = this.ResourceGroupName, Name = this.Name, VirtualWan = new PSResourceId() { Id = resolvedVirtualWan.Id }, AddressPrefix = this.AddressPrefix, Location = this.Location }; virtualHub.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>(); if (this.HubVnetConnection != null) { virtualHub.VirtualNetworkConnections.AddRange(this.HubVnetConnection); } virtualHub.RouteTable = this.RouteTable; WriteObject(this.CreateOrUpdateVirtualHub( this.ResourceGroupName, this.Name, virtualHub, this.Tag)); }); }
public override void Execute() { base.Execute(); var present = true; try { this.NetworkClient.NetworkManagementClient.VirtualHubs.Get(this.ResourceGroupName, this.Name); } catch (Exception ex) { if (ex is Microsoft.Azure.Management.Network.Models.ErrorException || ex is Rest.Azure.CloudException) { // Resource is not present present = false; } else { throw; } } if (present) { throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName)); } ConfirmAction( Properties.Resources.CreatingResourceMessage, Name, () => { WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); PSVirtualHub virtualHub = new PSVirtualHub { ResourceGroupName = this.ResourceGroupName, Name = this.Name, Location = this.Location }; virtualHub.RouteTables = new List <PSVirtualHubRouteTable>(); string ipConfigName = "ipconfig1"; HubIpConfiguration ipconfig = new HubIpConfiguration { Subnet = new Subnet() { Id = this.HostedSubnet } }; var virtualHubModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualHub>(virtualHub); virtualHubModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); virtualHubModel.Sku = "Standard"; this.NetworkClient.NetworkManagementClient.VirtualHubs.CreateOrUpdate(this.ResourceGroupName, this.Name, virtualHubModel); this.NetworkClient.NetworkManagementClient.VirtualHubIpConfiguration.CreateOrUpdate(this.ResourceGroupName, this.Name, ipConfigName, ipconfig); virtualHubModel = this.NetworkClient.NetworkManagementClient.VirtualHubs.Get(this.ResourceGroupName, this.Name); virtualHub = NetworkResourceManagerProfile.Mapper.Map <PSVirtualHub>(virtualHubModel); virtualHub.ResourceGroupName = this.ResourceGroupName; AddIpConfigurtaionToPSVirtualHub(virtualHub, this.ResourceGroupName, this.Name, ipConfigName); var virtualRouter = new PSVirtualRouter(virtualHub); virtualRouter.Tag = TagsConversionHelper.CreateTagHashtable(virtualHubModel.Tags); WriteObject(virtualRouter, true); }); }
public override void Execute() { base.Execute(); if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase)) { var hub = this.InputObject; this.ResourceGroupName = hub.ResourceGroupName; this.Name = hub.Name; } else { if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(ResourceId); this.Name = parsedResourceId.ResourceName; this.ResourceGroupName = parsedResourceId.ResourceGroupName; } } PSVirtualHub virtualHubToUpdate = this.GetVirtualHub(this.ResourceGroupName, this.Name); if (virtualHubToUpdate == null) { throw new PSArgumentException(Properties.Resources.VirtualHubToUpdateNotFound); } //// VirtualHubRouteTable if (virtualHubToUpdate.RouteTables == null) { virtualHubToUpdate.RouteTables = new List <PSVirtualHubRouteTable>(); virtualHubToUpdate.RouteTables.AddRange(this.RouteTable); } else { foreach (var routeTable in this.RouteTable) { // see if routeTable with same name already exists in hub, // if it does then remove it and add the route table that we received as input // if it does not exist then directly add the input var routeTableToRemove = virtualHubToUpdate.RouteTables.FirstOrDefault(rt => rt.Name.Equals(routeTable.Name, StringComparison.OrdinalIgnoreCase)); if (routeTableToRemove != null) { virtualHubToUpdate.RouteTables.Remove(routeTableToRemove); } virtualHubToUpdate.RouteTables.Add(routeTable); } } //// Update the virtual hub ConfirmAction( Properties.Resources.SettingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); WriteObject(this.CreateOrUpdateVirtualHub( this.ResourceGroupName, this.Name, virtualHubToUpdate, this.Tag)); }); }