Move max instnace check to playground config
This commit is contained in:
@@ -38,6 +38,20 @@ func NewInstance(rw http.ResponseWriter, req *http.Request) {
|
|||||||
return
|
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)
|
i, err := core.InstanceNew(s, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pwd.SessionComplete(err) {
|
if pwd.SessionComplete(err) {
|
||||||
|
|||||||
@@ -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) {
|
func (p *pwd) InstanceNew(session *types.Session, conf types.InstanceConfig) (*types.Instance, error) {
|
||||||
defer observeAction("InstanceNew", time.Now())
|
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)
|
prov, err := p.getProvisioner(conf.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -87,4 +87,5 @@ type Playground struct {
|
|||||||
FacebookClientSecret string `json:"facebook_client_secret" bson:"facebook_client_secret"`
|
FacebookClientSecret string `json:"facebook_client_secret" bson:"facebook_client_secret"`
|
||||||
DockerClientID string `json:"docker_client_id" bson:"docker_client_id"`
|
DockerClientID string `json:"docker_client_id" bson:"docker_client_id"`
|
||||||
DockerClientSecret string `json:"docker_client_secret" bson:"docker_client_secret"`
|
DockerClientSecret string `json:"docker_client_secret" bson:"docker_client_secret"`
|
||||||
|
MaxInstances int `json:"max_instances" bson:"max_instances"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user