'Add an object to the collection
with_copy is a bit of a misnomer, but lots of internal add operations
can run with "with_copy" as False. True means a real final commit, as if
entered from the command line (or basically, by a user).
With with_copy as False, the particular add call might just be being run
during deserialization, in which case extra semantics around the add don\'t really apply.
So, in that case, don\'t run any triggers and don\'t deal with any actual files.'

def add(self, ref, save=False, with_copy=False, with_triggers=True, with_sync=True, quick_pxe_update=False, check_for_duplicate_names=False, check_for_duplicate_netinfo=False, logger=None):

    item_base.Item.remove_from_cache(ref)
    if (ref is None):
        raise CX('Unable    to    add    a    None    object')
    if (ref.name is None):
        raise CX('Unable    to    add    an    object    without    a    name')
    ref.check_if_valid()
    if (ref.uid == ''):
        ref.uid = self.collection_mgr.generate_uid()
    if (save is True):
        now = time.time()
        if (ref.ctime == 0):
            ref.ctime = now
        ref.mtime = now
    if (self.lite_sync is None):
        self.lite_sync = action_litesync.CobblerLiteSync(self.collection_mgr, logger=logger)
    if (with_copy and (not save)):
        save = with_copy
    if (not save):
        with_triggers = False
        with_sync = False
    self.__duplication_checks(ref, check_for_duplicate_names, check_for_duplicate_netinfo)
    if (ref.COLLECTION_TYPE != self.collection_type()):
        raise CX(_('API    error:    storing    wrong    data    type    in    collection'))
    if (save and with_triggers):
        utils.run_triggers(self.api, ref, ('/var/lib/cobbler/triggers/add/%s/pre/*' % self.collection_type()))
    self.lock.acquire()
    try:
        self.listing[ref.name.lower()] = ref
    finally:
        self.lock.release()
    if save:
        self.collection_mgr.serialize_item(self, ref)
        if with_sync:
            if isinstance(ref, item_system.System):
                if (ref.virt_type == 'openvz'):
                    ref.netboot_enabled = False
                self.lite_sync.add_single_system(ref.name)
            elif isinstance(ref, item_profile.Profile):
                if (ref.virt_type == 'openvz'):
                    ref.enable_menu = 0
                self.lite_sync.add_single_profile(ref.name)
            elif isinstance(ref, item_distro.Distro):
                self.lite_sync.add_single_distro(ref.name)
            elif isinstance(ref, item_image.Image):
                self.lite_sync.add_single_image(ref.name)
            elif isinstance(ref, item_repo.Repo):
                pass
            elif isinstance(ref, item_mgmtclass.Mgmtclass):
                pass
            elif isinstance(ref, item_package.Package):
                pass
            elif isinstance(ref, item_file.File):
                pass
            else:
                print (_('Internal    error.    Object    type    not    recognized:    %s') % type(ref))
        if ((not with_sync) and quick_pxe_update):
            if isinstance(ref, item_system.System):
                self.lite_sync.update_system_netboot_status(ref.name)
        if with_triggers:
            utils.run_triggers(self.api, ref, '/var/lib/cobbler/triggers/change/*', [], logger)
            utils.run_triggers(self.api, ref, ('/var/lib/cobbler/triggers/add/%s/post/*' % self.collection_type()), [], logger)
    parent = ref.get_parent()
    if (parent is not None):
        parent.children[ref.name] = ref
