Skip to content

Commit

Permalink
Add checkbox to start vm after creation
Browse files Browse the repository at this point in the history
  • Loading branch information
subuk committed Nov 23, 2019
1 parent 34a70c8 commit 88697a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions compute/compute.go
Expand Up @@ -69,6 +69,7 @@ type VirtualMachineCreateParams struct {
Volumes []VirtualMachineCreateParamsVolume
Interfaces []VirtualMachineCreateParamsInterface
Config VirtualMachineCreateParamsConfig
Start bool
}

func (service *Service) VirtualMachineCreate(params VirtualMachineCreateParams) (*VirtualMachine, error) {
Expand Down Expand Up @@ -135,6 +136,11 @@ func (service *Service) VirtualMachineCreate(params VirtualMachineCreateParams)
service.virt.Delete(vm.Id) // Ignore error
return nil, util.NewError(err, "cannot publish event virtual machine created")
}
if params.Start {
if err := service.virt.Start(vm.Id); err != nil {
return nil, util.NewError(err, "cannot start vm")
}
}
return vm, nil
}

Expand Down
9 changes: 9 additions & 0 deletions templates/virtual-machine/add.html
Expand Up @@ -118,6 +118,15 @@ <h4>Create Virtual Machine</h4>
</div>
</div>

<div class="form-group row">
<div class="col-md-12">
<div class="custom-control custom-checkbox">
<input id="start" name="Start" value="true" class="custom-control-input" type="checkbox" checked/>
<label class="custom-control-label" for="start">Start immediately after creation</label>
</div>
</div>
</div>

<div class="form-group row">
<div class="col-md-12">
<button class="btn btn-primary" data-loading="<i class='icon-refresh icons'></i> Creating Virtual Machine..." type="submit">Create Virtual Machine</button>
Expand Down
11 changes: 9 additions & 2 deletions web/env_handler_virtual_machine.go
Expand Up @@ -202,6 +202,7 @@ func (env *Environ) VirtualMachineAddFormProcess(rw http.ResponseWriter, req *ht
VCpus: int(vcpus),
Arch: req.Form.Get("Arch"),
MemoryKb: uint(memoryMb) * 1024,
Start: req.Form.Get("Start") == "true",
Volumes: []compute.VirtualMachineCreateParamsVolume{rootVolumeParams},
Interfaces: []compute.VirtualMachineCreateParamsInterface{mainInterface},
Config: compute.VirtualMachineCreateParamsConfig{
Expand All @@ -215,8 +216,14 @@ func (env *Environ) VirtualMachineAddFormProcess(rw http.ResponseWriter, req *ht
env.error(rw, req, err, "cannot fetch create vm", http.StatusInternalServerError)
return
}
redirectUrl := env.url("virtual-machine-detail", "id", vm.Id)
http.Redirect(rw, req, redirectUrl.Path, http.StatusFound)

redirectPath := ""
if params.Start {
redirectPath = env.url("virtual-machine-console-show", "id", vm.Id).Path
} else {
redirectPath = env.url("virtual-machine-detail", "id", vm.Id).Path
}
http.Redirect(rw, req, redirectPath, http.StatusFound)
}

func (env *Environ) VirtualMachineDeleteFormShow(rw http.ResponseWriter, req *http.Request) {
Expand Down

0 comments on commit 88697a0

Please sign in to comment.