From ddcf5cf7bcd933c5f6b3f050c809d215eacdfab4 Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Fri, 8 Sep 2017 19:46:49 -0300 Subject: [PATCH] Update windows provisioner --- api.go | 2 +- provisioner/windows.go | 41 ++--------------------------------------- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/api.go b/api.go index be9eaa9..5d50b0c 100644 --- a/api.go +++ b/api.go @@ -22,7 +22,7 @@ func main() { s := initStorage() f := initFactory(s) - ipf := provisioner.NewInstanceProvisionerFactory(provisioner.NewWindowsASG(f, s), provisioner.NewDinD(f, s)) + ipf := provisioner.NewInstanceProvisionerFactory(provisioner.NewWindows(f, s), provisioner.NewDinD(f, s)) sp := provisioner.NewOverlaySessionProvisioner(f) core := pwd.NewPWD(f, e, s, sp, ipf) diff --git a/provisioner/windows.go b/provisioner/windows.go index 8bb88eb..12b096d 100644 --- a/provisioner/windows.go +++ b/provisioner/windows.go @@ -1,9 +1,6 @@ package provisioner import ( - "bytes" - "encoding/json" - "errors" "fmt" "io" "log" @@ -47,7 +44,7 @@ type instanceInfo struct { id string } -func NewWindowsASG(f docker.FactoryApi, st storage.StorageApi) *windows { +func NewWindows(f docker.FactoryApi, st storage.StorageApi) *windows { return &windows{factory: f, storage: st} } @@ -57,7 +54,6 @@ func (d *windows) InstanceNew(session *types.Session, conf types.InstanceConfig) if err != nil { return nil, err } - labels := map[string]string{ "io.tutorius.networkid": session.Id, "io.tutorius.networking.remote.ip": winfo.privateIP, @@ -123,39 +119,6 @@ func (d *windows) InstanceDelete(session *types.Session, instance *types.Instanc return d.releaseInstance(instance.WindowsId) } -type execRes struct { - ExitCode int `json:"exit_code"` - Error string `json:"error"` - Stdout string `json:"stdout"` - Stderr string `json:"stderr"` -} - -func (d *windows) InstanceExec(instance *types.Instance, cmd []string) (int, error) { - execBody := struct { - Cmd []string `json:"cmd"` - }{Cmd: cmd} - - b, err := json.Marshal(execBody) - if err != nil { - return -1, err - } - resp, err := http.Post(fmt.Sprintf("http://%s:222/exec", instance.IP), "application/json", bytes.NewReader(b)) - if err != nil { - log.Println(err) - return -1, err - } - if resp.StatusCode != 200 { - log.Printf("Error exec on instance %s. Got %d\n", instance.Name, resp.StatusCode) - return -1, fmt.Errorf("Error exec on instance %s. Got %d\n", instance.Name, resp.StatusCode) - } - var ex execRes - err = json.NewDecoder(resp.Body).Decode(&ex) - if err != nil { - return -1, err - } - return ex.ExitCode, nil -} - func (d *windows) releaseInstance(instanceId string) error { return d.storage.WindowsInstanceDelete(instanceId) } @@ -262,7 +225,7 @@ func (d *windows) getWindowsInstanceInfo(sessionId string) (*instanceInfo, error avInstanceId := d.pickFreeInstance(sessionId, availInstances, assignedInstancesIds) if len(avInstanceId) == 0 { - return nil, errors.New("No Windows instance available") + return nil, OutOfCapacityError } iout, err := ec2Service.DescribeInstances(&ec2.DescribeInstancesInput{