예제 #1
0
def search_duplicate():
    """ Search for duplicate IP address elements.
    It is also possible to filter the search by name, comment, or IP address
     
    :return: list of dict items holding href,type and name
    """
    return element_by_href_as_json(fetch_entry_point('search_duplicate'))
예제 #2
0
 def __get__(self, instance, cls=None):
     # Does the instance already have meta data
     if instance is not None and instance._meta:
         return instance._meta.href
     else:
         if hasattr(cls, 'typeof'):
             if instance is not None:
                 element = fetch_href_by_name(
                     instance.name, filter_context=instance.typeof)
                 if element.json:
                     instance._meta = Meta(**element.json[0])
                     return instance._meta.href
                 raise ElementNotFound(
                     'Cannot find specified element: {}, type: {}'.format(
                         unicode_to_bytes(instance.name), instance.typeof))
             else:
                 try:
                     element = fetch_entry_point(cls.typeof)
                 except UnsupportedEntryPoint as e:
                     raise ElementNotFound(e)
                 return element
         else:
             raise ElementNotFound(
                 'This class does not have the required attribute '
                 'and cannot be referenced directly, type: {}'.format(
                     instance))
예제 #3
0
def element_references_as_smcresult(element_href):
    """
    Return references for an element given the element href. The
    return is the full SMCResult object.
    
    :param str element_href: element reference
    :return: :py:class:`smc.api.web.SMCResult`
    """
    href = fetch_entry_point('references_by_element')
    return fetch_json_by_post(href=href, json={'value': element_href})
예제 #4
0
    def vss_contexts(self):
        """
        Return all virtual contexts for this VSS Container.

        :return list VSSContext
        """
        result = self.make_request(
            href=fetch_entry_point('visible_virtual_engine_mapping'),
            params={'filter': self.name})
        if result.get('mapping', []):
            return [Element.from_href(ve)
                for ve in result['mapping'][0].get('virtual_engine', [])]
        return []
예제 #5
0
def element_references(element_href):
    """
    Return references for an element given the element href. The result is
    filtered based on the SMCResult. If error, empty list is returned

    :param str element_href: element reference
    :return: list list of references where element is used
    """
    href = fetch_entry_point('references_by_element')
    result = fetch_json_by_post(href=href, json={'value': element_href})
    if result.json:
        return result.json
    return []
예제 #6
0
    def referenced_by(self):
        """
        Show all references for this element. A reference means that this
        element is being used, for example, in a policy rule, as a member of
        a group, etc.

        :return: list referenced elements
        :rtype: list(Element)
        """
        href = fetch_entry_point('references_by_element')
        return [
            Element.from_meta(**ref) for ref in self.make_request(
                method='create', href=href, json={'value': self.href})
        ]
예제 #7
0
파일: search.py 프로젝트: artlog/smc-python
def element_entry_point(name):
    """ Get specified element from cache based on the entry point verb from SMC api
    To get the entry points available, you can call web_api.get_all_entry_points()
    For example::
    
        element_entry_point('log_server')
    
    :param name: top level entry point name
    :return: href: else None
    """
    if name:   
        element = fetch_entry_point(name)
        if element:
            return element
예제 #8
0
def element_entry_point(name):
    """ Get specified element from cache based on the entry point verb from SMC api
    To get the entry points available, you can call web_api.get_all_entry_points()
    For example::
    
        element_entry_point('log_server')
    
    :param name: top level entry point name
    :return: href: else None
    """
    if name:
        try:
            return fetch_entry_point(name)
        except UnsupportedEntryPoint:
            pass
예제 #9
0
    def vss_contexts(self):
        """
        Return all virtual contexts for this VSS Container.

        :return list VSSContext
        """
        result = self.make_request(
            href=fetch_entry_point("visible_virtual_engine_mapping"),
            params={"filter": self.name})

        if "mapping" in result:
            return [
                Element.from_href(ve)
                for ve in result["mapping"][0].get("virtual_engine", [])
            ]
        return []  # pre-6.5
예제 #10
0
def ElementCreator(cls, json):
    """
    Helper method for create classmethods. Returns the href if
    creation is successful. This is a lazy load that will provide
    only the meta for the element. Additional attribute access
    will load the full data.

    :return: instance of type Element with meta
    :rtype: Element
    """
    result = SMCRequest(href=fetch_entry_point(cls.typeof), json=json).create()

    if result.msg:
        raise CreateElementFailed(result.msg)

    return cls(json.get('name'), type=cls.typeof, href=result.href)
예제 #11
0
def search_unused():
    """ Search for all unused elements 
    :return: list of dict items holding href,type and name
    """
    return element_by_href_as_json(fetch_entry_point('search_unused'))
예제 #12
0
 def __init__(self):
     entry = fetch_entry_point('system')
     super(System, self).__init__(href=entry)
예제 #13
0
 def test_fetch_entry_point_failure(self):
     self.assertRaises(UnsupportedEntryPoint,
                       lambda: fetch_entry_point('tedgsgshf'))
예제 #14
0
 def __init__(self):
     entry = fetch_entry_point('system')
     super(System, self).__init__(href=entry)
예제 #15
0
파일: search.py 프로젝트: artlog/smc-python
def search_duplicate():
    """ Search all duplicate elements 
    :return: list of dict items holding href,type and name
    """
    return element_by_href_as_json(fetch_entry_point('search_duplicate'))
예제 #16
0
파일: search.py 프로젝트: artlog/smc-python
def search_unused():
    """ Search for all unused elements 
    :return: list of dict items holding href,type and name
    """
    return element_by_href_as_json(fetch_entry_point('search_unused'))