Update windows provisioner
This commit is contained in:
2
api.go
2
api.go
@@ -22,7 +22,7 @@ func main() {
|
|||||||
s := initStorage()
|
s := initStorage()
|
||||||
f := initFactory(s)
|
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)
|
sp := provisioner.NewOverlaySessionProvisioner(f)
|
||||||
|
|
||||||
core := pwd.NewPWD(f, e, s, sp, ipf)
|
core := pwd.NewPWD(f, e, s, sp, ipf)
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package provisioner
|
package provisioner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -47,7 +44,7 @@ type instanceInfo struct {
|
|||||||
id string
|
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}
|
return &windows{factory: f, storage: st}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +54,6 @@ func (d *windows) InstanceNew(session *types.Session, conf types.InstanceConfig)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"io.tutorius.networkid": session.Id,
|
"io.tutorius.networkid": session.Id,
|
||||||
"io.tutorius.networking.remote.ip": winfo.privateIP,
|
"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)
|
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 {
|
func (d *windows) releaseInstance(instanceId string) error {
|
||||||
return d.storage.WindowsInstanceDelete(instanceId)
|
return d.storage.WindowsInstanceDelete(instanceId)
|
||||||
}
|
}
|
||||||
@@ -262,7 +225,7 @@ func (d *windows) getWindowsInstanceInfo(sessionId string) (*instanceInfo, error
|
|||||||
avInstanceId := d.pickFreeInstance(sessionId, availInstances, assignedInstancesIds)
|
avInstanceId := d.pickFreeInstance(sessionId, availInstances, assignedInstancesIds)
|
||||||
|
|
||||||
if len(avInstanceId) == 0 {
|
if len(avInstanceId) == 0 {
|
||||||
return nil, errors.New("No Windows instance available")
|
return nil, OutOfCapacityError
|
||||||
}
|
}
|
||||||
|
|
||||||
iout, err := ec2Service.DescribeInstances(&ec2.DescribeInstancesInput{
|
iout, err := ec2Service.DescribeInstances(&ec2.DescribeInstancesInput{
|
||||||
|
|||||||
Reference in New Issue
Block a user