{% raw %} Here at SovLabs, we offer up many tips and tricks to use for deploying virtual machines. A recent common query is “how to add additional NICs to a virtual machine on a blueprint?” Use cases vary. Perhaps for one application a single NIC suffices, but you may need two NICs when deployed for a different app, or perhaps in one environment there is a separate OOB management network. Whatever the reason, here are two ways to add additional NICs to virtual machines on the fly.
Requirements
Both of these solutions require a SovLabs IPAM/DNS license and a configured IPAM endpoint at at least one IPAM profile. You can find out more about using IPAM profiles on our modules pages. Both of these solutions also leverage SovLabs_IPAMProfile_nic1 which is one of several behind-the-scenes property groups leveraged by the SovLabs IPAM profile framework.
You’ll also need a blueprint with one VM and an existing NIC0 configured using an IPAM profile. And since we are using the SovLabs IPAM profiles to manipulate the network configuration, neither of these solutions require network components on your VM.
Adding a property with the Property Toolkit Module
The first method is actually illustrated step-by-step on our How-To pages. This method leverages our Property Toolkit Module to add the custom property group SovLabs_IPAMProfile_nic1 to the blueprint when needed.
You can follow along on the guide referenced above, but basically you add a boolean Custom Property (here named josh001-AddNIC1 with a label of Add a network?) to your blueprint…
…and then add SovLabs_CreateProperties_AddNic1 custom property.
The SovLabs_CreateProperties part of the name triggers the SovLabs Property Toolkit module to create a new property based on the value. The Template Engine logic statement in the value field is:
{“name”: “{% if josh001-AddNIC1 == ‘true’ %}SovLabs_IPAMProfile_nic1
{% else %}NoNic1Required{% endif %}”,
“value”: “{% if josh001-AddNIC1 == ‘true’ %}IPAMSolar60NIC1
{% else %}NoNic1Required{% endif %}”}
This logic statement will create a new property with a name of SovLabs_IPAMProfile_nic1 and a value of IPAMSolar60NIC1 when the “Add a network?” checkbox is selected. Otherwise a property of NoNic1Required is created with a value of NoNic1Required, which will be ignored during a request.
Setting a value on an existing property
If you have not licensed the SovLabs Property Toolkit, or are just looking for other options, you can also add the SovLabs_IPAMProfile_nic1 property to the VM directly, and provide it a value as needed.
For this method, you use the same josh001-AddNIC1 boolean property, but add the SovLabs_IPAMProfile_nic1 property with a slightly different Template Engine logic.
Here, the logic is:
{% if josh001-AddNIC1 == ‘true’ %}IPAMSolar60NIC1{% endif %}
This logic sets the value of SovLabs_IPAMProfile_nic1 to IPAMSolar60NIC1 when the checkbox is selected, and otherwise leaves it blank.
Checking your work
When you are working with Template Engine logic, don’t forget to leverage the SovLabs Template Tester.
The Template Tester lets you check both the properties for a deployed VM, and quickly test logic out against those properties.
Here are the properties of a VM deployed with a second NIC (note there is some photoshop editing to make it readable).
If you post the logic into the Template field…
You’ll see the resulting output:
To check the logic when the josh001-AddNIC1 boolean isn’t checked, you can edit the Properties JSON field, setting it to false.
And check the resulting output to verify the value is blank when the checkbox is cleared:
Conclusion
We hope that you found these solutions for dynamically adding NICs to blueprints useful and can come away with a better understanding of simple uses of the Property Toolkit and Template Engine.
Note that these solutions just scratch the surface, especially with Property Toolkit. Adding properties on the fly means not having blank/unused properties if you don’t want them, and, of course, Property Toolkit is really good at more exotic stuff like automatically renaming your deployments and making component profiles dynamic. You can also make adding NICs more exotic by leveraging the Template Engine to create the IPAM profile name on the fly using properties from throughout the hierarchy – not just a static profile name like I used.
Happy Clouding! {% endraw %}