Re: How to pass parameters to hook scripts ?

140 views
Skip to first unread message

Guido Trotter

unread,
May 22, 2013, 11:16:52 AM5/22/13
to gan...@googlegroups.com

You can use tags, perhaps that the script can read. Would that work?

Thanks,

Guido

On 22 May 2013 17:13, "hugo lassiege" <hlas...@gmail.com> wrote:
Hi,

I'm wondering if it's possible to pass parameters to the hook scripts executed by Ganeti when I create a new instance.
In fact, I'm trying to use those parameters in hook scripts to customize the configuration of the machine once installed.

Maybe it's not a good use of hook scripts. What is the best practice for this this kind of requirements ?

Thanks,
Hugo

Guido Trotter

unread,
May 22, 2013, 12:04:30 PM5/22/13
to hugo lassiege, gan...@googlegroups.com
+list:

gnt-instance add has --tags that can be used to add tags at instance creation.
Moreover if you want to add it later you can always add the tag and
then run an instance reinstall.

Thanks,

Guido

On Wed, May 22, 2013 at 6:00 PM, hugo lassiege <hlas...@gmail.com> wrote:
> If my understanding is right, I can add a tag only to an existing instance.
> And there is no hook associated to "add tag" operation :/

hugo lassiege

unread,
May 22, 2013, 12:10:25 PM5/22/13
to gan...@googlegroups.com, hugo lassiege

I think I can use this feature. I'll let you known

Thanks !

hugo lassiege

unread,
May 23, 2013, 4:51:44 AM5/23/13
to gan...@googlegroups.com, hugo lassiege

I've tried but unfornately I'm not able to read the parameter from the script.
I've read the documentation : http://docs.ganeti.org/ganeti/current/html/hooks.html and I've tried GANETI_INSTANCE_TAGS and INSTANCE_TAGS. But all of those variables are empty.

Any idea ?

Guido Trotter

unread,
May 23, 2013, 5:27:08 AM5/23/13
to gan...@googlegroups.com, hugo lassiege
On Thu, May 23, 2013 at 10:51 AM, hugo lassiege <hlas...@gmail.com> wrote:
>
> I've tried but unfornately I'm not able to read the parameter from the
> script.
> I've read the documentation :
> http://docs.ganeti.org/ganeti/current/html/hooks.html and I've tried
> GANETI_INSTANCE_TAGS and INSTANCE_TAGS. But all of those variables are
> empty.
>
> Any idea ?

I see GANETI_INSTANCE_TAGS populated in the environment of the hook.
For example I created a hook called "myenv" in
/etc/ganeti/hooks/instance-add-post.d that does:
#!/bin/bash

env > /tmp/testtest

and
# cat /tmp/testtest | grep -i tag
GANETI_POST_INSTANCE_TAGS=tmp:test:test
GANETI_INSTANCE_TAGS=tmp:test:test

Now, that said, if you want to customize the instances that you
create, wouldn't os variants and os parameters be better than hooks
and tags? (sorry, yesterday I was in a hurry and didn't realize the
situation fully)

Thanks,

Guido

Hugo Lassiège

unread,
May 23, 2013, 5:58:28 AM5/23/13
to Guido Trotter, gan...@googlegroups.com
Ok, weird. I use the REST API with a POST on /2/instances/

{
            "__version__":   1,
            "instance_name": "instance8.test",
            "pnode":         "peanuts-node1",
            "snode":         "peanuts-node2",
            "tags": ["dummy:dummy", "param1:value1"],
            "os_type":       "debootstrap+wheezy",
            "mode":          "create",
            "disk_template": "drbd",
            "beparams":      { "memory": "512m" },
            "disks":         [ {
                               "mode": "rw",
                               "size": "1G"
                             } ],
            "nics":         [ {} ]
}


I thought the tags would be read. I displayed the full env in a log file :

touch /tmp/testHook
env >> /tmp/testGanetiHook01


But the tags are not found in the resulted file.

Concerning your second question, I have to read the documentation more about that. It's my first day on Ganeti ;)


2013/5/23 Guido Trotter <ultr...@gmail.com>

Guido Trotter

unread,
May 23, 2013, 6:11:47 AM5/23/13
to Hugo Lassiège, gan...@googlegroups.com
Does the resulting instance have them if you do a list-tags ?
Do you see them in gnt-job show <job-id>?
If not perhaps it's a RAPI bug.

Thanks,

Guido

Hugo Lassiège

unread,
May 23, 2013, 6:22:47 AM5/23/13
to Guido Trotter, gan...@googlegroups.com
yes, it's available in the list-tags :

root@peanuts-node1:/etc/ganeti/instance-debootstrap/hooks# gnt-instance list-tags instance8.test
dummy:dummy
param1:value1

I continue to investigate.



2013/5/23 Guido Trotter <ultr...@gmail.com>

Hugo Lassiège

unread,
May 23, 2013, 6:28:09 AM5/23/13
to Guido Trotter, gan...@googlegroups.com
ok, it works if the script is here :

/etc/ganeti/hooks/instance-add-post.d

Previously my script was here :

etc/ganeti/instance-debootstrap/hooks

I have to understand the difference between the two.

Thanks for your help !



2013/5/23 Hugo Lassiège <hlas...@gmail.com>

Guido Trotter

unread,
May 23, 2013, 6:47:47 AM5/23/13
to Hugo Lassiège, gan...@googlegroups.com
On Thu, May 23, 2013 at 12:28 PM, Hugo Lassiège <hlas...@gmail.com> wrote:
> ok, it works if the script is here :
>
> /etc/ganeti/hooks/instance-add-post.d
>
> Previously my script was here :
>
> etc/ganeti/instance-debootstrap/hooks
>
> I have to understand the difference between the two.
>
> Thanks for your help !
>

One are Ganeti scripts, one are instance-debootstrap scripts.
Apparently it seems we're not exporting tags to the OSes, and as such
they don't get to their hooks either.
You can file a bug if you feel this should change, but please note
that if you want to customize the *install* the best way is via os
parameters (which indeed can be read by hooks). Please read the
ganeti-os-interface manpage for more information about that.

Thanks,

Guido

hugo lassiege

unread,
May 24, 2013, 4:31:31 AM5/24/13
to gan...@googlegroups.com, Hugo Lassiège
Just for information, for our use case it works well with tags.
About your suggestion to use os parameters, I'm not sure it's ok in our use case. We drive the instance creations with the REST API and those parameters vary according to user inputs. It won't be flexible enough to use os parameters written in file on the Ganeti Cluster.

That said, it's ok for us right now, it would be  better if tags were exposed in instance-deboostrap hooks but it works.
Reply all
Reply to author
Forward
0 new messages