<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="moz-cite-prefix">On 11/27/2013 01:05 PM, Carlos Martín
      Sánchez wrote:<br>
    </div>
    <blockquote
cite="mid:CAEPYvF+rp4NaV1hNVG8=-vODLj4JBQ2KVL236Bc51X0yRX0D0w@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">Hi,<br>
        </div>
        <div class="gmail_extra">
          <div><br>
          </div>
          <div>
            <div class="gmail_extra">
              <div class="gmail_quote">On Tue, Nov 26, 2013 at 4:02 PM,
                Olivier Sallou <span dir="ltr"><<a
                    moz-do-not-send="true"
                    href="mailto:olivier.sallou@irisa.fr"
                    target="_blank">olivier.sallou@irisa.fr</a>></span> wrote:<br>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
                  <div bgcolor="#FFFFFF" text="#000000">
                    <div><br>
                      <div>On 11/26/2013 03:04 PM, Simon Boulet wrote:</div>
                    </div>
                    <div>
                      <blockquote type="cite">
                        <div dir="ltr">
                          <div class="gmail_extra">
                            <div class="gmail_quote">
                              <div><br>
                              </div>
                              <div>Perhaps that's the real problem
                                here... I'm not very familiar with
                                context.sh script. Is the entire VM
                                template available (including the
                                USER_TEMPLATE) or only the CONTEXT
                                section?</div>
                            </div>
                          </div>
                        </div>
                      </blockquote>
                      <br>
                    </div>
                    user_template is not set by itelf in the vm context
                    file, only the context. But in my context, I add
                    variables that refer to USER_TEMPLATE (but it is
                    right that there are not set in first place, only
                    after hooks). So it seems that we can refer to
                    USER_TEMPLATE var, but only if there are predefined,
                    not added in a hook (template not
                    regenerated/calculated).<br>
                    <br>
                    the best would be to have user_template vars added
                    to the context.sh file in addition to the one in the
                    vm template, AFTER the hooks.<br>
                  </div>
                </blockquote>
              </div>
            </div>
          </div>
        </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">
          True, you can get the whole VM (XML format encoded in base64)
          with the pre-defined context attribute $TEMPLATE [1]. But that
          will be done the moment the VM is created, before the on
          create hooks can update the template.</div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">
          We should change the behaviour and parse the context when the
          VM is deployed, or at least the $TEMPLATE variable... A more
          generic approach could be to add a synchronized hook before
          the VM is created, to allow to edit it before it is parsed by
          oned.</div>
      </div>
    </blockquote>
    I think that a hook before VM is created, providing the vm info
    (user, vm id etc..) would be perfect. But could we get the vm id is
    VM is not yet created ? (vmid is necessary to update its user
    template).<br>
    <br>
    I can manage for the moment this issue, I manage some things
    directly in the VM or via an external server requested by the VM at
    startup but it would be easier and better to do this directly in
    OpenNebula via hooks as suggested<br>
    <br>
    Olivier<br>
    <blockquote
cite="mid:CAEPYvF+rp4NaV1hNVG8=-vODLj4JBQ2KVL236Bc51X0yRX0D0w@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">Meanwhile, I think you have to options:</div>
        <div class="gmail_extra">- Edit the VMs before they are sent to
          OpenNebula, in the ruby API [2][3]</div>
        <div class="gmail_extra">
          - Edit the script that creates the cdrom iso [4] and insert
          your variables, or the onevm show -x output. It will be
          located in /var/lib/one/remotes/tm/shared/context</div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">
          Regards</div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">
          <div>
            <div dir="ltr">[1] <a moz-do-not-send="true"
                href="http://opennebula.org/documentation:rel4.2:cong"
                target="_blank">http://opennebula.org/documentation:rel4.2:cong</a><br>
            </div>
            <div dir="ltr">[2] <a moz-do-not-send="true"
href="http://opennebula.org/doc/4.2/oca/ruby/OpenNebula/Template.html#instantiate-instance_method"
                target="_blank">http://opennebula.org/doc/4.2/oca/ruby/OpenNebula/Template.html#instantiate-instance_method</a><br>
            </div>
            <div dir="ltr">[3] <a moz-do-not-send="true"
href="http://opennebula.org/doc/4.2/oca/ruby/OpenNebula/VirtualMachine.html#allocate-instance_method"
                target="_blank">http://opennebula.org/doc/4.2/oca/ruby/OpenNebula/VirtualMachine.html#allocate-instance_method</a></div>
            <div dir="ltr">[4] <a moz-do-not-send="true"
href="https://github.com/OpenNebula/one/blob/master/src/tm_mad/common/context">https://github.com/OpenNebula/one/blob/master/src/tm_mad/common/context</a><br>
              --<br>
              <div>Carlos Martín, MSc<br>
                Project Engineer</div>
              <div>OpenNebula - Flexible Enterprise Cloud Made Simple<br>
                <div><span
style="border-collapse:collapse;color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px"><a
                      moz-do-not-send="true"
                      href="http://www.opennebula.org/" target="_blank">www.OpenNebula.org</a> | <a
                      moz-do-not-send="true"
                      href="mailto:cmartin@opennebula.org"
                      target="_blank">cmartin@opennebula.org</a> | <a
                      moz-do-not-send="true"
                      href="http://twitter.com/opennebula"
                      target="_blank">@OpenNebula</a></span><span
style="border-collapse:collapse;color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px"></span></div>
              </div>
            </div>
          </div>
          <br>
        </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">
          <div class="gmail_quote">On Tue, Nov 26, 2013 at 4:02 PM,
            Olivier Sallou <span dir="ltr"><<a
                moz-do-not-send="true"
                href="mailto:olivier.sallou@irisa.fr" target="_blank">olivier.sallou@irisa.fr</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
              <div bgcolor="#FFFFFF" text="#000000">
                <div> <br>
                  <div>On 11/26/2013 03:04 PM, Simon Boulet wrote:<br>
                  </div>
                  <blockquote type="cite">
                    <div dir="ltr">Bonjour Olivier,
                      <div><br>
                      </div>
                      <div>I think there are two issues in your
                        question.<br>
                        <div><br>
                        </div>
                        <div class="gmail_extra">
                          <div class="gmail_quote">On Tue, Nov 26, 2013
                            at 5:55 AM, Olivier Sallou <span dir="ltr"><<a
                                moz-do-not-send="true"
                                href="mailto:olivier.sallou@irisa.fr"
                                target="_blank">olivier.sallou@irisa.fr</a>></span>
                            wrote:<br>
                            <blockquote class="gmail_quote"
                              style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
                              <div bgcolor="#FFFFFF" text="#000000">
                                <div> <br>
                                  <div>On 11/26/2013 11:51 AM, Olivier
                                    Sallou wrote:<br>
                                  </div>
                                  <blockquote type="cite"> <br>
                                    <div>On 11/26/2013 11:14 AM, Carlos
                                      Martín Sánchez wrote:<br>
                                    </div>
                                    <blockquote type="cite">
                                      <div dir="ltr">
                                        <div>stored in VM/USER_TEMPLATE.
                                          You can see this with the
                                          onevm show -x command. The
                                          onevm update action only
                                          allows to edit the
                                          USER_TEMPLATE attributes, and
                                          as you described, the create
                                          hook is triggered after the VM
                                          has been correctly created.</div>
                                        <div><br>
                                        </div>
                                      </div>
                                    </blockquote>
                                  </blockquote>
                                </div>
                              </div>
                            </blockquote>
                            <div><br>
                            </div>
                            <div>First, yes, you can use the VM CREATE
                              hooks to inject or change the
                              USER_TEMPLATE attributes by issuing the
                              onevm update action. To prevent VMs from
                              being deployed before the hooks has run,
                              you can set VM_SUBMIT_ON_HOLD = "YES", and
                              have your hook do a onevm release at the
                              end of its execution for the scheduler to
                              pick and deploy the VM. This will make
                              sure that when the VM is deployed, the
                              template contains all the attributes you
                              wanted.</div>
                            <div>
                              <div><br>
                              </div>
                              <div>You can also do some extra
                                sanitization / filtering and not allow
                                the VM to be deployed if contains some
                                missing attributes, etc. by not calling
                                the onevm release at the end.</div>
                            </div>
                            <div><br>
                            </div>
                            <div>This works very well for us. In fact,
                              we do some heavy stuff in the hooks, such
                              as attaching additional IP addresses,
                              attaching or detaching disks, etc.
                              dynamically according to external sources,
                              such as the OpenNebula user template (but
                              also external databases, CRM, etc.)</div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </blockquote>
                </div>
                My hook job is ok regarding vm user_template  update, I
                tried with and without VM_SUBMIT_ON_HOLD (thanks for the
                hint), but I have the same issue, my user_template
                variables are not set in the context.sh file.
                <div><br>
                  <blockquote type="cite">
                    <div dir="ltr">
                      <div>
                        <div class="gmail_extra">
                          <div class="gmail_quote">
                            <div><span style="color:rgb(80,0,80)"> </span><br>
                            </div>
                            <blockquote class="gmail_quote"
                              style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
                              <div bgcolor="#FFFFFF" text="#000000">
                                <div>
                                  <blockquote type="cite"> What I expect
                                    is to get my USER_TEMPLATE in the
                                    context.sh mounted in my VM.<br>
                                    <br>
                                    A basic use case is to generate a
                                    unique password for a web
                                    application running in the VM. I'd
                                    like to generate the passsword with
                                    a hook and send the password to the
                                    user by mail (until here, this is
                                    fine). The generated password is
                                    also in the VM context/template so
                                    that it appears in the context.sh of
                                    the VM. At startup, a specific init
                                    script read the VM contextualization
                                    and init the web application with
                                    the password provided.<br>
                                  </blockquote>
                                </div>
                                The above example could be managed
                                directly in the VM, without specific
                                contextualization, but there are cases
                                where some variables could be user
                                dependent, so those variables would need
                                to be set dynamically on opennebula
                                server side.
                                <div>
                                  <div><br>
                                  </div>
                                </div>
                              </div>
                            </blockquote>
                            <div><br>
                            </div>
                            <div><br>
                            </div>
                            <div>Perhaps that's the real problem here...
                              I'm not very familiar with context.sh
                              script. Is the entire VM template
                              available (including the USER_TEMPLATE) or
                              only the CONTEXT section?</div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </blockquote>
                  <br>
                </div>
                user_template is not set by itelf in the vm context
                file, only the context. But in my context, I add
                variables that refer to USER_TEMPLATE (but it is right
                that there are not set in first place, only after
                hooks). So it seems that we can refer to USER_TEMPLATE
                var, but only if there are predefined, not added in a
                hook (template not regenerated/calculated).<br>
                <br>
                the best would be to have user_template vars added to
                the context.sh file in addition to the one in the vm
                template, AFTER the hooks.<br>
                <br>
                Olivier<br>
                <blockquote type="cite">
                  <div dir="ltr">
                    <div>
                      <div class="gmail_extra">
                        <div class="gmail_quote">
                          <div><br>
                          </div>
                          <div>Simon</div>
                        </div>
                        <br>
                      </div>
                    </div>
                  </div>
                </blockquote>
                <div> <br>
                  <pre cols="72">-- 
Olivier Sallou
IRISA / University of Rennes 1
Campus de Beaulieu, 35000 RENNES - FRANCE
Tel: 02.99.84.71.95

gpg key id: 4096R/326D8438  (<a moz-do-not-send="true" href="http://keyring.debian.org" target="_blank">keyring.debian.org</a>)
Key fingerprint = 5FB4 6F83 D3B9 5204 6335  D26D 78DC 68DB 326D 8438

</pre>
                </div>
              </div>
              <br>
              _______________________________________________<br>
              Users mailing list<br>
              <a moz-do-not-send="true"
                href="mailto:Users@lists.opennebula.org" target="_blank">Users@lists.opennebula.org</a><br>
              <a moz-do-not-send="true"
                href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org"
                target="_blank">http://lists.opennebula.org/listinfo.cgi/users-opennebula.org</a><br>
              <br>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Olivier Sallou
IRISA / University of Rennes 1
Campus de Beaulieu, 35000 RENNES - FRANCE
Tel: 02.99.84.71.95

gpg key id: 4096R/326D8438  (keyring.debian.org)
Key fingerprint = 5FB4 6F83 D3B9 5204 6335  D26D 78DC 68DB 326D 8438

</pre>
  </body>
</html>