Пример #1
0
def make_net_model(net_spec):
    try:
        net_model = dhcp.NetModel(False, net_spec)
    except TypeError:
        # use_namespace option was removed during Mitaka cycle.
        net_model = dhcp.NetModel(net_spec)
        net_model._ns_name = None

    return net_model
Пример #2
0
 def get_network_info(self, network_id):
     """Make a remote process call to retrieve network info."""
     cctxt = self.client.prepare()
     network = cctxt.call(self.context, 'get_network_info',
                          network_id=network_id, host=self.host)
     if network:
         return dhcp.NetModel(self.use_namespaces, network)
Пример #3
0
 def get_active_networks_info(self):
     """Make a remote process call to retrieve all network info."""
     networks = self.call(self.context,
                          self.make_msg('get_active_networks_info',
                                        host=self.host),
                          topic=self.topic)
     return [dhcp.NetModel(self.use_namespaces, n) for n in networks]
Пример #4
0
 def get_active_networks_info(self):
     """Make a remote process call to retrieve all network info."""
     cctxt = self.client.prepare(version='1.1')
     networks = cctxt.call(self.context,
                           'get_active_networks_info',
                           host=self.host)
     return [dhcp.NetModel(self.use_namespaces, n) for n in networks]
Пример #5
0
    def on_ports_changed(self):
        # Check whether we should really do the following processing.
        if self.suppress_on_ports_changed:
            LOG.debug("Don't recalculate subnets yet;"
                      " must be processing a snapshot")
            return

        # Get current NetModel description of the Calico network.
        net = self.agent.cache.get_network_by_id(NETWORK_ID)
        LOG.debug("net: %s %s %s", net.id, net.subnets, net.ports)

        # See if we need to update the subnets in the NetModel.
        new_subnets = self.calculate_new_subnets(net.ports, net.subnets)
        if new_subnets is None:
            # No change to subnets, so just need 'reload_allocations' to tell
            # Dnsmasq about the new port.
            self.agent.call_driver('reload_allocations', net)
        else:
            # Subnets changed, so need to 'restart' the DHCP driver.
            net = dhcp.NetModel(
                False, {
                    "id": net.id,
                    "subnets": new_subnets,
                    "ports": net.ports,
                    "tenant_id": "calico",
                    "mtu": constants.DEFAULT_NETWORK_MTU
                })
            LOG.debug("new net: %s %s %s", net.id, net.subnets, net.ports)

            # Next line - i.e. just discarding the existing cache - is to work
            # around Neutron bug that the DHCP port is not entered into the
            # cache's port_lookup dict.
            self.agent.cache = NetworkCache()
            self.agent.cache.put(net)
            self.agent.call_driver('restart', net)
Пример #6
0
 def get_network_info(self, network_id):
     """Make a remote process call to retrieve network info."""
     network = self.call(self.context,
                         self.make_msg('get_network_info',
                                       network_id=network_id,
                                       host=self.host))
     if network:
         return dhcp.NetModel(self.use_namespaces, network)
Пример #7
0
 def _empty_network(self):
     """Construct and return an empty network model."""
     return dhcp.NetModel(
         False, {
             "id": NETWORK_ID,
             "subnets": [],
             "ports": [],
             "mtu": constants.DEFAULT_NETWORK_MTU
         })
Пример #8
0
 def create_network_dict(self, net_id, subnets=None, ports=None):
     subnets = [] if not subnets else subnets
     ports = [] if not ports else ports
     net_dict = dhcp.NetModel(use_namespaces=True, d={
         "id": net_id,
         "subnets": subnets,
         "ports": ports,
         "admin_state_up": True,
         "tenant_id": uuidutils.generate_uuid(), })
     return net_dict
Пример #9
0
 def create_network_dict(self, net_id, subnets=None, ports=None,
                         non_local_subnets=None):
     subnets = [] if not subnets else subnets
     ports = [] if not ports else ports
     non_local_subnets = [] if not non_local_subnets else non_local_subnets
     net_dict = dhcp.NetModel(id=net_id,
                              subnets=subnets,
                              non_local_subnets=non_local_subnets,
                              ports=ports,
                              admin_state_up=True,
                              project_id=uuidutils.generate_uuid())
     return net_dict
Пример #10
0
def kill_dhcp(conf, namespace):
    """Disable DHCP for a network if DHCP is still active."""
    network_id = namespace.replace(dhcp.NS_PREFIX, '')

    dhcp_driver = importutils.import_object(
        conf.dhcp_driver,
        conf=conf,
        network=dhcp.NetModel(conf.use_namespaces, {'id': network_id}),
        plugin=FakeDhcpPlugin())

    if dhcp_driver.active:
        dhcp_driver.disable()
Пример #11
0
 def _populate_networks_cache(self):
     """Populate the networks cache when the DHCP-agent starts."""
     try:
         existing_networks = self.dhcp_driver_cls.existing_dhcp_networks(
             self.conf)
         for net_id in existing_networks:
             net = dhcp.NetModel({"id": net_id, "subnets": [], "ports": []})
             self.cache.put(net)
     except NotImplementedError:
         # just go ahead with an empty networks cache
         LOG.debug(
             "The '%s' DHCP-driver does not support retrieving of a "
             "list of existing networks", self.conf.dhcp_driver)
Пример #12
0
    def get_networks(self, filters=None, fields=None):
        """Get networks.

        :param filters: The filters to apply.
                        E.g {"id" : ["<uuid of a network>", ...]}
        :param fields: A list of fields to collect, e.g ["id", "subnets"].
        :return: A list of NetModel where each object represent a network.
        """

        cctxt = self.client.prepare(version='1.7')
        nets = cctxt.call(self.context, 'get_networks', filters=filters,
                          fields=fields)
        return [dhcp.NetModel(net) for net in nets]
Пример #13
0
def kill_dhcp(conf, namespace):
    """Disable DHCP for a network if DHCP is still active."""
    root_helper = agent_config.get_root_helper(conf)
    network_id = namespace.replace(dhcp.NS_PREFIX, '')

    dhcp_driver = importutils.import_object(
        conf.dhcp_driver,
        conf=conf,
        process_monitor=_get_dhcp_process_monitor(conf, root_helper),
        network=dhcp.NetModel(conf.use_namespaces, {'id': network_id}),
        root_helper=root_helper,
        plugin=FakeDhcpPlugin())

    if dhcp_driver.active:
        dhcp_driver.disable()
Пример #14
0
    def get_active_networks_info(self):
        """Make a remote process call to retrieve all network info."""
        ret = self.call(
            self.context,
            self.make_msg('get_active_networks_info', host=self.host))
        networks = ret['networks']
        subnets = ret['subnets']
        ports = ret['ports']
        for network in networks:
            network['subnets'] = [
                subnet for subnet in subnets
                if subnet['network_id'] == network['id']
            ]
            network['ports'] = [
                port for port in ports if port['network_id'] == network['id']
            ]

        return [dhcp.NetModel(self.use_namespaces, n) for n in networks]
Пример #15
0
    def get_distributed_active_networks_info(self):
        ret = self.call(
            self.context,
            self.make_msg('get_distributed_active_networks_info',
                          host=self.host))
        networks = ret['networks']
        subnets = ret['subnets']
        ports = ret['ports']

        for network in networks:
            network['subnets'] = [
                subnet for subnet in subnets
                if subnet['network_id'] == network['id']
            ]
            network['ports'] = [
                port for port in ports if port['network_id'] == network['id']
            ]

        return [dhcp.NetModel(self.use_namespaces, n) for n in networks]
Пример #16
0
         fixed_ips=[fake_fixed_ipv6]))

fake_meta_port = dhcp.DictModel(
    dict(id='12345678-1234-aaaa-1234567890ab',
         mac_address='aa:bb:cc:dd:ee:ff',
         network_id='12345678-1234-5678-1234567890ab',
         device_owner=const.DEVICE_OWNER_ROUTER_INTF,
         device_id='forzanapoli',
         fixed_ips=[fake_meta_fixed_ip]))

FAKE_NETWORK_UUID = '12345678-1234-5678-1234567890ab'
FAKE_NETWORK_DHCP_NS = "qdhcp-%s" % FAKE_NETWORK_UUID

fake_network = dhcp.NetModel(
    dict(id=FAKE_NETWORK_UUID,
         tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa',
         admin_state_up=True,
         subnets=[fake_subnet1, fake_subnet2],
         ports=[fake_port1]))

fake_network_ipv6 = dhcp.NetModel(
    dict(id='12345678-1234-5678-1234567890ab',
         tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa',
         admin_state_up=True,
         subnets=[fake_ipv6_subnet],
         ports=[fake_ipv6_port]))

fake_network_ipv6_ipv4 = dhcp.NetModel(
    dict(id='12345678-1234-5678-1234567890ab',
         tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa',
         admin_state_up=True,
         subnets=[fake_ipv6_subnet, fake_subnet1],