diff --git a/handlers/new_instance.go b/handlers/new_instance.go index f91f685..711191f 100644 --- a/handlers/new_instance.go +++ b/handlers/new_instance.go @@ -38,6 +38,20 @@ func NewInstance(rw http.ResponseWriter, req *http.Request) { return } + instances, err := core.InstanceFindBySession(s) + + if err != nil { + log.Println(err) + rw.WriteHeader(http.StatusInternalServerError) + return + } + + if playground.InstancesMax > 0 && len(instances) > playground.MaxInstances { + log.Println(err) + rw.WriteHeader(http.StatusConflict) + return + } + i, err := core.InstanceNew(s, body) if err != nil { if pwd.SessionComplete(err) { diff --git a/pwd/instance.go b/pwd/instance.go index 5880e46..ba807e2 100644 --- a/pwd/instance.go +++ b/pwd/instance.go @@ -98,16 +98,6 @@ func (p *pwd) InstanceDelete(session *types.Session, instance *types.Instance) e func (p *pwd) InstanceNew(session *types.Session, conf types.InstanceConfig) (*types.Instance, error) { defer observeAction("InstanceNew", time.Now()) - instances, err := p.storage.InstanceFindBySessionId(session.Id) - if err != nil { - log.Println(err) - return nil, err - } - - if len(instances) >= 5 { - return nil, sessionComplete - } - prov, err := p.getProvisioner(conf.Type) if err != nil { return nil, err diff --git a/pwd/types/playground.go b/pwd/types/playground.go index 3f8df21..5fc34f7 100644 --- a/pwd/types/playground.go +++ b/pwd/types/playground.go @@ -87,4 +87,5 @@ type Playground struct { FacebookClientSecret string `json:"facebook_client_secret" bson:"facebook_client_secret"` DockerClientID string `json:"docker_client_id" bson:"docker_client_id"` DockerClientSecret string `json:"docker_client_secret" bson:"docker_client_secret"` + MaxInstances int `json:"max_instances" bson:"max_instances"` }