[gPXE-devel] (no subject)
Shao Miller
Shao.Miller at yrdsb.edu.on.ca
Mon Mar 15 09:59:12 EDT 2010
Stefan Hajnoczi wrote:
>
> I can't see how 'loopif' and executing scripts support a general
> if-else statement. Executing scripts allows code snippets to be
> called out to, but a conditional is still required to choose the right
> name for the script to call (think if-else statement).
>
> Maybe I am missing something?
>
Heheh, thus far I never intended to claim that 'exit' and 'loopif' could
support if-else flow control. 'exit' and 'loopif' were prompted by an
IRC user who wished for gPXE to poll a server for instructions,
otherwise idling. This scenario is similar to IBM Tivoli Provisioning
Manager for OS Deployment's idling strategy. 'exit' and 'loopif' can
directly support loops, which are a form of flow control that gPXE
doesn't currently have. That's what the commit comments were intended
to convey.
I think the bigger issue to tackle before flow control becomes highly
useful is controlling "erroring out" of scripts. A singular error at
this time will break out of all scripts.
As far as if-else functionality goes, consider this:
#!gpxe
# toplevel.gpxe
set exec0 #
set exec1 set
set next-script step1
set keep-running 1
imgload main.gpxe
boot main.gpxe
#!gpxe
# main.gpxe
imgload ${next-script}.gpxe
boot ${next-script}.gpxe
loopif ${keep-running}
#!gpxe
# stepX.gpxe
# exec becomes "${execX}"
set exec:hex 24:7B:65:78:65:63:${condition1:hex}:7D
set foo default_value
${exec} foo bar
# foo will contain "default_value" or "bar" depending on what condition1 was
# You could use the same :hex method to fill foo with instructions,
# so you could do:
# ${foo}
echo condition1: ${condition1}, foo: ${foo}
# ...
# We can set next-script based on conditions
# We can fill exitif variable with "exit" or "#" based on a condition
and do:
# ${exitif}
Some of this is obviously pretty tricky, but I think my point is that it
can be done... One could develop a "library" that makes some of this
easier and implements common uses. It's nowhere near as pretty as if-else.
Anyway, the merits of 'exit' and 'loopif' should please be considered
based on code size cost and that it helps users to loop, should they
need to. I don't mean to suggest them as the solution to all gPXE
script uses... We have Lynus' work from last Google Summer of Code
still as well as great discussions about the perfect scripting system,
as well as a lack of "stayin' alive" in current scripts, as well as a
lack of math &/ logic in current scripts.
It would be great if we could have 'exit', 'loopif', 'if', ': label',
and 'goto' all together, though 'loopif' could be accomplished by 'if
... goto', instead.
I value your thoughts thus far. :)
- Shao Miller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://etherboot.org/pipermail/gpxe-devel/attachments/20100315/27ad3bb9/attachment.html
More information about the gPXE-devel
mailing list