[Solved] How do I list available templates on Cloudforms to be used on a Service Catalog?

Hi, I hope everyone is okay. I’m new to Cloudforms and I’m trying to make a service catalog where the user can specify which template to use to create a new vm, and also to specify the vm memory size and cpu to be used later to create the new vm. My problem is that I’m not familiar with Ruby and I just want to create a dynamic dropdown where it lists my available templates, I searched for hours to see how to I manage it to list it but with no luck. Can someone please show me how to create a ruby method where I include it in my entry point for the dropdown list to show the current available templates?

PS: If anyone has an idea on how to create the ruby method for creating a new vm with these inputs please do not hesitate to assist on this task I would like to learn how to get it done.

Thank you for your attention.

The CloudForms automation book will probably be really helpful to you if you haven’t found it already. It has examples for doing quite a few things.

There’s also this CloudForms essentials repo by Kevin Morey which contains quite a lot of useful Automate methods, and also other user customizable forms and alerts and such. It’s pretty good at teaching by example too.


@01100010011001010110 Thank you for the help and I apologize for the delayed reply. I did indeed find the CloudForms automation book and it was very informative but I still couldn’t figure out how to list my available template.

$evm.vmdb(:vm_or_template).where(:template => true)

will provide you an array with the templates.

@xian Thank you for your reply, so I basically make a method with only that line of code and use it as entry point and it will list the templates?

If you want to use it in a service dialog to allow the user to select from a dropdown, you need to create a method and populate $evm.object with the names and ids of the templates in the resulting array of the code above. You’ll find some examples in the Dynamic Elements chapter.

I recommend experimenting with some really basic exercise before trying to solve your task. You have to invest your time and this book is really good at gradually adding information you’ll need. Try to make your dialog (and service) work with a fixed template first (make CPU and RAM select-able). Once this is working you can extend it further with the template selection.

@xian Thanks for the help, I did make a service catalog with a fixed template and fixed CPU and RAM at first just to see how it works and then I created it with a fixed template. I was a bit worried that I have to write my own method to create the vms and use the inputs from the dialog into the method. Since I am not familiar with Ruby I kind of found it difficult and tried to look for other options. The book is really handy and I will definitely devote lots of hours to getting the hang of it. It’s just that it’s my final year project and I don’t have that much time to learn everything from scratch but I can’t wait to dive in in all that knowledge once I finish.
So from what I’ve read from the book it said that I just need to use option_0_cores_per_socket and option_0_vm_memory and follow the naming convention it will be used straight from the dialog and get used to create the vm without needing to create my own method according to chapter 33, “Creating a Service Catalog Item”. Is that correct ?

That is right, and you can name those elements as cores_per_socket and vm_memory as well. The option_ prefix is needed only if you want to create a dialog for a service bundle. See Service Dialog Element Naming Convention and Creating the Service Dialog for the Bundle.

1 Like

Thank you so much for the help.

Hello @miiraheart @xian

Created a dynamic dropdown element with element name “linux_host_name”
pointing at below created method
I created a method under the /service/infrastructure/provisioning/methods/templateInstance

dialog_field = $evm.object

# sort_by: value / description / none
dialog_field["sort_by"] = "value"

# sort_order: ascending / descending
dialog_field["sort_order"] = "ascending"

# data_type: string / integer
dialog_field["data_type"] = "string"

# required: true / false
dialog_field["required"] = true

dialog_field["values"] = { "Template RHEL7.4_with1GB_boot" => "Template RHEL7.4_with1GB_boot", "Template RHEL7.5_with1GB_boot" => "Template RHEL7.5_with1GB_boot" }
dialog_field["default_value"] = "Template RHEL7.4_with1GB_boot"

When I ordered the VM.

Error: Source Template/Vm with id [111000000105251] has no EMS, unable to provision

I received this error.

Am I using the wrong element name or wrong procedure?

Thanking you,

Are these templates discovered on the provider?

Yes @xian