Commit a2bf964f authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: Properly support hooks

parent cb1e0cba
......@@ -60,6 +60,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) {
MaxCount: 0,
}
hook.Run(HookPreLaunch, nil, ui)
return
ui.Say("Launching a source AWS instance...\n")
runResp, err := ec2conn.RunInstances(runOpts)
if err != nil {
......
package amazonebs
// This hook is fired prior to launching the EC2 instance.
const HookPreLaunch = "amazonebs_pre_launch"
......@@ -90,3 +90,8 @@ func (c *config) LoadCommand(name string) (packer.Command, error) {
return plugin.Command(exec.Command(commandBin))
}
func (c *config) LoadHook(name string) (packer.Hook, error) {
log.Printf("Loading hook: %s\n", name)
return plugin.Hook(exec.Command(name))
}
......@@ -87,6 +87,7 @@ func main() {
envConfig.Commands = config.CommandNames()
envConfig.Components.Builder = config.LoadBuilder
envConfig.Components.Command = config.LoadCommand
envConfig.Components.Hook = config.LoadHook
env, err := packer.NewEnvironment(envConfig)
if err != nil {
......
......@@ -50,13 +50,12 @@ func (e *Environment) Hook(name string) (h packer.Hook, err error) {
return
}
_, err = rpc.Dial("tcp", reply)
client, err := rpc.Dial("tcp", reply)
if err != nil {
return
}
// TODO: Hook
h = nil
h = Hook(client)
return
}
......@@ -89,14 +88,14 @@ func (e *EnvironmentServer) Cli(args *EnvironmentCliArgs, reply *int) (err error
}
func (e *EnvironmentServer) Hook(name *string, reply *string) error {
_, err := e.env.Hook(*name)
hook, err := e.env.Hook(*name)
if err != nil {
return err
}
// Wrap it
// TODO: Register hook
server := rpc.NewServer()
RegisterHook(server, hook)
*reply = serveSingleConn(server)
return nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment