Hello,

I've been giving a bit of tought to this. Sorry for the late response.

There are several ways you could achieve this, but they all require a bit of hacking.

The simplest one (perhaps not the most elegant but still), is to modify TemplateJSON.rb instantiate() so that it inserts a random PW in the template, instantiates the new VM with it and then deletes the PW from the template, as follows:

        def instantiate(params=Hash.new)
            info()
            pw_hash = { 'PASSWORD' => generateRandomPw() }
            add_element("TEMPLATE", pw_hash)
            update('template_raw' => template_str())
            super(params['vm_name'])
            delete_element("TEMPLATE/PASSWORD")
            update('template_raw' => template_str())
        end

The PASSWORD will be visible in the VM Template tab of the VM information in Sunstone. If you need the password to be in the VM you would need to add_element inside the context section.

Note that if you would rather use Self-Service, theres is the posibility of modifying the .erb VM templates in /etc/one/occi_templates and insert any piece of custom ruby code right there as:

PASSWORD = "<%= generateRandomPw() %>"

You would then only need to modify updateVMInfo() in compute.js so that the password is shown in the VM information in the same way that the NAME or State are shown there.

As I say at the beginning, there are other solutions like modifying the Sunstone javascript code, or creating a sunstone pluging that overwrites the instantiate action and does this etc. but this one was the quickest to get what you want that I could think of.

Hector


En Sat, 18 Aug 2012 13:01:54 +0200, Ricardo Duarte <rjt...@hotmail.com> escribió:

Hi there,

I would like to generate a random password for each instance, but it should be readable/available under Sunstone. The plan is to slightly modify the virtual machine data table, and add a new column named "Service Password", or in alternative, users may look for it under the "Image Template" tab. What I am missing is how to make the password available to both Sunstone and the instance, and how to generate it before the machine boots. Looks like the easier way would be to auto-generate it and add it to CONTEXT. But how can I do it? Is there any hook I can use to generate a variable and add them to context, before the machine boots? Or do I have to modify the OpenNebula C core?

Thanks.


                                        


--
Hector Sanjuan
OpenNebula Developer
_______________________________________________
Users mailing list
Users@lists.opennebula.org
http://lists.opennebula.org/listinfo.cgi/users-opennebula.org

Reply via email to