summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2021-11-22 20:28:27 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2021-12-13 15:59:35 -0500
commit491a385ca6fd6e47c364d0bda0ffdf557eec6da0 (patch)
tree0f4905717b68e04976ab815ee473747dc59187df /classes
parent6fe326b68012b0eae5c951ab21d55b0ccfda84f9 (diff)
downloadmeta-virtualization-491a385ca6fd6e47c364d0bda0ffdf557eec6da0.tar.gz
config: introduce hostname generation hooks
Overriding hostname in a .conf file, via base-files: HOST_NAME="k3s-host" hostname_pn-base-files = "${HOST_NAME}" Is always a valid option, but if it is not configured, we can easily have two hosts with the same name on the network, confusing adddress assignement, etc. This commit introduces a way to generate a unique hostname based on the uuid of the build host, and the machine being built. If virt-unique-hostname is added to IMAGE_FEATURES, like the following: IMAGE_FEATURES += "virt-unique-hostname" IMAGE_FEATURES[validitems] += "virt-unique-hostname" Then a rootfs postprocessing hook will override hostnae to something unique. Note: this means your image will be reproducible on a single builder, but not between them. Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'classes')
-rw-r--r--classes/meta-virt-hosts.bbclass29
1 files changed, 29 insertions, 0 deletions
diff --git a/classes/meta-virt-hosts.bbclass b/classes/meta-virt-hosts.bbclass
new file mode 100644
index 00000000..80aefb76
--- /dev/null
+++ b/classes/meta-virt-hosts.bbclass
@@ -0,0 +1,29 @@
1# This doesn't work, since it seems to be too late for sanity checking.
2# IMAGE_FEATURES[validitems] += ' ${@bb.utils.contains("DISTRO_FEATURES", "virtualization", "virt-unique-hostname; ", "",d)}'
3
4ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "virt-unique-hostname", "virt_gen_hostname; ", "",d)}'
5ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "virt-unique-hostname", "virt_set_hostname; ", "",d)}'
6
7python virt_gen_hostname() {
8 import uuid
9
10 targetname = d.getVar("VIRT_TARGETNAME")
11 if targetname != None:
12 return
13
14 status, date = oe.utils.getstatusoutput("date +%d-%m-%y")
15 if status:
16 bb.warn("Can't get the date string for target hostname")
17
18 uuid = ':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff) for ele in range(0,8*6,8)][::-1])
19 if uuid:
20 targetname = "%s-%s" % (d.getVar("MACHINE"), uuid.split(":")[0])
21 else:
22 targetname = "%s-%s" % (d.getVar("MACHINE"), date)
23
24 d.setVar("VIRT_TARGETNAME", targetname)
25}
26
27virt_set_hostname() {
28 echo "${VIRT_TARGETNAME}" > ${IMAGE_ROOTFS}/etc/hostname
29}