protected override void ProcessRecord() { base.ProcessRecord(); ScriptBlock sb = ScriptBlock; if (null == sb) { // We must be using a "file" param set. ScriptBlockAst ast = LoadScript(File); sb = ast.GetScriptBlock(); } if (ParameterSetName.Contains("UseNewChildScope")) { WriteObject(InvokeScript(InvokeCommand, sb, UseNewChildScope), true); } else if (ParameterSetName.Contains("SessionState")) { WriteObject(this.InvokeCommand.InvokeScript(SessionStateScope, sb, null), true); } else { Util.Assert(ParameterSetName.Contains("Context")); WriteObject(InvokeWithContext(sb, WithContext, SaveContext), true); } } // end ProcessRecord()
public override void Execute() { base.Execute(); MNM.VerificationIPFlowParameters flowParameters = new MNM.VerificationIPFlowParameters(); flowParameters.Direction = this.Direction; flowParameters.LocalIPAddress = this.LocalIPAddress; flowParameters.LocalPort = this.LocalPort; flowParameters.Protocol = this.Protocol; flowParameters.RemoteIPAddress = this.RemoteIPAddress; flowParameters.RemotePort = this.RemotePort; flowParameters.TargetNicResourceId = this.TargetNetworkInterfaceId; flowParameters.TargetResourceId = this.TargetVirtualMachineId; MNM.VerificationIPFlowResult ipFlowVerify = new MNM.VerificationIPFlowResult(); if (ParameterSetName.Contains("SetByResource")) { ipFlowVerify = this.NetworkWatcherClient.VerifyIPFlow(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, flowParameters); } else { ipFlowVerify = this.NetworkWatcherClient.VerifyIPFlow(this.ResourceGroupName, this.NetworkWatcherName, flowParameters); } PSIPFlowVerifyResult psIPFlowVerify = Mapper.Map <PSIPFlowVerifyResult>(ipFlowVerify); WriteObject(psIPFlowVerify); }
/// <summary> /// Generates the model from user input. /// </summary> /// <param name="model">This is null since the sql virtual machine doesn't exist yet</param> /// <returns>The generated model from user input</returns> protected override IEnumerable <AzureSqlVMModel> ApplyUserInputToModel(IEnumerable <AzureSqlVMModel> model) { List <AzureSqlVMModel> newEntity = new List <AzureSqlVMModel>(); AzureSqlVMModel sqlVM = new AzureSqlVMModel(ResourceGroupName) { Name = this.Name, Location = this.Location, VirtualMachineId = RetrieveVirtualMachineId(ResourceGroupName, Name) }; if (ParameterSetName.Contains(InputObject)) { sqlVM.LicenseType = SqlVM.LicenseType; sqlVM.Offer = SqlVM.Offer; sqlVM.Sku = SqlVM.Sku; sqlVM.SqlManagementType = SqlVM.SqlManagementType; sqlVM.SqlVirtualMachineGroup = SqlVM.SqlVirtualMachineGroup; sqlVM.WsfcDomainCredentials = SqlVM.WsfcDomainCredentials; sqlVM.Tags = SqlVM.Tags; } else { sqlVM.LicenseType = this.LicenseType; sqlVM.Offer = this.Offer; sqlVM.Sku = this.Sku; sqlVM.SqlManagementType = this.SqlManagementType; sqlVM.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true); } newEntity.Add(sqlVM); return(newEntity); }
public void ParseVirtualNetworkObject() { //// Get VirtualNetworkRgName and VirtualNetworkName by ByVNResourceId if (ParameterSetName.Contains(BastionParameterSetNames.ByVNResourceId)) { var parsedResourceId = new ResourceIdentifier(this.VirtualNetworkId); this.VirtualNetworkRgName = parsedResourceId.ResourceGroupName; this.VirtualNetworkName = parsedResourceId.ResourceName; } //// Get Virtual Network by VirtualNetworkRgName and VirtualNetworkName if (ParameterSetName.Contains(BastionParameterSetNames.ByVNRGName + BastionParameterSetNames.ByVNName) || ParameterSetName.Contains(BastionParameterSetNames.ByVNResourceId)) { var vnet = this.VirtualNetworkClient.Get(this.VirtualNetworkRgName, VirtualNetworkName); this.VirtualNetwork = NetworkResourceManagerProfile.Mapper.Map <PSVirtualNetwork>(vnet); } else { //// Get virtual network by virtualNetworkObject this.VirtualNetwork = VirtualNetwork; } if (this.VirtualNetwork == null) { throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound, this.VirtualNetworkName)); } }
public override void Execute() { base.Execute(); MNM.QueryTroubleshootingParameters parameters = new MNM.QueryTroubleshootingParameters(); parameters.TargetResourceId = this.TargetResourceId; PSTroubleshootingResult troubleshoot = new PSTroubleshootingResult(); if (string.Equals(this.ParameterSetName, "SetByLocation", StringComparison.OrdinalIgnoreCase)) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new ArgumentException("There is no network watcher in location {0}", this.Location); } this.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); this.NetworkWatcherName = networkWatcher.Name; troubleshoot = GetTroubleshooting(this.ResourceGroupName, this.NetworkWatcherName, parameters); } else if (ParameterSetName.Contains("SetByResource")) { troubleshoot = GetTroubleshooting(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, parameters); } else { troubleshoot = GetTroubleshooting(this.ResourceGroupName, this.NetworkWatcherName, parameters); } WriteObject(troubleshoot); }
public override void Execute() { base.Execute(); string resourceGroupName; string name; if (ParameterSetName.Contains("SetByResource")) { resourceGroupName = this.NetworkWatcher.ResourceGroupName; name = this.NetworkWatcher.Name; } else { resourceGroupName = this.ResourceGroupName; name = this.NetworkWatcherName; } var present = this.IsPacketCapturePresent(resourceGroupName, name, this.PacketCaptureName); if (!present) { ConfirmAction( Properties.Resources.CreatingResourceMessage, this.PacketCaptureName, () => { var packetCapture = CreatePacketCapture(); WriteObject(packetCapture); }); } }
public override void Execute() { base.Execute(); MNM.NextHopParameters parameters = new MNM.NextHopParameters(); parameters.DestinationIPAddress = this.DestinationIPAddress; parameters.SourceIPAddress = this.SourceIPAddress; parameters.TargetNicResourceId = this.TargetNetworkInterfaceId; parameters.TargetResourceId = this.TargetVirtualMachineId; MNM.NextHopResult nextHop = new MNM.NextHopResult(); if (ParameterSetName.Contains("SetByResource")) { nextHop = this.NetworkWatcherClient.GetNextHop(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, parameters); } else { nextHop = this.NetworkWatcherClient.GetNextHop(this.ResourceGroupName, this.NetworkWatcherName, parameters); } PSNextHopResult psNextHop = NetworkResourceManagerProfile.Mapper.Map <PSNextHopResult>(nextHop); WriteObject(psNextHop); }
public override void Execute() { base.Execute(); MNM.ConnectivityParameters parameters = new MNM.ConnectivityParameters(); parameters.Source = new MNM.ConnectivitySource(); parameters.Source.ResourceId = this.SourceId; parameters.Source.Port = this.SourcePort; parameters.Destination = new MNM.ConnectivityDestination(); parameters.Destination.ResourceId = this.DestinationId; parameters.Destination.Address = this.DestinationAddress; parameters.Destination.Port = this.DestinationPort; MNM.ConnectivityInformation result = new MNM.ConnectivityInformation(); if (ParameterSetName.Contains("SetByResource")) { result = this.NetworkWatcherClient.CheckConnectivity(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, parameters); } else { result = this.NetworkWatcherClient.CheckConnectivity(this.ResourceGroupName, this.NetworkWatcherName, parameters); } PSConnectivityInformation psResult = NetworkResourceManagerProfile.Mapper.Map <PSConnectivityInformation>(result); WriteObject(psResult); }
public void ParsePublicIpAddressObject() { //// Get PublicIpAddressRgName and PublicIpAddressName by PublicIpAddressId if (ParameterSetName.Contains(BastionParameterSetNames.ByIpResourceId)) { var parsedResourceId = new ResourceIdentifier(this.PublicIpAddressId); this.PublicIpAddressRgName = parsedResourceId.ResourceGroupName; this.PublicIpAddressName = parsedResourceId.ResourceName; } //// Get PublicIpAddress by PublicIpAddressRgName and PublicIpAddressName if (ParameterSetName.Contains(BastionParameterSetNames.ByIpRGName + BastionParameterSetNames.ByIpName) || ParameterSetName.Contains(BastionParameterSetNames.ByIpResourceId)) { var publicIp = this.PublicIPAddressesClient.Get(this.PublicIpAddressRgName, this.PublicIpAddressName); this.PublicIpAddress = NetworkResourceManagerProfile.Mapper.Map <PSPublicIpAddress>(publicIp); } else { //// Get PublicIpAddress by publicIpObject this.PublicIpAddress = PublicIpAddress; } if (this.PublicIpAddress == null) { throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound, this.PublicIpAddressName)); } }
public override void Execute() { base.Execute(); string connectionMonitorName = this.Name; string resourceGroupName = string.Empty; string networkWatcherName = string.Empty; if (ParameterSetName.Contains("SetByResourceId")) { ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails(); connectionMonitorDetails = this.GetConnectionMonitorDetails(this.ResourceId); connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName; resourceGroupName = connectionMonitorDetails.ResourceGroupName; networkWatcherName = connectionMonitorDetails.NetworkWatcherName; } else if (ParameterSetName.Contains("SetByResource")) { resourceGroupName = this.NetworkWatcher.ResourceGroupName; networkWatcherName = this.NetworkWatcher.Name; } else if (ParameterSetName.Contains("SetByName")) { resourceGroupName = this.ResourceGroupName; networkWatcherName = this.NetworkWatcherName; } else { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new ArgumentException("There is no network watcher in the specified location"); } resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); networkWatcherName = networkWatcher.Name; } if (!string.IsNullOrEmpty(connectionMonitorName)) { PSConnectionMonitorResult connectionMonitor = new PSConnectionMonitorResult(); connectionMonitor = this.GetConnectionMonitor(resourceGroupName, networkWatcherName, connectionMonitorName); WriteObject(connectionMonitor); } else { List <PSConnectionMonitorResult> psConnectionMonitorList = new List <PSConnectionMonitorResult>(); var connectionMonitorList = this.ConnectionMonitors.List(resourceGroupName, networkWatcherName); foreach (var cm in connectionMonitorList) { PSConnectionMonitorResult psConnectionMonitor = NetworkResourceManagerProfile.Mapper.Map <PSConnectionMonitorResult>(cm); psConnectionMonitorList.Add(psConnectionMonitor); } WriteObject(psConnectionMonitorList, true); } }
public override void Execute() { base.Execute(); if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualHubObject)) { this.ResourceGroupName = this.VirtualHub.ResourceGroupName; this.VirtualHubName = this.VirtualHub.Name; } if (ParameterSetName.Contains(CortexParameterSetNames.ByHubBgpConnectionObject)) { this.PopulateResourceInfoFromInputObject(); } if (ParameterSetName.Contains(CortexParameterSetNames.ByHubBgpConnectionResourceId)) { this.PopulateResourceInfoFromId(this.ResourceId); } var hubVnetConnection = GetHubVnetConnection(); var bgpConnectionToUpdate = new MNM.BgpConnection { Name = this.Name, PeerAsn = this.PeerAsn, PeerIp = this.PeerIp, HubVirtualNetworkConnection = hubVnetConnection }; this.ConfirmAction( Properties.Resources.SettingResourceMessage, this.Name, () => { this.WriteObject(this.CreateOrUpdateVirtualHubBgpConnection(this.ResourceGroupName, this.VirtualHubName, this.Name, bgpConnectionToUpdate)); }); }
protected override void ProcessRecord() { base.ProcessRecord(); InvokeFunctionRequest request; if (ParameterSetName.Contains(FromFileSet)) { InvokeFunctionBody = System.IO.File.OpenRead(GetAbsoluteFilePath(InvokeFunctionBodyFromFile)); } try { request = new InvokeFunctionRequest { FunctionId = FunctionId, InvokeFunctionBody = InvokeFunctionBody, FnIntent = FnIntent, FnInvokeType = FnInvokeType, OpcRequestId = OpcRequestId }; response = client.InvokeFunction(request).GetAwaiter().GetResult(); HandleOutput(); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public override void Execute() { base.Execute(); if (ParameterSetName.Contains("SetByResourceId")) { ResourceIdentifier flowLogInfo = new ResourceIdentifier(this.ResourceId); this.Name = flowLogInfo.ResourceName; this.ResourceGroupName = flowLogInfo.ResourceGroupName; string parent = flowLogInfo.ParentResource; string[] tokens = parent.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); this.NetworkWatcherName = tokens[1]; } else if (ParameterSetName.Contains("SetByResource")) { this.ResourceGroupName = this.NetworkWatcher.ResourceGroupName; this.NetworkWatcherName = this.NetworkWatcher.Name; } else if (ParameterSetName.Contains("SetByLocation")) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new PSArgumentException(Properties.Resources.NoNetworkWatcherFound); } this.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); this.NetworkWatcherName = networkWatcher.Name; } else if (ParameterSetName.Contains("SetByInputObject")) { ResourceIdentifier flowLogInfo = new ResourceIdentifier(this.InputObject.Id); this.Name = flowLogInfo.ResourceName; this.ResourceGroupName = flowLogInfo.ResourceGroupName; string parent = flowLogInfo.ParentResource; string[] tokens = parent.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); this.NetworkWatcherName = tokens[1]; } ConfirmAction( Properties.Resources.RemoveResourceMessage, this.Name, () => { this.FlowLogs.Delete(this.ResourceGroupName, this.NetworkWatcherName, this.Name); if (PassThru) { WriteObject(true); } }); }
public override void Execute() { base.Execute(); connectionMonitorName = this.Name; if (ParameterSetName.Contains("SetByResourceId")) { ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails(); connectionMonitorDetails = this.GetConnectionMonitorDetails(this.ResourceId); connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName; resourceGroupName = connectionMonitorDetails.ResourceGroupName; networkWatcherName = connectionMonitorDetails.NetworkWatcherName; } else if (ParameterSetName.Contains("SetByResource")) { resourceGroupName = this.NetworkWatcher.ResourceGroupName; networkWatcherName = this.NetworkWatcher.Name; } else if (ParameterSetName.Contains("SetByName")) { resourceGroupName = this.ResourceGroupName; networkWatcherName = this.NetworkWatcherName; } else if (ParameterSetName.Contains("SetByInputObject")) { ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails(); connectionMonitorDetails = this.GetConnectionMonitorDetails(this.InputObject.Id); connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName; resourceGroupName = connectionMonitorDetails.ResourceGroupName; networkWatcherName = connectionMonitorDetails.NetworkWatcherName; } else { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new ArgumentException("There is no network watcher in the specified location"); } resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); networkWatcherName = networkWatcher.Name; } var present = this.IsConnectionMonitorPresent(resourceGroupName, networkWatcherName, connectionMonitorName); if (!present) { throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound); } var connectionMonitor = UpdateConnectionMonitor(); WriteObject(connectionMonitor); }
/// <summary> /// /// </summary> /*[Parameter()] * public SwitchParameter AsBytes * { * get { return asBytes; } * set { asBytes = value; } * } * private SwitchParameter asBytes;*/ #endregion Parameters #region Cmdlet Overrides /// <summary> /// /// </summary> protected override void BeginProcessing() { NativeMethods.checkAdmin(); if (ParameterSetName.Contains("Volume")) { NativeMethods.getVolumeName(ref volume); } }
public override void Execute() { base.Execute(); string connectionMonitorName = this.Name; string resourceGroupName = this.ResourceGroupName; string networkWatcherName = this.NetworkWatcherName; if (ParameterSetName.Contains("SetByResourceId")) { ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails(); connectionMonitorDetails = this.GetConnectionMonitorDetails(this.ResourceId); connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName; resourceGroupName = connectionMonitorDetails.ResourceGroupName; networkWatcherName = connectionMonitorDetails.NetworkWatcherName; } else if (ParameterSetName.Contains("SetByResource")) { resourceGroupName = this.NetworkWatcher.ResourceGroupName; networkWatcherName = this.NetworkWatcher.Name; } else if (ParameterSetName.Contains("SetByInputObject")) { ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails(); connectionMonitorDetails = this.GetConnectionMonitorDetails(this.InputObject.Id); connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName; resourceGroupName = connectionMonitorDetails.ResourceGroupName; networkWatcherName = connectionMonitorDetails.NetworkWatcherName; } else if (ParameterSetName.Contains("SetByLocation")) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new ArgumentException("There is no network watcher in location {0}", this.Location); } resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); networkWatcherName = networkWatcher.Name; } ConfirmAction( Properties.Resources.RemoveResourceMessage, connectionMonitorName, () => { this.ConnectionMonitors.Start(resourceGroupName, networkWatcherName, connectionMonitorName); if (PassThru) { WriteObject(true); } }); }
public override void Execute() { base.Execute(); string connectionMonitorName = this.Name; string resourceGroupName = string.Empty; string networkWatcherName = string.Empty; if (ParameterSetName.Contains("SetByResourceId")) { ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails(); connectionMonitorDetails = this.GetConnectionMonitorDetails(this.ResourceId); connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName; resourceGroupName = connectionMonitorDetails.ResourceGroupName; networkWatcherName = connectionMonitorDetails.NetworkWatcherName; } else if (ParameterSetName.Contains("SetByResource")) { resourceGroupName = this.NetworkWatcher.ResourceGroupName; networkWatcherName = this.NetworkWatcher.Name; } else if (ParameterSetName.Contains("SetByName")) { resourceGroupName = this.ResourceGroupName; networkWatcherName = this.NetworkWatcherName; } else if (ParameterSetName.Contains("SetByInputObject")) { ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails(); connectionMonitorDetails = this.GetConnectionMonitorDetails(this.InputObject.Id); connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName; resourceGroupName = connectionMonitorDetails.ResourceGroupName; networkWatcherName = connectionMonitorDetails.NetworkWatcherName; } else { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new ArgumentException("There is no network watcher in the specified location"); } resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); networkWatcherName = networkWatcher.Name; } MNM.ConnectionMonitorQueryResult queryResult = this.ConnectionMonitors.Query(resourceGroupName, networkWatcherName, connectionMonitorName); PSConnectionMonitorQueryResult psQueryResult = NetworkResourceManagerProfile.Mapper.Map <PSConnectionMonitorQueryResult>(queryResult); WriteObject(psQueryResult); }
private void HandleOutput() { if (ParameterSetName.Contains(WriteToFileSet)) { WriteToOutputFile(OutputFile, response.InputStream); } else { WriteOutput(response, response.InputStream); } }
private PSLocalNetworkGateway CreateLocalNetworkGateway() { var localnetGateway = new PSLocalNetworkGateway(); localnetGateway.Name = this.Name; localnetGateway.ResourceGroupName = this.ResourceGroupName; localnetGateway.Location = this.Location; localnetGateway.LocalNetworkAddressSpace = new PSAddressSpace(); localnetGateway.LocalNetworkAddressSpace.AddressPrefixes = this.AddressPrefix?.ToList(); if (ParameterSetName.Contains(ByLocalNetworkGatewayIpAddress)) { localnetGateway.GatewayIpAddress = this.GatewayIpAddress; localnetGateway.Fqdn = string.Empty; } else if (ParameterSetName.Contains(ByLocalNetworkGatewayFqdn)) { localnetGateway.Fqdn = this.Fqdn; localnetGateway.GatewayIpAddress = string.Empty; } if (this.PeerWeight < 0) { throw new PSArgumentException("PeerWeight cannot be negative"); } if (this.Asn > 0 && !string.IsNullOrEmpty(this.BgpPeeringAddress)) { localnetGateway.BgpSettings = new PSBgpSettings() { Asn = this.Asn, BgpPeeringAddress = this.BgpPeeringAddress, PeerWeight = this.PeerWeight }; } else if ((!string.IsNullOrEmpty(this.BgpPeeringAddress) && this.Asn == 0) || (string.IsNullOrEmpty(this.BgpPeeringAddress) && this.Asn > 0)) { throw new PSArgumentException("For a BGP session to be established over IPsec, the local network gateway's ASN and BgpPeeringAddress must both be specified."); } // Map to the sdk object var localnetGatewayModel = NetworkResourceManagerProfile.Mapper.Map <MNM.LocalNetworkGateway>(localnetGateway); localnetGatewayModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); // Execute the Create Local Network Gateway call this.LocalNetworkGatewayClient.CreateOrUpdate(this.ResourceGroupName, this.Name, localnetGatewayModel); var getLocalNetworkGateway = this.GetLocalNetworkGateway(this.ResourceGroupName, this.Name); return(getLocalNetworkGateway); }
public override void Execute() { base.Execute(); string connectionMonitorName = this.Name; string resourceGroupName = this.ResourceGroupName; string networkWatcherName = this.NetworkWatcherName; if (ParameterSetName.Contains("SetByResourceId")) { ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails(); connectionMonitorDetails = this.GetConnectionMonitorDetails(this.ResourceId); connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName; resourceGroupName = connectionMonitorDetails.ResourceGroupName; networkWatcherName = connectionMonitorDetails.NetworkWatcherName; } else if (ParameterSetName.Contains("SetByResource")) { resourceGroupName = this.NetworkWatcher.ResourceGroupName; networkWatcherName = this.NetworkWatcher.Name; } else if (ParameterSetName.Contains("SetByLocation")) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new PSArgumentException(Properties.Resources.NoNetworkWatcherFound); } resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); networkWatcherName = networkWatcher.Name; } if (ShouldGetByName(resourceGroupName, connectionMonitorName)) { var connectionMonitor = this.GetConnectionMonitor(resourceGroupName, networkWatcherName, connectionMonitorName, true); WriteObject(connectionMonitor); } else { var connectionMonitorList = this.ConnectionMonitors.List(resourceGroupName, networkWatcherName); List <PSConnectionMonitorResult> psConnectionMonitorList = new List <PSConnectionMonitorResult>(); foreach (var connectionMonitor in connectionMonitorList) { psConnectionMonitorList.Add(ConvertConnectionMonitorResultV2ToPSFormat(connectionMonitor)); } WriteObject(SubResourceWildcardFilter(Name, psConnectionMonitorList), true); } }
public override void Execute() { base.Execute(); if (ParameterSetName.Contains("SetByResourceId")) { ResourceIdentifier flowLogInfo = new ResourceIdentifier(this.ResourceId); this.Name = flowLogInfo.ResourceName; this.ResourceGroupName = flowLogInfo.ResourceGroupName; string parent = flowLogInfo.ParentResource; string[] tokens = parent.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); this.NetworkWatcherName = tokens[1]; } else if (ParameterSetName.Contains("SetByResource")) { this.ResourceGroupName = this.NetworkWatcher.ResourceGroupName; this.NetworkWatcherName = this.NetworkWatcher.Name; } else if (ParameterSetName.Contains("SetByLocation")) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new PSArgumentException(Properties.Resources.NoNetworkWatcherFound); } this.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); this.NetworkWatcherName = networkWatcher.Name; } if (ShouldGetByName(this.ResourceGroupName, this.Name)) { MNM.FlowLog flowLogResult = this.FlowLogs.Get(this.ResourceGroupName, this.NetworkWatcherName, this.Name); WriteObject(NetworkResourceManagerProfile.Mapper.Map <PSFlowLogResource>(flowLogResult)); } else { var flowLogResults = this.FlowLogs.List(this.ResourceGroupName, this.NetworkWatcherName); List <PSFlowLogResource> flowLogs = new List <PSFlowLogResource>(); foreach (var flowLogResult in flowLogResults) { flowLogs.Add(NetworkResourceManagerProfile.Mapper.Map <PSFlowLogResource>(flowLogResult)); } WriteObject(SubResourceWildcardFilter(this.Name, flowLogs), true); } }
private PSPacketCaptureResult CreatePacketCapture() { MNM.PacketCapture packetCaptureProperties = new MNM.PacketCapture(); if (this.BytesToCapturePerPacket != null) { packetCaptureProperties.BytesToCapturePerPacket = this.BytesToCapturePerPacket; } if (this.TotalBytesPerSession != null) { packetCaptureProperties.TotalBytesPerSession = this.TotalBytesPerSession; } if (this.TimeLimitInSeconds != null) { packetCaptureProperties.TimeLimitInSeconds = this.TimeLimitInSeconds; } packetCaptureProperties.Target = this.TargetVirtualMachineId; packetCaptureProperties.StorageLocation = new MNM.PacketCaptureStorageLocation(); packetCaptureProperties.StorageLocation.FilePath = this.LocalFilePath; packetCaptureProperties.StorageLocation.StorageId = this.StorageAccountId; packetCaptureProperties.StorageLocation.StoragePath = this.StoragePath; if (this.Filter != null) { packetCaptureProperties.Filters = new List <MNM.PacketCaptureFilter>(); foreach (PSPacketCaptureFilter filter in this.Filter) { MNM.PacketCaptureFilter filterMNM = Mapper.Map <MNM.PacketCaptureFilter>(filter); packetCaptureProperties.Filters.Add(filterMNM); } } PSPacketCaptureResult getPacketCapture = new PSPacketCaptureResult(); // Execute the Create NetworkWatcher call if (ParameterSetName.Contains("SetByResource")) { this.PacketCaptures.Create(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, this.PacketCaptureName, packetCaptureProperties); getPacketCapture = this.GetPacketCapture(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, this.PacketCaptureName); } else { this.PacketCaptures.Create(this.ResourceGroupName, this.NetworkWatcherName, this.PacketCaptureName, packetCaptureProperties); getPacketCapture = this.GetPacketCapture(this.ResourceGroupName, this.NetworkWatcherName, this.PacketCaptureName); } return(getPacketCapture); }
public override void Execute() { base.Execute(); string resourceGroupName; string name; if (string.Equals(this.ParameterSetName, "SetByLocation", StringComparison.OrdinalIgnoreCase)) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new ArgumentException("There is no network watcher in location {0}", this.Location); } resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); name = networkWatcher.Name; } else if (ParameterSetName.Contains("SetByResource")) { resourceGroupName = this.NetworkWatcher.ResourceGroupName; name = this.NetworkWatcher.Name; } else { resourceGroupName = this.ResourceGroupName; name = this.NetworkWatcherName; } ConfirmAction( Properties.Resources.CreatingResourceMessage, "FlowLogConfig", () => { MNM.FlowLogInformation parameters = new MNM.FlowLogInformation(); parameters.TargetResourceId = this.TargetResourceId; parameters.Enabled = this.EnableFlowLog; parameters.StorageId = this.StorageAccountId; if (this.EnableRetention == true || this.EnableRetention == false) { parameters.RetentionPolicy = new MNM.RetentionPolicyParameters(); parameters.RetentionPolicy.Enabled = this.EnableRetention; parameters.RetentionPolicy.Days = this.RetentionInDays; } PSFlowLog flowLog = new PSFlowLog(); flowLog = SetFlowLogConfig(resourceGroupName, name, parameters); WriteObject(flowLog); }); }
public override void Execute() { base.Execute(); if (ParameterSetName.Contains(SetByResourceId)) { PopulateBaseParametersFromResourceID(this.ResourceId); } else if (ParameterSetName.Contains(SetByResource)) { this.ResourceGroupName = this.NetworkWatcher.ResourceGroupName; this.NetworkWatcherName = this.NetworkWatcher.Name; this.Location = this.NetworkWatcher.Location; } else if (ParameterSetName.Contains(SetByLocation)) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new PSArgumentException(Properties.Resources.NoNetworkWatcherFound); } this.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); this.NetworkWatcherName = networkWatcher.Name; } else if (ParameterSetName.Contains(SetByName)) { MNM.NetworkWatcher networkWatcher = this.NetworkClient.NetworkManagementClient.NetworkWatchers.Get(this.ResourceGroupName, this.NetworkWatcherName); this.Location = networkWatcher.Location; } else if (ParameterSetName.Contains(SetByInputObject)) { PopulateBaseParametersFromResourceID(this.InputObject.Id); PopulateRequestParametersFromInputObject(); } var present = this.IsFlowLogPresent(this.ResourceGroupName, this.NetworkWatcherName, this.Name); ConfirmAction( Force.IsPresent, string.Format(Properties.Resources.OverwritingResource, this.Name), Properties.Resources.CreatingResourceMessage, this.Name, () => { PSFlowLogResource flowLog = CreateFlowLog(); WriteObject(flowLog); }, () => present); }
private PSConnectionMonitorResult UpdateConnectionMonitor(string resourceGroupName, string networkWatcherName) { MNM.ConnectionMonitor parameters = new MNM.ConnectionMonitor { Source = new MNM.ConnectionMonitorSource { ResourceId = this.SourceResourceId, Port = this.SourcePort }, Destination = new MNM.ConnectionMonitorDestination { ResourceId = this.DestinationResourceId, Address = this.DestinationAddress, Port = this.DestinationPort }, Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) }; if (this.ConfigureOnly) { parameters.AutoStart = false; } if (this.MonitoringIntervalInSeconds != null) { parameters.MonitoringIntervalInSeconds = this.MonitoringIntervalInSeconds; } PSConnectionMonitorResult getConnectionMonitor = new PSConnectionMonitorResult(); // Execute the CreateOrUpdate Connection monitor call if (ParameterSetName.Contains("SetByResource") && !ParameterSetName.Contains("SetByResourceId")) { parameters.Location = this.NetworkWatcher.Location; } else if (ParameterSetName.Contains("SetByLocation")) { parameters.Location = this.Location; } else { MNM.NetworkWatcher networkWatcher = this.NetworkClient.NetworkManagementClient.NetworkWatchers.Get(resourceGroupName, networkWatcherName); parameters.Location = networkWatcher.Location; } this.ConnectionMonitors.CreateOrUpdate(resourceGroupName, networkWatcherName, connectionMonitorName, parameters); getConnectionMonitor = this.GetConnectionMonitor(resourceGroupName, networkWatcherName, connectionMonitorName); return(getConnectionMonitor); }
public override void Execute() { base.Execute(); if (ParameterSetName.Contains("SetByResource")) { this.ResourceGroupName = this.NetworkWatcher.ResourceGroupName; this.NetworkWatcherName = this.NetworkWatcher.Name; } else if (ParameterSetName.Contains("SetByLocation")) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new PSArgumentException(Properties.Resources.NoNetworkWatcherFound); } this.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); this.NetworkWatcherName = networkWatcher.Name; } else if (ParameterSetName.Contains("SetByConnectionMonitorV2Object")) { if (string.IsNullOrEmpty(this.ConnectionMonitor.ResourceGroupName) || string.IsNullOrEmpty(this.ConnectionMonitor.NetworkWatcherName)) { throw new PSArgumentException(Properties.Resources.MissingBaseParametersInConnectionMonitor); } this.ResourceGroupName = this.ConnectionMonitor.ResourceGroupName; this.NetworkWatcherName = this.ConnectionMonitor.NetworkWatcherName; this.Name = this.ConnectionMonitor.Name; } var present = this.IsConnectionMonitorPresent(this.ResourceGroupName, this.NetworkWatcherName, this.Name); bool isConnectionMonitorV2 = ParameterSetName.Contains("V2") ? true : false; ConfirmAction( Force.IsPresent, string.Format(Properties.Resources.OverwritingResource, this.Name), Properties.Resources.CreatingResourceMessage, this.Name, () => { var connectionMonitor = CreateConnectionMonitor(this.ResourceGroupName, this.NetworkWatcherName, isConnectionMonitorV2); WriteObject(connectionMonitor); }, () => present); }
public override void Execute() { base.Execute(); if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualHubObject)) { this.ResourceGroupName = this.VirtualHub.ResourceGroupName; this.VirtualHubName = this.VirtualHub.Name; } else if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualHubResourceId)) { var parsedResourceId = new ResourceIdentifier(this.VirtualHubId); this.ResourceGroupName = parsedResourceId.ResourceGroupName; this.VirtualHubName = parsedResourceId.ResourceName; } if (this.IsVirtualHubBgpConnectionPresent(this.ResourceGroupName, this.VirtualHubName, this.Name)) { throw new PSArgumentException(string.Format(Properties.Resources.ChildResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName, this.VirtualHubName)); } MNM.SubResource hubVnetConnection = null; if (ParameterSetName.Contains(CortexParameterSetNames.ByHubVirtualNetworkConnectionObject)) { hubVnetConnection = new MNM.SubResource(this.VirtualHubVnetConnection.Id); } else if (ParameterSetName.Contains(CortexParameterSetNames.ByHubVirtualNetworkConnectionResourceId)) { hubVnetConnection = new MNM.SubResource(this.VirtualHubVnetConnectionId); } var bgpConnectionToCreate = new MNM.BgpConnection { Name = this.Name, PeerAsn = this.PeerAsn, PeerIp = this.PeerIp, HubVirtualNetworkConnection = hubVnetConnection }; this.ConfirmAction( Properties.Resources.CreatingResourceMessage, this.Name, () => { WriteVerbose(string.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); WriteObject(this.CreateOrUpdateVirtualHubBgpConnection(this.ResourceGroupName, this.VirtualHubName, this.Name, bgpConnectionToCreate)); }); }
public override void Execute() { base.Execute(); if (!ParameterSetName.Contains(Microsoft.Azure.Commands.Network.Properties.Resources.SetByResourceId)) { if (this.Subnet != null) { this.SubnetId = this.Subnet.Id; } if (this.PublicIpAddress != null) { this.PublicIpAddressId = this.PublicIpAddress.Id; } } }
public override void Execute() { base.Execute(); MNM.SecurityGroupViewParameters properties = new MNM.SecurityGroupViewParameters(); properties.TargetResourceId = this.TargetVirtualMachineId; PSSecurityGroupViewResult securityGroupView = new PSSecurityGroupViewResult(); if (ParameterSetName.Contains("SetByResource")) { securityGroupView = GetSecurityGroupView(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, properties); } else { securityGroupView = GetSecurityGroupView(this.ResourceGroupName, this.NetworkWatcherName, properties); } WriteObject(securityGroupView); }
public override void Execute() { base.Execute(); MNM.FlowLogStatusParameters parameters = new MNM.FlowLogStatusParameters(); parameters.TargetResourceId = this.TargetResourceId; PSFlowLog flowLog = new PSFlowLog(); if (ParameterSetName.Contains("SetByResource")) { flowLog = GetFlowLogStatus(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, parameters); } else { flowLog = GetFlowLogStatus(this.ResourceGroupName, this.NetworkWatcherName, parameters); } WriteObject(flowLog); }