'Prevents adding objects with the same name.
Prevents adding or editing to provide the same IP, or MAC.
Enforcement is based on whether the API caller requests it.'

def __duplication_checks(self, ref, check_for_duplicate_names, check_for_duplicate_netinfo):

    if check_for_duplicate_names:
        match = None
        if isinstance(ref, item_system.System):
            match = self.api.find_system(ref.name)
        elif isinstance(ref, item_profile.Profile):
            match = self.api.find_profile(ref.name)
        elif isinstance(ref, item_distro.Distro):
            match = self.api.find_distro(ref.name)
        elif isinstance(ref, item_repo.Repo):
            match = self.api.find_repo(ref.name)
        elif isinstance(ref, item_image.Image):
            match = self.api.find_image(ref.name)
        elif isinstance(ref, item_mgmtclass.Mgmtclass):
            match = self.api.find_mgmtclass(ref.name)
        elif isinstance(ref, item_package.Package):
            match = self.api.find_package(ref.name)
        elif isinstance(ref, item_file.File):
            match = self.api.find_file(ref.name)
        else:
            raise CX('internal    error,    unknown    object    type')
        if match:
            raise CX(_("An    object    already    exists    with    that    name.        Try    'edit'?"))
    if (not check_for_duplicate_netinfo):
        return
    if isinstance(ref, item_system.System):
        for (name, intf) in ref.interfaces.iteritems():
            match_ip = []
            match_mac = []
            match_hosts = []
            input_mac = intf['mac_address']
            input_ip = intf['ip_address']
            input_dns = intf['dns_name']
            if ((not self.api.settings().allow_duplicate_macs) and (input_mac is not None) and (input_mac != '')):
                match_mac = self.api.find_system(mac_address=input_mac, return_list=True)
            if ((not self.api.settings().allow_duplicate_ips) and (input_ip is not None) and (input_ip != '')):
                match_ip = self.api.find_system(ip_address=input_ip, return_list=True)
            if ((not self.api.settings().allow_duplicate_hostnames) and (input_dns is not None) and (input_dns != '')):
                match_hosts = self.api.find_system(dns_name=input_dns, return_list=True)
            for x in match_mac:
                if (x.name != ref.name):
                    raise CX((_("Can't    save    system    %s.    The    MAC    address    (%s)    is    already    used    by    system    %s    (%s)") % (ref.name, intf['mac_address'], x.name, name)))
            for x in match_ip:
                if (x.name != ref.name):
                    raise CX((_("Can't    save    system    %s.    The    IP    address    (%s)    is    already    used    by    system    %s    (%s)") % (ref.name, intf['ip_address'], x.name, name)))
            for x in match_hosts:
                if (x.name != ref.name):
                    raise CX((_("Can't    save    system    %s.        The    dns    name    (%s)    is    already    used    by    system    %s    (%s)") % (ref.name, intf['dns_name'], x.name, name)))
