コード例 #1
0
ファイル: customers.py プロジェクト: jpmontez/hammer
class Communications(object):

    def __init__(self, config, master, culprits):
        self.username = config.credentials['username']
        self.password = config.credentials['password']
        self.template = config.template
        self.master = master
        self.culprits = culprits

        self.lefty = Lefty(self.username, self.password)

        self.forms = []
        self.tickets = []

    def send(self):
        self.forms = map(self.fill_out_form, self.culprits)
        self.tickets = map(self.create_ticket, self.culprits)

    def fill_out_form(self, culprit):
        LOG.info('Filling out ticket')
        culprit.form = yaml.load(Template(self.template).substitute(
            addresses=', '.join(culprit.instances),
            master=self.master
        ))
        return culprit.form

    def create_ticket(self, culprit):
        LOG.info('Creating ticket')

        def _find_match(category_name, sub_category_name):
            return (sub_category for category in self.lefty.get_categories()
                    if category_name in category['name']
                    for sub_category in category['sub_categories']
                    if sub_category_name in sub_category['name'])

        match = next(_find_match('Cloud Servers', 'General Support'))

        payload = {
            "subject": culprit.form["subject"],
            "description": culprit.form["description"],
            "group": "Cloud Servers / Core Services",
            "category_id": match["category_id"],
            "comment": {
                "is_public": False,
                "text": culprit.form["comment"]
            },
            "sub_category_id": match["sub_category_id"],
            "status": "Pending Customer",
        }

        return self.lefty.create_ticket(culprit.account, payload)
コード例 #2
0
ファイル: customers.py プロジェクト: jpmontez/hammer
    def __init__(self, config, master, culprits):
        self.username = config.credentials['username']
        self.password = config.credentials['password']
        self.template = config.template
        self.master = master
        self.culprits = culprits

        self.lefty = Lefty(self.username, self.password)

        self.forms = []
        self.tickets = []