forked from Telmate/terraform-provider-proxmox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grant Gongaware
committed
Feb 11, 2017
1 parent
4c6ca72
commit 6195fc0
Showing
3 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package proxmox | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/communicator" | ||
"github.com/hashicorp/terraform/communicator/remote" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
// "github.com/hashicorp/terraform/terraform" | ||
// "github.com/mitchellh/go-linereader" | ||
"io" | ||
) | ||
|
||
// preprovision VM (setup eth0 and hostname) | ||
|
||
func preProvisionUbuntu(d *schema.ResourceData) error { | ||
|
||
// Get a new communicator | ||
comm, err := communicator.New(d.State()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = runCommand(comm, "echo cool > /tmp/test") | ||
|
||
comm.Disconnect() | ||
|
||
return err | ||
} | ||
|
||
// runCommand is used to run already prepared commands | ||
func runCommand( | ||
comm communicator.Communicator, | ||
command string) error { | ||
|
||
_, outW := io.Pipe() | ||
_, errW := io.Pipe() | ||
//outDoneCh := make(chan struct{}) | ||
//errDoneCh := make(chan struct{}) | ||
// go copyOutput(o, outR, outDoneCh) | ||
// go copyOutput(o, errR, errDoneCh) | ||
|
||
cmd := &remote.Cmd{ | ||
Command: command, | ||
Stdout: outW, | ||
Stderr: errW, | ||
} | ||
|
||
err := comm.Start(cmd) | ||
if err != nil { | ||
return fmt.Errorf("Error executing command %q: %v", cmd.Command, err) | ||
} | ||
|
||
cmd.Wait() | ||
if cmd.ExitStatus != 0 { | ||
err = fmt.Errorf( | ||
"Command %q exited with non-zero exit status: %d", cmd.Command, cmd.ExitStatus) | ||
} | ||
|
||
// Wait for output to clean up | ||
outW.Close() | ||
errW.Close() | ||
//<-outDoneCh | ||
//<-errDoneCh | ||
|
||
return err | ||
} | ||
|
||
// | ||
// func copyOutput(o terraform.UIOutput, r io.Reader, doneCh chan<- struct{}) { | ||
// defer close(doneCh) | ||
// lr := linereader.New(r) | ||
// for line := range lr.Ch { | ||
// o.Output(line) | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters