def get_all_alerts(tree): """ Returns list of all alerts specified in tree. Format: [ { "id": <id of alert>, "path": <path to script>, "description": <alert description>, "instance_attributes": <list of nvpairs>, "meta_attributes": <list of nvpairs>, "recipients_list": <list of alert's recipients> } ] tree -- cib etree node """ alert_list = [] for alert in get_alerts(tree).findall("./alert"): alert_list.append({ "id": alert.get("id"), "path": alert.get("path"), "description": alert.get("description", ""), "instance_attributes": get_nvset(get_sub_element(alert, "instance_attributes")), "meta_attributes": get_nvset(get_sub_element(alert, "meta_attributes")), "recipient_list": get_all_recipients(alert) }) return alert_list
def get_all_recipients(alert): """ Returns list of all recipient of specified alert. Format: [ { "id": <id of recipient>, "value": <value of recipient>, "description": <recipient description>, "instance_attributes": <list of nvpairs>, "meta_attributes": <list of nvpairs> } ] alert -- parent element of recipients to return """ recipient_list = [] for recipient in alert.findall("./recipient"): recipient_list.append({ "id": recipient.get("id"), "value": recipient.get("value"), "description": recipient.get("description", ""), "instance_attributes": get_nvset(get_sub_element(recipient, "instance_attributes")), "meta_attributes": get_nvset(get_sub_element(recipient, "meta_attributes")) }) return recipient_list
def get_all_alerts(tree): """ Returns list of all alerts specified in tree. Format: [ { "id": <id of alert>, "path": <path to script>, "description": <alert description>, "instance_attributes": <list of nvpairs>, "meta_attributes": <list of nvpairs>, "recipients_list": <list of alert's recipients> } ] tree -- cib etree node """ alert_list = [] for alert in get_alerts(tree).findall("./alert"): alert_list.append({ "id": alert.get("id"), "path": alert.get("path"), "description": alert.get("description", ""), "instance_attributes": get_nvset( get_sub_element(alert, "instance_attributes") ), "meta_attributes": get_nvset( get_sub_element(alert, "meta_attributes") ), "recipient_list": get_all_recipients(alert) }) return alert_list
def get_all_recipients(alert): """ Returns list of all recipient of specified alert. Format: [ { "id": <id of recipient>, "value": <value of recipient>, "description": <recipient description>, "instance_attributes": <list of nvpairs>, "meta_attributes": <list of nvpairs> } ] alert -- parent element of recipients to return """ recipient_list = [] for recipient in alert.findall("./recipient"): recipient_list.append({ "id": recipient.get("id"), "value": recipient.get("value"), "description": recipient.get("description", ""), "instance_attributes": get_nvset( get_sub_element(recipient, "instance_attributes") ), "meta_attributes": get_nvset( get_sub_element(recipient, "meta_attributes") ) }) return recipient_list
def test_success(self): nvset = etree.XML(""" <nvset> <nvpair id="nvset-name1" name="name1" value="value1"/> <nvpair id="nvset-name2" name="name2" value="value2"/> <nvpair id="nvset-name3" name="name3"/> </nvset> """) self.assertEqual( [ { "id": "nvset-name1", "name": "name1", "value": "value1" }, { "id": "nvset-name2", "name": "name2", "value": "value2" }, { "id": "nvset-name3", "name": "name3", "value": "" }, ], nvpair.get_nvset(nvset), )
def test_success(self): nvset = etree.XML( """ <nvset> <nvpair id="nvset-name1" name="name1" value="value1"/> <nvpair id="nvset-name2" name="name2" value="value2"/> <nvpair id="nvset-name3" name="name3"/> </nvset> """ ) self.assertEqual( [ { "id": "nvset-name1", "name": "name1", "value": "value1" }, { "id": "nvset-name2", "name": "name2", "value": "value2" }, { "id": "nvset-name3", "name": "name3", "value": "" } ], nvpair.get_nvset(nvset) )