Esempio n. 1
0
    def create_subnet(self,
                      context,
                      label,
                      tenant_id,
                      quantum_net_id,
                      priority,
                      cidr=None,
                      gateway=None,
                      gateway_v6=None,
                      cidr_v6=None,
                      dns1=None,
                      dns2=None):
        """Re-use the basic FlatManager create_networks method to
           initialize the networks and fixed_ips tables in Nova DB.

           Also stores a few more fields in the networks table that
           are needed by Quantum but not the FlatManager.
        """
        admin_context = context.elevated()
        subnet_size = len(netaddr.IPNetwork(cidr))
        networks = manager.FlatManager.create_networks(
            self.net_manager, admin_context, label, cidr, False, 1,
            subnet_size, cidr_v6, gateway, gateway_v6, quantum_net_id, None,
            dns1, dns2)

        if len(networks) != 1:
            raise Exception(_("Error creating network entry"))

        network = networks[0]
        net = {
            "project_id": tenant_id,
            "priority": priority,
            "uuid": quantum_net_id
        }
        db.network_update(admin_context, network['id'], net)
Esempio n. 2
0
    def create_subnet(self, context, label, tenant_id,
                      quantum_net_id, priority, cidr=None,
                      gateway=None, gateway_v6=None, cidr_v6=None,
                      dns1=None, dns2=None):
        """Re-use the basic FlatManager create_networks method to
           initialize the networks and fixed_ips tables in Nova DB.

           Also stores a few more fields in the networks table that
           are needed by Quantum but not the FlatManager.
        """
        admin_context = context.elevated()
        subnet_size = len(netaddr.IPNetwork(cidr))
        networks = manager.FlatManager.create_networks(self.net_manager,
                    admin_context, label, cidr,
                    False, 1, subnet_size, cidr_v6, gateway,
                    gateway_v6, quantum_net_id, None, dns1, dns2,
                    ipam=True)
        #TODO(tr3buchet): refactor passing in the ipam key so that
        # it's no longer required. The reason it exists now is because
        # nova insists on carving up IP blocks. What ends up happening is
        # we create a v4 and an identically sized v6 block. The reason
        # the quantum tests passed previosly is nothing prevented an
        # incorrect v6 address from being assigned to the wrong subnet

        if len(networks) != 1:
            raise Exception(_("Error creating network entry"))

        network = networks[0]
        net = {"project_id": tenant_id,
               "priority": priority,
               "uuid": quantum_net_id}
        db.network_update(admin_context, network['id'], net)
Esempio n. 3
0
    def test_instance_dns(self):
        fixedip = '192.168.0.101'
        self.mox.StubOutWithMock(db, 'network_get')
        self.mox.StubOutWithMock(db, 'network_update')
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(
            db, 'virtual_interface_get_by_instance_and_network')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')

        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(
            mox.IgnoreArg(), mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn({'id': 0})

        db.instance_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
            {'security_groups': [{
                'id': 0
            }]})

        db.instance_get(self.context, 1).AndReturn({'display_name': HOST})
        db.fixed_ip_associate_pool(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(fixedip)
        db.network_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(networks[0])
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
                                              networks[0]['id'])
        addresses = self.network.instance_dns_manager.get_entries_by_name(HOST)
        self.assertEqual(len(addresses), 1)
        self.assertEqual(addresses[0], fixedip)
Esempio n. 4
0
    def _on_set_network_host(self, context, network_id):
        """Called when this host becomes the host for a network."""
        network = self.db.network_get(context, network_id)
        if not network['vpn_public_address']:
            net = {}
            address = FLAGS.vpn_ip
            net['vpn_public_address'] = address
            db.network_update(context, network_id, net)
        else:
            address = network['vpn_public_address']
        self.driver.ensure_vlan_bridge(network['vlan'],
                                       network['bridge'],
                                       network['bridge_interface'],
                                       network)

        # NOTE(vish): only ensure this forward if the address hasn't been set
        #             manually.
        if address == FLAGS.vpn_ip and hasattr(self.driver,
                                               "ensure_vlan_forward"):
            self.driver.ensure_vlan_forward(FLAGS.vpn_ip,
                                            network['vpn_public_port'],
                                            network['vpn_private_address'])
        if not FLAGS.fake_network:
            self.driver.update_dhcp(context, network_id)
            if(FLAGS.use_ipv6):
                self.driver.update_ra(context, network_id)
Esempio n. 5
0
    def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
        self.mox.StubOutWithMock(db, 'network_get')
        self.mox.StubOutWithMock(db, 'network_update')
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(
            db, 'virtual_interface_get_by_instance_and_network')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')

        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(
            mox.IgnoreArg(), mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn({'id': 0})

        db.instance_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
            {'security_groups': [{
                'id': 0
            }]})
        db.instance_get(self.context, 1).AndReturn({'display_name': HOST})
        db.fixed_ip_associate_pool(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn('192.168.0.101')
        db.network_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(networks[0])
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
                                              networks[0]['id'])
Esempio n. 6
0
    def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
        self.mox.StubOutWithMock(db, 'network_get')
        self.mox.StubOutWithMock(db, 'network_update')
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(db,
                              'virtual_interface_get_by_instance_and_network')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')

        db.fixed_ip_update(mox.IgnoreArg(),
                           mox.IgnoreArg(),
                           mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
                mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})

        db.instance_get(mox.IgnoreArg(),
                        mox.IgnoreArg()).AndReturn({'security_groups':
                                                             [{'id': 0}]})
        db.fixed_ip_associate_pool(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn('192.168.0.101')
        db.network_get(mox.IgnoreArg(),
                       mox.IgnoreArg()).AndReturn(networks[0])
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
                                              networks[0]['id'])
Esempio n. 7
0
    def update(self, req, id, body):
        """Configure cloudpipe parameters for the project."""

        context = req.environ['nova.context']
        authorize(context)

        if id != "configure-project":
            msg = _("Unknown action %s") % id
            raise webob.exc.HTTPBadRequest(explanation=msg)

        project_id = context.project_id

        try:
            params = body['configure_project']
            vpn_ip = params['vpn_ip']
            vpn_port = params['vpn_port']
        except (TypeError, KeyError):
            raise webob.exc.HTTPUnprocessableEntity()

        networks = db.project_get_networks(context, project_id)
        for network in networks:
            db.network_update(context, network['id'], {
                'vpn_public_address': vpn_ip,
                'vpn_public_port': int(vpn_port)
            })
        return webob.exc.HTTPAccepted()
Esempio n. 8
0
    def create_subnet(self, context, label, tenant_id,
                      quantum_net_id, priority, cidr=None,
                      gateway=None, gateway_v6=None, cidr_v6=None,
                      dns1=None, dns2=None):
        """Re-use the basic FlatManager create_networks method to
           initialize the networks and fixed_ips tables in Nova DB.

           Also stores a few more fields in the networks table that
           are needed by Quantum but not the FlatManager.
        """
        admin_context = context.elevated()
        subnet_size = len(netaddr.IPNetwork(cidr))
        networks = manager.FlatManager.create_networks(self.net_manager,
                    admin_context, label, cidr,
                    False, 1, subnet_size, cidr_v6, gateway,
                    gateway_v6, quantum_net_id, None, dns1, dns2)

        if len(networks) != 1:
            raise Exception(_("Error creating network entry"))

        network = networks[0]
        net = {"project_id": tenant_id,
               "priority": priority,
               "uuid": quantum_net_id}
        db.network_update(admin_context, network['id'], net)
Esempio n. 9
0
    def test_instance_dns(self):
        fixedip = '192.168.0.101'
        self.mox.StubOutWithMock(db, 'network_get')
        self.mox.StubOutWithMock(db, 'network_update')
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(db,
                              'virtual_interface_get_by_instance_and_network')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')

        db.fixed_ip_update(mox.IgnoreArg(),
                           mox.IgnoreArg(),
                           mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
                mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})

        db.instance_get(mox.IgnoreArg(),
                        mox.IgnoreArg()).AndReturn({'security_groups':
                                                             [{'id': 0}]})

        db.instance_get(self.context,
                        1).AndReturn({'display_name': HOST})
        db.fixed_ip_associate_pool(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(fixedip)
        db.network_get(mox.IgnoreArg(),
                       mox.IgnoreArg()).AndReturn(networks[0])
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
                                              networks[0]['id'])
        addresses = self.network.instance_dns_manager.get_entries_by_name(HOST)
        self.assertEqual(len(addresses), 1)
        self.assertEqual(addresses[0], fixedip)
Esempio n. 10
0
    def create_subnet(self, context, label, tenant_id,
                      quantum_net_id, priority, cidr=None,
                      gateway=None, gateway_v6=None, cidr_v6=None,
                      dns1=None, dns2=None):
        """Re-use the basic FlatManager create_networks method to
           initialize the networks and fixed_ips tables in Nova DB.

           Also stores a few more fields in the networks table that
           are needed by Quantum but not the FlatManager.
        """
        admin_context = context.elevated()
        subnet_size = len(netaddr.IPNetwork(cidr))
        networks = manager.FlatManager._do_create_networks(self.net_manager,
                    admin_context, label, cidr,
                    False, 1, subnet_size, cidr_v6, gateway,
                    gateway_v6, quantum_net_id, None, dns1, dns2,
                    ipam=True)
        #TODO(tr3buchet): refactor passing in the ipam key so that
        # it's no longer required. The reason it exists now is because
        # nova insists on carving up IP blocks. What ends up happening is
        # we create a v4 and an identically sized v6 block. The reason
        # the quantum tests passed previosly is nothing prevented an
        # incorrect v6 address from being assigned to the wrong subnet

        if len(networks) != 1:
            raise Exception(_("Error creating network entry"))

        network = networks[0]
        net = {"project_id": tenant_id,
               "priority": priority,
               "uuid": quantum_net_id}
        db.network_update(admin_context, network['id'], net)
    def update(self, req, id, body):
        """Configure cloudpipe parameters for the project."""

        context = req.environ['nova.context']
        authorize(context)

        if id != "configure-project":
            msg = _("Unknown action %s") % id
            raise webob.exc.HTTPBadRequest(explanation=msg)

        project_id = context.project_id

        try:
            params = body['configure_project']
            vpn_ip = params['vpn_ip']
            vpn_port = params['vpn_port']
        except (TypeError, KeyError):
            raise webob.exc.HTTPUnprocessableEntity()

        networks = db.project_get_networks(context, project_id)
        for network in networks:
            db.network_update(context, network['id'],
                              {'vpn_public_address': vpn_ip,
                               'vpn_public_port': int(vpn_port)})
        return webob.exc.HTTPAccepted()
Esempio n. 12
0
 def _update_network_host(self, context, net_uuid):
     """Set the host column in the networks table: note that this won't
        work with multi-host but QuantumManager doesn't support that
        anyways.  The floating IPs mixin required network['host'] to be
        set."""
     entry = db.network_get_by_uuid(context.elevated(), net_uuid)
     entry['host'] = self.host
     db.network_update(context.elevated(), entry['id'], entry)
Esempio n. 13
0
 def _update_network_host(self, context, net_uuid):
     """Set the host column in the networks table: note that this won't
        work with multi-host but QuantumManager doesn't support that
        anyways.  The floating IPs mixin required network['host'] to be
        set."""
     entry = db.network_get_by_uuid(context.elevated(), net_uuid)
     entry['host'] = self.host
     db.network_update(context.elevated(), entry['id'], entry)
Esempio n. 14
0
    def test_set_network_hosts(self):
        self.mox.StubOutWithMock(db, "network_get_all")
        self.mox.StubOutWithMock(db, "network_set_host")
        self.mox.StubOutWithMock(db, "network_update")

        db.network_get_all(mox.IgnoreArg()).AndReturn([networks[0]])
        db.network_set_host(mox.IgnoreArg(), networks[0]["id"], mox.IgnoreArg()).AndReturn(HOST)
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()

        self.network.set_network_hosts(None)
Esempio n. 15
0
    def change(self, project_id, ip, port):
        """Change the ip and port for a vpn.

        this will update all networks associated with a project
        not sure if that's the desired behavior or not, patches accepted

        """
        # TODO(tr3buchet): perhaps this shouldn't update all networks
        # associated with a project in the future
        admin_context = context.get_admin_context()
        networks = db.project_get_networks(admin_context, project_id)
        for network in networks:
            db.network_update(admin_context, network["id"], {"vpn_public_address": ip, "vpn_public_port": int(port)})
Esempio n. 16
0
    def _setup_network(self, context, network_ref):
        """Sets up network on this host."""
        if not network_ref["vpn_public_address"]:
            net = {}
            address = FLAGS.vpn_ip
            net["vpn_public_address"] = address
            network_ref = db.network_update(context, network_ref["id"], net)
        else:
            address = network_ref["vpn_public_address"]
        network_ref["dhcp_server"] = self._get_dhcp_ip(context, network_ref)

        mac_address = self.generate_mac_address()
        dev = self.driver.plug(network_ref, mac_address)
        self.driver.initialize_gateway_device(dev, network_ref)

        # NOTE(vish): only ensure this forward if the address hasn't been set
        #             manually.
        if address == FLAGS.vpn_ip and hasattr(self.driver, "ensure_vpn_forward"):
            self.driver.ensure_vpn_forward(
                FLAGS.vpn_ip, network_ref["vpn_public_port"], network_ref["vpn_private_address"]
            )
        if not FLAGS.fake_network:
            self.driver.update_dhcp(context, dev, network_ref)
            if FLAGS.use_ipv6:
                self.driver.update_ra(context, dev, network_ref)
                gateway = utils.get_my_linklocal(dev)
                self.db.network_update(context, network_ref["id"], {"gateway_v6": gateway})
Esempio n. 17
0
    def change(self, project_id, ip, port):
        """Change the ip and port for a vpn.

        this will update all networks associated with a project
        not sure if that's the desired behavior or not, patches accepted

        """
        # TODO(tr3buchet): perhaps this shouldn't update all networks
        # associated with a project in the future
        admin_context = context.get_admin_context()
        networks = db.project_get_networks(admin_context, project_id)
        for network in networks:
            db.network_update(admin_context,
                              network['id'],
                              {'vpn_public_address': ip,
                               'vpn_public_port': int(port)})
Esempio n. 18
0
    def _setup_network(self, context, network_ref):
        """Sets up network on this host."""
        if not network_ref['vpn_public_address']:
            net = {}
            address = FLAGS.vpn_ip
            net['vpn_public_address'] = address
            network_ref = db.network_update(context, network_ref['id'], net)
        else:
            address = network_ref['vpn_public_address']
        network_ref['dhcp_server'] = self._get_dhcp_ip(context, network_ref)
        self.driver.ensure_vlan_bridge(network_ref['vlan'],
                                       network_ref['bridge'],
                                       network_ref['bridge_interface'],
                                       network_ref)

        # NOTE(vish): only ensure this forward if the address hasn't been set
        #             manually.
        if address == FLAGS.vpn_ip and hasattr(self.driver,
                                               "ensure_vlan_forward"):
            self.driver.ensure_vlan_forward(FLAGS.vpn_ip,
                                            network_ref['vpn_public_port'],
                                            network_ref['vpn_private_address'])
        if not FLAGS.fake_network:
            self.driver.update_dhcp(context, network_ref)
            if(FLAGS.use_ipv6):
                self.driver.update_ra(context, network_ref)
                gateway = utils.get_my_linklocal(network_ref['bridge'])
                self.db.network_update(context, network_ref['id'],
                                       {'gateway_v6': gateway})
Esempio n. 19
0
    def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
        self.mox.StubOutWithMock(db, "network_get")
        self.mox.StubOutWithMock(db, "network_update")
        self.mox.StubOutWithMock(db, "fixed_ip_associate_pool")
        self.mox.StubOutWithMock(db, "instance_get")
        self.mox.StubOutWithMock(db, "virtual_interface_get_by_instance_and_network")
        self.mox.StubOutWithMock(db, "fixed_ip_update")

        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
            {"id": 0}
        )

        db.instance_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({"security_groups": [{"id": 0}]})
        db.fixed_ip_associate_pool(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn("192.168.0.101")
        db.network_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(networks[0])
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST, networks[0]["id"])
Esempio n. 20
0
    def modify(self,
               fixed_range,
               project=None,
               host=None,
               dis_project=None,
               dis_host=None):
        """Associate/Disassociate Network with Project and/or Host
        arguments: network project host
        leave any field blank to ignore it
        """
        admin_context = context.get_admin_context()
        network = db.network_get_by_cidr(admin_context, fixed_range)
        net = {}
        # User can choose the following actions each for project and host.
        # 1) Associate (set not None value given by project/host parameter)
        # 2) Disassociate (set None by disassociate parameter)
        # 3) Keep unchanged (project/host key is not added to 'net')
        if dis_project:
            net['project_id'] = None
        if dis_host:
            net['host'] = None

        # The --disassociate-X are boolean options, but if they user
        # mistakenly provides a value, it will be used as a positional argument
        # and be erroneously interepreted as some other parameter (e.g.
        # a project instead of host value). The safest thing to do is error-out
        # with a message indicating that there is probably a problem with
        # how the disassociate modifications are being used.
        if dis_project or dis_host:
            if project or host:
                error_msg = "ERROR: Unexpected arguments provided. Please " \
                    "use separate commands."
                print(error_msg)
                return (1)
            db.network_update(admin_context, network['id'], net)
            return

        if project:
            net['project_id'] = project
        if host:
            net['host'] = host

        db.network_update(admin_context, network['id'], net)
Esempio n. 21
0
def update_ra(context, network_id):
    network_ref = db.network_get(context, network_id)

    conffile = _ra_file(network_ref['bridge'], 'conf')
    with open(conffile, 'w') as f:
        conf_str = """
interface %s
{
   AdvSendAdvert on;
   MinRtrAdvInterval 3;
   MaxRtrAdvInterval 10;
   prefix %s
   {
        AdvOnLink on;
        AdvAutonomous on;
   };
};
""" % (network_ref['bridge'], network_ref['cidr_v6'])
        f.write(conf_str)

    # Make sure radvd can actually read it (it setuid()s to "nobody")
    os.chmod(conffile, 0644)

    pid = _ra_pid_for(network_ref['bridge'])

    # if radvd is already running, then tell it to reload
    if pid:
        out, _err = _execute('cat',
                             '/proc/%d/cmdline' % pid,
                             check_exit_code=False)
        if conffile in out:
            try:
                _execute('sudo', 'kill', pid)
            except Exception as exc:  # pylint: disable=W0703
                LOG.debug(_("killing radvd threw %s"), exc)
        else:
            LOG.debug(_("Pid %d is stale, relaunching radvd"), pid)
    command = _ra_cmd(network_ref)
    _execute(*command)
    db.network_update(
        context, network_id,
        {"gateway_v6": utils.get_my_linklocal(network_ref['bridge'])})
Esempio n. 22
0
def update_ra(context, network_id):
    network_ref = db.network_get(context, network_id)

    conffile = _ra_file(network_ref['bridge'], 'conf')
    with open(conffile, 'w') as f:
        conf_str = """
interface %s
{
   AdvSendAdvert on;
   MinRtrAdvInterval 3;
   MaxRtrAdvInterval 10;
   prefix %s
   {
        AdvOnLink on;
        AdvAutonomous on;
   };
};
""" % (network_ref['bridge'], network_ref['cidr_v6'])
        f.write(conf_str)

    # Make sure radvd can actually read it (it setuid()s to "nobody")
    os.chmod(conffile, 0644)

    pid = _ra_pid_for(network_ref['bridge'])

    # if radvd is already running, then tell it to reload
    if pid:
        out, _err = _execute('cat', '/proc/%d/cmdline'
                             % pid, check_exit_code=False)
        if conffile in out:
            try:
                _execute('sudo', 'kill', pid)
            except Exception as exc:  # pylint: disable=W0703
                LOG.debug(_('killing radvd threw %s'), exc)
        else:
            LOG.debug(_('Pid %d is stale, relaunching radvd'), pid)
    command = _ra_cmd(network_ref)
    _execute(*command)
    db.network_update(context, network_id,
                      {'gateway_v6':
                       utils.get_my_linklocal(network_ref['bridge'])})
Esempio n. 23
0
def update_ra(context, network_id):
    network_ref = db.network_get(context, network_id)

    conffile = _ra_file(network_ref["bridge"], "conf")
    with open(conffile, "w") as f:
        conf_str = """
interface %s
{
   AdvSendAdvert on;
   MinRtrAdvInterval 3;
   MaxRtrAdvInterval 10;
   prefix %s
   {
        AdvOnLink on;
        AdvAutonomous on;
   };
};
""" % (
            network_ref["bridge"],
            network_ref["cidr_v6"],
        )
        f.write(conf_str)

    # Make sure radvd can actually read it (it setuid()s to "nobody")
    os.chmod(conffile, 0644)

    pid = _ra_pid_for(network_ref["bridge"])

    # if radvd is already running, then tell it to reload
    if pid:
        out, _err = _execute("cat /proc/%d/cmdline" % pid, check_exit_code=False)
        if conffile in out:
            try:
                _execute("sudo kill %d" % pid)
            except Exception as exc:  # pylint: disable-msg=W0703
                LOG.debug(_("killing radvd threw %s"), exc)
        else:
            LOG.debug(_("Pid %d is stale, relaunching radvd"), pid)
    command = _ra_cmd(network_ref)
    _execute(command)
    db.network_update(context, network_id, {"ra_server": utils.get_my_linklocal(network_ref["bridge"])})
Esempio n. 24
0
    def modify(self, fixed_range, project=None, host=None,
               dis_project=None, dis_host=None):
        """Associate/Disassociate Network with Project and/or Host
        arguments: network project host
        leave any field blank to ignore it
        """
        admin_context = context.get_admin_context()
        network = db.network_get_by_cidr(admin_context, fixed_range)
        net = {}
        #User can choose the following actions each for project and host.
        #1) Associate (set not None value given by project/host parameter)
        #2) Disassociate (set None by disassociate parameter)
        #3) Keep unchanged (project/host key is not added to 'net')
        if dis_project:
            net['project_id'] = None
        if dis_host:
            net['host'] = None

        # The --disassociate-X are boolean options, but if they user
        # mistakenly provides a value, it will be used as a positional argument
        # and be erroneously interepreted as some other parameter (e.g.
        # a project instead of host value). The safest thing to do is error-out
        # with a message indicating that there is probably a problem with
        # how the disassociate modifications are being used.
        if dis_project or dis_host:
            if project or host:
                error_msg = "ERROR: Unexpected arguments provided. Please " \
                    "use separate commands."
                print(error_msg)
                return(1)
            db.network_update(admin_context, network['id'], net)
            return

        if project:
            net['project_id'] = project
        if host:
            net['host'] = host

        db.network_update(admin_context, network['id'], net)
Esempio n. 25
0
    def _on_set_network_host(self, context, network_id):
        """Called when this host becomes the host for a network."""
        network_ref = self.db.network_get(context, network_id)
        if not network_ref['vpn_public_address']:
            net = {}
            address = FLAGS.vpn_ip
            net['vpn_public_address'] = address
            db.network_update(context, network_id, net)
        else:
            address = network_ref['vpn_public_address']
        self.driver.ensure_vlan_bridge(network_ref['vlan'],
                                       network_ref['bridge'], network_ref)

        # NOTE(vish): only ensure this forward if the address hasn't been set
        #             manually.
        if address == FLAGS.vpn_ip:
            self.driver.ensure_vlan_forward(FLAGS.vpn_ip,
                                            network_ref['vpn_public_port'],
                                            network_ref['vpn_private_address'])
        if not FLAGS.fake_network:
            self.driver.update_dhcp(context, network_id)
            if (FLAGS.use_ipv6):
                self.driver.update_ra(context, network_id)
Esempio n. 26
0
 def save(self, context):
     updates = self._get_primitive_changes()
     if 'netmask_v6' in updates:
         # NOTE(danms): For some reason, historical code stores the
         # IPv6 netmask as just the CIDR mask length, so convert that
         # back here before saving for now.
         updates['netmask_v6'] = netaddr.IPNetwork(
             updates['netmask_v6']).netmask
     set_host = 'host' in updates
     if set_host:
         db.network_set_host(context, self.id, updates.pop('host'))
     if updates:
         db_network = db.network_update(context, self.id, updates)
     elif set_host:
         db_network = db.network_get(context, self.id)
     else:
         db_network = None
     if db_network is not None:
         self._from_db_object(context, self, db_network)
Esempio n. 27
0
 def save(self, context):
     updates = self._get_primitive_changes()
     if 'netmask_v6' in updates:
         # NOTE(danms): For some reason, historical code stores the
         # IPv6 netmask as just the CIDR mask length, so convert that
         # back here before saving for now.
         updates['netmask_v6'] = netaddr.IPNetwork(
             updates['netmask_v6']).netmask
     set_host = 'host' in updates
     if set_host:
         db.network_set_host(context, self.id, updates.pop('host'))
     if updates:
         db_network = db.network_update(context, self.id, updates)
     elif set_host:
         db_network = db.network_get(context, self.id)
     else:
         db_network = None
     if db_network is not None:
         self._from_db_object(context, self, db_network)