diff options
Diffstat (limited to 'src/lib/Bcfg2/Server')
-rw-r--r-- | src/lib/Bcfg2/Server/Core.py | 2 | ||||
-rwxr-xr-x | src/lib/Bcfg2/Server/Encryption.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Ldap.py | 17 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Metadata.py | 6 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Packages/Apt.py | 10 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Probes.py | 5 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/migrations/0001_initial.py | 45 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/migrations/__init__.py | 0 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/models.py | 34 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/south_migrations/0001_initial.py | 70 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/south_migrations/__init__.py | 0 |
11 files changed, 172 insertions, 19 deletions
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index ad78800fb..445bc17b5 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -91,7 +91,7 @@ def close_db_connection(func): for connection in django.db.connections.all(): connection.close() else: - django.db.close_connection() + django.db.close_connection() # pylint: disable=E1101 return rv return inner diff --git a/src/lib/Bcfg2/Server/Encryption.py b/src/lib/Bcfg2/Server/Encryption.py index b60302871..c6cd4232e 100755 --- a/src/lib/Bcfg2/Server/Encryption.py +++ b/src/lib/Bcfg2/Server/Encryption.py @@ -176,7 +176,7 @@ def ssl_encrypt(plaintext, passwd, algorithm=None, salt=None): def is_encrypted(val): """ Make a best guess if the value is encrypted or not. This just checks to see if ``val`` is a base64-encoded string whose content - starts with "Salted__", so it may have (rare) false positives. It + starts with "Salted\\_\\_", so it may have (rare) false positives. It will not have false negatives. """ try: return b64decode(val).startswith("Salted__") diff --git a/src/lib/Bcfg2/Server/Plugins/Ldap.py b/src/lib/Bcfg2/Server/Plugins/Ldap.py index 895c6380f..757150300 100644 --- a/src/lib/Bcfg2/Server/Plugins/Ldap.py +++ b/src/lib/Bcfg2/Server/Plugins/Ldap.py @@ -119,22 +119,27 @@ class Ldap(Bcfg2.Server.Plugin.Plugin, class LdapConnection(Debuggable): """ Connection to an LDAP server. """ - __scopes__ = { - 'base': ldap.SCOPE_BASE, - 'one': ldap.SCOPE_ONELEVEL, - 'sub': ldap.SCOPE_SUBTREE, - } - def __init__(self, host="localhost", port=389, binddn=None, bindpw=None): Debuggable.__init__(self) + if HAS_LDAP: + msg = "Python ldap module is required for Ldap plugin" + self.logger.error(msg) + raise Bcfg2.Server.Plugin.PluginInitError(msg) + self.host = host self.port = port self.binddn = binddn self.bindpw = bindpw self.conn = None + self.__scopes__ = { + 'base': ldap.SCOPE_BASE, + 'one': ldap.SCOPE_ONELEVEL, + 'sub': ldap.SCOPE_SUBTREE, + } + def __del__(self): """ Disconnection if the instance is destroyed. """ self.disconnect() diff --git a/src/lib/Bcfg2/Server/Plugins/Metadata.py b/src/lib/Bcfg2/Server/Plugins/Metadata.py index 30f60fffe..40504e15e 100644 --- a/src/lib/Bcfg2/Server/Plugins/Metadata.py +++ b/src/lib/Bcfg2/Server/Plugins/Metadata.py @@ -42,6 +42,9 @@ def load_django_models(): HAS_DJANGO = False return + if django.VERSION[0] == 1 and django.VERSION[1] >= 7: + django.setup() # pylint: disable=E1101 + class MetadataClientModel(models.Model, # pylint: disable=W0621 Bcfg2.Server.Plugin.PluginDatabaseModel): """ django model for storing clients in the database """ @@ -100,9 +103,6 @@ def load_django_models(): except MetadataClientModel.DoesNotExist: return False - if django.VERSION[0] == 1 and django.VERSION[1] >= 7: - django.setup() # pylint: disable=E1101 - class XMLMetadataConfig(Bcfg2.Server.Plugin.XMLFileBacked): """Handles xml config files and all XInclude statements""" diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Apt.py b/src/lib/Bcfg2/Server/Plugins/Packages/Apt.py index 7de79e2f3..2637fadfe 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Apt.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Apt.py @@ -34,8 +34,12 @@ class AptCollection(Collection): for source in self: if source.rawurl: - self.logger.info("Packages: Skipping rawurl %s" % - source.rawurl) + if source.rawurl[-1] != '/': + source.rawurl = source.rawurl + "/" + index = source.rawurl.rfind("/", 0, -1) + lines.append("deb %s %s" % + (source.rawurl[:index], + source.rawurl[index + 1:])) else: lines.append("deb %s %s %s" % (source.url, source.version, " ".join(source.components))) @@ -44,7 +48,7 @@ class AptCollection(Collection): (source.url, source.version, " ".join(source.components))) - lines.append("") + lines.append("") return "\n".join(lines) diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py index 573c9af71..33b0d4284 100644 --- a/src/lib/Bcfg2/Server/Plugins/Probes.py +++ b/src/lib/Bcfg2/Server/Plugins/Probes.py @@ -27,13 +27,18 @@ def load_django_models(): # pylint: disable=W0602 global ProbesDataModel, ProbesGroupsModel, HAS_DJANGO # pylint: enable=W0602 + try: + import django from django.db import models HAS_DJANGO = True except ImportError: HAS_DJANGO = False return + if django.VERSION[0] == 1 and django.VERSION[1] >= 7: + django.setup() # pylint: disable=E1101 + class ProbesDataModel(models.Model, # pylint: disable=W0621,W0612 Bcfg2.Server.Plugin.PluginDatabaseModel): """ The database model for storing probe data """ diff --git a/src/lib/Bcfg2/Server/migrations/0001_initial.py b/src/lib/Bcfg2/Server/migrations/0001_initial.py new file mode 100644 index 000000000..3b3dca455 --- /dev/null +++ b/src/lib/Bcfg2/Server/migrations/0001_initial.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.9 on 2016-08-17 18:52 +from __future__ import unicode_literals + +import Bcfg2.Server.Plugin.helpers +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='MetadataClientModel', + fields=[ + ('hostname', models.CharField(max_length=255, primary_key=True, serialize=False)), + ('version', models.CharField(max_length=31, null=True)), + ], + bases=(models.Model, Bcfg2.Server.Plugin.helpers.PluginDatabaseModel), + ), + migrations.CreateModel( + name='ProbesDataModel', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('hostname', models.CharField(max_length=255)), + ('probe', models.CharField(max_length=255)), + ('timestamp', models.DateTimeField(auto_now=True)), + ('data', models.TextField(null=True)), + ], + bases=(models.Model, Bcfg2.Server.Plugin.helpers.PluginDatabaseModel), + ), + migrations.CreateModel( + name='ProbesGroupsModel', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('hostname', models.CharField(max_length=255)), + ('group', models.CharField(max_length=255)), + ], + bases=(models.Model, Bcfg2.Server.Plugin.helpers.PluginDatabaseModel), + ), + ] diff --git a/src/lib/Bcfg2/Server/migrations/__init__.py b/src/lib/Bcfg2/Server/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/lib/Bcfg2/Server/migrations/__init__.py diff --git a/src/lib/Bcfg2/Server/models.py b/src/lib/Bcfg2/Server/models.py index 9c0153c74..7f28fd0d8 100644 --- a/src/lib/Bcfg2/Server/models.py +++ b/src/lib/Bcfg2/Server/models.py @@ -4,20 +4,44 @@ import sys import logging import Bcfg2.Options import Bcfg2.Server.Plugins +from Bcfg2.Compat import walk_packages -LOGGER = logging.getLogger(__name__) +LOGGER = logging.getLogger('Bcfg2.Server.models') MODELS = [] INTERNAL_DATABASE_VERSION = None -class _OptionContainer(object): - """Options for Bcfg2 database models.""" +def _get_all_plugins(): + rv = [] + for submodule in walk_packages(path=Bcfg2.Server.Plugins.__path__, + prefix="Bcfg2.Server.Plugins."): + module = submodule[1].rsplit('.', 1)[-1] + if module == 'Reporting': + # Exclude Reporting plugin. The reporting database + # is handled separately in Bcfg2.Reporting. + continue + if submodule[1] == "Bcfg2.Server.Plugins.%s" % module: + # we only include direct children of + # Bcfg2.Server.Plugins -- e.g., all_plugins should + # include Bcfg2.Server.Plugins.Cfg, but not + # Bcfg2.Server.Plugins.Cfg.CfgInfoXML + rv.append(module) + return rv + + +_ALL_PLUGINS = _get_all_plugins() + +class _OptionContainer(object): # we want to provide a different default plugin list -- # namely, _all_ plugins, so that the database is guaranteed to # work, even if /etc/bcfg2.conf isn't set up properly - options = [Bcfg2.Options.Common.plugins] + options = [ + Bcfg2.Options.Option( + cf=('server', 'plugins'), type=Bcfg2.Options.Types.comma_list, + default=_ALL_PLUGINS, dest="models_plugins", + action=Bcfg2.Options.PluginsAction)] @staticmethod def options_parsed_hook(): @@ -39,7 +63,7 @@ def load_models(plugins=None): global MODELS if not plugins: - plugins = Bcfg2.Options.setup.plugins + plugins = Bcfg2.Options.setup.models_plugins if MODELS: # load_models() has been called once, so first unload all of diff --git a/src/lib/Bcfg2/Server/south_migrations/0001_initial.py b/src/lib/Bcfg2/Server/south_migrations/0001_initial.py new file mode 100644 index 000000000..864c311e5 --- /dev/null +++ b/src/lib/Bcfg2/Server/south_migrations/0001_initial.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +from south.utils import datetime_utils as datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding model 'MetadataClientModel' + db.create_table(u'Server_metadataclientmodel', ( + ('hostname', self.gf('django.db.models.fields.CharField')(max_length=255, primary_key=True)), + ('version', self.gf('django.db.models.fields.CharField')(max_length=31, null=True)), + )) + db.send_create_signal('Server', ['MetadataClientModel']) + + # Adding model 'ProbesDataModel' + db.create_table(u'Server_probesdatamodel', ( + (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('hostname', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('probe', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('timestamp', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), + ('data', self.gf('django.db.models.fields.TextField')(null=True)), + )) + db.send_create_signal('Server', ['ProbesDataModel']) + + # Adding model 'ProbesGroupsModel' + db.create_table(u'Server_probesgroupsmodel', ( + (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('hostname', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('group', self.gf('django.db.models.fields.CharField')(max_length=255)), + )) + db.send_create_signal('Server', ['ProbesGroupsModel']) + + + def backwards(self, orm): + # Deleting model 'MetadataClientModel' + db.delete_table(u'Server_metadataclientmodel') + + # Deleting model 'ProbesDataModel' + db.delete_table(u'Server_probesdatamodel') + + # Deleting model 'ProbesGroupsModel' + db.delete_table(u'Server_probesgroupsmodel') + + + models = { + 'Server.metadataclientmodel': { + 'Meta': {'object_name': 'MetadataClientModel'}, + 'hostname': ('django.db.models.fields.CharField', [], {'max_length': '255', 'primary_key': 'True'}), + 'version': ('django.db.models.fields.CharField', [], {'max_length': '31', 'null': 'True'}) + }, + 'Server.probesdatamodel': { + 'Meta': {'object_name': 'ProbesDataModel'}, + 'data': ('django.db.models.fields.TextField', [], {'null': 'True'}), + 'hostname': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'probe': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}) + }, + 'Server.probesgroupsmodel': { + 'Meta': {'object_name': 'ProbesGroupsModel'}, + 'group': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'hostname': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) + } + } + + complete_apps = ['Server']
\ No newline at end of file diff --git a/src/lib/Bcfg2/Server/south_migrations/__init__.py b/src/lib/Bcfg2/Server/south_migrations/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/lib/Bcfg2/Server/south_migrations/__init__.py |