kayrus / deploy-vm

Libvirt wrapper to spawn VMs using cloud images
GNU General Public License v2.0
59 stars 19 forks source link

Add freebsd support #8

Open kayrus opened 8 years ago

kayrus commented 8 years ago

https://pellaeon.github.io/bsd-cloudinit/

merovigen commented 7 years ago

Hey kayrus. I tested cloud-init on FreeBSD 10 and can tell you that bsd-cloudinit does not support NoCloud and ConfigDrive datastores. For my project I used cloud-init 0.7.7 (it does support FreeBSD, but not in official way). Just need to disable "sync" mounting by default and add distro password changing method. If you are interested, please let me know and I'll share my investiations.

kayrus commented 7 years ago

sure. I test lot of macos related stuff in freebsd. and I have to recreate freebsd VMs quite frequently. sshkeys/network configuration takes a lot of time

merovigen commented 7 years ago

Unfortunately, I didn't fork cloud-init on github and can't show you code examples, but I am planning to do this. So, here are changes, that I made to cloud-init 0.7.7: 1) make password changing disto-specific

--- a/cloudinit/config/cc_set_passwords.py
+++ b/cloudinit/config/cc_set_passwords.py
@@ -75,8 +75,10 @@ def handle(_name, cfg, cloud, log, args):

         ch_in = '\n'.join(plist_in) + '\n'
         try:
-            log.debug("Changing password for %s:", users)
-            util.subp(['chpasswd'], ch_in)
+            log.debug("Changing password for %s: %s", users, ch_in)
+            us, pa = ch_in.split(':', 1)
+            cloud.distro.set_passwd(us, pa)
+            # util.subp(['chpasswd'], ch_in)
         except Exception as e:
             errors.append(e)
             util.logexc(log, "Failed to set passwords with chpasswd for %s",

2) comment sync mounting (I am sure there is a better way to do it):

--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1601,10 +1601,10 @@ def mount_cb(device, callback, data=None, rw=False, mtype=None, sync=True):
                         mountopts.append('rw')
                     else:
                         mountopts.append('ro')
-                    if sync:
+                    #if sync:
                         # This seems like the safe approach to do
                         # (ie where this is on by default)
-                        mountopts.append("sync")
+                    #    mountopts.append("sync")
                     if mountopts:
                         mountcmd.extend(["-o", ",".join(mountopts)])
                     if mtype:

Here are steps to install cloud-init package on FreeBSD 10: 1) install python setuptools (AFAIR, package name is py-setuptools) 2) install package e2fsprogs (to use blkid) 3) install cloud-init python2.7 setup.py install --init-system=sysvinit_freebsd 4) by default installer brings you cloud.cfg for ubuntu although there is config for FreeBSD, so be sure to check /usr/local/etc/cloud/cloud.cfg for proper options 4) on FreeBSD config files from /usr/local/etc/cloud/cloud.cfg.d does not work (I did not manage to guess why), so to use proper logging you should move logging settings to main config 5) To minimize cloud-init datastore searching time I edited datastore_list in config and left only preffered datasources (NoCloud and ConfigDrive) 6) Finally, you need to activate cloud-init in /etc/rc.conf: cloudinit_enable="YES"

I use static network settings in meta-data file with NoCloud and it works perfectly, renaming interface and commiting settings in /etc/rc.conf. But there is one little problem - on first boot after customizing routing does not start, so I added command /etc/rc.d/routing start to runcmd. Root user password changing and ssh key commiting works too. Didn't try other functions like package installing though.

kayrus commented 7 years ago

i'll test these changes this week. p.s. There should be a way to propose these patches to freebsd developers.

merovigen commented 7 years ago

I used cloud-init from launchpad, not from FreeBSD ports. Actually, I didn't know there is a port for it) So I'll test it too to see the difference.

EDIT: checked freebsd port version of cloud-init 0.7.6 There are the same problems, starting from blkid utility missing and to the config problems.