Esempio n. 1
0
def do_backup_status_report(operation, status, status_code, message, taskId,
                            commandStartTimeUTCTicks, blobUri):
    global backup_logger, hutil
    backup_logger.log(msg="{0},{1},{2},{3}".format(operation, status,
                                                   status_code, message),
                      local=True)
    time_delta = datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)
    time_span = timedelta_total_seconds(time_delta) * 1000
    date_string = r'\/Date(' + str((int)(time_span)) + r')\/'
    date_place_holder = 'e2794170-c93d-4178-a8da-9bc7fd91ecc0'
    stat = [{
        "version": hutil._context._version,
        "timestampUTC": date_place_holder,
        "status": {
            "name": hutil._context._name,
            "operation": operation,
            "status": status,
            "code": status_code,
            "taskId": taskId,
            "commandStartTimeUTCTicks": commandStartTimeUTCTicks,
            "formattedMessage": {
                "lang": "en-US",
                "message": message
            }
        }
    }]
    status_report_msg = json.dumps(stat)
    status_report_msg = status_report_msg.replace(date_place_holder,
                                                  date_string)
    blobWriter = BlobWriter(hutil)
    blobWriter.WriteBlob(status_report_msg, blobUri)
    return status_report_msg
 def commit_to_blob(self, logbloburi):
     log_to_blob = ""
     blobWriter = BlobWriter(self.hutil)
     # append the wala log at the end.
     try:
         # distro information
         if (self.hutil is not None and self.hutil.patching is not None
                 and self.hutil.patching.distro_info is not None):
             distro_str = ""
             if (len(self.hutil.patching.distro_info) > 1):
                 distro_str = self.hutil.patching.distro_info[
                     0] + " " + self.hutil.patching.distro_info[1]
             else:
                 distro_str = self.hutil.patching.distro_info[0]
             self.msg = "Distro Info:" + distro_str + "\n" + self.msg
         self.msg = "Guest Agent Version is :" + waagent.GuestAgentVersion + "\n" + self.msg
         with open("/var/log/waagent.log", 'rb') as file:
             file.seek(0, os.SEEK_END)
             length = file.tell()
             seek_len_abs = 1024 * 10
             if (length < seek_len_abs):
                 seek_len_abs = length
             file.seek(0 - seek_len_abs, os.SEEK_END)
             tail_wala_log = file.read()
             log_to_blob = self.hutil.fetch_log_message(
             ) + "Tail of previous logs:" + self.prev_log + "Tail of WALA Log:" + tail_wala_log + "Tail of shell script log:" + self.hutil.get_shell_script_log(
             )
     except Exception as e:
         errMsg = 'Failed to get the waagent log with error: %s, stack trace: %s' % (
             str(e), traceback.format_exc())
         self.hutil.log(errMsg)
     blobWriter.WriteBlob(log_to_blob, logbloburi)
 def commit(self, logbloburi):
     #commit to local file system first, then commit to the network.
     self.hutil.log(self.msg)
     blobWriter = BlobWriter(self.hutil)
     # append the wala log at the end.
     try:
         # distro information
         if(self.hutil is not None and self.hutil.patching is not None and self.hutil.patching.distro_info is not None):
             distro_str = ""
             if(len(self.hutil.patching.distro_info)>1):
                 distro_str = self.hutil.patching.distro_info[0] + " " + self.hutil.patching.distro_info[1]
             else:
                 distro_str = self.hutil.patching.distro_info[0]
             self.msg = "Distro Info:" + distro_str + "\n" + self.msg
         self.msg = "Guest Agent Version is :" + waagent.GuestAgentVersion + "\n" + self.msg
         with open("/var/log/waagent.log", 'rb') as file:
             file.seek(0, os.SEEK_END)
             length = file.tell()
             seek_len_abs = 1024 * 10
             if(length < seek_len_abs):
                 seek_len_abs = length
             file.seek(0 - seek_len_abs, os.SEEK_END)
             tail_wala_log = file.read()
             self.msg = self.msg + "Tail of WALA Log:" + tail_wala_log
     except Exception as e:
         errMsg = 'Failed to get the waagent log with error: %s, stack trace: %s' % (str(e), traceback.format_exc())
         self.hutil.log(errMsg)
     blobWriter.WriteBlob(self.msg, logbloburi)
 def commit_to_blob(self, logbloburi):
     UploadStatusAndLog = self.hutil.get_strvalue_from_configfile(
         'UploadStatusAndLog', 'True')
     if (UploadStatusAndLog == None or UploadStatusAndLog == 'True'):
         log_to_blob = ""
         blobWriter = BlobWriter(self.hutil)
         # append the wala log at the end.
         try:
             # distro information
             if (self.hutil is not None and self.hutil.patching is not None
                     and self.hutil.patching.distro_info is not None):
                 distro_str = ""
                 if (len(self.hutil.patching.distro_info) > 1):
                     distro_str = self.hutil.patching.distro_info[
                         0] + " " + self.hutil.patching.distro_info[1]
                 else:
                     distro_str = self.hutil.patching.distro_info[0]
                 self.msg = "Distro Info:" + distro_str + "\n" + self.msg
             self.msg = "Guest Agent Version is :" + waagent.GuestAgentVersion + "\n" + self.msg
             log_to_blob = str(self.hutil.fetch_log_message()
                               ) + "Tail of shell script log:" + str(
                                   self.hutil.get_shell_script_log())
         except Exception as e:
             errMsg = 'Failed to get the waagent log with error: %s, stack trace: %s' % (
                 str(e), traceback.format_exc())
             self.hutil.log(errMsg)
         blobWriter.WriteBlob(log_to_blob, logbloburi)
Esempio n. 5
0
def status_report(status, status_code, message, snapshot_info = None):
    global backup_logger,hutil,para_parser
    trans_report_msg = None
    try:
        if(para_parser is not None and para_parser.statusBlobUri is not None and para_parser.statusBlobUri != ""):
            trans_report_msg = hutil.do_status_report(operation='Enable',status=status,\
                    status_code=str(status_code),\
                    message=message,\
                    taskId=para_parser.taskId,\
                    commandStartTimeUTCTicks=para_parser.commandStartTimeUTCTicks,\
                    snapshot_info=snapshot_info)
    except Exception as e:
        err_msg='cannot write status to the status file, Exception %s, stack trace: %s' % (str(e), traceback.format_exc())
        backup_logger.log(err_msg, True, 'Warning')
    try:
        if(para_parser is not None and para_parser.statusBlobUri is not None and para_parser.statusBlobUri != ""):
            blobWriter = BlobWriter(hutil)
            if(trans_report_msg is not None):
                blobWriter.WriteBlob(trans_report_msg,para_parser.statusBlobUri)
                backup_logger.log("trans status report message:",True)
                backup_logger.log(trans_report_msg,True)
            else:
                backup_logger.log("trans_report_msg is none",True)
    except Exception as e:
        err_msg='cannot write status to the status blob'
        backup_logger.log(err_msg, True, 'Warning')
Esempio n. 6
0
def do_backup_status_report(operation, status, status_code, message, taskId, commandStartTimeUTCTicks, blobUri):
    global backup_logger,hutil
    backup_logger.log(msg="{0},{1},{2},{3}".format(operation, status, status_code, message),local=True)
    time_delta = datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)
    time_span = timedelta_total_seconds(time_delta) * 1000
    date_string = r'\/Date(' + str((int)(time_span)) + r')\/'
    date_place_holder = 'e2794170-c93d-4178-a8da-9bc7fd91ecc0'
    sub_stat = []
    status_report_msg = do_json(operation, status, sub_stat, status_code, message, taskId, commandStartTimeUTCTicks)
    status_report_msg = status_report_msg.replace(date_place_holder,date_string)
    blobWriter = BlobWriter(hutil)
    blobWriter.WriteBlob(status_report_msg,blobUri)
    return status_report_msg
Esempio n. 7
0
def status_report_to_blob(blob_report_msg):
    global backup_logger,hutil,para_parser
    try:
        if(para_parser is not None and para_parser.statusBlobUri is not None and para_parser.statusBlobUri != ""):
            blobWriter = BlobWriter(hutil)
            if(blob_report_msg is not None):
                blobWriter.WriteBlob(blob_report_msg,para_parser.statusBlobUri)
                backup_logger.log("blob status report message:",True)
                backup_logger.log(blob_report_msg,True)
            else:
                backup_logger.log("blob_report_msg is none",True)
    except Exception as e:
        err_msg='cannot write status to the status blob'+traceback.format_exc()
        backup_logger.log(err_msg, True, 'Warning')
Esempio n. 8
0
def status_report_to_blob(blob_report_msg):
    global backup_logger,hutil,para_parser
    UploadStatusAndLog = hutil.get_strvalue_from_configfile('UploadStatusAndLog','True')        
    if(UploadStatusAndLog == None or UploadStatusAndLog == 'True'):
        try:
            if(para_parser is not None and para_parser.statusBlobUri is not None and para_parser.statusBlobUri != ""):
                blobWriter = BlobWriter(hutil)
                if(blob_report_msg is not None):
                    blobWriter.WriteBlob(blob_report_msg,para_parser.statusBlobUri)
                    backup_logger.log("blob status report message:",True)
                    backup_logger.log(blob_report_msg,True)
                else:
                    backup_logger.log("blob_report_msg is none",True)
        except Exception as e:
            err_msg='cannot write status to the status blob'+traceback.format_exc()
            backup_logger.log(err_msg, True, 'Warning')
def status_report(status,status_code,message):
    global backup_logger,hutil,para_parser
    trans_report_msg = None
    if(para_parser is not None and para_parser.statusBlobUri is not None and para_parser.statusBlobUri != ""):
        trans_report_msg = hutil.do_status_report(operation='Enable',status=status,\
                status_code=str(status_code),\
                message=message,\
                taskId=para_parser.taskId,\
                commandStartTimeUTCTicks=para_parser.commandStartTimeUTCTicks)
        blobWriter = BlobWriter(hutil)
        blobWriter.WriteBlob(trans_report_msg,para_parser.statusBlobUri)
        if(trans_report_msg is not None):
            backup_logger.log("trans status report message:")
            backup_logger.log(trans_report_msg)
        else:
            backup_logger.log("trans_report_msg is none")
Esempio n. 10
0
def status_report(status, status_code, message, snapshot_info = None):
    global MyPatching,backup_logger,hutil,para_parser,total_used_size,size_calculation_failed
    trans_report_msg = None
    try:
        if total_used_size == -1 :
            sizeCalculation = SizeCalculation.SizeCalculation(patching = MyPatching , logger = backup_logger)
            total_used_size,size_calculation_failed = sizeCalculation.get_total_used_size()
            number_of_blobs = len(para_parser.blobs)
            maximum_possible_size = number_of_blobs * 1099511627776
            if(total_used_size>maximum_possible_size):
                total_used_size = maximum_possible_size
            backup_logger.log("Assertion Check, total size : {0} ,maximum_possible_size : {1}".format(total_used_size,maximum_possible_size),True)
        if(para_parser is not None and para_parser.statusBlobUri is not None and para_parser.statusBlobUri != ""):
            trans_report_msg = hutil.do_status_report(operation='Enable',status=status,\
                    status_code=str(status_code),\
                    message=message,\
                    taskId=para_parser.taskId,\
                    commandStartTimeUTCTicks=para_parser.commandStartTimeUTCTicks,\
                    snapshot_info=snapshot_info,\
                    total_size = total_used_size,\
                    failure_flag = size_calculation_failed)
    except Exception as e:
        err_msg='cannot write status to the status file, Exception %s, stack trace: %s' % (str(e), traceback.format_exc())
        backup_logger.log(err_msg, True, 'Warning')
    try:
        if(para_parser is not None and para_parser.statusBlobUri is not None and para_parser.statusBlobUri != ""):
            blobWriter = BlobWriter(hutil)
            if(trans_report_msg is not None):
                blobWriter.WriteBlob(trans_report_msg,para_parser.statusBlobUri)
                backup_logger.log("trans status report message:",True)
                backup_logger.log(trans_report_msg,True)
            else:
                backup_logger.log("trans_report_msg is none",True)
    except Exception as e:
        err_msg='cannot write status to the status blob'
        backup_logger.log(err_msg, True, 'Warning')
 def commit(self, logbloburi):
     #commit to local file system first, then commit to the network.
     self.hutil.log(self.msg)
     blobWriter = BlobWriter(self.hutil)
     blobWriter.WriteBlob(self.msg,logbloburi)