def copy_partition(self, PartitionListWidgetFrom, PartitionListWidgetTo, fromurl, fromid, fromkey, tourl, toid, tokey): logger.info("[Partitions]Copying Partition(s)") try: selecteditems = PartitionListWidgetFrom.selectedItems() if len(selecteditems) > 0: # make sure something was selected fromsumo = SumoLogic(fromid, fromkey, endpoint=fromurl, log_level=self.mainwindow.log_level) tosumo = SumoLogic(toid, tokey, endpoint=tourl, log_level=self.mainwindow.log_level) for selecteditem in selecteditems: for object in PartitionListWidgetFrom.currentcontent: if object['name'] == str(selecteditem.text()): item_id = object['id'] partitions_export = fromsumo.get_partition(item_id) status = tosumo.create_partition(partitions_export['name'], partitions_export['routingExpression'], analytics_tier=partitions_export['analyticsTier'], retention_period=partitions_export['retentionPeriod'], is_compliant=partitions_export['isCompliant']) self.update_partition_list(PartitionListWidgetTo, tourl, toid, tokey) return else: self.mainwindow.errorbox('You have not made any selections.') return except Exception as e: logger.exception(e) self.mainwindow.errorbox('Something went wrong:' + str(e)) self.update_partition_list(PartitionListWidgetTo, tourl, toid, tokey) return
def restore_partition(self, PartitionListWidget, url, id, key): logger.info("[Partitions]Restoring partitions(s)") if PartitionListWidget.updated == True: filter = "JSON (*.json)" filelist, status = QtWidgets.QFileDialog.getOpenFileNames(self, "Open file(s)...", os.getcwd(), filter) if len(filelist) > 0: sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level) for file in filelist: try: with open(file) as filepointer: partition_backup = json.load(filepointer) except Exception as e: logger.exception(e) self.mainwindow.errorbox( "Something went wrong reading the file. Do you have the right file permissions? Does it contain valid JSON?") return try: status = sumo.create_partition(partition_backup['name'], partition_backup['routingExpression'], analytics_tier=partition_backup['analyticsTier'], retention_period=partition_backup['retentionPeriod'], is_compliant=partition_backup['isCompliant']) except Exception as e: logger.exception(e) self.mainwindow.errorbox('Something went wrong:\n\n' + str(e)) return self.update_partition_list(PartitionListWidget, url, id, key) else: self.mainwindow.errorbox("Please select at least one file to restore.") return else: self.mainwindow.errorbox("Please update the directory list before restoring content") return