Add boot loader field to distro

Allow user to override which boot loader he/she wants to use to netboot
a distribution instead of always automatically selecting it. TFTP/DHCP
files generation can now know which boot loader was selected.

It is needed for distros, because some distros, particularly
little-endian powerpc ones, need to use grub2, while historical
distributions can continue to use yaboot. Additionally, PowerKVM
installations need to be able to use pxelinux.

Note that I'm currently working around an issue I hit with the presence
(or lack) of utils.SIGNATURE_CACHE. In manage_import_signatures.py,
utils.SIGNATURE_CACHE is {}, because (I think) it's loaded before the
signatures are in CobblerAPI. If we were to fix that issue, we could
simplify the utils code, which currently handles two call-paths, one of
which has the SIGNATURE_CACHE available and one that doesn't (thus
relying on the API function to get to it).

Many thanks to Alan Evangelista <alanoe@linux.vnet.ibm.com> for comments
and review on this patch as well as the original functionality to add
boot loaders to system objects.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Add boot loader to system

Allow user to override which boot loader he/she wants to use to netboot
a system instead of always automatically selecting it. TFTP/DHCP file
generation code can now know which boot loader was selected now that the
boot loader selection can be overridden.

It is needed for systems, because on certain Power8 systems running in
baremetal, petitboot is used to netboot and requires a pxelinux
configuration regardless of distribution (which might use yaboot or
grub2 normally). The platform ("PowerNV") could be used to determine
this, but currently Cobbler doesn not have a notion of platform.

Based off a patch by Alan Evangelista <alanoe@linux.vnet.ibm.com>.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
api: provide more verbose output when signatures fail to load

Currently, if the signatures fail to load, a silent return occurs and
authentication (amongst other functionality) fails. Provide more helpful
output before returning.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
pxegen: don't delete boot directory unconditionally

Nexenta is going to overwrite tftpboot/boot, but that needs to be
maintained for grub2 support.

Note this means that Nexenta and grub2 cannot be supported at the same
time.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
save_boot_device: wait for root to show up

This is a regression in the snippet, which doesn't work in FC20 and
RHEL7 at least.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
set_next_server: inherit is inserted now

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
cobbler: improve error messages

When the serializer encounters an error, it does not provide enough
context for the error to debug.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
6b6363a8 ("Remove methods which create items from Config class") broke imports

The $subject commit removes two methods (new_distro, new_profile) that
are being used by existing code (added in f7ca250).

Fix for issue https://github.com/cobbler/cobbler/issues/1345

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Fixes: 6b6363a8 ("Remove methods which create items from Config class")
Commit c02e212 ("changed ui for batch profile change to jquery") is missing

The changes necessary from $subject commit were reverted upstream, but
that in turn broke profile selection popups (e.g., bulk actions ->
change profile from system list page). The original code did have a bug
in it, which provoked the exception seen in 2b5f68e, as it was not
intializing the profiles array to an empty list.

Fix for https://github.com/cobbler/cobbler/issues/1333.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Fixes: 2b5f68e ("Fix Django exceptions when lists (eg. distro/profiles) are empty.")
Fixes: 632dcdd ("Remove unused variable.")
manage_import_signatures: search for architectures in reverse length order

For RHEL7 on ppc64, for example, Cobbler ends up creating both a ppc and ppc64
entry. Leaving aside the fact that I don't think 32-bit ppc is supported by
RHEL7 (at least not with this iso, that's for sure), the issue is that both
"ppc" and "ppc64" (both listed in signature["supported_arches"]) are "found"
within the signature["kernel_arch"] file which contains "ppc64".

Two fixes are needed:

1) self.get_valid_arches() should return a reverse-sorted list by length
(longest first)
2) If a match is found (foo[arch] will be set to 1), the arch loop should be
broken out of, as the first match found is the most specific (matches the most
characters)

Fixes  https://github.com/cobbler/cobbler/issues/1332

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Commit d6888de ("Rename ks_mirror directory") broke imports

The string length ("ks_mirror" versus "distro_mirror") is no longer 10.
Use an explicit len() call.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Fixes: d6888de ("Rename ks_mirror directory")
post_install_network_config_deb: add gateway information

On power systems, at least, no default route is created without a
gateway defined in the system configuration. Since interfaces can
override the gateway, we only use the global gateway if no per-interface
gatway is defined.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
post_install_network_config_deb: remove unused variables

These variables would need to be defined differently for Debian based
systems, anyways.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
DHCP: export name-server information to DHCP clients

If name servers are defined for a system, send them over DHCP, when in
use. This avoids one prompt in Ubuntu preseed configurations.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Ubuntu: auto configure netcfg over command-line

For network booting the Ubuntu installer, we need to configure the
network before we can grab the preseed. The first network interface with
link is selected in the preseed with 'd-i netcfg/choose_interface select
auto', so pass this to the installer on the command-line.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
remove remaining missed references to "kickstart"

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Rename pxesystem_ppc.template to yaboot_ppc.template

It is not really a PXE template, and it only works for yaboot.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
utils: differentiate between copying files and directories

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
utils: fix inversion of logic in copyfile

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Fixes: 8c406e21 ("PEP8 - cobbler/utils.py")
cobbler: add powerpc grub2 support

GRUB2 is a highly modular and flexible replacement for GRUB. Newer
distributions (FC20+, RHEL7+, SLES12+, Ubuntu 14.04+) support GRUB2 on
Power, and yaboot is now deprecated there. Add "grub2" as a valid
boot_loader type, and provide a template for its config file. GRUB2
will only be used if a signature on import indicates the distribution
should use it instead of yaboot. Eventually, we would probably remove
yaboot support (or switch the default around, at least).

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
---
Jorgen, I also need to provide you with a binary grub2 tarball that can
be used by get_loaders, I think. What is the process to do that, as they
are not in the repository?