nix-community / nixops-vbox

NixOps VirtualBox backend [maintainer=@AmineChikhaoui]
GNU Lesser General Public License v3.0
22 stars 15 forks source link

Support for VirtualBox network resources #2

Open onixie opened 4 years ago

onixie commented 4 years ago

Motivation to the change

As I proposed in https://github.com/NixOS/nixops/issues/1223, this PR focuses on enabling VirtualBox backend to create virtual networks (Host-only and NatNetwork which VirtualBox supports) and manage those networks as NixOps resources. It also generalizes the network adaptor configurations for the machines, removes the hard-coded constraints which pressumes the existence of a DHCP-enabled vboxnet0 link device in user's environment. After this PR, similar like libvirt backend, user can explicitly specify what networks each adaptor should be attached to. Finally, when using with Virtualbox >= v6.1, the new virtual network resources allow user specify static IPv4 address from DHCP range and bind to a specific machine. And this can finally solve the unpredictable address issue.

Test results

I tested the changes on the following environments,

OS: Ubuntu 18.04, MacOS High Sierra NixOps: master branch Nixpkgs: unstable channel VirtualBox: v5.2, v6.0 and v6.1 Virtualbox image: nixops-19.09

And tried the following frequently used commands: create, deploy, redeploy, start, stop, destroy, check, info without problems. Though there are some corner cases I wasn't able to cover, I think it's already stable enough to be shared and used with NixOps developers and decent users.

So hope this PR can be approved and merged. Thank you for any comments.

Regards

nixos-discourse commented 4 years ago

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/pr-to-support-network-resources-for-virtualbox-backend-in-nixops/6066/1

chrisportela commented 3 years ago

I tried merging this and got it mostly working, but I'm getting some strange error where Nix doesn't like the format of the deployment.virtualbox.networks option.

onixie commented 3 years ago

@chrisportela

Thanks for verifying my PR.

The code should have no issue to run with nixops 1.8. I actually use it in one of my personal project for network provisioning for a HA K8S cluster running on VirtualBox or Libvirt.

https://github.com/onixie/nikops/blob/master/shell.nix#L14 https://github.com/onixie/nikops/blob/master/src/cluster.nix#L44 https://github.com/onixie/nikops/blob/master/src/cluster.nix#L61-L63

Beside the above usage, I also did some tests with other combination of the options.

Due to my lack of time recently, I couldn't manage to update it with the latest version of nix and nixops.