netbox-community / customizations

A collection of community submitted and maintained customizations including reports, scripts, validators and export templates
MIT License
204 stars 55 forks source link

Script create_vm.py error when Cluster have site. #70

Open joaolucasmacedo opened 2 years ago

joaolucasmacedo commented 2 years ago

Looks like when a selected cluster have a site the script returns an error.

I'm running Netbox 3.3.2 with Python 3.10.

Maybe it is something related to the newer Netbox version.

celeroncool commented 2 months ago

I have fixed this by adding the following two lines to the end of class and def run:

class NewVM(Script):
    class Meta:
        name = "New VM"
        description = "Create a new VM"

    vm_name = StringVar(label="VM name")
....
    site = ObjectVar(model=Site, required=True)`
   def run(self, data, commit):
        vm = VirtualMachine(
            name=data["vm_name"],
....
            site=data.get("site"),
        )