/// <summary>1. Convert the list of virtual machines into Virtual machine crawler entities /// 2. Add the entity into the table using the batch operation task</summary> /// <param name="virtualMachines">List of virtual machines, which needs to push into table</param> /// <param name="resourceGroupName"></param> /// <param name="log">Trace writer instance</param> /// <returns>Returns the list of the insert batch operation as task.</returns> private static TableBatchOperation InsertOrReplaceEntitiesIntoTable(List <IVirtualMachine> virtualMachines, string resourceGroupName, TraceWriter log) { if (virtualMachines.Count == 0) { return(null); } var batchOperation = new TableBatchOperation(); foreach (var eachVirtualMachine in virtualMachines) { try { var partitionKey = resourceGroupName; batchOperation.InsertOrReplace(VirtualMachineHelper.ConvertToVirtualMachineEntity(eachVirtualMachine, partitionKey)); } catch (Exception e) { log.Error($"timercrawlerforvirtualmachines threw the exception ", e, "InsertEntitiesIntoTable"); } } return(batchOperation); }
/// <summary>Get the virtual machine batch operation.</summary> /// <param name="virtualMachines">List of the virtual machines</param> /// <param name="partitionKey"></param> /// <param name="log"></param> /// <returns></returns> private static TableBatchOperation GetVirtualMachineBatchOperation(IList <IVirtualMachine> virtualMachines, string partitionKey, TraceWriter log) { if (virtualMachines == null) { return(null); } var virtualMachineTableBatchOperation = new TableBatchOperation(); partitionKey = partitionKey.Replace(Delimeters.ForwardSlash, Delimeters.Exclamatory); foreach (var eachVirtualMachine in virtualMachines) { try { var virtualMachineEntity = VirtualMachineHelper.ConvertToVirtualMachineEntity( eachVirtualMachine, partitionKey, eachVirtualMachine.ResourceGroupName); virtualMachineEntity.VirtualMachineGroup = VirtualMachineGroup.AvailabilitySets.ToString(); virtualMachineTableBatchOperation.InsertOrReplace(virtualMachineEntity); } catch (Exception ex) { log.Error($"timercrawlerforavailableset threw the exception ", ex, "GetVirtualMachineBatchOperation"); } } return(virtualMachineTableBatchOperation); }
/// <summary>Insert the list of the scale set virtual machine instances into the table.</summary> /// <param name="virtualMachines">List of the virtual machines.</param> /// <param name="resourceGroupName">Resource group name of the scale set</param> /// <param name="scaleSetId">Id of the scale set</param> /// <param name="availabilityZone">Availability zone id of the scale set</param> /// <returns></returns> private static TableBatchOperation GetVirtualMachineBatchOperation(IEnumerable <IVirtualMachineScaleSetVM> virtualMachines, string resourceGroupName, string scaleSetId, int?availabilityZone) { if (virtualMachines == null) { return(null); } var virtualMachineBatchOperation = new TableBatchOperation(); foreach (var eachVirtualMachine in virtualMachines) { // Azure table doesnot allow partition key with forward slash var partitionKey = scaleSetId.Replace(Delimeters.ForwardSlash, Delimeters.Exclamatory); virtualMachineBatchOperation.InsertOrReplace(VirtualMachineHelper.ConvertToVirtualMachineEntity(eachVirtualMachine, resourceGroupName, scaleSetId, partitionKey, availabilityZone, VirtualMachineGroup.VirtualMachineScaleSets.ToString())); } return(virtualMachineBatchOperation); }