summaryrefslogtreecommitdiffstats
path: root/src/lib/Server
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-01-13 20:00:16 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-01-13 20:00:16 +0000
commit5b8fd8cb103f31ef0d67c0fd4bbedfec0988c6af (patch)
tree42156b849284060c18d5e19b893473b4375dca7a /src/lib/Server
parent95e0e4207468efc253aabe0d36dfb816aac59653 (diff)
downloadbcfg2-5b8fd8cb103f31ef0d67c0fd4bbedfec0988c6af.tar.gz
bcfg2-5b8fd8cb103f31ef0d67c0fd4bbedfec0988c6af.tar.bz2
bcfg2-5b8fd8cb103f31ef0d67c0fd4bbedfec0988c6af.zip
Add support for alternate VCS backends
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5023 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server')
-rw-r--r--src/lib/Server/Core.py38
-rwxr-xr-xsrc/lib/Server/Reports/importscript.py16
-rw-r--r--src/lib/Server/Reports/reports/fixtures/initial_version.xml4
-rw-r--r--src/lib/Server/Reports/reports/models_new.py2
-rw-r--r--src/lib/Server/Reports/reports/models_old.py2
-rw-r--r--src/lib/Server/Reports/reports/templates/clients/client-nodebox.html2
-rw-r--r--src/lib/Server/Reports/updatefix.py4
7 files changed, 48 insertions, 20 deletions
diff --git a/src/lib/Server/Core.py b/src/lib/Server/Core.py
index 0961ed23a..a99af4aa9 100644
--- a/src/lib/Server/Core.py
+++ b/src/lib/Server/Core.py
@@ -1,5 +1,9 @@
'''Bcfg2.Server.Core provides the runtime support for bcfg2 modules'''
-__revision__ = '$Revision$'
+__revision__ = '$Revision: 5014 $'
+
+from ConfigParser import ConfigParser, NoSectionError, NoOptionError
+c = ConfigParser()
+c.read('/etc/bcfg2.conf')
from time import time
@@ -24,7 +28,7 @@ class CoreInitError(Exception):
class Core(object):
'''The Core object is the container for all Bcfg2 Server logic, and modules'''
- def __init__(self, repo, plugins, password, svn, encoding,
+ def __init__(self, repo, plugins, password, vcs, encoding,
filemonitor='default'):
object.__init__(self)
self.datastore = repo
@@ -41,13 +45,15 @@ class Core(object):
self.plugins = {}
self.revision = '-1'
self.password = password
- self.svn = svn
self.encoding = encoding
try:
- if self.svn:
+ self.vcs = c.get('server', 'vcs')
+ if self.vcs == 'svn':
self.read_svn_revision()
+ elif self.vcs == 'git':
+ self.read_git_revision()
except:
- self.svn = False
+ self.vcs = 'none'
if '' in plugins:
plugins.remove('')
@@ -208,8 +214,24 @@ class Core(object):
def Service(self):
'''Perform periodic update tasks'''
count = self.fam.Service()
- if count and self.svn:
- self.read_svn_revision()
+ if count:
+ if self.vcs == 'svn':
+ self.read_svn_revision()
+ elif self.vcs == 'git':
+ self.read_git_revision()
+
+ def read_git_revision(self):
+ try:
+ data = os.popen("env LC_ALL=C git ls-remote %s" %
+ (self.datastore)).readlines()
+ revline = [line.split('\t')[0].strip() for line in data if \
+ line.split('\t')[1].strip() == 'refs/heads/master'][-1]
+ self.revision = revline
+ except IndexError:
+ logger.error("Failed to read git ls-remote; disabling git support")
+ logger.error('''Ran command "git ls-remote %s"''' % (self.datastore))
+ logger.error("Got output: %s" % data)
+ self.vcs = 'none'
def read_svn_revision(self):
'''Read svn revision information for the bcfg2 repository'''
@@ -223,7 +245,7 @@ class Core(object):
logger.error("Failed to read svn info; disabling svn support")
logger.error('''Ran command "svn info %s"''' % (self.datastore))
logger.error("Got output: %s" % data)
- self.svn = False
+ self.vcs = 'none'
def GetDecisions(self, metadata, mode):
result = []
diff --git a/src/lib/Server/Reports/importscript.py b/src/lib/Server/Reports/importscript.py
index 763056c20..bb26647f2 100755
--- a/src/lib/Server/Reports/importscript.py
+++ b/src/lib/Server/Reports/importscript.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
'''Imports statistics.xml and clients.xml files in to database backend for new statistics engine'''
-__revision__ = '$Revision$'
+__revision__ = '$Revision: 4999 $'
import os, sys, binascii
try:
@@ -98,13 +98,13 @@ def load_stats(cdata, sdata, vlevel, quick=False, location=''):
continue
else:
newint = Interaction(client=c_inst,
- timestamp=timestamp,
- state=statistics.get('state', default="unknown"),
- repo_revision=statistics.get('revision',default="unknown"),
- client_version=statistics.get('client_version',default="unknown"),
- goodcount=statistics.get('good',default="0"),
- totalcount=statistics.get('total',default="0"),
- server=location)
+ timestamp = timestamp,
+ state = statistics.get('state', default="unknown"),
+ repo_rev_code = statistics.get('revision',default="unknown"),
+ client_version = statistics.get('client_version',default="unknown"),
+ goodcount = statistics.get('good',default="0"),
+ totalcount = statistics.get('total',default="0"),
+ server = location)
newint.save()
current_interaction = newint
if vlevel > 0:
diff --git a/src/lib/Server/Reports/reports/fixtures/initial_version.xml b/src/lib/Server/Reports/reports/fixtures/initial_version.xml
index 9edb8fe57..4fc05b7af 100644
--- a/src/lib/Server/Reports/reports/fixtures/initial_version.xml
+++ b/src/lib/Server/Reports/reports/fixtures/initial_version.xml
@@ -20,4 +20,8 @@
<field type='IntegerField' name='version'>10</field>
<field type='DateTimeField' name='updated'>2008-08-22 11:28:50</field>
</object>
+ <object pk="5" model="reports.internaldatabaseversion">
+ <field type='IntegerField' name='version'>11</field>
+ <field type='DateTimeField' name='updated'>2009-01-13 12:26:10</field>
+ </object>
</django-objects>
diff --git a/src/lib/Server/Reports/reports/models_new.py b/src/lib/Server/Reports/reports/models_new.py
index 3b1a005da..c8f649089 100644
--- a/src/lib/Server/Reports/reports/models_new.py
+++ b/src/lib/Server/Reports/reports/models_new.py
@@ -111,7 +111,7 @@ class Interaction(models.Model):
client = models.ForeignKey(Client, related_name="interactions",)
timestamp = models.DateTimeField()#Timestamp for this record
state = models.CharField(max_length=32)#good/bad/modified/etc
- repo_revision = models.IntegerField()#repo revision at time of interaction
+ repo_rev_code = models.CharField(max_length=64)#repo revision at time of interaction
client_version = models.CharField(max_length=32)#Client Version
goodcount = models.IntegerField()#of good config-items
totalcount = models.IntegerField()#of total config-items
diff --git a/src/lib/Server/Reports/reports/models_old.py b/src/lib/Server/Reports/reports/models_old.py
index a45fb0d30..aee66fd7d 100644
--- a/src/lib/Server/Reports/reports/models_old.py
+++ b/src/lib/Server/Reports/reports/models_old.py
@@ -111,7 +111,7 @@ class Interaction(models.Model):
client = models.ForeignKey(Client, related_name="interactions", core=True)
timestamp = models.DateTimeField()#Timestamp for this record
state = models.CharField(maxlength=32)#good/bad/modified/etc
- repo_revision = models.IntegerField()#repo revision at time of interaction
+ repo_rev_code = models.CharField(maxlength=64)#repo revision at time of interaction
client_version = models.CharField(maxlength=32)#Client Version
goodcount = models.IntegerField()#of good config-items
totalcount = models.IntegerField()#of total config-items
diff --git a/src/lib/Server/Reports/reports/templates/clients/client-nodebox.html b/src/lib/Server/Reports/reports/templates/clients/client-nodebox.html
index daa8bb245..5aae03c30 100644
--- a/src/lib/Server/Reports/reports/templates/clients/client-nodebox.html
+++ b/src/lib/Server/Reports/reports/templates/clients/client-nodebox.html
@@ -9,7 +9,7 @@
<tr><td width="43%"><h2>Node: <span class="nodename">
<a href="{% url Bcfg2.Server.Reports.reports.views.client_detail client.name,pk=i.id %}">{{client.name}}</a></span></h2></td>
<td width="23%">
- {% if interaction.repo_revision %}Revision: {{interaction.repo_revision}}{% endif %}
+ {% if interaction.repo_rev_code %}Revision: {{interaction.repo_rev_code}}{% endif %}
</td>
<td width="33%"><div class="statusborder">
<div class="greenbar" style="width: {{interaction.percentgood}}%;">&nbsp;</div>
diff --git a/src/lib/Server/Reports/updatefix.py b/src/lib/Server/Reports/updatefix.py
index f3679892e..4a35c31ea 100644
--- a/src/lib/Server/Reports/updatefix.py
+++ b/src/lib/Server/Reports/updatefix.py
@@ -60,6 +60,8 @@ _fixes = [_merge_database_table_entries,
"drop table reports_repository;",
"drop table reports_metadata;",
"alter table reports_interaction add server varchar(256) not null default 'N/A';",
+ # fix revision data type to support $VCS hashes
+ "alter table reports_interaction add repo_rev_code varchar(64) default '';",
]
# this will calculate the last possible version of the database
@@ -95,7 +97,7 @@ def dosync():
# if we get here with no error then the database has existing tables
fresh = False
except:
- logger.debug("there was an error while detecting the freshnest of the database")
+ logger.debug("there was an error while detecting the freshness of the database")
#we should get here if the database is new
fresh = True