Add image_name parameter to SessionDeploy
This commit is contained in:
@@ -28,6 +28,7 @@ func NewSession(rw http.ResponseWriter, req *http.Request) {
|
||||
reqDur := req.Form.Get("session-duration")
|
||||
stack := req.Form.Get("stack")
|
||||
stackName := req.Form.Get("stack_name")
|
||||
imageName := req.Form.Get("image_name")
|
||||
|
||||
if stack != "" {
|
||||
stack = formatStack(stack)
|
||||
@@ -43,7 +44,7 @@ func NewSession(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
}
|
||||
duration := config.GetDuration(reqDur)
|
||||
s, err := core.SessionNew(duration, stack, stackName)
|
||||
s, err := core.SessionNew(duration, stack, stackName, imageName)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
//TODO: Return some error code
|
||||
|
||||
@@ -15,7 +15,7 @@ func TestClientNew(t *testing.T) {
|
||||
|
||||
p := NewPWD(docker, tasks, broadcast, storage)
|
||||
|
||||
session, err := p.SessionNew(time.Hour, "", "")
|
||||
session, err := p.SessionNew(time.Hour, "", "", "")
|
||||
assert.Nil(t, err)
|
||||
|
||||
client := p.ClientNew("foobar", session)
|
||||
@@ -43,7 +43,7 @@ func TestClientResizeViewPort(t *testing.T) {
|
||||
|
||||
p := NewPWD(docker, tasks, broadcast, storage)
|
||||
|
||||
session, err := p.SessionNew(time.Hour, "", "")
|
||||
session, err := p.SessionNew(time.Hour, "", "", "")
|
||||
assert.Nil(t, err)
|
||||
client := p.ClientNew("foobar", session)
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestInstanceNew(t *testing.T) {
|
||||
|
||||
p := NewPWD(dock, tasks, broadcast, storage)
|
||||
|
||||
session, err := p.SessionNew(time.Hour, "", "")
|
||||
session, err := p.SessionNew(time.Hour, "", "", "")
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestInstanceNew_Concurrency(t *testing.T) {
|
||||
|
||||
p := NewPWD(dock, tasks, broadcast, storage)
|
||||
|
||||
session, err := p.SessionNew(time.Hour, "", "")
|
||||
session, err := p.SessionNew(time.Hour, "", "", "")
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -144,7 +144,7 @@ func TestInstanceNew_WithNotAllowedImage(t *testing.T) {
|
||||
|
||||
p := NewPWD(dock, tasks, broadcast, storage)
|
||||
|
||||
session, err := p.SessionNew(time.Hour, "", "")
|
||||
session, err := p.SessionNew(time.Hour, "", "", "")
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -192,7 +192,7 @@ func TestInstanceNew_WithCustomHostname(t *testing.T) {
|
||||
|
||||
p := NewPWD(dock, tasks, broadcast, storage)
|
||||
|
||||
session, err := p.SessionNew(time.Hour, "", "")
|
||||
session, err := p.SessionNew(time.Hour, "", "", "")
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ type pwd struct {
|
||||
}
|
||||
|
||||
type PWDApi interface {
|
||||
SessionNew(duration time.Duration, stack string, stackName string) (*Session, error)
|
||||
SessionNew(duration time.Duration, stack string, stackName, imageName string) (*Session, error)
|
||||
SessionClose(session *Session) error
|
||||
SessionGetSmallestViewPort(session *Session) ViewPort
|
||||
SessionDeployStack(session *Session) error
|
||||
|
||||
@@ -45,13 +45,14 @@ type Session struct {
|
||||
Ready bool `json:"ready"`
|
||||
Stack string `json:"stack"`
|
||||
StackName string `json:"stack_name"`
|
||||
ImageName string `json:"image_name"`
|
||||
closingTimer *time.Timer `json:"-"`
|
||||
scheduled bool `json:"-"`
|
||||
clients []*Client `json:"-"`
|
||||
ticker *time.Ticker `json:"-"`
|
||||
}
|
||||
|
||||
func (p *pwd) SessionNew(duration time.Duration, stack, stackName string) (*Session, error) {
|
||||
func (p *pwd) SessionNew(duration time.Duration, stack, stackName, imageName string) (*Session, error) {
|
||||
defer observeAction("SessionNew", time.Now())
|
||||
|
||||
sessionsMutex.Lock()
|
||||
@@ -72,6 +73,7 @@ func (p *pwd) SessionNew(duration time.Duration, stack, stackName string) (*Sess
|
||||
stackName = "pwd"
|
||||
}
|
||||
s.StackName = stackName
|
||||
s.ImageName = imageName
|
||||
|
||||
log.Printf("NewSession id=[%s]\n", s.Id)
|
||||
|
||||
@@ -161,7 +163,7 @@ func (p *pwd) SessionDeployStack(s *Session) error {
|
||||
|
||||
s.Ready = false
|
||||
p.broadcast.BroadcastTo(s.Id, "session ready", false)
|
||||
i, err := p.InstanceNew(s, InstanceConfig{})
|
||||
i, err := p.InstanceNew(s, InstanceConfig{ImageName: s.ImageName})
|
||||
if err != nil {
|
||||
log.Printf("Error creating instance for stack [%s]: %s\n", s.Stack, err)
|
||||
return err
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestSessionNew(t *testing.T) {
|
||||
|
||||
before := time.Now()
|
||||
|
||||
s, e := p.SessionNew(time.Hour, "", "")
|
||||
s, e := p.SessionNew(time.Hour, "", "", "")
|
||||
expectedSessions[s.Id] = s
|
||||
|
||||
assert.Nil(t, e)
|
||||
@@ -64,11 +64,12 @@ func TestSessionNew(t *testing.T) {
|
||||
assert.Equal(t, s.Id, createdNetworkId)
|
||||
assert.True(t, s.Ready)
|
||||
|
||||
s, _ = p.SessionNew(time.Hour, "stackPath", "stackName")
|
||||
s, _ = p.SessionNew(time.Hour, "stackPath", "stackName", "imageName")
|
||||
expectedSessions[s.Id] = s
|
||||
|
||||
assert.Equal(t, "stackPath", s.Stack)
|
||||
assert.Equal(t, "stackName", s.StackName)
|
||||
assert.Equal(t, "imageName", s.ImageName)
|
||||
assert.False(t, s.Ready)
|
||||
|
||||
assert.NotNil(t, s.closingTimer)
|
||||
@@ -173,7 +174,7 @@ func TestSessionSetup(t *testing.T) {
|
||||
storage := &mockStorage{}
|
||||
|
||||
p := NewPWD(dock, tasks, broadcast, storage)
|
||||
s, e := p.SessionNew(time.Hour, "", "")
|
||||
s, e := p.SessionNew(time.Hour, "", "", "")
|
||||
assert.Nil(t, e)
|
||||
|
||||
err := p.SessionSetup(s, SessionSetupConf{
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<button id="start" type="submit">Start Session</button>
|
||||
<input id="stack" type="hidden" name="stack" value=""/>
|
||||
<input id="stack_name" type="hidden" name="stack_name" value=""/>
|
||||
<input id="image_name" type="hidden" name="image_name" value=""/>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
@@ -42,5 +43,9 @@
|
||||
if (stack) {
|
||||
document.getElementById('stack_name').value = stackName;
|
||||
}
|
||||
var imageName = getParameterByName('image_name');
|
||||
if (stack) {
|
||||
document.getElementById('image_name').value = imageName;
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<input type="hidden" name="session-duration" value="4h"/>
|
||||
<input id="stack" type="hidden" name="stack" value=""/>
|
||||
<input id="stack_name" type="hidden" name="stack_name" value=""/>
|
||||
<input id="image_name" type="hidden" name="image_name" value=""/>
|
||||
<button id="create" style="display:none;">Create session</button>
|
||||
</form>
|
||||
<img src="/assets/large_h.png" />
|
||||
@@ -43,6 +44,10 @@
|
||||
if (stackName) {
|
||||
document.getElementById('stack_name').value = stackName;
|
||||
}
|
||||
var imageName = getParameterByName('image_name');
|
||||
if (imageName) {
|
||||
document.getElementById('image_name').value = imageName;
|
||||
}
|
||||
if (document.cookie.indexOf('session_id') > -1) {
|
||||
document.getElementById('create').style = "";
|
||||
document.getElementById('recaptcha').style = "display:none;";
|
||||
|
||||
Reference in New Issue
Block a user