Beispiel #1
0
def update_cmdb(cmdb, var, pref, forced_find):
    '''Handle CMDB settings if present.

CMDB is updated with var. var is also augmented with the cmdb entry
found.
'''

    def update_entry(entry, cmdb, idx):
        'Update var using a cmdb entry and save the full cmdb on disk.'
        entry.update(var)
        var.update(entry)
        var['used'] = 1
        cmdb[idx] = var

    # First pass to lookup if the var is already in the database
    # and if this is the case, reuse the entry.
    idx = 0
    for entry in cmdb:
        if is_included(pref, entry):
            update_entry(entry, cmdb, idx)
            break
        idx += 1
    else:
        # not looking for $$ type matches
        if not forced_find:
            # Second pass, find a not used entry.
            idx = 0
            for entry in cmdb:
                if 'used' not in entry:
                    update_entry(entry, cmdb, idx)
                    break
                idx += 1
            else:
                raise CmdbError("No more entry in the CMDB, aborting.")
        else:
            raise CmdbError("No entry matched in the CMDB, aborting.")
    return True
Beispiel #2
0
 def test_is_included_more(self):
     a = {'a': 1, 'b': 2}
     b = {'a': 1, 'b': 2, 'c': 3}
     self.assertTrue(generate.is_included(a, b))
Beispiel #3
0
 def test_is_included_different(self):
     a = {'a': 1}
     b = {'a': 2}
     self.assertTrue(not generate.is_included(a, b))
Beispiel #4
0
 def test_is_included_same(self):
     a = {'a': 1}
     self.assertTrue(generate.is_included(a, a))
Beispiel #5
0
 def test_is_included_more(self):
     a = {'a': 1, 'b': 2}
     b = {'a': 1, 'b': 2, 'c': 3}
     self.assertTrue(generate.is_included(a, b))
Beispiel #6
0
 def test_is_included_different(self):
     a = {'a': 1}
     b = {'a': 2}
     self.assertTrue(not generate.is_included(a, b))
Beispiel #7
0
 def test_is_included_same(self):
     a = {'a': 1}
     self.assertTrue(generate.is_included(a, a))