Simpler startInstance & friends?
Jeroen Vermeulen
jtv at canonical.com
Tue Mar 12 04:17:05 UTC 2013
Hi all,
Raphaël Badin and I have been looking at the startInstance() and
userData() code in the ec2 and openstack providers. It was pretty hard
to figure out what goes on. But having had to do that anyway, we think
we have found a way to simplify it and make it more manageable. I'm
bringing it up here because somebody may find it useful.
The only call sites we are aware of for startInstance are Bootstrap()
and StartInstance(). It looks to us as if this code could be simpler
with 3 changes:
1. The caller passes "tools" to startInstance(), but if tools is nil,
startInstance() looks for tools. This can only happen if the caller is
StartInstance(). Moving the check in there enables other changes below.
2. startInstance() can take a user-data blob as a parameter. The caller
first creates it by calling userData().
This takes away a lot of the information going into startInstance().
The big differences between the two call sites are now at the call site,
instead of inside startInstance().
3. The startInstanceParams struct type is effectively a wrapper for
cloudinit.MachineConfig. Once it's no longer shared between
startInstance() and userData(), it becomes easier just to use MachineConfig.
I don't know if anybody would be interested in trying this, but since we
had to figure out the code anyway, we might as well share.
Jeroen
More information about the Juju-dev
mailing list