Enthusiast
Enthusiast

VRA 8.1 - Adding/Removing NICs Before Provisioning

Jump to solution

Does anyone know if it's possible to add/remove nics before provisioning starts...kinda like changing the blueprint on the fly?

In our environment, we have several different network configurations depending on what type and where a server is being built.  It could have 1-3 nics of varying port group needs.  We'd prefer to use one blueprint with one form and drive the logic from there.  But I can't figure out a way to manipulate the blueprint for those different cases - there is no count property on a network, so we can't set that to 0 to "remove" a nic.  And passing in an array of networks from a hidden input on the form may not be doable because we don't know any of the network Ids - which that array seems to need.

Can we manipulate the number of nics during Network Configure or Network Provision events?  Meaning, can we add in new nics or remove nics during those phases?  Or during some other event topic before provisioning kicks off?

We are are aware that we can make changes after the server is built during the post provisioning, but that would be the least optimal approach I think.  So really just looking for options before that.  For example, a blueprint with no networks attached, and then build them on the fly - either via inputs or during some events.  Or build a blueprint with 3 networks and remove 1 or more along the way if needed.

Any help is appreciated, thanks.

0 Kudos
1 Solution

Accepted Solutions
Enthusiast
Enthusiast

So far this seems promising.  Each network object has a count property set to 0 or 1.  They also each have a deviceIndex.  I don't believe this property has any meaning on the Network object itself (it's not in the list of properties when you click on one), but we can use it when mapping the network objects to the networks array on the vsphere machine, where that property does have meaning.

The map_by() function seems to be able to loop through an array, and run a "function" on each item, e.g. return an object like we do here.  Those results are put into a new array, effectively creating our array of network objects on the machine object.

So in this case, the array consists of each of our network objects.  For each one we create an object with a property of network with a value of the nic's id, as well as a property called deviceIndex set to the deviceIndex of the Network object.  For example, the following

resources:

  vSphereVM2:

    type: Cloud.vSphere.Machine

    properties:

      networks: '${map_by(resource.Nic0[*] + resource.Nic1[*] + resource.Nic2[*],nic => {"network":nic.id, "deviceIndex":nic.deviceIndex})}'

  Nic0:

    type: Cloud.vSphere.Network

    properties:

      count: 1

      deviceIndex: 0

  Nic1:

    type: Cloud.vSphere.Network

    properties:

      count: 1

      deviceIndex: 2

  Nic2:

    type: Cloud.vSphere.Network

    properties:

      count: 1

      deviceIndex: 1

would result in a networks array that would like this:

resources:

  vSphereVM2:

    type: Cloud.vSphere.Machine

    properties:

      networks:

          - network: <Nic0's ID>

             deviceIndex: 0

          - network: <Nic1's ID>

            deviceIndex: 2

          -network: <Nic2's Id>

            deviceIndex: 1

Now to toggle a NIC "off", simply set its count property to 0 and it will be ignored during the mapping.  The deviceIndex is used here to force the order that we want the NICs to be added - otherwise, we may not configure them correctly.

Our goal will be to set the counts and indexes automatically based on the form input, which should be easy enough hopefully.

View solution in original post

0 Kudos
5 Replies
Hot Shot
Hot Shot

emacintosh

Does this help?

Introducing Blueprint Expressions in Cloud Assembly --> see Leveraging a “Zero” Count

https://blogs.vmware.com/management/2019/02/blueprinting-expressions-in-cloud-assembly.html

0 Kudos
Enthusiast
Enthusiast

I think it could, but I would need to know where that count property might exist for the nics.  The network objects on the vsphere machine object don't have a count a property, so I can't set them to 0, which is what I thought would be a great way to go. 

Do you happen to know of another place where a count property could help drive the network configuration?

0 Kudos
Hot Shot
Hot Shot

emacintosh

No, sorry.

0 Kudos
Enthusiast
Enthusiast

I think I was mistaken about the count property.  I may have been looking to put the count on the list of networks defined on the vm, not the count property on the network itself.  There are some other threads out here about people trying to do similar for both disks and networks, and they're using the undocumented map_to_object function in the blueprint (the function is only mentioned in an example in the release notes).

So I am headed down the same path now and will share my results here once I have a better idea of if/how this will work.

0 Kudos
Enthusiast
Enthusiast

So far this seems promising.  Each network object has a count property set to 0 or 1.  They also each have a deviceIndex.  I don't believe this property has any meaning on the Network object itself (it's not in the list of properties when you click on one), but we can use it when mapping the network objects to the networks array on the vsphere machine, where that property does have meaning.

The map_by() function seems to be able to loop through an array, and run a "function" on each item, e.g. return an object like we do here.  Those results are put into a new array, effectively creating our array of network objects on the machine object.

So in this case, the array consists of each of our network objects.  For each one we create an object with a property of network with a value of the nic's id, as well as a property called deviceIndex set to the deviceIndex of the Network object.  For example, the following

resources:

  vSphereVM2:

    type: Cloud.vSphere.Machine

    properties:

      networks: '${map_by(resource.Nic0[*] + resource.Nic1[*] + resource.Nic2[*],nic => {"network":nic.id, "deviceIndex":nic.deviceIndex})}'

  Nic0:

    type: Cloud.vSphere.Network

    properties:

      count: 1

      deviceIndex: 0

  Nic1:

    type: Cloud.vSphere.Network

    properties:

      count: 1

      deviceIndex: 2

  Nic2:

    type: Cloud.vSphere.Network

    properties:

      count: 1

      deviceIndex: 1

would result in a networks array that would like this:

resources:

  vSphereVM2:

    type: Cloud.vSphere.Machine

    properties:

      networks:

          - network: <Nic0's ID>

             deviceIndex: 0

          - network: <Nic1's ID>

            deviceIndex: 2

          -network: <Nic2's Id>

            deviceIndex: 1

Now to toggle a NIC "off", simply set its count property to 0 and it will be ignored during the mapping.  The deviceIndex is used here to force the order that we want the NICs to be added - otherwise, we may not configure them correctly.

Our goal will be to set the counts and indexes automatically based on the form input, which should be easy enough hopefully.

View solution in original post

0 Kudos