Beispiel #1
0
def check_rt_multiple_projects(g):
    """route-target belonging to several tenants
    """
    asNumber = g.V().hasLabel('global_system_config').values(
        'autonomous_system').next()
    rtPattern = "target:%d:.*" % asNumber
    r = g.V().hasLabel("route_target") \
             .has('display_name') \
             .filter(lambda: "it.get().value('display_name').matches('%s')" % rtPattern) \
             .where(
                 __.in_().hasLabel("routing_instance").out().hasLabel("virtual_network").out().hasLabel("project").dedup().count().is_(gt(1))
             ) \
             .map(
                 union(
                     __.id(),
                     map(__.in_().hasLabel("routing_instance").out().hasLabel("virtual_network").out().hasLabel("project").dedup().map(
                         union(__.id(), __.values('fq_name')).fold()
                     ).fold())
                 ).fold()
             ).toList()
    if len(r) > 0:
        printo('Found %d %s:' %
               (len(r), check_rt_multiple_projects.__doc__.strip()))
    for dup in r:
        printo('  route-target/%s' % dup[0])
        for p in dup[1]:
            printo('    - project/%s - %s' % (p[0], ":".join(p[1])))
    return r
def check_duplicate_ip_addresses(g):
    """networks with duplicate ip addresses
    """
    r = g.V().hasLabel("virtual_network").as_('vn').flatMap(
        union(
            select('vn'),
            __.in_().hasLabel("instance_ip").has("instance_ip_address").group(
            ).by("instance_ip_address").unfold().filter(
                lambda: "it.get().value.size() > 1")).fold().filter(
                    lambda: "it.get().size() > 1")).toList()
    if len(r) > 0:
        printo('Found %d %s:' %
               (len(r), check_duplicate_ip_addresses.__doc__.strip()))
    for dup in r:
        # FIXME:
        dup[0].label = 'virtual_network'
        # First item is the vn
        r_ = v_to_r(dup[0])
        printo('  - %s/%s - %s' % (r_.type, r_.uuid, r_.fq_name))
        for ips in dup[1:]:
            for ip, iips in ips.items():
                printo("      %s:" % ip)
                for iip in iips:
                    r_ = v_to_r(iip)
                    printo('        - %s/%s - %s' %
                           (r_.type, r_.uuid, r_.fq_name))
    return r
 def wrapper(*args):
     t = fun(*args)
     # we should be able to fold() fq_name: https://issues.apache.org/jira/browse/TINKERPOP-1711
     r = t.map(union(label(), id(), values('fq_name')).fold()).toList()
     # convert gremlin result in [Resource]
     resources = []
     for r_ in r:
         res_type = r_[0].replace('_', '-')
         uuid = r_[1]["@value"]
         fq_name = r_[2]
         resources.append(Resource(res_type, uuid=uuid, fq_name=fq_name))
     return resources
Beispiel #4
0
 def wrapper(*args):
     t = fun(*args)
     r = t.map(
         union(label(), id(), coalesce(values('fq_name'),
                                       constant(''))).fold()).toList()
     # convert gremlin result in [Resource]
     resources = []
     for r_ in r:
         res_type = r_[0].replace('_', '-')
         uuid = text_type(r_[1])
         fq_name = r_[2]
         resources.append(Resource(res_type, uuid=uuid, fq_name=fq_name))
     return resources