def element_by_href_as_smcresult(href): """ Get specified element returned as an SMCElement object :param href: href direct link to object :return: SMCElement with etag, href and element field holding json, else None """ if href: element = fetch_json_by_href(href) if element: return element
def element_by_href_as_json(href): """ Get specified element by href :param href: link to object :return: json data representing element, else None """ if href: element = fetch_json_by_href(href) if element: return element.json
def element_by_href_as_smcresult(href, params=None): """ Get specified element returned as an SMCResult object :param href: href direct link to object :return: :py:class:`smc.api.web.SMCResult` with etag, href and element field holding json, else None """ if href: element = fetch_json_by_href(href, params=params) if element: return element
def element_by_href_as_json(href, params=None): """ Get specified element by href :param href: link to object :param params: optional search query parameters :return: json data representing element, else None """ if href: element = fetch_json_by_href(href, params=params) if element: return element.json
def element_name_by_href(href): """ The element href is known, possibly from a reference in an elements json. You want to retrieve the name of this element. :param str href: href of element :return: str name of element, or None """ if href: element = fetch_json_by_href(href) if element.json: return element.json.get('name')
def element_attribute_by_href(href, attr_name): """ The element href is known and you want to retrieve a specific attribute from that element. For example, if you want a specific attribute by it's name:: search.element_attribute_by_href(href_to_resource, 'name') :param str href: href of element :param str attr_name: name of attribute :return: str value of attribute """ if href: element = fetch_json_by_href(href) if element.json: return element.json.get(attr_name)
def element_name_and_type_by_href(href): """ Retrieve the element name and type of element based on the href. You may have a href that is within another element reference and want more information on that reference. :param str href: href of element :return: tuple (name, type) """ if href: element = fetch_json_by_href(href) if element.json: for entries in element.json.get('link'): if entries.get('rel') == 'self': typeof = entries.get('type') return (element.json.get('name'), typeof)
def generic_list_builder(typeof, name=None, exact_match=True, klazz=None): """ Build the query to SMC based on parameters :param list name: Name of host object (optional) :param exact_match: Do exact match against name field (default True) :return: list :py:class:`smc.elements.collections.Element` """ if not klazz: klazz = SMCElement result=[] if not name: lst = fetch_json_by_href( session.cache.get_entry_href(typeof)).json if lst: for item in lst: result.append(klazz(**item)) else: #Filter provided for element in name: for item in fetch_href_by_name(element, filter_context=typeof, exact_match=exact_match).json: result.append(klazz(**item)) return result