コード例 #1
0
ファイル: add_router.py プロジェクト: ned21/aquilon
    def render(self, session, dbuser, fqdn, building, ip, network_environment,
               comments, **arguments):
        dbnet_env = NetworkEnvironment.get_unique_or_default(
            session, network_environment)
        self.az.check_network_environment(dbuser, dbnet_env)

        if building:
            dbbuilding = Building.get_unique(session, building, compel=True)
        else:
            dbbuilding = None

        (short, dbdns_domain) = parse_fqdn(session, fqdn)
        dbfqdn = Fqdn.get_or_create(session,
                                    name=short,
                                    dns_domain=dbdns_domain,
                                    dns_environment=dbnet_env.dns_environment)
        if ip:
            dbnetwork = get_net_id_from_ip(session, ip, dbnet_env)
            dbdns_rec = ARecord.get_or_create(session,
                                              fqdn=dbfqdn,
                                              ip=ip,
                                              network=dbnetwork)
        else:
            dbdns_rec = ARecord.get_unique(session, dbfqdn, compel=True)
            ip = dbdns_rec.ip
            dbnetwork = dbdns_rec.network

        assert ip in dbnetwork.network, "IP %s is outside network %s" % (
            ip, dbnetwork.ip)

        if ip in dbnetwork.router_ips:
            raise ArgumentError(
                "IP address {0} is already present as a router "
                "for {1:l}.".format(ip, dbnetwork))

        # Policy checks are valid only for internal networks
        if dbnetwork.is_internal:
            if ip >= dbnetwork.first_usable_host or \
               int(ip) - int(dbnetwork.ip) in dbnetwork.reserved_offsets:
                raise ArgumentError(
                    "IP address {0} is not a valid router address "
                    "on {1:l}.".format(ip, dbnetwork))

        dbnetwork.routers.append(
            RouterAddress(ip=ip,
                          location=dbbuilding,
                          dns_environment=dbdns_rec.fqdn.dns_environment,
                          comments=comments))
        session.flush()

        # TODO: update the templates of Zebra hosts on the network

        return
コード例 #2
0
ファイル: update_router.py プロジェクト: jrha/aquilon
    def render(self, session, fqdn, ip, building, comments, **arguments):
        if fqdn:
            dbdns_rec = ARecord.get_unique(session, fqdn, compel=True)
            ip = dbdns_rec.ip
        if not ip:
            raise ArgumentError("Please specify either --ip or --fqdn.")

        router = RouterAddress.get_unique(session, ip=ip, compel=True)

        if building:
            dbbuilding = Building.get_unique(session, name=building,
                                             compel=True)
            router.location = dbbuilding

        if comments:
            router.comments = comments

        session.flush()
コード例 #3
0
ファイル: update_router.py プロジェクト: ned21/aquilon
    def render(self, session, fqdn, ip, building, comments, **arguments):
        if fqdn:
            dbdns_rec = ARecord.get_unique(session, fqdn, compel=True)
            ip = dbdns_rec.ip
        if not ip:
            raise ArgumentError("Please specify either --ip or --fqdn.")

        router = RouterAddress.get_unique(session, ip=ip, compel=True)

        if building:
            dbbuilding = Building.get_unique(session,
                                             name=building,
                                             compel=True)
            router.location = dbbuilding

        if comments:
            router.comments = comments

        session.flush()
コード例 #4
0
        if params["type"] == "loopback":
            relaxed = True
        else:
            relaxed = False

        for ipstr, label in params["ip"].items():
            ip = IPv4Address(ipstr)

            if ip not in ip_to_iface:
                # Unknown network etc.
                continue

            if ip not in addr_by_ip:
                add_address(iface, ifname, ip, label, relaxed)

    # Check router addresses
    if "router_ips" in data:
        for ipstr in data["router_ips"]:
            ip = IPv4Address(ipstr)
            try:
                dbnetwork = get_net_id_from_ip(session, ip, dbnet_env)
                rtr = RouterAddress.get_unique(session, ip=ip,
                                               network=dbnetwork)
                if not rtr:
                    add_router(ip)
            except NotFoundException:
                warning("Skipping router IP address %s: network not found." %
                        ip)

    return results
コード例 #5
0
 def add_router(self, dbnetwork, ip):
     dbnetwork.routers.append(
         RouterAddress(ip=ip, dns_environment=self.dns_env))
     self.logger.client_info("Adding router {0:s} to "
                             "{1:l}".format(ip, dbnetwork))