[lxc-devel] [PATCHv2] lxc-create: Store template information in config
Stéphane Graber
stgraber at ubuntu.com
Fri Nov 30 22:45:01 UTC 2012
On 11/30/2012 05:23 PM, Natanael Copa wrote:
> On Fri, 30 Nov 2012 17:01:59 -0500
> Stéphane Graber <stgraber at ubuntu.com> wrote:
>
>> Change lxc-create to add the name of the template, checksum and any
>> parameters
>> to the container's configuration.
>> This makes it easier to debug and figure out exactly how a container
>> was built.
>>
>> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
>> ---
>> src/lxc/lxc-create.in | 36 +++++++++++++++++++++++-------------
>> 1 file changed, 23 insertions(+), 13 deletions(-)
>>
>> diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
>> index 30f0c22..7a50633 100644
>> --- a/src/lxc/lxc-create.in
>> +++ b/src/lxc/lxc-create.in
>> @@ -281,7 +281,29 @@ if [ ! -r "$lxc_config" ]; then
>> exit 1
>> fi
>> -cp $lxc_config $lxc_path/$lxc_name/config
>> +# Allow for a path to be provided as the template name
>> +if [ -x $lxc_template ]; then
>
> if [ -x "$lxc_template" ]; then
>
> other wise will posix shell barf if $lxc_template is empty.
Yeah, I spotted those and noticed quite a few more bashisms so I just
kept the current "style" to minimize the diff and assumed that this
would be fixed with your effort of getting everything actually
posix-compliant :)
>> + template_path=$lxc_template
>> +else
>> + template_path=${templatedir}/lxc-$lxc_template
>> +fi
>> +
>> +if ! [ -x "$template_path" ]; then
>> + echo "$(basename $0): unknown template '$lxc_template'" >&2
>> + cleanup
>> +fi
>> +
>> +if [ ! -z $lxc_template ]; then
>
> Same here. Do:
> if [ ! -z "$lxc_template" ]; then
>
>> + sum=$(sha1sum $template_path | cut -d ' ' -f1)
>> + echo "# Template used to create this container: $lxc_template" >>
>> $lxc_path/$lxc_name/config
>> + if [ -n "$*" ]; then
>
> I'm not sure this is ok. I'd do:
>
> if [ $# -gt 0 ]; then
>
>> + echo "# Parameters passed to the template: $*" >>
>
> echo "# Parameters passed to the template: $@" >>
>
>> $lxc_path/$lxc_name/config
>> + fi
>> + echo "# Checksum of the template script (SHA-1): $sum" >>
>> $lxc_path/$lxc_name/config
>> + echo "" >> $lxc_path/$lxc_name/config
>> +fi
>> +
>> +cat $lxc_config >> $lxc_path/$lxc_name/config
>> if [ -n "$custom_rootfs" ]; then
>> if grep -q "lxc.rootfs" $lxc_path/$lxc_name/config ; then
>> @@ -301,18 +323,6 @@ if [ $backingstore = "lvm" ]; then
>> fi
>> if [ ! -z $lxc_template ]; then
>> - # Allow for a path to be provided as the template name
>> - if [ -x $lxc_template ]; then
>> - template_path=$lxc_template
>> - else
>> - template_path=${templatedir}/lxc-$lxc_template
>> - fi
>> -
>> - if ! [ -x "$template_path" ]; then
>> - echo "$(basename $0): unknown template '$lxc_template'" >&2
>> - cleanup
>> - fi
>> -
>> $template_path --path=$lxc_path/$lxc_name --name=$lxc_name $*
>> if [ $? -ne 0 ]; then
>> echo "$(basename $0): failed to execute template
>> '$lxc_template'" >&2
>
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20121130/2f6a402e/attachment.pgp>
More information about the lxc-devel
mailing list