'Builds the full kernel options line.'

def build_kernel_options(self, system, profile, distro, image, arch, autoinstall_path):

    management_interface = None
    if (system is not None):
        blended = utils.blender(self.api, False, system)
        try:
            for intf in system.interfaces.keys():
                if system.interfaces[intf]['management']:
                    management_interface = intf
                    break
        except:
            pass
    elif (profile is not None):
        blended = utils.blender(self.api, False, profile)
    else:
        blended = utils.blender(self.api, False, image)
    append_line = ''
    kopts = blended.get('kernel_options', dict())
    kopts = utils.revert_strip_none(kopts)
    if (system and arch and ('ppc' in arch)):
        for intf in system.interfaces.keys():
            mac_address = system.interfaces[intf]['mac_address']
            ip_address = system.interfaces[intf]['ip_address']
            if (mac_address and ip_address):
                kopts['BOOTIF'] = ('01-' + mac_address)
                kopts['ksdevice'] = mac_address
                break
    if ('initrd' in kopts):
        append_line = (',%s' % kopts.pop('initrd'))
    hkopts = utils.dict_to_string(kopts)
    append_line = ('%s    %s' % (append_line, hkopts))
    if ((autoinstall_path is not None) and (autoinstall_path != '')):
        try:
            ipaddress = socket.gethostbyname_ex(blended['http_server'])[2][0]
        except socket.gaierror:
            ipaddress = blended['http_server']
        URL_REGEX = '[a-zA-Z]*://.*'
        local_autoinstall_file = (not re.match(URL_REGEX, autoinstall_path))
        if local_autoinstall_file:
            if (system is not None):
                autoinstall_path = ('http://%s/cblr/svc/op/autoinstall/system/%s' % (ipaddress, system.name))
            else:
                autoinstall_path = ('http://%s/cblr/svc/op/autoinstall/profile/%s' % (ipaddress, profile.name))
        if ((distro.breed is None) or (distro.breed == 'redhat')):
            append_line += '    kssendmac'
            append_line = ('%s    ks=%s' % (append_line, autoinstall_path))
            gpxe = blended['enable_gpxe']
            if gpxe:
                append_line = append_line.replace('ksdevice=bootif', 'ksdevice=${net0/mac}')
        elif (distro.breed == 'suse'):
            append_line = ('%s    autoyast=%s' % (append_line, autoinstall_path))
        elif ((distro.breed == 'debian') or (distro.breed == 'ubuntu')):
            append_line = ('%s    auto-install/enable=true    priority=critical    netcfg/choose_interface=auto    url=%s' % (append_line, autoinstall_path))
            if management_interface:
                append_line += ('    netcfg/choose_interface=%s' % management_interface)
        elif (distro.breed == 'freebsd'):
            append_line = ('%s    ks=%s' % (append_line, autoinstall_path))
            translations = {'ksdevice': 'interface', 'lang': 'locale'}
            for (k, v) in translations.iteritems():
                append_line = append_line.replace(('%s=' % k), ('%s=' % v))
            append_line = append_line.replace('interface=bootif', '')
        elif (distro.breed == 'vmware'):
            if (distro.os_version.find('esxi') != (-1)):
                append_line = ('    ks=%s    %s' % (autoinstall_path, hkopts))
                append_line = append_line.replace('kssendmac', '')
            else:
                append_line = ('%s    vmkopts=debugLogToSerial:1    mem=512M    ks=%s' % (append_line, autoinstall_path))
            append_line = append_line.replace('ksdevice=bootif', '')
        elif (distro.breed == 'xen'):
            if (distro.os_version.find('xenserver620') != (-1)):
                img_path = os.path.join('/images', distro.name)
                append_line = ('append    %s/xen.gz    dom0_max_vcpus=2    dom0_mem=752M    com1=115200,8n1    console=com1,vga    ---    %s/vmlinuz    xencons=hvc    console=hvc0    console=tty0    install    answerfile=%s    ---    %s/install.img' % (img_path, img_path, autoinstall_path, img_path))
                return append_line
        elif (distro.breed == 'powerkvm'):
            append_line += '    kssendmac'
            append_line = ('%s    kvmp.inst.auto=%s' % (append_line, autoinstall_path))
    if ((distro is not None) and (distro.breed in ['debian', 'ubuntu'])):
        domain = 'local.lan'
        if (system is not None):
            if ((system.hostname is not None) and (system.hostname != '')):
                hostname = system.hostname.split('.')[0]
                _domain = system.hostname.split('.')[1:]
                if _domain:
                    domain = '.'.join(_domain)
            else:
                hostname = system.name
        else:
            hostname = profile.name.replace('_', '')
        append_line = ('%s    hostname=%s' % (append_line, hostname))
        append_line = ('%s    domain=%s' % (append_line, domain))
        append_line = ('%s    suite=%s' % (append_line, distro.os_version))
    elif ((distro is not None) and (distro.breed == 'nexenta')):
        append_line = ('-B    iso_nfs_path=%s:/var/www/cobbler/links/%s,auto_install=1' % (blended['next_server'], distro.name))
    if ((arch is not None) and arch.startswith('arm')):
        append_line = ('%s    fixrtc    vram=48M    omapfb.vram=0:24M' % append_line)
    if ('autoinstall_meta' in blended):
        blended.update(blended['autoinstall_meta'])
    append_line = self.templar.render(append_line, utils.flatten(blended), None)
    if (len(append_line) >= 255):
        self.logger.warning('warning:    kernel    option    length    exceeds    255')
    return append_line
