示例#1
0
 def _personalize(self, template, **kwargs):
     """Populate the given email template with customized values
      
     Assumes that the template placeholders are uppercased argument
     keywords enclosed by `<>`.
     """
     template = get_absolute_path(template)
     with open(template, "r") as f:
         msg = f.read()
     for key in kwargs:
         if kwargs[key] is not None:
             placeholder = "<{}>".format(key.upper())
             msg = string.replace(msg, placeholder, kwargs[key])
     return msg
示例#2
0
def build_request_details(request_list, template):
    """Build the list of request details to be sent in the reminder message"""
    template = get_absolute_path(template)
    all_details = ""
    with open(template, "r") as f:
        detail_base = f.read()
    f.close()
    for request in request_list:
        item_details = detail_base
        for key in request:
            placeholder = "<{}>".format(key.upper())
            item_details = string.replace(item_details, placeholder,
                                          request[key])
        all_details += "\n-----\n{}".format(item_details)

    return all_details
示例#3
0
    def dump_to_file(self, target_path='/tmp', label=None):
        """ Print email body to a file.
        
        Back up the personalized email message if the email cannot be sent.
        The output file is placed in the directory specified by target_path
        and labeled with the first portion of the email address and either
        the optional 'label' or the email subject.
        """
        if not label:
            label = self.subject
        email_parts = self.receiver.split('@')
        out_file = "{0}_{1}.txt".format(email_parts[0], label)

        file_path = get_absolute_path(os.path.join(target_path, out_file))

        with open(file_path, 'w') as f:
            f.write(self.body)
        f.close()
        return file_path
示例#4
0
    args = parser.parse_args()
   
    if args.config is not None:
        CONFIG_FILE = set_config_file(args.config)
    else:
        CONFIG_FILE = set_config_file()

    # configuration
    config = ConfigParser.ConfigParser()
    config.read(CONFIG_FILE)
    admin_user = config.get('auth', 'admin_user')
    admin_pwd = config.get('auth', 'admin_pwd')
    admin_project = config.get('auth', 'admin_project')
    auth_url = config.get('auth', 'auth_url')
    nova_version = config.get('nova', 'version')
    quota_auth_file = get_absolute_path(config.get('quota_sheet', 'auth_file'))
    quota_worksheet_key = config.get('quota_sheet', 'worksheet_key')
    quota_template = config.get('quota_email', 'template')

    # openstack auth
    auth = v3.Password(auth_url=auth_url,
                       username=admin_user,
                       user_domain_id='default',
                       project_name=admin_project,
                       project_domain_id='default',
                       password=admin_pwd)
    session = session.Session(auth=auth)
    keystone = client.Client(session=session)
    all_ks_projects = keystone.projects.list()
    quota_manager = QuotaManager(session=session, nova_version=nova_version)
    
示例#5
0
    auth_url = config.get('auth', 'auth_url')
    nova_version = config.get('nova', 'version')

    setpass_url = config.get('setpass', 'setpass_url')
    auth = v3.Password(auth_url=auth_url,
                       username=admin_user,
                       user_domain_id='default',
                       password=admin_pwd,
                       project_domain_id='default',
                       project_name=admin_project)
    session = session.Session(auth=auth)

    openstack = Openstack(session=session,
                          nova_version=nova_version,
                          setpass_url=setpass_url)
    auth_file = get_absolute_path(config.get("excelsheet", "auth_file"))
    worksheet_key = config.get("excelsheet", "worksheet_key")
    quotas = dict(config.items('quotas'))
    email_defaults = dict(config.items('email_defaults'))

    sheet = spreadsheet.Spreadsheet(auth_file, worksheet_key)
    rows = sheet.get_all_rows("Form Responses 1")

    content, bad_rows = parse_rows(rows, select_user=args.user)

    copy_index = []
    subscribe_emails = []

    # Get these once at the beginning and update them as we add users and
    # projects with the script
    ks_users = openstack.keystone.users.list()
if __name__ == '__main__':

    parser = argparse.ArgumentParser(
        description="Notify helpdesk of new approved requests")
    parser.add_argument('-c',
                        '--config',
                        metavar="<config_file>",
                        help='Specify configuration file.')
    parser.add_argument('-l',
                        '--log',
                        metavar='<log_file>',
                        help='Turn on logging and log to the specified file.')
    args = parser.parse_args()

    CONFIG_FILE = set_config_file(args.config)
    config = ConfigParser.ConfigParser()
    config.read(CONFIG_FILE)
    # FIXME right now it fails if full path to file is not specified
    # for auth_file, quota_auth_file, or helpdesk_template
    auth_file = get_absolute_path(config.get('excelsheet', 'auth_file'))
    worksheet_key = config.get('excelsheet', 'worksheet_key')
    helpdesk_email = config.get('helpdesk', 'email')
    helpdesk_template = get_absolute_path(config.get('helpdesk', 'template'))
    reminder_email = config.get('reminder', 'email')
    reminder_template = get_absolute_path(config.get('reminder', 'template'))
    quota_auth_file = get_absolute_path(config.get('quota_sheet', 'auth_file'))
    quota_worksheet_key = config.get('quota_sheet', 'worksheet_key')

    check_requests('access', auth_file, worksheet_key)
    check_requests('quota', quota_auth_file, quota_worksheet_key)