예제 #1
0
def createCSVFiles():

    global todayonly
    global cp_filePath
    global licensesAvailableFile
    global licensesAvailableRawFile

    # CSV File Names

    filepath = ''
    if cp_filePath:
        filepath = cp_filePath

    licensesAvailableFile = filepath + 'licensesAvailable-01-Users-' + todayisshort + '.csv'
    licensesAvailableRawFile = filepath + 'licensesAvailable-02-All-' + todayisshort + '.csv'

    # Generate  CSV file headers
    licensesAvailableHeader = ("UserID", "UserUid", "UserName", "First Name",
                               "Last Name", "Email", "OrgId", "Org",
                               "Archive Guid", "Device Name", "Archive Size",
                               "Expire Date")

    # Write CSV File Headers

    c42Lib.writeCSVappend(
        licensesAvailableHeader, licensesAvailableFile,
        'w')  # Write the headers to the license available list file
    c42Lib.writeCSVappend(
        licensesAvailableHeader, licensesAvailableRawFile,
        'w')  # Write the headers to the license available list file
def createCSVFiles():

	global todayonly
	global cp_filePath
	global licensesAvailableFile
	global licensesAvailableRawFile

# CSV File Names

	filepath = ''
	if cp_filePath:
		filepath = cp_filePath

	licensesAvailableFile    = filepath+'licensesAvailable-01-Users-'+todayisshort+'.csv'
	licensesAvailableRawFile = filepath+'licensesAvailable-02-All-'+todayisshort+'.csv'

	# Generate  CSV file headers
	licensesAvailableHeader = ("UserID","UserUid","UserName","First Name","Last Name","Email","OrgId","Org","Archive Guid","Device Name","Archive Size","Expire Date")

	# Write CSV File Headers

	c42Lib.writeCSVappend (licensesAvailableHeader, licensesAvailableFile,'w') # Write the headers to the license available list file
	c42Lib.writeCSVappend (licensesAvailableHeader, licensesAvailableRawFile,'w') # Write the headers to the license available list file
def licensesAvailableList ():

	global totalcount
	global totalAvailableCount
	global coldStorageArchivesProcessed
	global elapsed_time
	global todayonly
	global orgList
	global licensesAvailableFile
	global licensesAvailableRawFile

	totalcount = 0
	totalAvailableCount = 0


	usersInColdStorage = {}

	#Get Org List to use

	if not orgList:
		# Specific orgs not specified, gathering a list of all orgs.
		orgList = c42Lib.getAllOrgs()


	print ""
	print "========== " + str(len(orgList)) + " To Be Processed"
	print ""

	# Get Archives in Cold Storage by Org

	orgCount = 0

	for orgIndex, org in enumerate(orgList):

		orgName = org['orgName']
		orgUid  = org['orgUid']
		orgId   = org['orgId']

		orgCount += 1

		print ""
		print "========== " + str(orgCount) + " / " + str(len(orgList)) + " | Getting Cold Storage for Org : [ "+str(orgId)+" ] " + orgName
		print ""

		# Will loop just in case it's a really really long list
		currentPage = 1
		keepLooping = True


		coldStorageParams = {}
		coldStorageParams['orgId']  = orgId
		coldStorageParams['pgNum']  = currentPage
		coldStorageParams['pgSize'] = 250
		coldStorageParams['srtDir'] = 'desc'

		# Initial check to make sure there is data to be had

		coldStorageList = []
		coldStorageInfo = c42Lib.getColdStorage(coldStorageParams)

		coldStorageRowCount = len(coldStorageInfo['coldStorageRows'])

		if coldStorageInfo['totalCount'] < 1 or coldStorageRowCount < 1:
			keepLooping = False
			print ""
			print "========== Org Has No Data"
			print ""


		while keepLooping:

			coldStorageList = []
			coldStorageInfo = c42Lib.getColdStorage(coldStorageParams)

			if not coldStorageInfo['coldStorageRows'] or len(coldStorageInfo['coldStorageRows']) < 1:
				keepLooping = False

			if coldStorageInfo:

				coldStorageList = coldStorageInfo['coldStorageRows']

				#Loop Through List of Users - check if user has BackupUsage - if yes, discard.  If no, add to list.

				for deviceIndex, device in enumerate(coldStorageList):

					# Get User Info

					userIsActive = True

					userParams = {}
					userParams['userId']           = device['sourceUserId']
					userParams['idType']           = "id"
					userParams['incBackupUsage']   = "true"
					userParams['incComputerCount'] = "true"

					userInfo = c42Lib.getUser(userParams)

					userInfo = userInfo[0]

					# print device

					if not device['sourceComputerName']:
						device['sourceComptuerName'] = 'NO_DEVICE_NAME'

					userIsActive = userInfo['active']

					userHasBackupUsage = False
					userHasBackupComputers = True

					if userInfo['backupUsage']:
						userHasBackupUsage = True

					if int(userInfo['computerCount']) == 0:
						userHasBackupComputers = False

					print ""
					if userIsActive and userHasBackupUsage and userHasBackupComputers:

						print "========== " + str(device['sourceComputerName']) + " | " + str(userInfo['username']) + " | Backup Devices : " + str(userInfo['computerCount']) + " | Status : " + str(userInfo['status'])

					
					else:

						print "========== " + str(device['sourceComputerName']) + " | " + str(userInfo['username']) + " | Not Active"
					
					totalcount += 1

					if not userHasBackupComputers or userIsActive == False : # User does not have any other archives!  Can be on the list!

						print "++++++++++ " + str(totalcount).zfill(6) + " | Device : " + str(device['sourceComputerName']) + " | " + str(userInfo['username']) + " has NO other active devices."

						#look up user to see if they're in the existing cold storage list.

						if usersInColdStorage and device['sourceUserId'] in usersInColdStorage: # If the user already exists in the cold storage lists we will compare archive expire dates

							print "           User already exists in cold storage.  Checking Dates."

							existingInList = usersInColdStorage[device['sourceUserId']]

							#print existingInList

							# Covert Date to Something useful
							listExpireDate = existingInList['archiveHoldExpireDate']
							# listExpireDate = datetime.strptime(listExpireDate, '%Y-%m-%d')

							thisExpireDate = device['archiveHoldExpireDate'][:-6].replace("T"," ")
							thisExpireDate = datetime.strptime(thisExpireDate, '%Y-%m-%d %H:%M:%S.%f')
							thisExpireDate = datetime.date(thisExpireDate)

							# Compare expire dates - if the current cold storage date is sooner, use it instead
							if thisExpireDate > listExpireDate:

								print "           This device has a later expire date.  Swapping it out."
								print "               In List : " + str(listExpireDate)
								print "           This Device : " + str(thisExpireDate)

								# Build dictionary value object
								replaceUserInCold = {}
								replaceUserInCold['userName']   	        = userInfo['username']
								replaceUserInCold['userUid']				= userInfo['userUid']
								replaceUserInCold['firstName']      	   	= device['sourceUserFirstName']
								replaceUserInCold['firstName']       		= device['sourceUserLastName']
								replaceUserInCold['email']          	    = device['sourceUserEmail']
								replaceUserInCold['orgId']					= device['orgId']
								replaceUserInCold['orgName']			 	= device['orgName']
								replaceUserInCold['archiveGuid']      	    = device['archiveGuid']
								replaceUserInCold['sourceComputerName']     = device['sourceComputerName']
								replaceUserInCold['archiveBytes']      		= device['archiveBytes']
								replaceUserInCold['archiveHoldExpireDate']  = thisExpireDate

								# Replace existing user with new values.
								usersInColdStorage[device['sourceUserId']]  = replaceUserInCold

								# Write this out to the raw file that will show every cold storage device
								rawDeviceRow = (device['sourceUserId'],userInfo['userUid'],userInfo['username'],device['sourceUserFirstName'],device['sourceUserLastName'],device['sourceUserEmail'],device['orgId'],device['orgName'],device['archiveGuid'],device['sourceComputerName'],device['archiveBytes'],thisExpireDate)
								c42Lib.writeCSVappend (rawDeviceRow, licensesAvailableRawFile,'a+')

								replaceDeviceRow = (device['sourceUserId'],userInfo['userUid'],userInfo['username'],device['sourceUserFirstName'],device['sourceUserLastName'],device['sourceUserEmail'],device['orgId'],device['orgName'],device['archiveGuid'],device['sourceComputerName'],device['archiveBytes'],thisExpireDate)
								c42Lib.writeCSVappend (replaceDeviceRow, licensesAvailableFile,'a+')

								#print usersInColdStorage[device['sourceUserId']]
								#raw_input()
							else:
								print "           This device has an earlier expire date.  NOT Swapping it out."
								print "               In List : " + str(listExpireDate)
								print "           This Device : " + str(thisExpireDate)
								
								rawDeviceRow = (device['sourceUserId'],userInfo['userUid'],userInfo['username'],device['sourceUserFirstName'],device['sourceUserLastName'],device['sourceUserEmail'],device['orgId'],device['orgName'],device['archiveGuid'],device['sourceComputerName'],device['archiveBytes'],thisExpireDate)
								c42Lib.writeCSVappend (rawDeviceRow, licensesAvailableRawFile,'a+')


						else:

							print "           Adding user/device as new to list."

							# Covert Date to Something useful
							listExpireDate = device['archiveHoldExpireDate'][:-6].replace("T"," ")
							listExpireDate = datetime.strptime(listExpireDate, '%Y-%m-%d %H:%M:%S.%f')
							listExpireDate = datetime.date(listExpireDate)

							# Build dictionary value object
							newUserInCold = {}
							newUserInCold['userName']      		    = userInfo['username']
							newUserInCold['userUid']       		    = userInfo['userUid']
							newUserInCold['firstName']     		    = device['sourceUserFirstName']
							newUserInCold['firstName']     		    = device['sourceUserLastName']
							newUserInCold['email']        		    = device['sourceUserEmail']
							newUserInCold['orgId']					= device['orgId']
							newUserInCold['orgName']				= device['orgName']
							newUserInCold['archiveGuid']        	= device['archiveGuid']
							newUserInCold['sourceComputerName'] 	= device['sourceComputerName']
							newUserInCold['archiveBytes']       	= device['archiveBytes']
							newUserInCold['archiveHoldExpireDate']  = listExpireDate

							# Insert into dictionary with userID as key
							usersInColdStorage[device['sourceUserId']] = newUserInCold
							totalAvailableCount += 1

							# Add to raw list
							rawDeviceRow = (device['sourceUserId'],userInfo['userUid'],userInfo['username'],device['sourceUserFirstName'],device['sourceUserLastName'],device['sourceUserEmail'],device['orgId'],device['orgName'],device['archiveGuid'],device['sourceComputerName'],device['archiveBytes'],listExpireDate)
							c42Lib.writeCSVappend (rawDeviceRow, licensesAvailableRawFile,'a+')

							# Write this out to the raw file that will show every cold storage device

							newDeviceRow = (device['sourceUserId'],userInfo['userUid'],userInfo['username'],device['sourceUserFirstName'],device['sourceUserLastName'],device['sourceUserEmail'],device['orgId'],device['orgName'],device['archiveGuid'],device['sourceComputerName'],device['archiveBytes'],listExpireDate)
							c42Lib.writeCSVappend (newDeviceRow, licensesAvailableFile,'a+')

							#print usersInColdStorage[device['sourceUserId']]
							#raw_input()

					else:

						userDeviceCount = userInfo['computerCount']

						print "---------- " + str(totalcount).zfill(6) + " | Device : " + str(device['sourceComputerName']) + " | " + str(userInfo['username']) + " has "  + str(userDeviceCount).zfill(2) + " other active devices."

			
					if totalcount%50 == 0:
					
						elapsed_time = time.time() - start_time
					
						print ""
						print "====================================================================================="
						print ""
						print "                     Processing Org : [ "+str(orgId)+" ] " + orgName
						print ""
						print "                    Total Processed : " + str(totalcount) 
						print "Users With Licenses to Be Available : " + str(totalAvailableCount)
						print ""
						print "                       Elapsed Time : " + str(time.strftime('%H:%M:%S', time.gmtime(elapsed_time)))
						print "                         Start TIme : " + str(time.strftime('%H:%M:%S', time.gmtime(start_time)))
						print "                 Current Time Stamp : " + str(time.strftime('%H:%M:%S', time.gmtime(time.time())))
						print "====================================================================================="			
						print ""		


				elapsed_time = time.time() - start_time
				
				print ""
				print "====================================================================================="
				print "                    Total Processed : " + str(totalcount) 
				print "Users With Licenses to Be Available : " + str(totalAvailableCount)
				print ""
				print "                       Elapsed Time : " + str(time.strftime('%H:%M:%S', time.gmtime(elapsed_time)))
				print "                         Start TIme : " + str(time.strftime('%H:%M:%S', time.gmtime(start_time)))
				print "                 Current Time Stamp : " + str(time.strftime('%H:%M:%S', time.gmtime(time.time())))
				print "====================================================================================="			
				print ""

			else:

				keepLooping = False

			currentPage += 1
			coldStorageParams['pgNum'] = currentPage
예제 #4
0
def licensesAvailableList():

    global totalcount
    global totalAvailableCount
    global coldStorageArchivesProcessed
    global elapsed_time
    global todayonly
    global orgList
    global licensesAvailableFile
    global licensesAvailableRawFile

    totalcount = 0
    totalAvailableCount = 0

    usersInColdStorage = {}

    #Get Org List to use

    if not orgList:
        # Specific orgs not specified, gathering a list of all orgs.
        orgList = c42Lib.getAllOrgs()

    print ""
    print "========== " + str(len(orgList)) + " To Be Processed"
    print ""

    # Get Archives in Cold Storage by Org

    orgCount = 0

    for orgIndex, org in enumerate(orgList):

        orgName = org['orgName']
        orgUid = org['orgUid']
        orgId = org['orgId']

        orgCount += 1

        print ""
        print "========== " + str(orgCount) + " / " + str(
            len(orgList)) + " | Getting Cold Storage for Org : [ " + str(
                orgId) + " ] " + orgName
        print ""

        # Will loop just in case it's a really really long list
        currentPage = 1
        keepLooping = True

        coldStorageParams = {}
        coldStorageParams['orgId'] = orgId
        coldStorageParams['pgNum'] = currentPage
        coldStorageParams['pgSize'] = 250
        coldStorageParams['srtDir'] = 'desc'

        # Initial check to make sure there is data to be had

        coldStorageList = []
        coldStorageInfo = c42Lib.getColdStorage(coldStorageParams)

        coldStorageRowCount = len(coldStorageInfo['coldStorageRows'])

        if coldStorageInfo['totalCount'] < 1 or coldStorageRowCount < 1:
            keepLooping = False
            print ""
            print "========== Org Has No Data"
            print ""

        while keepLooping:

            coldStorageList = []
            coldStorageInfo = c42Lib.getColdStorage(coldStorageParams)

            if not coldStorageInfo['coldStorageRows'] or len(
                    coldStorageInfo['coldStorageRows']) < 1:
                keepLooping = False

            if coldStorageInfo:

                coldStorageList = coldStorageInfo['coldStorageRows']

                #Loop Through List of Users - check if user has BackupUsage - if yes, discard.  If no, add to list.

                for deviceIndex, device in enumerate(coldStorageList):

                    # print device

                    # Get User Info

                    userParams = {}
                    userParams['userId'] = device['sourceUserId']
                    userParams['idType'] = "id"
                    userParams['incBackupUsage'] = "true"

                    userInfo = c42Lib.getUser(userParams)

                    userInfo = userInfo[0]

                    totalcount += 1

                    if not userInfo[
                            'backupUsage']:  # User does not have any other archives!  Can be on the list!

                        print "++++++++++ " + str(totalcount).zfill(
                            6
                        ) + " | Device : " + device[
                            'sourceComputerName'] + " | " + userInfo[
                                'username'] + " has NO other active devices."

                        #look up user to see if they're in the existing cold storage list.

                        if usersInColdStorage and device[
                                'sourceUserId'] in usersInColdStorage:  # If the user already exists in the cold storage lists we will compare archive expire dates

                            print "           User already exists in cold storage.  Checking Dates."

                            existingInList = usersInColdStorage[
                                device['sourceUserId']]

                            #print existingInList

                            # Covert Date to Something useful
                            listExpireDate = existingInList[
                                'archiveHoldExpireDate']
                            # listExpireDate = datetime.strptime(listExpireDate, '%Y-%m-%d')

                            thisExpireDate = device[
                                'archiveHoldExpireDate'][:-6].replace(
                                    "T", " ")
                            thisExpireDate = datetime.strptime(
                                thisExpireDate, '%Y-%m-%d %H:%M:%S.%f')
                            thisExpireDate = datetime.date(thisExpireDate)

                            rawDeviceRow = (device['sourceUserId'],
                                            userInfo['userUid'],
                                            userInfo['username'],
                                            device['sourceUserFirstName'],
                                            device['sourceUserLastName'],
                                            device['sourceUserEmail'],
                                            device['orgId'], device['orgName'],
                                            device['archiveGuid'],
                                            device['sourceComputerName'],
                                            device['archiveBytes'],
                                            thisExpireDate)
                            c42Lib.writeCSVappend(rawDeviceRow,
                                                  licensesAvailableRawFile,
                                                  'a+')

                            # Compare expire dates - if the current cold storage date is sooner, use it instead
                            if thisExpireDate > listExpireDate:

                                print "           This device has a later expire date.  Swapping it out."
                                print "               In List : " + str(
                                    listExpireDate)
                                print "           This Device : " + str(
                                    thisExpireDate)

                                # Build dictionary value object
                                replaceUserInCold = {}
                                replaceUserInCold['userName'] = userInfo[
                                    'username']
                                replaceUserInCold['userUid'] = userInfo[
                                    'userUid']
                                replaceUserInCold['firstName'] = device[
                                    'sourceUserFirstName']
                                replaceUserInCold['firstName'] = device[
                                    'sourceUserLastName']
                                replaceUserInCold['email'] = device[
                                    'sourceUserEmail']
                                replaceUserInCold['orgId'] = device['orgId']
                                replaceUserInCold['orgName'] = device[
                                    'orgName']
                                replaceUserInCold['archiveGuid'] = device[
                                    'archiveGuid']
                                replaceUserInCold[
                                    'sourceComputerName'] = device[
                                        'sourceComputerName']
                                replaceUserInCold['archiveBytes'] = device[
                                    'archiveBytes']
                                replaceUserInCold[
                                    'archiveHoldExpireDate'] = thisExpireDate

                                # Replace existing user with new values.
                                usersInColdStorage[
                                    device['sourceUserId']] = replaceUserInCold

                                # Write this out to the raw file that will show every cold storage device

                                replaceDeviceRow = (
                                    device['sourceUserId'],
                                    userInfo['userUid'], userInfo['username'],
                                    device['sourceUserFirstName'],
                                    device['sourceUserLastName'],
                                    device['sourceUserEmail'], device['orgId'],
                                    device['orgName'], device['archiveGuid'],
                                    device['sourceComputerName'],
                                    device['archiveBytes'], thisExpireDate)
                                c42Lib.writeCSVappend(replaceDeviceRow,
                                                      licensesAvailableFile,
                                                      'a+')

                                #print usersInColdStorage[device['sourceUserId']]
                                #raw_input()
                            else:
                                print "           This device has an earlier expire date.  NOT Swapping it out."
                                print "               In List : " + str(
                                    listExpireDate)
                                print "           This Device : " + str(
                                    thisExpireDate)

                        else:

                            print "           Adding user/device as new to list."

                            # Covert Date to Something useful
                            listExpireDate = device[
                                'archiveHoldExpireDate'][:-6].replace(
                                    "T", " ")
                            listExpireDate = datetime.strptime(
                                listExpireDate, '%Y-%m-%d %H:%M:%S.%f')
                            listExpireDate = datetime.date(listExpireDate)

                            # Build dictionary value object
                            newUserInCold = {}
                            newUserInCold['userName'] = userInfo['username']
                            newUserInCold['userUid'] = userInfo['userUid']
                            newUserInCold['firstName'] = device[
                                'sourceUserFirstName']
                            newUserInCold['firstName'] = device[
                                'sourceUserLastName']
                            newUserInCold['email'] = device['sourceUserEmail']
                            newUserInCold['orgId'] = device['orgId']
                            newUserInCold['orgName'] = device['orgName']
                            newUserInCold['archiveGuid'] = device[
                                'archiveGuid']
                            newUserInCold['sourceComputerName'] = device[
                                'sourceComputerName']
                            newUserInCold['archiveBytes'] = device[
                                'archiveBytes']
                            newUserInCold[
                                'archiveHoldExpireDate'] = listExpireDate

                            # Insert into dictionary with userID as key
                            usersInColdStorage[
                                device['sourceUserId']] = newUserInCold
                            totalAvailableCount += 1

                            # Add to raw list
                            rawDeviceRow = (device['sourceUserId'],
                                            userInfo['userUid'],
                                            userInfo['username'],
                                            device['sourceUserFirstName'],
                                            device['sourceUserLastName'],
                                            device['sourceUserEmail'],
                                            device['orgId'], device['orgName'],
                                            device['archiveGuid'],
                                            device['sourceComputerName'],
                                            device['archiveBytes'],
                                            listExpireDate)
                            c42Lib.writeCSVappend(rawDeviceRow,
                                                  licensesAvailableRawFile,
                                                  'a+')

                            # Write this out to the raw file that will show every cold storage device

                            newDeviceRow = (device['sourceUserId'],
                                            userInfo['userUid'],
                                            userInfo['username'],
                                            device['sourceUserFirstName'],
                                            device['sourceUserLastName'],
                                            device['sourceUserEmail'],
                                            device['orgId'], device['orgName'],
                                            device['archiveGuid'],
                                            device['sourceComputerName'],
                                            device['archiveBytes'],
                                            listExpireDate)
                            c42Lib.writeCSVappend(newDeviceRow,
                                                  licensesAvailableFile, 'a+')

                            #print usersInColdStorage[device['sourceUserId']]
                            #raw_input()

                    else:

                        userDeviceCount = len(userInfo['backupUsage'])

                        print "---------- " + str(totalcount).zfill(
                            6) + " | Device : " + device[
                                'sourceComputerName'] + " | " + userInfo[
                                    'username'] + " has " + str(
                                        userDeviceCount).zfill(
                                            2) + " other active devices."

                    if totalcount % 10 == 0:

                        elapsed_time = time.time() - start_time

                        print ""
                        print "====================================================================================="
                        print ""
                        print "                     Processing Org : [ " + str(
                            orgId) + " ] " + orgName
                        print ""
                        print "                    Total Processed : " + str(
                            totalcount)
                        print "Users With Licenses to Be Available : " + str(
                            totalAvailableCount)
                        print ""
                        print "                       Elapsed Time : " + str(
                            time.strftime('%H:%M:%S',
                                          time.gmtime(elapsed_time)))
                        print "                         Start TIme : " + str(
                            time.strftime('%H:%M:%S', time.gmtime(start_time)))
                        print "                 Current Time Stamp : " + str(
                            time.strftime('%H:%M:%S', time.gmtime(
                                time.time())))
                        print "====================================================================================="
                        print ""

                elapsed_time = time.time() - start_time

                print ""
                print "====================================================================================="
                print "                    Total Processed : " + str(
                    totalcount)
                print "Users With Licenses to Be Available : " + str(
                    totalAvailableCount)
                print ""
                print "                       Elapsed Time : " + str(
                    time.strftime('%H:%M:%S', time.gmtime(elapsed_time)))
                print "                         Start TIme : " + str(
                    time.strftime('%H:%M:%S', time.gmtime(start_time)))
                print "                 Current Time Stamp : " + str(
                    time.strftime('%H:%M:%S', time.gmtime(time.time())))
                print "====================================================================================="
                print ""

            else:

                keepLooping = False

            currentPage += 1
            coldStorageParams['pgNum'] = currentPage