diff options
| -rw-r--r-- | classes/meta-virt-hosts.bbclass | 29 | ||||
| -rw-r--r-- | conf/layer.conf | 1 |
2 files changed, 30 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 | |||
| 4 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "virt-unique-hostname", "virt_gen_hostname; ", "",d)}' | ||
| 5 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "virt-unique-hostname", "virt_set_hostname; ", "",d)}' | ||
| 6 | |||
| 7 | python 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 | |||
| 27 | virt_set_hostname() { | ||
| 28 | echo "${VIRT_TARGETNAME}" > ${IMAGE_ROOTFS}/etc/hostname | ||
| 29 | } | ||
diff --git a/conf/layer.conf b/conf/layer.conf index 149b42ee..4a1448a4 100644 --- a/conf/layer.conf +++ b/conf/layer.conf | |||
| @@ -57,5 +57,6 @@ K8S_CONFIG_PATH = "${LAYERDIR}/conf/distro/include/k8s-versions.inc" | |||
| 57 | USER_CLASSES:append = " meta-virt-cfg" | 57 | USER_CLASSES:append = " meta-virt-cfg" |
| 58 | USER_CLASSES:append = " meta-virt-k8s-cfg" | 58 | USER_CLASSES:append = " meta-virt-k8s-cfg" |
| 59 | USER_CLASSES:append = " meta-virt-xen-cfg" | 59 | USER_CLASSES:append = " meta-virt-xen-cfg" |
| 60 | USER_CLASSES:append = " meta-virt-hosts" | ||
| 60 | 61 | ||
| 61 | HOSTTOOLS_NONFATAL += "getent" | 62 | HOSTTOOLS_NONFATAL += "getent" |
