VMware Cloud Community
sprouse94
Enthusiast
Enthusiast
Jump to solution

Check VM name before provisioning (vRA 8.1)

I have created a blueprint that asks the user for the server function (Web, DB, App, etc...) so the VM can be named in accordance with the company naming policy.  I was able to set up an Action to generate a new name based on that input and have the subscription set up to change the name at creation.  All of this is working great however, sometime the generated name already exists (limited to just a few numbers in the name) and the deployment fails.  The simple solution is to check if the name already exists in Virtual Center and if it does just increase the number until it is a unique name.

All of the examples I find on the Web uses the vcPlugin option, which no longer exists in vRA 8.x.  Looks like everything has moved to the REST API?  Can someone point me in the right direction of how I can generate a name for the VM at creation and check to see if it already exists?

I am only dealing with a local install / virtual center.

1 Solution

Accepted Solutions
pizzle85
Expert
Expert
Jump to solution

I have set up an action that i can use in my service broker forms and i can call in the first stage of the deployment process to validate API requests which aren't validated by the form. Assuming you only have one vCenter you could do something simple like:

var vms = Server.findAllForType('VC:VirtualMachine', vmName)

for each (vm in vms) {

     if (vm.name == vmName) {

          throw 'A VM with the same name ' + vm.name  + already exists!'

      }

}

return ''

View solution in original post

1 Reply
pizzle85
Expert
Expert
Jump to solution

I have set up an action that i can use in my service broker forms and i can call in the first stage of the deployment process to validate API requests which aren't validated by the form. Assuming you only have one vCenter you could do something simple like:

var vms = Server.findAllForType('VC:VirtualMachine', vmName)

for each (vm in vms) {

     if (vm.name == vmName) {

          throw 'A VM with the same name ' + vm.name  + already exists!'

      }

}

return ''