[one-users] Reference CONTEXT variables within CONTEXT

Valentin Bud valentin.bud at gmail.com
Thu May 16 00:28:14 PDT 2013


I am trying to reference the CONTEXT variables from within CONTEXT.

For example, I define the DOMAIN="domain.tld" and the HOSTNAME="host".
I would like to have a variable FQDN="$HOST.$DOMAIN.".

I have tried to achieve the above using the following in CONTEXT section
of the template.

Case I
--

$ onetemplate show vars

TEMPLATE CONTENTS
CONTEXT=[
  DOMAIN="domain.tld",
  FQDN="$DOMAIN.$HOSTNAME.",
  HOSTNAME="host" ]

[... output omitted for brevity ...]

Instantiating the template results in the following variables added to
the VM.

$ onevm show vars

VIRTUAL MACHINE TEMPLATE
CONTEXT=[
  DISK_ID="1",
  DOMAIN="domain.tld",
  *FQDN="..",*
  HOSTNAME="host",
  TARGET="hda" ]

Case II
--

$ onetemplate show vars

CONTEXT=[
  DOMAIN="domain.tld",
  FQDN="$CONTEXT[$DOMAIN].$CONTEXT[$HOSTNAME].",
  HOSTNAME="host" ]
[... output omitted for brevity ...]

Same result in the VM.

$ onevm show vars

VIRTUAL MACHINE TEMPLATE
CONTEXT=[
  DISK_ID="1",
  DOMAIN="domain.tld",
  *FQDN=".."*,
  HOSTNAME="host",
  TARGET="hda" ]
[... output omitted for brevity ...]

Is it possible to achieve what am I trying or should I search for a new
solution?

I have a simple use case. I am generating, via a hook, the ssh keys for
the VM in question. At boot I copy the keys from /mnt to /etc/ssh via 
a crafted one-context script. Awesome mechanism by the way :-).

I am generating the keys in
CONTEXT_FILES_LOCATION=/var/lib/cloud/context/host.domain.tld.

I would like to use the following in the CONTEXT section:

CONTEXT=[
CONTEXT_FILES_LOCATION=/var/lib/cloud/context/host.domain.tld./,
DOMAIN="domain.tld",
FILES="$CONTEXT_FILES_LOCATION/$FQDN/ssh_host_rsa_key ...",
HOSTNAME="host",
FQDN="$HOSTNAME.$DOMAIN." ]

This makes the template much more dynamic. I would just change the HOSTNAME
and the paths would get generated dynamically.

Any help is appreciated.

Cheers and Goodwill,

--
Valentin Bud
www.databus.pro | valentin at databus.pro


More information about the Users mailing list