Esempio n. 1
0
def clear_virtual_topology_for_tenants(tenant_name_prefix):
    """
    Delete the virtual topology for tenants whose name starts
    with tenant_name_prefix

    Args:
        tenant_name_prefix: the prefix of the tenant name
    """

    api = get_midonet_api()
    tenants = filter(lambda x: x.name.startswith(tenant_name_prefix),
                     list_tenants())

    for tenant in tenants:
        # delete routers
        for router in api.get_routers({'tenant_id': tenant.id}):
            # unlink and delete all router ports
            for port in router.get_ports():
                if port.get_type() == 'InteriorRouter':
                    if port.get_peer_id():
                        port.unlink()
                port.delete()
            # delete router
            router.delete()

        # delete bridges
        for bridge in api.get_bridges({'tenant_id': tenant.id}):
            # unlink and delete all bridge ports
            for port in bridge.get_ports():
                if port.get_type() == 'InteriorBridge':
                    if port.get_peer_id():
                        port.unlink()
                port.delete()
            # delete router
            bridge.delete()

        # delete chains
        for chain in api.get_chains({'tenant_id': tenant.id}):
            for rule in chain.get_rules():
                rule.delete()
            chain.delete()
Esempio n. 2
0
def clear_virtual_topology_for_tenants(tenant_name_prefix):
    """
    Delete the virtual topology for tenants whose name starts
    with tenant_name_prefix

    Args:
        tenant_name_prefix: the prefix of the tenant name
    """

    api = get_midonet_api()
    tenants = filter(lambda x: x.name.startswith(tenant_name_prefix),
                     list_tenants())

    for tenant in tenants:
        # delete routers
        for router in api.get_routers({'tenant_id': tenant.id}):
            # unlink and delete all router ports
            for port in router.get_ports():
                if port.get_type() == 'InteriorRouter':
                    if port.get_peer_id():
                        port.unlink()
                port.delete()
            # delete router
            router.delete()

        # delete bridges
        for bridge in api.get_bridges({'tenant_id': tenant.id}):
            # unlink and delete all bridge ports
            for port in bridge.get_ports():
                if port.get_type() == 'InteriorBridge':
                    if port.get_peer_id():
                        port.unlink()
                port.delete()
            # delete router
            bridge.delete()

        # delete chains
        for chain in api.get_chains({'tenant_id': tenant.id}):
            for rule in chain.get_rules():
                rule.delete()
            chain.delete()