Skip to content

Commit

Permalink
Allow to specify interface vlan on vm create page
Browse files Browse the repository at this point in the history
  • Loading branch information
subuk committed Sep 1, 2019
1 parent b886463 commit ac4e026
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
14 changes: 8 additions & 6 deletions compute/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ type VirtualMachineCreateParamsVolume struct {
}

type VirtualMachineCreateParamsInterface struct {
Network string
Mac string
Model string
Network string
Mac string
Model string
AccessVlan uint
}

type VirtualMachineCreateParams struct {
Expand Down Expand Up @@ -97,9 +98,10 @@ func (service *Service) VirtualMachineCreate(params VirtualMachineCreateParams)
return nil, util.NewError(err, "network get failed")
}
iface := &VirtualMachineAttachedInterface{
Type: network.Type,
Network: ifaceParams.Network,
Mac: ifaceParams.Mac,
Type: network.Type,
Network: ifaceParams.Network,
Mac: ifaceParams.Mac,
AccessVlan: ifaceParams.AccessVlan,
}
interfaces = append(interfaces, iface)
}
Expand Down
10 changes: 7 additions & 3 deletions templates/virtual-machine/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ <h4>Create Virtual Machine</h4>
</div>

<div class="form-group row">
<div class="col-md-6">
<div class="col-md-4">
<label>Network</label>
<select required="required" class="form-control" name="Network">
{{ range .Networks }}
<option value="{{ .Name }}">{{ .Name }} ({{ .Type }})</option>
{{ end }}
</select>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label>MAC Address</label>
<input class="form-control" name="Mac" id="Mac">
<input class="form-control" name="Mac" id="Mac" placeholder="00:00:00:00:00:00">
</div>
<div class="col-md-4">
<label for="AccessVlan">Vlan</label>
<input type="number" class="form-control" name="AccessVlan" id="AccessVlan">
</div>
</div>

Expand Down
13 changes: 11 additions & 2 deletions web/env_handler_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,22 @@ func (env *Environ) VirtualMachineAddFormProcess(rw http.ResponseWriter, req *ht
vcpus, err := strconv.ParseInt(req.Form.Get("Vcpus"), 10, 16)
if err != nil {
http.Error(rw, "invalid vcpus value: "+err.Error(), http.StatusBadRequest)
return
}
memoryMb, err := strconv.ParseUint(req.Form.Get("MemoryMb"), 10, 64)
if err != nil {
http.Error(rw, "invalid memoryMb value: "+err.Error(), http.StatusBadRequest)
return
}
rootVolumeSizeGb, err := strconv.ParseUint(req.Form.Get("RootVolumeSizeGb"), 10, 64)
if err != nil {
http.Error(rw, "invalid root volume size: "+err.Error(), http.StatusBadRequest)
return
}
accessVlan, err := strconv.ParseUint(req.Form.Get("AccessVlan"), 10, 16)
if err != nil {
http.Error(rw, "invalid vlan: "+err.Error(), http.StatusBadRequest)
return
}
rootVolumeParams := compute.VirtualMachineCreateParamsVolume{
Name: req.Form.Get("RootVolumeName"), Pool: req.Form.Get("RootVolumePool"),
Expand All @@ -187,8 +195,9 @@ func (env *Environ) VirtualMachineAddFormProcess(rw http.ResponseWriter, req *ht
Format: req.Form.Get("RootVolumeFormat"), SizeMb: rootVolumeSizeGb * 1024,
}
mainInterface := compute.VirtualMachineCreateParamsInterface{
Network: req.Form.Get("Network"),
Mac: req.Form.Get("Mac"),
Network: req.Form.Get("Network"),
Mac: req.Form.Get("Mac"),
AccessVlan: uint(accessVlan),
}
params := compute.VirtualMachineCreateParams{
Id: req.Form.Get("Name"),
Expand Down

0 comments on commit ac4e026

Please sign in to comment.