9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov#
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# Abstract directory server instance class
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov#
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# Copyright (c) 2015 Red Hat, Inc.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# Author: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov#
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# This is free software; you can redistribute it and/or modify it
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# under the terms of the GNU General Public License as published by
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# the Free Software Foundation; version 2 only
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov#
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# This program is distributed in the hope that it will be useful, but
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# WITHOUT ANY WARRANTY; without even the implied warranty of
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# General Public License for more details.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov#
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# You should have received a copy of the GNU General Public License
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov# along with this program. If not, see <http://www.gnu.org/licenses/>.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov#
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashovimport ldap
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov
60713f738cedb6e4239604baf6619a0ca986fa49Michal Židek
948c1a4d423dba289342844fb177bd5fa9828fc0Lukas Slebodnikclass DS(object):
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov """Abstract directory server instance."""
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov def __init__(self, dir, port, base_dn, admin_rdn, admin_pw):
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov """
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov Initialize the instance.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov Arguments:
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov dir Path to the root of the filesystem hierarchy to create
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov the instance under.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov port TCP port on localhost to bind the server to.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov base_dn Base DN.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov admin_rdn Administrator DN, relative to BASE_DN.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov admin_pw Administrator password.
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov """
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov self.dir = dir
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov self.port = port
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov self.ldap_url = "ldap://localhost:" + str(self.port)
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov self.base_dn = base_dn
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov self.admin_rdn = admin_rdn
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov self.admin_dn = admin_rdn + "," + base_dn
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov self.admin_pw = admin_pw
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov def setup(self):
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov """Setup the instance"""
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov raise NotImplementedError()
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov def teardown(self):
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov """Teardown the instance"""
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov raise NotImplementedError()
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov def bind(self):
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov """Connect to the server and bind as admin, return connection."""
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov conn = ldap.initialize(self.ldap_url)
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov conn.simple_bind_s(self.admin_dn, self.admin_pw)
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov return conn