# Path: hardware/generate.py
# def is_included(dict1, dict2):
#     """Test if dict1 is included in dict2."""
# 
#     for key, value in dict1.items():
#         try:
#             if dict2[key] != value:
#                 return False
#         except KeyError:
#             return False
#     return True


import errno
import logging
import os
import pprint
import shutil
from hardware.generate import is_included
        if "generate(" in open(filename).read(20):
            shutil.copy2(filename, filename + ".orig")
    except IOError as xcpt:
        LOG.warning("Unable to backup CMDB (%s) %s" % (filename, str(xcpt)))
    # save the new version of the cmdb
    try:
        pprint.pprint(cmdb, stream=open(filename, 'w'))
    except IOError as xcpt:
        LOG.error("exception while saving CMDB (%s) %s" % (filename,
                                                           str(xcpt)))


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:

# Path: hardware/generate.py
# def is_included(dict1, dict2):
#     """Test if dict1 is included in dict2."""
# 
#     for key, value in dict1.items():
#         try:
#             if dict2[key] != value:
#                 return False
#         except KeyError:
#             return False
#     return True


# Path: hardware/cmdb.py
import errno
import logging
import os
import pprint
import shutil
from hardware.generate import is_included

        if "generate(" in open(filename).read(20):
            shutil.copy2(filename, filename + ".orig")
    except IOError as xcpt:
        LOG.warning("Unable to backup CMDB (%s) %s" % (filename, str(xcpt)))
    # save the new version of the cmdb
    try:
        pprint.pprint(cmdb, stream=open(filename, 'w'))
    except IOError as xcpt:
        LOG.error("exception while saving CMDB (%s) %s" % (filename,
                                                           str(xcpt)))


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):