def build_sysversion(config_registry): sysversion = '%s-%s' % (config_registry['version/version'], config_registry['version/patchlevel'], ) if config_registry.get('version/security-patchlevel'): sysversion = "%s-%s" % (sysversion, config_registry['version/security-patchlevel'], ) if config_registry.get('version/erratalevel'): sysversion = "%s errata%s" % (sysversion, config_registry['version/erratalevel'], ) return sysversion
def open_database_connection(config_registry, pkgdbu=False, db_server=None): connection_info = { # see <http://www.postgresql.org/docs/8.4/static/libpq-connect.html> 'dbname': 'pkgdb', } if config_registry.is_true('pkgdb/requiressl'): connection_info['sslmode'] = 'require' if pkgdbu: # 'host' not specified -> localhost over Unix-domain socket (connection type "local") connection_info['user'] = '******' password_file = '/etc/postgresql/pkgdb.secret' else: if db_server is None: db_server = get_dbservername(config_registry['domainname']) if db_server is None: return None connection_info['host'] = db_server connection_info['user'] = config_registry.get( 'pkgdb/user', '%s$' % (config_registry['hostname'], )) password_file = config_registry.get('pkgdb/pwdfile', '/etc/machine.secret') connection_info['password'] = open(password_file, 'rb').read().rstrip('\n') connectstring = ' '.join([ "%s='%s'" % ( key, value.replace('\\', '\\\\').replace("'", "\\'"), ) for ( key, value, ) in connection_info.items() ]) connection = pgdb.connect(database=connectstring) return connection
def open_database_connection(config_registry, pkgdbu=False, db_server=None): connection_info = { # see <http://www.postgresql.org/docs/8.4/static/libpq-connect.html> 'dbname': 'pkgdb', } if config_registry.is_true('pkgdb/requiressl'): connection_info['sslmode'] = 'require' if pkgdbu: # 'host' not specified -> localhost over Unix-domain socket (connection type "local") connection_info['user'] = '******' password_file = '/etc/postgresql/pkgdb.secret' else: if db_server is None: db_server = get_dbservername(config_registry['domainname']) if db_server is None: return None connection_info['host'] = db_server connection_info['user'] = config_registry.get('pkgdb/user', '%s$' % (config_registry['hostname'], )) password_file = config_registry.get('pkgdb/pwdfile', '/etc/machine.secret') connection_info['password'] = open(password_file, 'rb').read().rstrip('\n') connectstring = ' '.join( [ "%s='%s'" % (key, value.replace('\\', '\\\\').replace("'", "\\'"), ) for (key, value, ) in connection_info.items() ] ) connection = pgdb.connect(database=connectstring) return connection
def get_dns_server(config_registry, active_services): if config_registry.is_true('ad/member'): ad_domain_info = univention.lib.admember.lookup_adds_dc() server = ad_domain_info.get('DC IP') else: hostname = config_registry.get('hostname') domainname = config_registry.get('domainname') if set(active_services) >= {'Samba 4', 'DNS'}: server = ".".join([hostname, domainname]) else: ## TODO: Memberserver in Samba 4 domain server = None return server
def check_nsupdate(config_registry, server): hostname = config_registry.get('hostname') domainname = config_registry.get('domainname') try: check_dns_machine_principal(server, hostname, domainname) except UpdateError as error: yield error if config_registry.get('samba4/role') == 'DC': try: check_dns_server_principal(hostname, domainname) except UpdateError as error: yield error
def action_scan(connection, cursor, config_registry): '''put systems <sysname> in the database and updates it with the current package state''' connection.rollback() sysname = config_registry['hostname'] sysversion = '%s-%s' % ( config_registry['version/version'], config_registry['version/patchlevel'], ) if config_registry.get('version/security-patchlevel'): sysversion = "%s-%s" % ( sysversion, config_registry['version/security-patchlevel'], ) sysrole = config_registry['server/role'] ldaphostdn = config_registry['ldap/hostdn'] apt_pkg.init() architecture = apt_pkg.Config.find("APT::Architecture") log('Starting scan of system %r' % (sysname, )) try: sql_put_sys_in_systems(cursor, sysname, sysversion, sysrole, ldaphostdn, architecture) fake_null = False except pgdb.DatabaseError: # assume we are connected to a univention-pkgdb < 6.0.7-1 (old schema) connection.rollback() # retry for old schema sql_put_sys_in_systems_no_architecture(cursor, sysname, sysversion, sysrole, ldaphostdn) fake_null = True # old schema has NOT NULL, thus we have to use '' instead of None scan_and_store_packages(cursor, sysname, fake_null) connection.commit() log('end of scan for system %r' % (sysname, )) return 0
def action_fill_testdb(connection, cursor, config_registry): '''Fülle Testdatenbank''' connection.rollback() sysversion = '%s-%s' % ( config_registry['version/version'], config_registry['version/patchlevel'], ) if config_registry.get('version/security-patchlevel'): sysversion = "%s-%s" % ( sysversion, config_registry['version/security-patchlevel'], ) sysrole = config_registry['server/role'] ldaphostdn = config_registry['ldap/hostdn'] apt_pkg.init() architecture = apt_pkg.Config.find("APT::Architecture") log('start fill of testdb ') for sysname in ['testsystem%04d' % (i, ) for i in xrange(1, 1500)]: try: sql_put_sys_in_systems(cursor, sysname, sysversion, sysrole, ldaphostdn, architecture) fake_null = False except pgdb.DatabaseError: # assume we are connected to a univention-pkgdb < 6.0.7-1 (old schema) connection.rollback() # retry for old schema sql_put_sys_in_systems_no_architecture(cursor, sysname, sysversion, sysrole, ldaphostdn) fake_null = True # old schema has NOT NULL, thus we have to use '' instead of None scan_and_store_packages(cursor, sysname, fake_null) connection.commit() log('end of fill testdb') return 0
def action_scan(connection, cursor, config_registry): '''put systems <sysname> in the database and updates it with the current package state''' connection.rollback() sysname = config_registry['hostname'] sysversion = '%s-%s' % (config_registry['version/version'], config_registry['version/patchlevel'], ) if config_registry.get('version/security-patchlevel'): sysversion = "%s-%s" % (sysversion, config_registry['version/security-patchlevel'], ) sysrole = config_registry['server/role'] ldaphostdn = config_registry['ldap/hostdn'] apt_pkg.init() architecture = apt_pkg.Config.find("APT::Architecture") log('Starting scan of system %r' % (sysname, )) try: sql_put_sys_in_systems(cursor, sysname, sysversion, sysrole, ldaphostdn, architecture) fake_null = False except pgdb.DatabaseError: # assume we are connected to a univention-pkgdb < 6.0.7-1 (old schema) connection.rollback() # retry for old schema sql_put_sys_in_systems_no_architecture(cursor, sysname, sysversion, sysrole, ldaphostdn) fake_null = True # old schema has NOT NULL, thus we have to use '' instead of None scan_and_store_packages(cursor, sysname, fake_null) connection.commit() log('end of scan for system %r' % (sysname, )) return 0
def action_fill_testdb(connection, cursor, config_registry): '''Fülle Testdatenbank''' connection.rollback() sysversion = '%s-%s' % (config_registry['version/version'], config_registry['version/patchlevel'], ) if config_registry.get('version/security-patchlevel'): sysversion = "%s-%s" % (sysversion, config_registry['version/security-patchlevel'], ) sysrole = config_registry['server/role'] ldaphostdn = config_registry['ldap/hostdn'] apt_pkg.init() architecture = apt_pkg.Config.find("APT::Architecture") log('start fill of testdb ') for sysname in ['testsystem%04d' % (i, ) for i in xrange(1, 1500)]: try: sql_put_sys_in_systems(cursor, sysname, sysversion, sysrole, ldaphostdn, architecture) fake_null = False except pgdb.DatabaseError: # assume we are connected to a univention-pkgdb < 6.0.7-1 (old schema) connection.rollback() # retry for old schema sql_put_sys_in_systems_no_architecture(cursor, sysname, sysversion, sysrole, ldaphostdn) fake_null = True # old schema has NOT NULL, thus we have to use '' instead of None scan_and_store_packages(cursor, sysname, fake_null) connection.commit() log('end of fill testdb') return 0