예제 #1
0
파일: ccs_quagga.py 프로젝트: libzz/amiral
    def getLinkArea(session_id, link_id):
        """Determines which OSPF area the link should fall into by default"""
        session = getSessionE(session_id)

        link = ccs_link(session_id, link_id)
        res = session.query("SELECT area_no FROM quagga_ospf_area WHERE " \
                "link_class_id=%s ORDER BY area_no LIMIT 1", \
                (link["class_id"]))
        if len(res) == 0:
            return -1

        return res[0]["area_no"]
예제 #2
0
파일: ccs_bind.py 프로젝트: libzz/amiral
    def updateDNSServer(self, host_id, is_master, dns_ip_address):
        """Updates the details of the DNS service.

        Returns SUCCESS.
        """
        session = getSessionE(self._session_id)

        ################## Validate incoming data ##################
        if is_master=="t":
            is_master = "t"
        else:
            is_master = "f"
        if dns_ip_address == "":
            dns_ip_address="NULL"
        else:
            # Get the link that DNS Server IPs come from
            values = self.getPropertyValues()
            link_id = values[DNS_SERVER_LINK_PROPERTY]
            if link_id == -1:
                raise ccs_bnd_error("No link specified. Cannot set IP!")
            link = ccs_link(self._session_id, link_id)
            netblock = link["network_address"]
            # Check it's in a valid network
            if not inNetwork(ipnum(dns_ip_address), cidrToNetwork(netblock),
                    cidrToNetmask(netblock)):
                raise ccs_bind_error("Invalid DNS IP address")

        ################## Update the database ##################
        if dns_ip_address == "NULL":
            session.execute("UPDATE dns_server SET is_master=%s, " \
                    "dns_ip_address=NULL WHERE host_id=%s", 
                    (is_master, host_id))
        else:
            session.execute("UPDATE dns_server SET is_master=%s, " \
                    "dns_ip_address=%s WHERE host_id=%s", 
                    (is_master, dns_ip_address, host_id))
            
        ################## Clean Up and Return ##################
        return True