コード例 #1
0
def sendTicketNotification(clientName, projectName, warningNumber, receiverEmail, systems):
	myprint('Sending mail to ' + clientName + " with email: " + receiverEmail)
	msg = formatTicketWarning(clientName, warningNumber, systems)
	subject = ('SDSC Cloud Account [' + projectName + '] - [' + warningNumber.title() +']')
	receiverEmail = []
	receiverEmail += BAD_TICKET_LISTENERS
	# receiverEmail.append(receiverEmail)
	sendMail(REPLY_EMAIL, receiverEmail, subject, msg)
コード例 #2
0
def notifyUser(project_name, email, warningNumber, remainingTime):
    if warningNumber == FIRST:
        subj = 'The trial project for "{0}" is expiring soon'
        msg = 'Dear {0} project user,\n\n This message is a warning that your trial project "{0}" will expire within {1} days.  After {1} days, it will be deleted.\n\n'
        msg += 'SDSC Cloud Support'
    else:
        subj = 'The trial project for "{0}" has expired'
        msg = 'Dear {0} project user,\n\n This message is a notification that your trial project "{0}" has expired and the project was deleted.  Please contact SDSC Support with any concerns.\n\n'
        msg += 'SDSC Cloud Support'
    subj = subj.format(project_name)
    msg = msg.format(project_name, remainingTime)
    sendMail('*****@*****.**', email, subj, msg)
コード例 #3
0
def saveOrphans(orphan_names, orphan_ids):
    qString = ''
    qData = []
    for name, uid in zip(orphan_names, orphan_ids):
        qString += "insert into orphan_accounts (account_name, account_id) VALUES (%s, %s);"
        qData.append(str(name))
        qData.append(str(uid))
        sendMail(
            '*****@*****.**', [name] + WATCHERS,
            'SDSC Cloud User Account Inactivity',
            'Dear SDSC Cloud User,\n\nYour user account, {0}, does not belong to any active projects.  The user account will automatically be deleted if it is not associated with an active project within 14 days.\n\nPlease contact us by replying to this email if you need your user account to remain active.\n\nRegards,\nSDSC Cloud Support Team'
            .format(name))
    query(qString, tuple(qData), False)
コード例 #4
0
def unpackProjectData(data):
	data = json.loads(data)
	project_name = data['projectName']
	contact_name = data['contactName']
	contact_email = data['contactEmail']
	users = data['users']
	if data['isTrial']:
		index = TRIAL_INDEX
		warningTime = data['warningTime']
		expirationTime = data['expirationTime']
	else:
		index = data['index']
		warningTime = None
		expirationTime = None


	try:
		global sdscStone
		sdscStone.createProject(project_name = project_name, contact_name = contact_name, contact_email = contact_email, billing_field = index, attachNetwork = ATTACH_NETWORK)
	except Name_Conflict:
		raise ProjectNameTaken()

	if index == TRIAL_INDEX:
		trial_checker.saveTrialProject(project_name, warningTime, expirationTime)
	else:
		if ' ' in contact_name:
			indexOfSpace = contact_name.index(' ')
			first_name = contact_name[:indexOfSpace]
			last_name = contact_name[indexOfSpace + 1:]
		else:
			first_name = contact_name
			last_name = contact_name
		title = None #auto set in create ticket
		assignees = None #auto set in create ticket
		ticketNumber = tEditor.createTicket(project_name, index, first_name, last_name, contact_email, title, assignees)
		#probably uneeded refresh now
		sdscStone = keyStoneUtility.KeyStoneUtility(username = credentials.open_stack_username, password=credentials.open_stack_pw, auth_url = credentials.open_stack_url, 
		auth_url_dep = credentials.open_stack_url_dep, tenant_name=credentials.open_stack_username)
		sdscStone.setBillingInfo(project_name, str(ticketNumber))

	usersAndPasswords = [{'username': u, 'password': '' if sdscStone.userExists(u) else getAndSendPassword(u)} for u in users]

	sdscStone.attachUsers(project_name, usersAndPasswords)

	sendMail("*****@*****.**", ["*****@*****.**", "*****@*****.**"], 
		"New Project Created ["+project_name+"]", project_name + " created for:\n" + "\n".join(users))
コード例 #5
0
def main():
    argCount = len(sys.argv)
    if argCount != 2:
        return
    #return
    data = json.loads(sys.argv[1])

    project_name = data[0]
    project_index = data[1].upper()

    if not validateProjectIndex(project_index):
        raise InvalidCharacters()

    project_o = pBuilder.getProject(project_name)
    if project_o == None:
        return

    contact_name = project_o.contact_name
    if ' ' in contact_name:
        indexOfSpace = contact_name.index(' ')
        first_name = contact_name[:indexOfSpace]
        last_name = contact_name[indexOfSpace + 1:]
    else:
        first_name = contact_name
        last_name = contact_name
    title = None  #auto set in create ticket
    assignees = None  #auto set in create ticket

    ticketNumber = tEditor.createTicket(project_name, project_index,
                                        first_name, last_name,
                                        project_o.contact_email, title,
                                        assignees)
    pBuilder.setBillingInfo(project_name, str(ticketNumber))

    query('delete from trial_projects where name = %s;', tuple([project_name]),
          False)

    subj = "Cloud Project Upgraded [{0}]".format(project_name)
    msg = "The Cloud Project " + project_name + " has been upgraded to a paid project \n\n\n Cloud-Web-Util"
    sendMail("*****@*****.**",
             ["*****@*****.**", "*****@*****.**"], subj, msg)
    print ticketNumber
コード例 #6
0
def notifyOrphans():
    orphan_names, orphan_ids = collectOrphans()

    previous_orphans = query(
        'select account_name, account_id from orphan_accounts', (), True)

    still_orphan = []
    for prev_orphan in previous_orphans:
        name = prev_orphan[0]
        if name in orphan_names:
            still_orphan.append(prev_orphan)

    for name, uid in still_orphan:
        keyStone.users.delete(user=uid)
        sendMail(
            '*****@*****.**', [name] + WATCHERS,
            'SDSC Cloud User Account Deleted',
            'Dear SDSC Cloud User,\n\nYour user account, {0}, has been deleted because it does not belong to any active projects.\n\nPlease contact us by replying to this email if you need your account re-created.\n\nRegards,\nSDSC Cloud Support Team'
            .format(name))

    query('delete from orphan_accounts;', (), False)
コード例 #7
0
def main():
	try:
		commvaultToCsv.main()
		commvaultFPEditor.main()
		subject = 'Commvault usage to Footprints Success!'
		msg = 'Commvault usage was successfully pushed to Footprints\n\nThanks to,\ncloud-web-util'
	except:
		subject = 'Error running commvault scripts'
		msg = traceback.format_exc()
		print err

	sendMail(FROM, ['*****@*****.**'], subject, msg)
	#sendMail(FROM, ['*****@*****.**', '*****@*****.**', '*****@*****.**'], subject, msg)


	args = []	

	month_ago = commvaultToCsv.month_ago

	now = datetime.date.today()

	if now.day <= 20: #usually not going to hit, as its run after the 19th
		now = month_ago(now)

	cYear = now.year
	cMonth = now.month
	cDay = 20
	endTime = datetime.date(cYear, cMonth, cDay)
	startTime = month_ago(endTime)

	today = datetime.date.today()
	today_f = today.strftime("%Y%m%d")

	cmd = 'cloud-billing -s {0} -e {1} -b reports/{2}.csv -i project_ignore_list.txt -p itemized/{3}/ --graphite --skip-glance --skip-cinder --skip-cinder-snapshots'
	cmd = cmd.format(startTime.strftime("%Y%m%d"), endTime.strftime("%Y%m%d"), today_f, endTime.strftime("%Y%m"))
	args.append(cmd)
	
	cmd = 'duracloud-billing -s {0} -e {1} -b reports/duracloud-{2}.csv -p itemized/duracloud-{3}'
	cmd = cmd.format(startTime.strftime("%Y%m%d"), endTime.strftime("%Y%m%d"), today_f, endTime.strftime("%Y%m"))
	args.append(cmd)
	
	args.append('git add itemized/{0}/'.format(endTime.strftime("%Y%m")))
	args.append('git add reports/{0}.csv'.format(today_f))
	args.append('git add reports/duracloud-{0}.csv'.format(today_f))
	args.append(['git', 'commit', '-m', '{0} Billing'.format(today.strftime("%b %Y"))])
	args.append('git push origin master')

	for arg in args:
		error = runProc(arg)
		if error:
			print error
			if 'To gitlab.sdsc.edu:billing/billing.git' not in error and 'Everything up-to-date' not in error:
				subject = 'Cloud Billing Failed'
				msg = error
				msg += '\n\n'
				msg += arg
				sendMail(FROM, TO, subject, msg)
				break
			else:
				error = None

	if not error:
		try:
			pyfootprints.csvToFootprints.main('billing/reports/{0}.csv'.format(today_f))
			subject = 'Cloud Billing to Footprints Success!'
			msg = 'Cloud Billing was successfully pushed to Footprints\n\nThanks to,\ncloud-web-util'
		except:
			subject = 'Error running Cloud to FP scripts'
			msg = traceback.format_exc()
		#sendMail(FROM, ['*****@*****.**', '*****@*****.**'], subject, msg)
		sendMail(FROM, ['*****@*****.**'], subject, msg)
コード例 #8
0
        keyStone.users.delete(user=uid)
        sendMail(
            '*****@*****.**', [name] + WATCHERS,
            'SDSC Cloud User Account Deleted',
            'Dear SDSC Cloud User,\n\nYour user account, {0}, has been deleted because it does not belong to any active projects.\n\nPlease contact us by replying to this email if you need your account re-created.\n\nRegards,\nSDSC Cloud Support Team'
            .format(name))

    query('delete from orphan_accounts;', (), False)


if __name__ == "__main__":
    if sys.argv[1] == 'collect':
        try:
            orphan_names, orphan_ids = collectOrphans()
            if len(orphan_names) == 0:
                sendMail(
                    '*****@*****.**', WATCHERS,
                    'SDSC Cloud Orphan Accounts',
                    'There were no orphaned cloud accounts found in keyStone.')
            else:
                saveOrphans(orphan_names, orphan_ids)
        except:
            sendMail('*****@*****.**', '*****@*****.**',
                     'Orphan collection failed', str(traceback.format_exc()))
    elif sys.argv[1] == 'delete':
        try:
            notifyOrphans()
        except:
            sendMail('*****@*****.**', '*****@*****.**',
                     'Orphan destruction failed', str(traceback.format_exc()))