2014-03-18 09:00:41 -07:00
|
|
|
package initialize
|
|
|
|
|
|
|
|
import (
|
2014-03-21 10:35:18 -07:00
|
|
|
"os"
|
2014-03-18 09:00:41 -07:00
|
|
|
"path"
|
2014-03-21 10:35:18 -07:00
|
|
|
"strings"
|
2014-03-18 09:00:41 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
const DefaultSSHKeyName = "coreos-cloudinit"
|
|
|
|
|
|
|
|
type Environment struct {
|
2014-03-21 10:35:18 -07:00
|
|
|
root string
|
|
|
|
workspace string
|
|
|
|
sshKeyName string
|
|
|
|
substitutions map[string]string
|
2014-03-18 09:00:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEnvironment(root, workspace string) *Environment {
|
2014-03-21 10:35:18 -07:00
|
|
|
substitutions := map[string]string{
|
|
|
|
"$public_ipv4": os.Getenv("COREOS_PUBLIC_IPV4"),
|
|
|
|
"$private_ipv4": os.Getenv("COREOS_PRIVATE_IPV4"),
|
|
|
|
}
|
|
|
|
return &Environment{root, workspace, DefaultSSHKeyName, substitutions}
|
2014-03-18 09:00:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Environment) Workspace() string {
|
|
|
|
return path.Join(self.root, self.workspace)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Environment) Root() string {
|
|
|
|
return self.root
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Environment) SSHKeyName() string {
|
|
|
|
return self.sshKeyName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Environment) SetSSHKeyName(name string) {
|
|
|
|
self.sshKeyName = name
|
|
|
|
}
|
2014-03-21 10:35:18 -07:00
|
|
|
|
|
|
|
func (self *Environment) Apply(data string) string {
|
|
|
|
for key, val := range self.substitutions {
|
|
|
|
data = strings.Replace(data, key, val, -1)
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|