[989] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | # $Id: $
|
---|
| 3 | #
|
---|
| 4 | # automatically generate the database model for web2py
|
---|
| 5 | # from the info we already have for dassModus
|
---|
| 6 | #
|
---|
| 7 | #
|
---|
| 8 | # we do have every information about the bacula configuration files.
|
---|
| 9 | # we now have to create the following database model:
|
---|
| 10 | # a table for each main configuration file:
|
---|
| 11 | # dird_conf,
|
---|
| 12 | # filed_conf,
|
---|
| 13 | # stored_conf,
|
---|
| 14 | # bconsole_conf
|
---|
| 15 | #
|
---|
| 16 | # in each bacula configuration file, we have two classes of ressources:
|
---|
| 17 | # 1.: Ressources, that can only appear once
|
---|
| 18 | # here, we can just create a reference to a table containing the
|
---|
| 19 | # configuration options of this ressource.
|
---|
| 20 | #
|
---|
| 21 | #
|
---|
| 22 | #
|
---|
| 23 | # 2.: Ressources, that can appear multiple times
|
---|
| 24 | # we need a table between the bacula configuration and the list of ressources.
|
---|
| 25 | #
|
---|
| 26 | # here, we have a link to a list of ressources
|
---|
| 27 | # example: a dird can have multiple client ressources:
|
---|
| 28 | #
|
---|
| 29 | #
|
---|
| 30 | #
|
---|
| 31 | #
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | from nosferatu.config_classes import *
|
---|
| 35 | from resource import Resource
|
---|
| 36 | from nosferatu import prettynames, auto_configrules
|
---|
| 37 |
|
---|
| 38 | #single_res=['dir_res']
|
---|
| 39 | ## this ressource can only appear once in the dir conf
|
---|
| 40 | #for res in single_res:
|
---|
| 41 | # print """db.define_table('dird_conf-%s',
|
---|
| 42 | # Field('name','string'),
|
---|
| 43 | # format='%%s(name)s)'
|
---|
| 44 | # """ % (res)
|
---|
| 45 |
|
---|
| 46 | #print """db.define_table('dird_conf',
|
---|
| 47 | # Field('name','string'),"""
|
---|
| 48 | #for res in single_res:
|
---|
| 49 | # print " Field('dird_conf-%s', reference dird_conf-%s)," % (res,res )
|
---|
| 50 | #print " format='%(name)s')"
|
---|
| 51 |
|
---|
| 52 |
|
---|
[990] | 53 |
|
---|
[991] | 54 | def item2field(confshort, item):
|
---|
[990] | 55 | if item.name == 'where' : # where cannot be a column name in sqlite
|
---|
| 56 | item.name = 'where_'
|
---|
| 57 |
|
---|
| 58 | if item.name in INTERNALLY_REFERENCED_ITEMS:
|
---|
| 59 | refname = item.name
|
---|
| 60 | if item.name.endswith('pool'):
|
---|
| 61 | refname = 'pool'
|
---|
[991] | 62 | print '### ' + refname
|
---|
| 63 |
|
---|
| 64 | fieldtype = 'reference %s_conf__%s' % (confshort,refname)
|
---|
[990] | 65 | defaultvalue = 0
|
---|
| 66 | return """ Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
|
---|
| 67 | else:
|
---|
| 68 | fieldtype = 'string'
|
---|
| 69 | defaultvalue = item.defaultvalue
|
---|
| 70 | if item.type == "store_bool":
|
---|
| 71 | fieldtype = "boolean"
|
---|
[991] | 72 | #print "#####%s %s %s" % (item.name, item.defaultvalue, defaultvalue)
|
---|
[990] | 73 | return """ Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
|
---|
| 74 | return """ Field('%s','%s', default='%s'), """ %(item.name, fieldtype , defaultvalue)
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 |
|
---|
[989] | 81 | dir_res_list = list()
|
---|
| 82 |
|
---|
[991] | 83 | confshort = 'dird'
|
---|
[989] | 84 | for res in auto_configrules.dird_resources:
|
---|
| 85 | res_name = res[0]
|
---|
| 86 | res_type = res[1]
|
---|
| 87 | res_items = res[2]
|
---|
| 88 | dir_res_list.append(res_name)
|
---|
| 89 | print
|
---|
| 90 | #print res_name
|
---|
[991] | 91 | print """db.define_table('%s_conf__%s', """ % (confshort,res_name)
|
---|
[989] | 92 | for item in res_items:
|
---|
| 93 | item.required=False
|
---|
| 94 | item.printall=True
|
---|
[991] | 95 | print item2field(confshort,item)
|
---|
[989] | 96 | print """ format='%(name)s')"""
|
---|
| 97 |
|
---|
| 98 |
|
---|
[991] | 99 | confshort = 'stored'
|
---|
[989] | 100 | stor_res_list = list()
|
---|
| 101 | for res in auto_configrules.stored_resources:
|
---|
| 102 | res_name = res[0]
|
---|
| 103 | res_type = res[1]
|
---|
| 104 | res_items = res[2]
|
---|
| 105 | stor_res_list.append(res_name)
|
---|
| 106 | print
|
---|
| 107 | #print res_name
|
---|
[991] | 108 | print """db.define_table('%s_conf__%s', """ % (confshort,res_name)
|
---|
[989] | 109 | for item in res_items:
|
---|
| 110 | item.required=False
|
---|
| 111 | item.printall=True
|
---|
[991] | 112 | print item2field(confshort,item)
|
---|
[989] | 113 | print """ format='%(name)s')"""
|
---|
| 114 |
|
---|
| 115 |
|
---|
[991] | 116 | confshort = 'filed'
|
---|
[989] | 117 | filed_res_list = list()
|
---|
| 118 | for res in auto_configrules.filed_resources:
|
---|
| 119 | res_name = res[0]
|
---|
| 120 | res_type = res[1]
|
---|
| 121 | res_items = res[2]
|
---|
| 122 | filed_res_list.append(res_name)
|
---|
| 123 | print
|
---|
| 124 | #print res_name
|
---|
[991] | 125 | print """db.define_table('%s_conf__%s', """ % (confshort,res_name)
|
---|
[989] | 126 | for item in res_items:
|
---|
| 127 | item.required=False
|
---|
| 128 | item.printall=True
|
---|
[991] | 129 | print item2field(confshort,item)
|
---|
[989] | 130 | print """ format='%(name)s')"""
|
---|
| 131 |
|
---|
[991] | 132 | confshort = 'cons'
|
---|
| 133 | cons_res_list = list()
|
---|
| 134 | for res in auto_configrules.console_resources:
|
---|
| 135 | res_name = res[0]
|
---|
| 136 | res_type = res[1]
|
---|
| 137 | res_items = res[2]
|
---|
| 138 | cons_res_list.append(res_name)
|
---|
| 139 | print
|
---|
| 140 | #print res_name
|
---|
| 141 | print """db.define_table('%s_conf__%s', """ % (confshort,res_name)
|
---|
| 142 | for item in res_items:
|
---|
| 143 | item.required=False
|
---|
| 144 | item.printall=True
|
---|
| 145 | print item2field(confshort,item)
|
---|
| 146 | print """ format='%(name)s')"""
|
---|
[989] | 147 |
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 |
|
---|
[991] | 152 | for res in dir_res_list:
|
---|
| 153 | print """db.define_table('dird_conf__%s_link',
|
---|
| 154 | Field('%s','reference dird_conf__%s'),
|
---|
| 155 | format = '%%(id)s')
|
---|
| 156 | """ % (res,res,res)
|
---|
| 157 | print """db.define_table('dird_conf',
|
---|
| 158 | Field('name','string'),"""
|
---|
[989] | 159 |
|
---|
[991] | 160 | for res in dir_res_list:
|
---|
| 161 | print " Field('dird_conf__%s', 'reference dird_conf__%s_link')," % (res,res )
|
---|
| 162 | print """ format='%(name)s')
|
---|
| 163 | """
|
---|
[989] | 164 |
|
---|
| 165 |
|
---|
| 166 |
|
---|
[991] | 167 | for res in stor_res_list:
|
---|
| 168 | print """db.define_table('stord_conf__%s_link',
|
---|
| 169 | Field('%s','reference stord_conf__%s'),
|
---|
[989] | 170 | format = '%%(id)s')
|
---|
| 171 | """ % (res,res,res)
|
---|
[991] | 172 | print """db.define_table('stord_conf',
|
---|
| 173 | Field('name','string'),"""
|
---|
[989] | 174 |
|
---|
[991] | 175 | for res in stor_res_list:
|
---|
| 176 | print " Field('stord_conf__%s', 'reference stord_conf__%s_link')," % (res,res )
|
---|
| 177 | print """ format='%(name)s')
|
---|
| 178 | """
|
---|
[989] | 179 |
|
---|
| 180 |
|
---|
[991] | 181 |
|
---|
| 182 | for res in filed_res_list:
|
---|
| 183 | print """db.define_table('filed_conf__%s_link',
|
---|
| 184 | Field('%s','reference filed_conf__%s'),
|
---|
| 185 | format = '%%(id)s')
|
---|
| 186 | """ % (res,res,res)
|
---|
| 187 | print """db.define_table('filed_conf',
|
---|
[989] | 188 | Field('name','string'),"""
|
---|
[991] | 189 |
|
---|
| 190 | for res in filed_res_list:
|
---|
| 191 | print " Field('filed_conf__%s', 'reference filed_conf__%s_link')," % (res,res )
|
---|
[989] | 192 | print """ format='%(name)s')
|
---|
| 193 | """
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 |
|
---|
[991] | 198 | for res in cons_res_list:
|
---|
| 199 | print """db.define_table('cons_conf__%s_link',
|
---|
| 200 | Field('%s','reference cons_conf__%s'),
|
---|
| 201 | format = '%%(id)s')
|
---|
| 202 | """ % (res,res,res)
|
---|
| 203 | print """db.define_table('cons_conf',
|
---|
| 204 | Field('name','string'),"""
|
---|
[989] | 205 |
|
---|
[991] | 206 | for res in cons_res_list:
|
---|
| 207 | print " Field('cons_conf__%s', 'reference cons_conf__%s_link')," % (res,res )
|
---|
| 208 | print """ format='%(name)s')
|
---|
| 209 | """
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | #Abhängikeiten:
|
---|
| 213 | # dird
|
---|
| 214 | # job/jobdefs ->client
|
---|
| 215 | # -> pool
|
---|
| 216 | # -> fileset
|
---|
| 217 | # -> pool
|
---|
| 218 | # -> messages
|
---|
| 219 | # -> schedule
|
---|
| 220 | # -> storage
|
---|
| 221 | # -> jobdefs
|
---|
| 222 | # -> job
|
---|
| 223 | # messages -> catalog
|
---|
| 224 | # counter -> catalog
|
---|
| 225 | # storage -> device
|
---|
| 226 | # director -> messages
|
---|
| 227 | # client -> catalog
|
---|
| 228 | # pool -> catalog, storage
|
---|
| 229 |
|
---|
| 230 |
|
---|
| 231 | # Reihenfolge:
|
---|
| 232 | # storage->catalog->fileset->pool->jobdefs->client->
|
---|
| 233 | # counter->messages->job->director
|
---|
| 234 |
|
---|
| 235 |
|
---|
| 236 |
|
---|
| 237 | # stored:
|
---|
| 238 | # autochanger -> device
|
---|
| 239 | # storage -> messages
|
---|
| 240 | # messages -> catalog
|
---|
| 241 |
|
---|
| 242 | # filed:
|
---|
| 243 | # messages -> catalog
|
---|
| 244 | # client/filedaemon -> messages
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 |
|
---|
| 249 |
|
---|