Beispiel #1
0
 def get_project_networks(self, admin_context):
     try:
         nets = db.network_get_all(admin_context.elevated())
     except exception.NoNetworksFound:
         return []
     # only return networks with a project_id set
     return [net for net in nets if net['project_id']]
 def get_project_networks(self, admin_context):
     try:
         nets = db.network_get_all(admin_context.elevated())
     except exception.NoNetworksFound:
         return []
     # only return networks with a project_id set
     return [net for net in nets if net['project_id']]
Beispiel #3
0
 def _delete_nets(self):
     for n in networks:
         ctx = context.RequestContext('user1', n['project_id'])
         db_nets = db.network_get_all(ctx.elevated())
         for x in db_nets:
             if x['label'] == n['label']:
                 n['uuid'] = x['uuid']
         self.net_man.delete_network(ctx, None, n['uuid'])
Beispiel #4
0
 def index(self, req):
     tenant_id = urlparse.parse_qs(req.environ["QUERY_STRING"]).get("tenant_id", [None])[0]
     context = req.environ["engine.context"]
     LOG.audit(_("Getting networks for project %s"), tenant_id or "<all>")
     if context.is_admin and not tenant_id:
         networks = db.network_get_all(context)
     elif tenant_id:
         networks = db.project_get_networks(context, tenant_id, associate=False)
     else:
         raise exc.HTTPNotFound()
     result = [network_dict(net_ref) for net_ref in networks]
     return {"networks": result}
Beispiel #5
0
 def index(self, req):
     tenant_id = urlparse.parse_qs(req.environ['QUERY_STRING']).get(
         'tenant_id', [None])[0]
     context = req.environ['engine.context']
     LOG.audit(_("Getting networks for project %s"), tenant_id or '<all>')
     if context.is_admin and not tenant_id:
         networks = db.network_get_all(context)
     elif tenant_id:
         networks = db.project_get_networks(context,
                                            tenant_id,
                                            associate=False)
     else:
         raise exc.HTTPNotFound()
     result = [network_dict(net_ref) for net_ref in networks]
     return {'networks': result}
Beispiel #6
0
def setup():
    import os
    import shutil

    from engine import context
    from engine import flags
    from engine import db
    from engine.db import migration
    from engine.network import manager as network_manager
    from engine.tests import fake_flags

    FLAGS = flags.FLAGS

    testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db)
    if os.path.exists(testdb):
        return
    migration.db_sync()
    ctxt = context.get_admin_context()
    network = network_manager.VlanManager()
    bridge_interface = FLAGS.flat_interface or FLAGS.vlan_interface
    network.create_networks(
        ctxt,
        label="test",
        cidr=FLAGS.fixed_range,
        multi_host=FLAGS.multi_host,
        num_networks=FLAGS.num_networks,
        network_size=FLAGS.network_size,
        cidr_v6=FLAGS.fixed_range_v6,
        gateway=FLAGS.gateway,
        gateway_v6=FLAGS.gateway_v6,
        bridge=FLAGS.flat_network_bridge,
        bridge_interface=bridge_interface,
        vpn_start=FLAGS.vpn_start,
        vlan_start=FLAGS.vlan_start,
        dns1=FLAGS.flat_network_dns,
    )
    for net in db.network_get_all(ctxt):
        network.set_network_host(ctxt, net)

    cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
    shutil.copyfile(testdb, cleandb)
Beispiel #7
0
def setup():
    import os
    import shutil

    from engine import context
    from engine import flags
    from engine import db
    from engine.db import migration
    from engine.network import manager as network_manager
    from engine.tests import fake_flags

    FLAGS = flags.FLAGS

    testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db)
    if os.path.exists(testdb):
        return
    migration.db_sync()
    ctxt = context.get_admin_context()
    network = network_manager.VlanManager()
    bridge_interface = FLAGS.flat_interface or FLAGS.vlan_interface
    network.create_networks(ctxt,
                            label='test',
                            cidr=FLAGS.fixed_range,
                            multi_host=FLAGS.multi_host,
                            num_networks=FLAGS.num_networks,
                            network_size=FLAGS.network_size,
                            cidr_v6=FLAGS.fixed_range_v6,
                            gateway=FLAGS.gateway,
                            gateway_v6=FLAGS.gateway_v6,
                            bridge=FLAGS.flat_network_bridge,
                            bridge_interface=bridge_interface,
                            vpn_start=FLAGS.vpn_start,
                            vlan_start=FLAGS.vlan_start,
                            dns1=FLAGS.flat_network_dns)
    for net in db.network_get_all(ctxt):
        network.set_network_host(ctxt, net)

    cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
    shutil.copyfile(testdb, cleandb)
Beispiel #8
0
    def setUp(self):
        super(QuantumEngineTestCase, self).setUp()

        self.net_man = quantum_manager.QuantumManager(
                ipam_lib="engine.network.quantum.engine_ipam_lib",
                q_conn=FakeQuantumClientConnection())

        # Tests seem to create some networks by default, which
        # we don't want.  So we delete them.

        ctx = context.RequestContext('user1', 'fake_project1').elevated()
        for n in db.network_get_all(ctx):
            db.network_delete_safe(ctx, n['id'])

        # Other unit tests (e.g., test_compute.py) have a nasty
        # habit of of creating fixed IPs and not cleaning up, which
        # can confuse these tests, so we remove all existing fixed
        # ips before starting.
        session = get_session()
        result = session.query(models.FixedIp).all()
        with session.begin():
            for fip_ref in result:
                session.delete(fip_ref)