Merge pull request #11 from bfirsh/cloud-backend-fixes

This commit is contained in:
Solomon Hykes 2014-05-26 19:39:26 -07:00
commit b69fb4ec3b
2 changed files with 28 additions and 28 deletions

View File

@ -52,19 +52,19 @@ type cloud struct {
}
type Container struct {
Id string
Id string
Image string
Tty bool
Tty bool
}
// returns true, if the connection was successful, false otherwise
type Tunnel struct {
url.URL
url.URL
}
func (t Tunnel) isActive() bool {
_, err := http.Get(t.String())
return err == nil
_, err := http.Get(t.String())
return err == nil
}
func (s *cloud) Install(eng *engine.Engine) error {
@ -83,7 +83,7 @@ func (s *cloud) Install(eng *engine.Engine) error {
}
cloud, err = NewCloudGCE(job.Args[3])
if err != nil {
job.Errorf("Unexpected error: %#v", err)
return job.Errorf("Unexpected error: %#v", err)
}
default:
return job.Errorf("Unknown cloud provider: %s", job.Args[0])
@ -91,39 +91,39 @@ func (s *cloud) Install(eng *engine.Engine) error {
ip, err := cloud.GetPublicIPAddress(instance, zone)
instanceRunning := len(ip) > 0
if !instanceRunning {
log.Print("Instance doesn't exist, creating....");
log.Print("Instance doesn't exist, creating....")
_, err = cloud.CreateInstance(instance, zone)
}
if err != nil {
job.Errorf("Unexpected error: %#v", err)
return job.Errorf("Unexpected error: %#v", err)
}
remotePort := 8000
localPort := 8001
apiVersion := "v1.10"
tunnelUrl, err := url.Parse(fmt.Sprintf("http://localhost:%d/%s/containers/json", localPort, apiVersion))
if err != nil {
return job.Errorf("Unexpected error: %#v", err)
}
tunnel := Tunnel{*tunnelUrl}
if err != nil {
return job.Errorf("Unexpected error: %#v", err)
}
tunnel := Tunnel{*tunnelUrl}
if !tunnel.isActive() {
fmt.Printf("Creating tunnel")
_, err = cloud.OpenSecureTunnel(instance, zone, localPort, remotePort)
if err != nil {
job.Errorf("Failed to open tunnel: %#v", err)
}
if !tunnel.isActive() {
fmt.Printf("Creating tunnel")
_, err = cloud.OpenSecureTunnel(instance, zone, localPort, remotePort)
if err != nil {
return job.Errorf("Failed to open tunnel: %#v", err)
}
}
host := fmt.Sprintf("tcp://localhost:%d", localPort)
client, err := newClient(host, apiVersion)
if err != nil {
job.Errorf("Unexpected error: %#v", err)
return job.Errorf("Unexpected error: %#v", err)
}
//job.Eng.Register("inspect", func(job *engine.Job) engine.Status {
// resp, err := client.call("GET", "/containers/
job.Eng.Register("create", func(job *engine.Job) engine.Status {
container := Container{
Image: job.Getenv("Image"),
Tty: job.Getenv("Tty") == "true",
Tty: job.Getenv("Tty") == "true",
}
data, err := json.Marshal(container)
resp, err := client.call("POST", "/containers/create", string(data))