Skip to content
Permalink
Browse files

Allow to specify interface vlan on vm create page

  • Loading branch information
subuk committed Sep 1, 2019
1 parent b886463 commit ac4e026b231f14565b1ff9e2d44a10aabaa7af8d
Showing with 26 additions and 11 deletions.
  1. +8 −6 compute/compute.go
  2. +7 −3 templates/virtual-machine/add.html
  3. +11 −2 web/env_handler_virtual_machine.go
@@ -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 {
@@ -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)
}
@@ -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>

@@ -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"),
@@ -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"),

0 comments on commit ac4e026

Please sign in to comment.
You can’t perform that action at this time.