private PSConnectionMonitorResult UpdateConnectionMonitor(bool isConnectionMonitorV2) { MNM.ConnectionMonitor connectionMonitor; if (isConnectionMonitorV2) { this.ValidateConnectionMonitorV2Request(this.TestGroup, this.Output); connectionMonitor = this.PopulateConnectionMonitorParametersFromV2Request(this.TestGroup, this.Output, this.Note); } else { connectionMonitor = new ConnectionMonitor() { Source = new MNM.ConnectionMonitorSource { ResourceId = this.SourceResourceId, Port = this.SourcePort }, Destination = new MNM.ConnectionMonitorDestination { ResourceId = this.DestinationResourceId, Address = this.DestinationAddress, Port = this.DestinationPort }, AutoStart = this.ConfigureOnly ? false : true, MonitoringIntervalInSeconds = this.MonitoringIntervalInSeconds }; } connectionMonitor.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); if (!string.IsNullOrEmpty(this.Location)) { connectionMonitor.Location = this.Location; } else if (this.NetworkWatcher != null) { connectionMonitor.Location = this.NetworkWatcher.Location; } else { MNM.NetworkWatcher networkWatcher = this.NetworkClient.NetworkManagementClient.NetworkWatchers.Get(this.ResourceGroupName, this.NetworkWatcherName); connectionMonitor.Location = networkWatcher.Location; } PSConnectionMonitorResult psConnectionMonitorResult; if (isConnectionMonitorV2) { this.ConnectionMonitors.CreateOrUpdate(this.ResourceGroupName, this.NetworkWatcherName, this.Name, connectionMonitor); psConnectionMonitorResult = this.GetConnectionMonitor(this.ResourceGroupName, this.NetworkWatcherName, this.Name, isConnectionMonitorV2); } else { ConnectionMonitorResult connectionMonitorResult = this.ConnectionMonitors.CreateOrUpdateV1(this.ResourceGroupName, this.NetworkWatcherName, this.Name, connectionMonitor).Result; psConnectionMonitorResult = MapConnectionMonitorResultToPSConnectionMonitorResultV1(connectionMonitorResult); } return(psConnectionMonitorResult); }
public PSNetworkWatcher ToPsNetworkWatcher(MNM.NetworkWatcher networkWatcher) { var psNetworkWatcher = NetworkResourceManagerProfile.Mapper.Map <PSNetworkWatcher>(networkWatcher); psNetworkWatcher.Tag = TagsConversionHelper.CreateTagHashtable(networkWatcher.Tags); return(psNetworkWatcher); }
public PSNetworkWatcher GetNetworkWatcher(string resourceGroupName, string name, string expandResource = null) { MNM.NetworkWatcher networkWatcher = this.NetworkWatcherClient.Get(resourceGroupName, name); PSNetworkWatcher psNetworkWatcher = ToPsNetworkWatcher(networkWatcher); psNetworkWatcher.ResourceGroupName = resourceGroupName; return(psNetworkWatcher); }
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); }
private void PopulateBaseParametersFromResourceID(string id) { ResourceIdentifier flowLogInfo = new ResourceIdentifier(id); if (!this.IsValidResourceId(flowLogInfo, "Microsoft.Network/networkWatchers/FlowLogs", validateParent: true, expectedParentType: "networkWatchers")) { throw new PSArgumentException(Properties.Resources.InvalidFlowLogResourceId); } this.Name = flowLogInfo.ResourceName; this.ResourceGroupName = flowLogInfo.ResourceGroupName; string parent = flowLogInfo.ParentResource; string[] tokens = parent.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); this.NetworkWatcherName = tokens[1]; MNM.NetworkWatcher networkWatcher = this.NetworkClient.NetworkManagementClient.NetworkWatchers.Get(this.ResourceGroupName, this.NetworkWatcherName); this.Location = networkWatcher.Location; }
private PSNetworkWatcher CreateNetworkWatcher() { var networkWatcher = new PSNetworkWatcher(); networkWatcher.Name = this.Name; networkWatcher.ResourceGroupName = this.ResourceGroupName; networkWatcher.Location = this.Location; networkWatcher.Tag = this.Tag; // Map to the sdk object var networkWatcherModel = NetworkResourceManagerProfile.Mapper.Map <MNM.NetworkWatcher>(networkWatcher); MNM.NetworkWatcher networkWatcherPropertiesModel = new MNM.NetworkWatcher(); networkWatcherPropertiesModel.Location = networkWatcher.Location; networkWatcherPropertiesModel.Tags = TagsConversionHelper.CreateTagDictionary(networkWatcher.Tag, validate: true); // Execute the Create NetworkWatcher call this.NetworkWatcherClient.CreateOrUpdate(this.ResourceGroupName, this.Name, networkWatcherPropertiesModel); var getNetworkWatcher = this.GetNetworkWatcher(this.ResourceGroupName, this.Name); return(getNetworkWatcher); }
private PSConnectionMonitorResult CreateConnectionMonitor(string resourceGroupName, string networkWatcherName, bool isConnectionMonitorV2) { MNM.ConnectionMonitor connectionMonitor; if (isConnectionMonitorV2) { if (ParameterSetName.Contains("SetByConnectionMonitorV2Object")) { this.TestGroup = this.ConnectionMonitor.TestGroups?.ToArray(); this.Output = this.ConnectionMonitor.Outputs?.ToArray(); this.Note = this.ConnectionMonitor.Notes; } this.ValidateConnectionMonitorV2Request(this.TestGroup, this.Output); connectionMonitor = this.PopulateConnectionMonitorParametersFromV2Request(this.TestGroup, this.Output, this.Note); } else { connectionMonitor = new ConnectionMonitor() { Source = new MNM.ConnectionMonitorSource { ResourceId = this.SourceResourceId, Port = this.SourcePort }, Destination = new MNM.ConnectionMonitorDestination { ResourceId = this.DestinationResourceId, Address = this.DestinationAddress, Port = this.DestinationPort }, AutoStart = this.ConfigureOnly.IsPresent, MonitoringIntervalInSeconds = this.MonitoringIntervalInSeconds }; } connectionMonitor.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); if (ParameterSetName.Contains("SetByResource")) { connectionMonitor.Location = this.NetworkWatcher.Location; } else if (ParameterSetName.Contains("SetByName") || ParameterSetName.Contains("SetByConnectionMonitorV2Object")) { MNM.NetworkWatcher networkWatcher = this.NetworkClient.NetworkManagementClient.NetworkWatchers.Get(this.ResourceGroupName, this.NetworkWatcherName); connectionMonitor.Location = networkWatcher.Location; } else { connectionMonitor.Location = this.Location; } PSConnectionMonitorResult psConnectionMonitorResult; if (isConnectionMonitorV2) { // This is only used for testing. Do not remove // string str = JsonConvert.SerializeObject(parameters, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); // WriteObject(str); this.ConnectionMonitors.CreateOrUpdate(resourceGroupName, networkWatcherName, this.Name, connectionMonitor); psConnectionMonitorResult = this.GetConnectionMonitor(resourceGroupName, networkWatcherName, this.Name, isConnectionMonitorV2); } else { ConnectionMonitorResult connectionMonitorResult = this.ConnectionMonitors.CreateOrUpdateV1(resourceGroupName, networkWatcherName, this.Name, connectionMonitor).Result; psConnectionMonitorResult = MapConnectionMonitorResultToPSConnectionMonitorResultV1(connectionMonitorResult); } return(psConnectionMonitorResult); }