Example #1
0
    def add_dhcp_route_option(self, bridge, cidr, gw_ip, dst_ip):
        """Add Option121 route to subnet

        :param bridge: Bridge to add the option route to
        :param cidr: subnet represented as x.x.x.x/y
        :param gw_ip: IP address of the next hop
        :param dst_ip: IP address of the destination, in x.x.x.x/y format
        """
        LOG.debug(
            _("MidoClient.add_dhcp_route_option called: "
              "bridge=%(bridge)s, cidr=%(cidr)s, gw_ip=%(gw_ip)s"
              "dst_ip=%(dst_ip)s"), {
                  "bridge": bridge,
                  "cidr": cidr,
                  "gw_ip": gw_ip,
                  "dst_ip": dst_ip
              })
        subnet = bridge.get_dhcp_subnet(net_util.subnet_str(cidr))
        if subnet is None:
            raise MidonetApiException(
                msg=_("Tried to access non-existent DHCP"))
        prefix, length = dst_ip.split("/")
        routes = [{
            'destinationPrefix': prefix,
            'destinationLength': length,
            'gatewayAddr': gw_ip
        }]
        cur_routes = subnet.get_opt121_routes()
        if cur_routes:
            routes = routes + cur_routes
        subnet.opt121_routes(routes).update()
Example #2
0
    def remove_dhcp_host(self, bridge, cidr, ip, mac):
        """Remove DHCP host entry

        :param bridge: bridge the DHCP is configured for
        :param cidr: subnet represented as x.x.x.x/y
        :param ip: IP address
        :param mac: MAC address
        """
        LOG.debug(
            _("MidoClient.remove_dhcp_host called: bridge=%(bridge)s, "
              "cidr=%(cidr)s, ip=%(ip)s, mac=%(mac)s"), {
                  'bridge': bridge,
                  'cidr': cidr,
                  'ip': ip,
                  'mac': mac
              })
        subnet = bridge.get_dhcp_subnet(net_util.subnet_str(cidr))
        if subnet is None:
            LOG.warn(_("Tried to delete mapping from non-existent subnet"))
            return

        for dh in subnet.get_dhcp_hosts():
            if dh.get_mac_addr() == mac and dh.get_ip_addr() == ip:
                LOG.debug(_("MidoClient.remove_dhcp_host: Deleting %(dh)r"),
                          {"dh": dh})
                dh.delete()
Example #3
0
    def delete_dhcp_host(self, bridge_id, cidr, ip, mac):
        """Delete DHCP host entry

        :param bridge_id: id of the bridge of the DHCP
        :param cidr: subnet represented as x.x.x.x/y
        :param ip: IP address
        :param mac: MAC address
        """
        LOG.debug(
            "MidoClient.delete_dhcp_host called: " "bridge_id=%(bridge_id)s, cidr=%(cidr)s, ip=%(ip)s, " "mac=%(mac)s",
            {"bridge_id": bridge_id, "cidr": cidr, "ip": ip, "mac": mac},
        )
        bridge = self.get_bridge(bridge_id)
        self.remove_dhcp_host(bridge, net_util.subnet_str(cidr), ip, mac)
Example #4
0
    def add_dhcp_host(self, bridge, cidr, ip, mac):
        """Add DHCP host entry

        :param bridge: bridge the DHCP is configured for
        :param cidr: subnet represented as x.x.x.x/y
        :param ip: IP address
        :param mac: MAC address
        """
        LOG.debug(_("MidoClient.add_dhcp_host called: bridge=%(bridge)s, "
                    "cidr=%(cidr)s, ip=%(ip)s, mac=%(mac)s"),
                  {'bridge': bridge, 'cidr': cidr, 'ip': ip, 'mac': mac})
        subnet = bridge.get_dhcp_subnet(net_util.subnet_str(cidr))
        if subnet is None:
            raise MidonetApiException(msg=_("Tried to add to"
                                            "non-existent DHCP"))

        subnet.add_dhcp_host().ip_addr(ip).mac_addr(mac).create()
Example #5
0
    def delete_dhcp_host(self, bridge_id, cidr, ip, mac):
        """Delete DHCP host entry

        :param bridge_id: id of the bridge of the DHCP
        :param cidr: subnet represented as x.x.x.x/y
        :param ip: IP address
        :param mac: MAC address
        """
        LOG.debug(
            _("MidoClient.delete_dhcp_host called: "
              "bridge_id=%(bridge_id)s, cidr=%(cidr)s, ip=%(ip)s, "
              "mac=%(mac)s"), {
                  'bridge_id': bridge_id,
                  'cidr': cidr,
                  'ip': ip,
                  'mac': mac
              })
        bridge = self.get_bridge(bridge_id)
        self.remove_dhcp_host(bridge, net_util.subnet_str(cidr), ip, mac)
Example #6
0
    def remove_dhcp_host(self, bridge, cidr, ip, mac):
        """Remove DHCP host entry

        :param bridge: bridge the DHCP is configured for
        :param cidr: subnet represented as x.x.x.x/y
        :param ip: IP address
        :param mac: MAC address
        """
        LOG.debug(_("MidoClient.remove_dhcp_host called: bridge=%(bridge)s, "
                    "cidr=%(cidr)s, ip=%(ip)s, mac=%(mac)s"),
                  {'bridge': bridge, 'cidr': cidr, 'ip': ip, 'mac': mac})
        subnet = bridge.get_dhcp_subnet(net_util.subnet_str(cidr))
        if subnet is None:
            LOG.warn(_("Tried to delete mapping from non-existent subnet"))
            return

        for dh in subnet.get_dhcp_hosts():
            if dh.get_mac_addr() == mac and dh.get_ip_addr() == ip:
                LOG.debug(_("MidoClient.remove_dhcp_host: Deleting %(dh)r"),
                          {"dh": dh})
                dh.delete()
Example #7
0
    def add_dhcp_host(self, bridge, cidr, ip, mac):
        """Add DHCP host entry

        :param bridge: bridge the DHCP is configured for
        :param cidr: subnet represented as x.x.x.x/y
        :param ip: IP address
        :param mac: MAC address
        """
        LOG.debug(
            _("MidoClient.add_dhcp_host called: bridge=%(bridge)s, "
              "cidr=%(cidr)s, ip=%(ip)s, mac=%(mac)s"), {
                  'bridge': bridge,
                  'cidr': cidr,
                  'ip': ip,
                  'mac': mac
              })
        subnet = bridge.get_dhcp_subnet(net_util.subnet_str(cidr))
        if subnet is None:
            raise MidonetApiException(msg=_("Tried to add to"
                                            "non-existent DHCP"))

        subnet.add_dhcp_host().ip_addr(ip).mac_addr(mac).create()
Example #8
0
    def add_dhcp_route_option(self, bridge, cidr, gw_ip, dst_ip):
        """Add Option121 route to subnet

        :param bridge: Bridge to add the option route to
        :param cidr: subnet represented as x.x.x.x/y
        :param gw_ip: IP address of the next hop
        :param dst_ip: IP address of the destination, in x.x.x.x/y format
        """
        LOG.debug(
            _(
                "MidoClient.add_dhcp_route_option called: "
                "bridge=%(bridge)s, cidr=%(cidr)s, gw_ip=%(gw_ip)s"
                "dst_ip=%(dst_ip)s"
            ),
            {"bridge": bridge, "cidr": cidr, "gw_ip": gw_ip, "dst_ip": dst_ip},
        )
        subnet = bridge.get_dhcp_subnet(net_util.subnet_str(cidr))
        if subnet is None:
            raise MidonetApiException(msg=_("Tried to access non-existent DHCP"))
        prefix, length = dst_ip.split("/")
        routes = [{"destinationPrefix": prefix, "destinationLength": length, "gatewayAddr": gw_ip}]
        subnet.opt121_routes(routes).update()