Exemple #1
0
def handleRevisionEvent(eventName, host_id, session_id, outputDir):
    """Receives callbacks to add extra information to the config revisions"""

    # Get a list of hosts running the RADIUS service
    radius = getServiceInstance(session_id, radius_service.serviceName)
    hosts = radius.getHostList()

    ca = ccs_ca()

    # Loop through each host and ensure that the certs/ directory is populated
    for host in hosts:
        try:
            # Check basic path existance
            hostdir = "%s/hosts/%s" % (outputDir, host)
            if not os.path.isdir(hostdir):
                # Host does not exist in the revision
                continue
            radiusdir = "%s/radius" % (hostdir)
            if not os.path.isdir(radiusdir):
                log_warn("Host '%s' does not have RADIUS templates!" % host)
                continue
            # Now check for the certs directory and the certificates
            certsdir = "%s/certs" % (radiusdir)
            ensureDirExists(certsdir)
            if not os.path.exists("%s/cacert.pem" % certsdir):
                cacert = ca.getFile("ca/cacert.pem")
                cacerts = ca.getFile("ca/cacerts.pem")
                fp = open("%s/cacert.pem" % certsdir, "w")
                fp.write(cacert)
                fp.write(cacerts)
                fp.close()
            if not os.path.exists("%s/dh" % certsdir):
                fp = open("%s/dh" % certsdir, "w")
                fp.close()
            if not os.path.exists("%s/random" % certsdir):
                log_command("openssl rand -out %s/random 1024" % certsdir)
            if not os.path.exists("%s/radius-key.pem" % certsdir):
                key = ca.getFile("ca/radius-key.pem")
                fp = open("%s/radius-key.pem" % certsdir, "w")
                fp.write(key)
                fp.close()
            if not os.path.exists("%s/radius-cert.pem" % certsdir):
                cert = ca.getFile("ca/radius-cert.pem")
                fp = open("%s/radius-cert.pem" % certsdir, "w")
                fp.write(cert)
                fp.close()
        except:
            log_error("Could not setup RADIUS certificates for %s" % host, \
                    sys.exc_info())
Exemple #2
0
def handleRevisionPrepEvent(eventName, host_id, session_id, outputDir):
    """Receives callbacks to add extra information to the config revisions"""
    
    # Get a list of hosts running the rrdbot service
    rrdbot = getServiceInstance(session_id, ccs_rrdbot.serviceName)

    ca = ccs_ca()

    try:
        certsdir = "%s/services/rrdbot/certs" % (outputDir)
        ensureDirExists(certsdir)
        if not os.path.exists("%s/key.pem" % certsdir):
            key = ca.getFile("ca/rrdbot-key.pem")
            fp = open("%s/key.pem" % certsdir, "w")
            fp.write(key)
            fp.close()
        if not os.path.exists("%s/cert.pem" % certsdir):
            cert = ca.getFile("ca/rrdbot-cert.pem")
            fp = open("%s/cert.pem" % certsdir, "w")
            fp.write(cert)
            fp.close()
    except:
        log_error("Could not setup rrdbot certificates for %s" % host, \
                sys.exc_info())
Exemple #3
0
    def getTemplateVariables(self):
        """Returns a dictionary containing template variables.

        Template variables contain information about this host that may be
        used in templates. This function attempts to be as comprehensive as
        possible in returning information about the host.

        WARNING: The returned dictionary could be very large!
        """
        global _kernels
        from ccs_interface import ccs_interface, INTERFACE_TYPE_ALIAS
        variables = {}
        
        # Include basic properties
        variables.update(filter_keys(self._properties))
        
        # Get interface information
        interfaces = self.getInterfaces()
        ilist = {}
        btargets = {}
        aliases = {}
        for n,iface in interfaces.items():
            if iface["interface_id"] == "" or iface["interface_id"] is None:
                continue
            niface = ccs_interface(self._session_id, \
                    iface["interface_id"])
            ifacevars = niface.getTemplateVariables()
            # Catch aliased interfaces here and store for later processing
            if iface["interface_type"] == INTERFACE_TYPE_ALIAS:
                if iface["raw_interface"] not in aliases.keys():
                    aliases[iface["raw_interface"]] = []
                aliases[iface["raw_interface"]].append(ifacevars)
                continue
            ifacevars["aliases"] = []
            # Handle bridge interface name resolution
            ifacevars["bridge_with"] = []
            ifacevars["bridge_interface_name"] = ""
            if ifacevars["bridge_interface"]!="" and \
                    ifacevars["bridge_interface"]!=-1:
                bi = ifacevars["bridge_interface"]
                bt = ccs_interface(self._session_id, bi)
                bn = bt["name"]
                ifacevars["bridge_interface_name"] = bn                        
                if bn in btargets.keys():
                    btargets[bn].append(iface["name"])
                else:
                    btargets[bn] = [iface["name"]]
            # Store interface
            ilist[iface["name"]] = ifacevars

        # Setup bridge targets
        for ifn,iflist in btargets.items():
            ilist[ifn]["bridge_with"] = iflist
            ilist[ifn]["bridge_interface_name"] = ifn
        
        # Setup aliases
        for n,iface in interfaces.items():
            if iface["interface_id"] not in aliases.keys():
                continue
            ilist[iface["name"]]["aliases"].extend( \
                    aliases[iface["interface_id"]])
        
        variables["interfaces"] = ilist

        # Output kernel name information
        kid = variables["kernel_id"]
        variables["kernel_name"] = "%s%s" % \
                (_kernels[kid]["upstream_release"], \
                _kernels[kid]["local_version"])

        # Get service information
        services = self.getServices()
        slist = {}
        for service in services:
            nservice = getServiceInstance(self._session_id, \
                    service["service_name"])
            slist[service["service_name"]] = \
                    nservice.getTemplateVariables(self.host_id)
        variables["service"] = slist
          
        return variables