Ejemplo n.º 1
0
def remove_deployment(server_id):
    """Initiates removal of replication deployment and back to slapd.conf

    Args:
        server_id (integer): id of server to be undeployed
    """

    thisServer = Server.query.get(server_id)
    servers = Server.query.filter(Server.id.isnot(server_id)).filter(
        Server.mmr.is_(True)).all()

    # We should check if this server is a provider for a server in cluster, so
    # iterate all servers in cluster
    for m in servers:
        ldp = LdapOLC('ldaps://{}:1636'.format(m.hostname), "cn=config",
                      m.ldap_password)
        r = None
        try:
            r = ldp.connect()
        except Exception as e:
            flash(
                "Connection to LDAPserver {0} at port 1636 was failed:"
                " {1}".format(m.hostname, e), "danger")

        if r:
            # If this server is a provider to another server, refuse to remove
            # deployment and update admin
            pd = ldp.getProviders()

            if thisServer.hostname in pd:
                flash(
                    "This server is a provider for Ldap Server {0}."
                    " Please first remove this server as provider.".format(
                        thisServer.hostname), "warning")
                return redirect(url_for('index.multi_master_replication'))

    # Start deployment removal celery task
    task = removeMultiMasterDeployement.delay(server_id)
    print "TASK STARTED", task.id
    head = "Removing Deployment"
    nextpage = "index.multi_master_replication"
    whatNext = "Multi Master Replication"
    return render_template("logger.html",
                           heading=head,
                           server=thisServer,
                           task=task,
                           nextpage=nextpage,
                           whatNext=whatNext)
Ejemplo n.º 2
0
def multi_master_replication():
    """Multi Master Replication view"""
    
    #Check if replication user (dn) and password has been configured
    app_config = AppConfiguration.query.first()
    if not app_config:
        flash("Repication user and/or password has not been defined."
              " Please go to 'Configuration' and set these before proceed.",
              "warning")

    if 'nongluuldapinfo' in session:
        del session['nongluuldapinfo']

    ldap_errors = []

    ldaps = Server.query.all()
    serverStats = {}


    #Collect replication information for all configured servers
    for ldp in ldaps:

        s = LdapOLC(
            "ldaps://{0}:1636".format(ldp.hostname), "cn=config",
            ldp.ldap_password)
        r = None
        try:
            r = s.connect()
        except Exception as e:
            ldap_errors.append(
                "Connection to LDAPserver {0} at port 1636 was failed:"
                " {1}".format(ldp.hostname, e))

        if r:
            sstat = s.getMMRStatus()
            if sstat['server_id']:
                serverStats[ldp.hostname] = sstat

    #If there is no ldap server, return to home
    if not ldaps:
        flash("Please add ldap servers.", "warning")
        return redirect(url_for('index.home'))
        
    return render_template('multi_master.html', 
                           ldapservers=ldaps,
                           serverStats=serverStats,
                           ldap_errors=ldap_errors,
                           )
Ejemplo n.º 3
0
def getLdapConn(addr, dn, passwd):
    ldp = LdapOLC('ldaps://{}:1636'.format(addr), dn, passwd)
    r = None
    try:
        r = ldp.connect()
    except Exception as e:
        flash(
            "Connection to LDAPserver {0} at port 1636 failed: {1}".format(
                addr, e), "danger")
        return
    if not r:
        flash(
            "Connection to LDAPserver {0} at port 1636 failed: {1}".format(
                addr, ldp.conn.result['description']), "danger")
        return
    return ldp
Ejemplo n.º 4
0
def multi_master_replication():
    app_config = AppConfiguration.query.first()
    pr_server = get_primary_server_id()
    if not app_config:
        flash(
            "Repication user and/or password has not been defined."
            " Please go to 'Configuration' and set these before proceed.",
            "warning")

    if 'nongluuldapinfo' in session:
        del session['nongluuldapinfo']

    ldaps = Server.query.all()
    serverStats = {}

    for ldp in ldaps:

        s = LdapOLC("ldaps://{0}:1636".format(ldp.hostname), "cn=config",
                    ldp.ldap_password)
        r = None
        try:
            r = s.connect()
        except Exception as e:
            flash(
                "Connection to LDAPserver {0} at port 1636 was failed:"
                " {1}".format(ldp.hostname, e), "warning")

        if not r:
            flash(
                "Connection to LDAPserver {0} at port 1636 has "
                "failed".format(ldp.hostname), "warning")

        if r:
            sstat = s.getMMRStatus()
            if sstat['server_id']:
                serverStats[ldp.hostname] = sstat
    if not ldaps:
        flash("Please add ldap servers.", "warning")
        return redirect(url_for('index.home'))

    return render_template(
        'multi_master.html',
        ldapservers=ldaps,
        serverStats=serverStats,
        pr_server=pr_server,
    )
Ejemplo n.º 5
0
def getLdapConn(addr, dn, passwd):
    """this function gets address, dn and password for ldap server, makes
    connection and return LdapOLC object."""
    
    ldp = LdapOLC('ldaps://{}:1636'.format(addr), dn, passwd)
    r = None
    try:
        r = ldp.connect()
    except Exception as e:
        flash("Connection to LDAPserver {0} at port 1636 failed: {1}".format(
            addr, e), "danger")
        return
    if not r:
        flash("Connection to LDAPserver {0} at port 1636 failed: {1}".format(
            addr, ldp.conn.result['description']), "danger")
        return
    return ldp
Ejemplo n.º 6
0
def remove_deployment(server_id):

    #server = Server.query.get(server_id)
    #if server.mmr:
    #    remove_provider.delay(server.id)
    #return redirect(url_for('index.multi_master_replication'))

    thisServer = Server.query.get(server_id)
    servers = Server.query.filter(Server.id.isnot(server_id)).filter(
        Server.mmr.is_(True)).all()

    for m in servers:
        ldp = LdapOLC('ldaps://{}:1636'.format(m.hostname), "cn=config",
                      m.ldap_password)
        r = None
        try:
            r = ldp.connect()
        except Exception as e:
            flash(
                "Connection to LDAPserver {0} at port 1636 was failed:"
                " {1}".format(m.hostname, e), "danger")

        if r:
            pd = ldp.getProviders()

            if thisServer.hostname in pd:
                flash(
                    "This server is a provider for Ldap Server {0}."
                    " Please first remove this server as provider.".format(
                        thisServer.hostname), "warning")
                return redirect(url_for('index.multi_master_replication'))

    task = removeMultiMasterDeployement.delay(server_id)
    print "TASK STARTED", task.id
    head = "Removing Deployment"
    nextpage = "index.multi_master_replication"
    whatNext = "Multi Master Replication"
    return render_template("logger.html",
                           heading=head,
                           server=thisServer,
                           task=task,
                           nextpage=nextpage,
                           whatNext=whatNext)
Ejemplo n.º 7
0
class LdapOlcTestCase(unittest.TestCase):
    def setUp(self):
        with patch('clustermgr.core.ldap_functions.Connection') as mockconn:
            self.conn = mockconn.return_value
            self.mgr = LdapOLC("0.0.0.0", "cn=config", "secret")
            self.mgr.connect()

    def tearDown(self):
        pass

    def test_add_provider_performs_a_modify_add(self):
        self.mgr.add_provider(1, 'server.example.com', 'cn=rep,o-gluu', 'pass')
        self.mgr.conn.modify.assert_called_once()
        call_args = self.mgr.conn.modify.call_args[0]
        self.assertIn('olcSyncRepl', call_args[1])
        self.assertEqual(MODIFY_ADD, call_args[1]['olcSyncRepl'][0][0])

    def test_add_provider_replaces_syncrepl_conf_if_id_already_exists(self):
        self.mgr.conn.entries = [{"olcSyncRepl": ["rid=1 replicate"]}]
        self.mgr.add_provider(1, 'server.example.com', 'cn=rep,o-gluu', 'pass')
        self.mgr.conn.search.assert_called_once()
        # modify should be called twice, once with delete and another with add
        assert self.mgr.conn.modify.call_count == 2
Ejemplo n.º 8
0
def multi_master_replication():
    """Multi Master Replication view for OpenLDAP"""

    # Check if replication user (dn) and password has been configured
    app_config = AppConfiguration.query.first()
    ldaps = Server.query.all()
    primary_server = Server.query.filter_by(primary_server=True).first()
    if not app_config:
        flash(
            "Repication user and/or password has not been defined."
            " Please go to 'Configuration' and set these before proceed.",
            "warning")
        return redirect(url_for('index.home'))

    if not ldaps:
        flash("Servers has not been added. " "Please add servers", "warning")
        return redirect(url_for('index.home'))

    ldap_errors = []

    prop = get_setup_properties()

    if prop['ldap_type'] == 'openldap':

        serverStats = {}

        # Collect replication information for all configured servers
        for ldp in ldaps:

            s = LdapOLC("ldaps://{0}:1636".format(ldp.hostname), "cn=config",
                        ldp.ldap_password)
            r = None
            try:
                r = s.connect()
            except Exception as e:
                ldap_errors.append(
                    "Connection to LDAPserver {0} at port 1636 was failed:"
                    " {1}".format(ldp.hostname, e))

            if r:
                sstat = s.getMMRStatus()
                if sstat['server_id']:
                    serverStats[ldp.hostname] = sstat

        # If there is no ldap server, return to home
        if not ldaps:
            flash("Please add ldap servers.", "warning")
            return redirect(url_for('index.home'))

        return render_template(
            'multi_master.html',
            ldapservers=ldaps,
            serverStats=serverStats,
            ldap_errors=ldap_errors,
            replication_status=sstat[primary_server.id],
        )

    else:

        rep_status = get_opendj_replication_status()

        stat = ''
        if not rep_status[0]:
            flash(rep_status[1], "warning")
        else:
            stat = rep_status[1]
        return render_template(
            'opendjmmr.html',
            servers=ldaps,
            stat=stat,
            app_conf=app_config,
        )
Ejemplo n.º 9
0
 def setUp(self):
     with patch('clustermgr.core.ldap_functions.Connection') as mockconn:
         self.conn = mockconn.return_value
         self.mgr = LdapOLC("0.0.0.0", "cn=config", "secret")
         self.mgr.connect()