Ticket #578: 0001-Added-an-admin-mode-to-bcfg2-so-we-can-find-out-what.patch

File 0001-Added-an-admin-mode-to-bcfg2-so-we-can-find-out-what.patch, 6.0 KB (added by stousignant@…, 11 years ago)

Patch to add an admin mode for deprecation detection

  • bcfg2/schemas/metadata.xsd

    From 8bde8ed2c279b492db1dca2bdbcc458d28a08ad1 Mon Sep 17 00:00:00 2001
    From: Steve Tousignant <steve@planes-laptop.(none)>
    Date: Tue, 15 Jul 2008 16:34:51 -0400
    Subject: [PATCH] Added an admin mode to bcfg2 so we can find out what group will get deprecated and when exactly
    
    This will help to clean up Bundler / Packages / Groups that are dangling but still used in the old profile.
    ---
     bcfg2/schemas/metadata.xsd               |    8 +++++-
     bcfg2/src/lib/Server/Admin/Deprecated.py |   44 ++++++++++++++++++++++++++++++
     bcfg2/src/lib/Server/Admin/__init__.py   |    2 +-
     bcfg2/src/lib/Server/Plugins/Metadata.py |   10 ++++++-
     4 files changed, 61 insertions(+), 3 deletions(-)
     create mode 100644 bcfg2/src/lib/Server/Admin/Deprecated.py
    
    diff --git a/bcfg2/schemas/metadata.xsd b/bcfg2/schemas/metadata.xsd
    index 9cb2e08..4615592 100644
    a b  
    2323    </xsd:restriction> 
    2424  </xsd:simpleType> 
    2525 
    26  
     26  <xsd:simpleType name='deprecatedType'> 
     27    <xsd:restriction base='xsd:string'> 
     28      <xsd:pattern value="now|[0-9]{4}-[0-9]{2}-[0-9]{2}" /> 
     29    </xsd:restriction> 
     30  </xsd:simpleType> 
     31   
    2732  <xsd:complexType name='groupType'> 
    2833    <xsd:choice minOccurs='0' maxOccurs='unbounded'> 
    2934      <xsd:element name='Bundle'> 
     
    4449    <xsd:attribute type='toolsetType' name='toolset' use='optional'/> 
    4550    <xsd:attribute type='xsd:string' name='category' use='optional'/> 
    4651    <xsd:attribute type='xsd:string' name='comment' use='optional'/> 
     52    <xsd:attribute type='deprecatedType' name='deprecated' use='optional' /> 
    4753  </xsd:complexType> 
    4854 
    4955  <xsd:complexType name='groupsType'> 
  • new file cfg2/src/lib/Server/Admin/Deprecated.py

    diff --git a/bcfg2/src/lib/Server/Admin/Deprecated.py b/bcfg2/src/lib/Server/Admin/Deprecated.py
    new file mode 100644
    index 0000000..a6650ba
    - +  
     1import Bcfg2.Server.Admin, Bcfg2.Logging, logging 
     2import datetime 
     3 
     4class Deprecated(Bcfg2.Server.Admin.Mode): 
     5    __shorthelp__ = 'bcfg2-admin deprecated [-d <days>] [-m <month>] [-y <years>]' 
     6    __longhelp__ = __shorthelp__ + '\n\tFind all clients that is in a deprecated group' 
     7 
     8    def __init__(self, configfile): 
     9        logging.root.setLevel(100) 
     10        Bcfg2.Logging.setup_logging(100, to_console=False, to_syslog=False) 
     11        Bcfg2.Server.Admin.Mode.__init__(self, configfile) 
     12         
     13        try: 
     14            self.bcore = Bcfg2.Server.Core.Core(self.get_repo_path(), 
     15                                                [], ['Metadata'], 
     16                                                'foo', False, 'UTF-8') 
     17        except Bcfg2.Server.Core.CoreInitError, msg: 
     18            self.errExit("Core load failed because %s" % msg) 
     19        [self.bcore.fam.Service() for _ in range(1)] 
     20        self.meta = self.bcore.metadata 
     21        while self.bcore.fam.Service(): 
     22            pass 
     23 
     24    def __call__(self, args): 
     25        Bcfg2.Server.Admin.Mode.__call__(self, args) 
     26        nextIsDay = False 
     27        days = 0 
     28        for arg in args: 
     29            if nextIsDay: 
     30                days = int(arg) 
     31            if arg == '-d': 
     32                nextIsDay = True 
     33 
     34        delta = datetime.timedelta(days) 
     35        for name, profile in self.meta.clients.items(): 
     36            endingSoonest = datetime.date(datetime.MAXYEAR,1,1) 
     37            for group in self.meta.groups[profile][1]: 
     38                if self.meta.deprecatedgroup.has_key(group): 
     39                    if endingSoonest > self.meta.deprecatedgroup[group]: 
     40                        endingSoonest = self.meta.deprecatedgroup[group] 
     41            datecheck = endingSoonest - delta 
     42            if datecheck < datetime.date.today(): 
     43                print "The client named %s will be deprecated the %s" % (name, endingSoonest.isoformat()) 
     44 
  • bcfg2/src/lib/Server/Admin/__init__.py

    diff --git a/bcfg2/src/lib/Server/Admin/__init__.py b/bcfg2/src/lib/Server/Admin/__init__.py
    index cff9eec..b66b069 100644
    a b  
    11__revision__ = '$Revision$' 
    22 
    33__all__ = ['Mode', 'Client', 'Compare', 'Fingerprint', 'Init', 'Minestruct', 
    4            'Pull', 'Query', 'Tidy', 'Viz'] 
     4           'Pull', 'Query', 'Tidy', 'Viz', 'Deprecated'] 
    55 
    66import ConfigParser, lxml.etree, logging 
    77 
  • bcfg2/src/lib/Server/Plugins/Metadata.py

    diff --git a/bcfg2/src/lib/Server/Plugins/Metadata.py b/bcfg2/src/lib/Server/Plugins/Metadata.py
    index 75b8045..3151412 100644
    a b  
    11'''This file stores persistent metadata for the BCFG Configuration Repository''' 
    22__revision__ = '$Revision$' 
    33 
    4 import lxml.etree, re, socket, time, fcntl, copy 
     4import lxml.etree, re, socket, time, fcntl, copy, datetime 
    55import Bcfg2.Server.Plugin 
    66 
    77class MetadataConsistencyError(Exception): 
    class Metadata(Bcfg2.Server.Plugin.MetadataPlugin, 
    192192            self.groups = {} 
    193193            grouptmp = {} 
    194194            self.categories = {} 
     195            self.deprecatedgroup = {} 
    195196            for group in xdata.xpath('//Groups/Group') \ 
    196197                    + xdata.xpath('Group'): 
    197198                grouptmp[group.get('name')] = tuple([[item.get('name') for item in group.findall(spec)] 
    class Metadata(Bcfg2.Server.Plugin.MetadataPlugin, 
    205206                    self.public.append(group.get('name')) 
    206207                if group.attrib.has_key('category'): 
    207208                    self.categories[group.get('name')] = group.get('category') 
     209                if group.attrib.has_key('deprecated'): 
     210                    if group.get('deprecated') == 'now': 
     211                        date = datetime.date.today() 
     212                    else: 
     213                        datestr = group.get('deprecated').split('-') 
     214                        date = datetime.date(int(datestr[0]), int(datestr[1]), int(datestr[2])) 
     215                    self.deprecatedgroup[group.get('name')] = date 
    208216            for group in grouptmp: 
    209217                # self.groups[group] => (bundles, groups, categories) 
    210218                self.groups[group] = ([], [], {})