suse-edge / nm-configurator

NetworkManager configuration tool
Apache License 2.0
7 stars 3 forks source link

Set hostname when applying network config #18

Closed atanasdinov closed 9 months ago

e-minguez commented 9 months ago

I'm not 100% sure setting the hostname in the file will be enough:

foo@edge385:~> hostname
edge385
foo@edge385:~> cat /etc/hostname 
foo@edge385:~> hostnamectl
   Static hostname: n/a                                
Transient hostname: edge385
         Icon name: computer-server
           Chassis: server
        Machine ID: xxx
           Boot ID: xxx
  Operating System: SUSE Linux Enterprise Server 15 SP4
       CPE OS Name: cpe:/o:suse:sles:15:sp4
            Kernel: Linux 5.14.21-150400.24.81-default
      Architecture: x86-64
   Hardware Vendor: HPE
    Hardware Model: xxx

https://www.redhat.com/sysadmin/set-hostname-linux

I've found these https://crates.io/crates/uu_hostname https://crates.io/crates/hostname but image

atanasdinov commented 9 months ago

Sorry, I should have put some kind of description. :smile:

Yes, this is exactly what we want. I've researched all different ways of setting up the hostname as well as read through the source code of the different implementations and setting the name in /etc/hostname is enough to set it as a "Static hostname" after a reboot.

Tested the current code in Combustion using the slemicro/create-vm.sh script (dropping the manual hostname setup) and after a reboot we observe the following:

node2:~ # hostnamectl
 Static hostname: node2
       Icon name: computer-vm
         Chassis: vm
      Machine ID: a8769599bd8c4125a2b5952e9be48a09
         Boot ID: 426f872337d840bfac33f5937fbc477e
  Virtualization: qemu
Operating System: SUSE Linux Enterprise Micro 5.4
     CPE OS Name: cpe:/o:suse:sle-micro:5.4
          Kernel: Linux 5.14.21-150400.24.46-default
    Architecture: arm64
 Hardware Vendor: QEMU
  Hardware Model: QEMU Virtual Machine

If we do need to set the transient hostname, I'll add a call to sethostname in a follow up.