Assign VM to a specific host device #3562

Closed
opened 2025-12-29 18:29:53 +01:00 by adam · 7 comments
Owner

Originally created by @igor-raits on GitHub (Apr 14, 2020).

Environment

  • Python version: 3.6
  • NetBox version: 2.7.8 (upgrading to 2.8.0 soon)

Proposed Functionality

Add ability to assign VMs to specific host devices (rather than clusters).

Use Case

We have bunch of VMs which are not run randomly on compute nodes, but rather on some specific hosts. Right now it is mandatory to assign VM to a cluster and then assign devices to it, but one device can't be in multiple clusters, so this is no-go.

Another thing is that we run OpenStack and VMs are run on different host devices and it would be very nice to be able to have the data in netbox where those VMs are running (so that you can query that).

Database Changes

Not sure.

External Dependencies

None.

Originally created by @igor-raits on GitHub (Apr 14, 2020). ### Environment * Python version: 3.6 * NetBox version: 2.7.8 (upgrading to 2.8.0 soon) ### Proposed Functionality Add ability to assign VMs to specific host devices (rather than clusters). ### Use Case We have bunch of VMs which are not run randomly on compute nodes, but rather on some specific hosts. Right now it is mandatory to assign VM to a cluster and then assign devices to it, but one device can't be in multiple clusters, so this is no-go. Another thing is that we run OpenStack and VMs are run on different host devices and it would be very nice to be able to have the data in netbox where those VMs are running (so that you can query that). ### Database Changes Not sure. ### External Dependencies None.
adam closed this issue 2025-12-29 18:29:53 +01:00
Author
Owner

@lampwins commented on GitHub (Apr 14, 2020):

You could easily create one cluster per device as this is meant to represent the hypervisor and the device represent the physical hardware.

I think more generally what you are describing is the concept of affinity rules which is not something core NetBox is likely to take on any time soon.

@lampwins commented on GitHub (Apr 14, 2020): You could easily create one cluster per device as this is meant to represent the hypervisor and the device represent the physical hardware. I think more generally what you are describing is the concept of affinity rules which is not something core NetBox is likely to take on any time soon.
Author
Owner

@candlerb commented on GitHub (Apr 14, 2020):

I do exactly this: where VMs are on standalone VM hosts, I create a cluster containing a single host, named the same as the host, and assign the VM to that.

I don't understand the comment "but one device can't be in multiple clusters, so this is no-go". Why would you want to assign a device to multiple clusters?

If a VM is mobile between devices A, B and C, then the VM should be assigned to a cluster containing A/B/C. Netbox doesn't reflect that a particular VM is running on (say) host A, because that's part of the cluster configuration, and in some cases could change minute-by-minute as machines are migrated to balance load. if you need to know where a particular VM is running right now, then the cluster's own management interface is the best way to retrieve it.

@candlerb commented on GitHub (Apr 14, 2020): I do exactly this: where VMs are on standalone VM hosts, I create a cluster containing a single host, named the same as the host, and assign the VM to that. I don't understand the comment "but one device can't be in multiple clusters, so this is no-go". Why would you want to assign a device to multiple clusters? If a VM is mobile between devices A, B and C, then the VM should be assigned to a cluster containing A/B/C. Netbox doesn't reflect that a particular VM is running on (say) host A, because that's part of the cluster configuration, and in some cases could change minute-by-minute as machines are migrated to balance load. if you need to know where a particular VM is running right now, then the cluster's own management interface is the best way to retrieve it.
Author
Owner

@igor-raits commented on GitHub (Apr 14, 2020):

I don't understand the comment "but one device can't be in multiple clusters, so this is no-go". Why would you want to assign a device to multiple clusters?

Let me describe our use-case a bit more..

We are running OpenStack in our company, so devices (hypervisors) are grouped in availability zones. e.g. cmp0001, cmp0006 are in zone01, cmp0002 and cmp0007 are in zone02 and cmp0011 is in its own zone called cmp0011. Then we have VMs which are run not as part of OpenStack on the same compute nodes (from zone01, zone02), e.g. bastion01a runs on cmp0001 and bastion01b runs on cmp0007.

We would like to store information in netbox which would contain mappings between:

  • cmp0001 → zone01
  • bastion01a → cmp0001
  • some-random-vm-in-openstack → cmp0002

Machines are not moving on their own between servers, but we would like to know where they run at this moment (the VMs are automatically added in netbox).

@igor-raits commented on GitHub (Apr 14, 2020): > I don't understand the comment "but one device can't be in multiple clusters, so this is no-go". Why would you want to assign a device to multiple clusters? Let me describe our use-case a bit more.. We are running OpenStack in our company, so devices (hypervisors) are grouped in availability zones. e.g. cmp0001, cmp0006 are in zone01, cmp0002 and cmp0007 are in zone02 and cmp0011 is in its own zone called cmp0011. Then we have VMs which are run not as part of OpenStack on the same compute nodes (from zone01, zone02), e.g. bastion01a runs on cmp0001 and bastion01b runs on cmp0007. We would like to store information in netbox which would contain mappings between: * cmp0001 → zone01 * bastion01a → cmp0001 * some-random-vm-in-openstack → cmp0002 Machines are not moving on their own between servers, but we would like to know where they run at this moment (the VMs are automatically added in netbox).
Author
Owner

@igor-raits commented on GitHub (Apr 14, 2020):

I was playing with this a bit more and I think if I create cluster for each compute node and have them as type=server and group=zone01/cmp0001 (depending on real aggregate in openstack) and as host devices only one matching compute node.... I think should do the trick.

@igor-raits commented on GitHub (Apr 14, 2020): I was playing with this a bit more and I think if I create cluster for each compute node and have them as type=server and group=zone01/cmp0001 (depending on real aggregate in openstack) and as host devices only one matching compute node.... I think should do the trick.
Author
Owner

@candlerb commented on GitHub (Apr 14, 2020):

  • bastion01a → cmp0001
  • some-random-vm-in-openstack → cmp0002

If you want to record the specific location of every VM in this way, then I suggest you make cmp0001 and cmp0002 be their own cluster.

Note: you can also have clusters with no devices. This is how I record (for example) LXD containers running inside a VM. I can't make a cluster which has VMs as members, so I have a cluster called "lxd" with no devices.

@candlerb commented on GitHub (Apr 14, 2020): > * bastion01a → cmp0001 > * some-random-vm-in-openstack → cmp0002 If you want to record the specific location of every VM in this way, then I suggest you make cmp0001 and cmp0002 be their own cluster. Note: you can also have clusters with no devices. This is how I record (for example) LXD containers running inside a VM. I can't make a cluster which has VMs as members, so I have a cluster called "lxd" with no devices.
Author
Owner

@igor-raits commented on GitHub (Apr 14, 2020):

Let me try this approach and I'll be back with results and if it works out - close bug.

Thanks for suggestions!

@igor-raits commented on GitHub (Apr 14, 2020): Let me try this approach and I'll be back with results and if it works out - close bug. Thanks for suggestions!
Author
Owner

@igor-raits commented on GitHub (Apr 14, 2020):

Yeah, this worked out perfectly.

Thanks again!

@igor-raits commented on GitHub (Apr 14, 2020): Yeah, this worked out perfectly. Thanks again!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3562