[one-users] Using USER template variable in VM Template

Ruben S. Montero rsmontero at opennebula.org
Mon Aug 27 15:36:57 PDT 2012


Hi

See comments inline.

On Mon, Aug 27, 2012 at 3:28 AM, Hyun Woo Kim <hyunwoo at fnal.gov> wrote:

> Dear Ruben,
>
> Thanks again for your response, I appreciate that.
>
> I am willing to hack the relevant API that will enable this.
> Before doing that, let me rephrase my questions one more time to clarify
> what I want,
> in order to find out which part will be the easiest to hack..
>
>
> The manual says that  possible values for VARIABLE in CONTEXT section are
> 1. hardcoded values
> 2. template variables such $VMID or $NIC which are sections in the VM
> template
> 3. $NETWORK or $IMAGE or $USER like
>    $NETWORK[attribute, NETWORK_ID=3]
>    $IMAGE[attribute, IMAGE_ID=2]
>    $USER[attribute, USER_ID=3] where attribute can be SSH_KEY or TEMPLATE
> 4. pre-defined variable: $UID and $TEMPLATE.
>
> Question 1.
> As UID points to the ID of the user(owner of the VM),
> is it possible to create a new "pre-defined variable" USERNAME or UNAME
> which points to the name of the owner of the VM?
>
>
This has to be implemented in the OpenNebula core, we will provide you a
patch in a few days.



> Question 2.
> Are SSH_KEY and TEMPLATE the only two <user_attributes>s available
>  for $USER? or is there more? if so, what are they?
> why can I not use NAME like
> CONTEXT = [
> username = $USER[NAME, USER_ID=$VID]
> ]
>
>
1.- Templates are free form, you can add anything you want. Please try, in
the command line:

>oneuser update
...
This will open your EDITOR, using the standard syntax you can add any
variable, e.g.:
NAME=my_user_name
PASSWORD=mypass
SSH_KEY=AHxa245...
LOGIN=my_login

Then simply add to the VM template:

CONTEXT = [
username = $USER[NAME]
login = $USER[LOGIN]
ssh = $USER[SSH_KEY]
]

2.- You do not need to "qualify" the USER, it will always refer to the user
creating the VM. Note that otherwise that will be a security hole, as you
could access other user data.

3.- There are no variables in the user template by default. Note the
<TEMPLATE/> element in oneuser show -x, before and after adding template
variables with oneuser update.


> Question(s) 3.
> Two major standard sections(DISK and NETWORK) in a VM Template
> they must access the database as follows;
> 1. DISK    : this must access image_pool
> 2. NETWORK : this must access network_pool
> Is this correct?
>

It is not accessing the DB, in a SQL manner. Data is gather from the
objects.


>
> Then, if I define a new section for instance USER2
> (I am not using USER, because it is already reserved keywork, right?)
>
> USER2 = [ USER_ID=$UID ]
>

Define where?. Note that variable substitution only happens within the
CONTEXT attribute.


> (assuming the predefined UID can be used in other sections as well besides
> CONTEXT)
>
> and in the CONTEXT section,
>
> CONTEXT = [
> username = $USER2[NAME]
> ]
>
> will this access the user_pool in the DB and get the NAME?
>
> No, you can only access values within the TEMPLATE element.


> If this does not work in the current configuration,
> can I modify the source code to enable this just like DISK and NETWORK
> sections
> access the DB?
>

Give us a couple of days and we will send you a patch to access the
extended user information.

Cheers

Ruben


>
> Thank you.
> Hyunwoo
>
>
>
> ________________________________________
> From: Ruben S. Montero [rsmontero at opennebula.org]
> Sent: Sunday, August 26, 2012 4:33 PM
> To: Hyun Woo Kim
> Cc: users at lists.opennebula.org
> Subject: Re: [one-users] Using USER template variable in VM Template
>
> Hi
>
> If you look at the output of the XML, -x option, there is something like:
>
>   <USER>
>     <ID>6</ID>
>     <GID>1</GID>
>     <GNAME>users</GNAME>
>     <NAME>demo</NAME>
>     <PASSWORD>89e495e7941cf9e40e6980d14a16bf023ccd4c91</PASSWORD>
>     <AUTH_DRIVER>core</AUTH_DRIVER>
>     <ENABLED>1</ENABLED>
>     <TEMPLATE/>
>     <DATASTORE_QUOTA/>
>     <NETWORK_QUOTA/>
>     <VM_QUOTA/>
>     <IMAGE_QUOTA/>
>   </USER>
>
> You can access to anything inside the <TEMPLATE/> element, empty by
> default.
>
> There is no direct way to include that information in a VM Template.
> This can be done at the API level with some hacking. (Unless you add
> NAME to TEMPLATE)
>
> The original set of pre-defined variables UID, TEMPLATE aren't
> obviously up-to-date. I've filled an issue to address this for the
> next release [1].
>
> Thanks
>
> Ruben
>
> [1] http://dev.opennebula.org/issues/1428
>
> On Sun, Aug 26, 2012 at 11:07 PM, Hyun Woo Kim <hyunwoo at fnal.gov> wrote:
> > Hi,
> >
> > Thanks very much for the response.
> >
> > Actually, your answer seems a bit different from what the manual says
> > and what I observe.
> >
> > I observe that the "USERS" actually have "TEMPLATE" attribute
> > which returns the contents of "user_pool" in the database
> > (We are using MySQL).
> > The contents of MySQL "user_pool" contain NAME field.
> > I thought these fields in DB and <user_attribute>s of USER template
> > somehow are related..
> >
> > Let me simplify my original question.
> > Is there anyway to fetch the NAME field of the DB for the
> > user who does "onetemplate instantiate"..?
> >
> > Thanks,
> > Hyunwoo
> >
> >
> >
> > Current version of OpenNebula can only access template variables from
> > users, or networks. By default users have an empty template, so there
> > is no NAME variable unless you define it, e.g. oneuser update. About
> > $UID, this variable is predefined so the OpenNebula core it is not
> > actually accessing the user information but that stored in the VM.
> >
> > Cheers
> >
> > Ruben
> >
> > On Fri, Aug 24, 2012 at 10:37 PM, Hyun Woo Kim <hyunwoo at fnal.gov> wrote:
> >> Dear Developers,
> >>
> >> I want to define a variable "username" in CONTEXT
> >> and replace it by a real user name who does
> >> onetemplate instantiate
> >>
> >> The CONTEXT section of my VM Template looks like the following;
> >> CONTEXT = [
> >> username    = "$USER[NAME]"
> >> ]
> >>
> >> I am following the instruction in
> >> http://opennebula.org/documentation:archives:rel3.2:template
> >> which says at the bottom ;
> >> ...
> >> Using User template variables
> >> $USER[ <user_attribute> ]: Any single value variable in the user
> template
> >> for example: ssh_key = "$USER[SSH_KEY]"
> >> The user_attribute can be TEMPLATE to include…
> >> …..
> >>
> >>
> >> So, I thought NAME can be one possible <user_attribute> like TEMPLATE,
> >> but this does not work..
> >> I even tried
> >> username    = "$USER[NAME, USER_ID=$UID]"
> >> username    = "$USER[NAME, ID=$UID]"
> >> username    = "$USER[NAME, USER_ID=2]"
> >> username    = "$USER[NAME, ID=2]"
> >> All fail..
> >>
> >> By the way,
> >> username    = "$UID" works and username is assigned my correct user id
> >>
> >> What am I doing wrong here?
> >>
> >>
> >> Thank you.
> >> Hyunwoo
> >> _______________________________________________
> >> Users mailing list
> >> Users at lists.opennebula.org
> >> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
> >>
> >
> >
> >
> > --
> > Ruben S. Montero, PhD
> > Project co-Lead and Chief Architect
> > OpenNebula - The Open Source Solution for Data Center Virtualization
> > www.OpenNebula.org | rsmontero at opennebula.org | @OpenNebula
>
>
>
> --
> Ruben S. Montero, PhD
> Project co-Lead and Chief Architect
> OpenNebula - The Open Source Solution for Data Center Virtualization
> www.OpenNebula.org | rsmontero at opennebula.org | @OpenNebula
>



-- 
Ruben S. Montero, PhD
Project co-Lead and Chief Architect
OpenNebula - The Open Source Solution for Data Center Virtualization
www.OpenNebula.org | rsmontero at opennebula.org | @OpenNebula
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20120828/433c8aea/attachment-0002.htm>


More information about the Users mailing list