Skip to content

Commit 9e561c4

Browse files
authored
Merge pull request #61 from NocDerEchte/pve-vm-tags
Add support for additional VM tags
2 parents b909f1e + 2c2c418 commit 9e561c4

5 files changed

Lines changed: 41 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ You can use [sample Ubuntu Server template](deploy/templates/ubuntu-server) for
109109
| `--pve-processor-cores` | `PVE_PROCESSOR_CORES` | *unset* | If set, number of processor cores to configure for the machine. |
110110
| `--pve-memory` | `PVE_MEMORY` | *unset* <sup>1</sup> | If set, amount of memory in MiB to configure for the machine. |
111111
| `--pve-memory-balloon` | `PVE_MEMORY_BALLOON` | *unset* <sup>1</sup> | If set, minimum amount of memory in MiB to configure for the machine.<br> If set to `0`, disables memory ballooning. |
112+
| `--pve-tags` | `PVE_TAGS` | *unset* | If set, Comma-separated list of tags to assign to the VM (eg. `foo,bar,foobar`). |
112113

113114
<sup>1</sup> - If only one of `--pve-memory` or `--pve-memory-balloon` is specified, the other one will automatically be defaulted to the same value except if `--pve-memory-balloon` is set to `0`.
114115

cmd/docker-machine-driver-pve/driver/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
flagMemory = "pve-memory"
2828
flagMemoryBalloon = "pve-memory-balloon"
2929
flagFullClone = "pve-full-clone"
30+
flagTags = "pve-tags"
3031
)
3132

3233
// Default values for flags.
@@ -76,6 +77,9 @@ type config struct {
7677

7778
// Forces full copy of all disks, even if underlying storage supports linked clones.
7879
FullClone bool
80+
81+
// Tags to apply to the machine.
82+
Tags []string
7983
}
8084

8185
// GetCreateFlags implements drivers.Driver.
@@ -156,6 +160,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
156160
EnvVar: flagEnvVarFromFlagName(flagFullClone),
157161
Usage: "Forces full copy of all disks, even if underlying storage supports linked clones.",
158162
},
163+
mcnflag.StringFlag{
164+
Name: flagTags,
165+
EnvVar: flagEnvVarFromFlagName(flagTags),
166+
Usage: "Comma-separated list of tags to assign to the VM",
167+
},
159168
}
160169
}
161170

@@ -258,6 +267,8 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
258267

259268
d.FullClone = opts.Bool(flagFullClone)
260269

270+
d.Tags = strings.Split(opts.String(flagTags), ",")
271+
261272
return nil
262273
}
263274

cmd/docker-machine-driver-pve/driver/driver.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,19 @@ func (d *Driver) initialize() error {
154154
return fmt.Errorf("failed to retrieve newly created Proxmox VE virtual machine ID='%d': %w", *d.PVEMachineID, err)
155155
}
156156

157-
tagTask, err := machine.AddTag(context.TODO(), pveMachineTag)
157+
d.Tags = append(d.Tags, pveMachineTag)
158+
159+
tagTask, err := machine.Config(context.TODO(), proxmox.VirtualMachineOption{
160+
Name: "tags",
161+
Value: d.Tags,
162+
})
158163

159164
if err == nil {
160165
err = d.waitForPVETaskToSucceed(context.TODO(), tagTask)
161166
}
162167

163168
if err != nil {
164-
return fmt.Errorf("failed to add tag '%s' to Proxmox VE virtual machine ID='%d': %w", pveMachineTag, *d.PVEMachineID, err)
169+
return fmt.Errorf("failed to add tags '%s' to Proxmox VE virtual machine ID='%d': %w", d.Tags, *d.PVEMachineID, err)
165170
}
166171

167172
log.Info("Configuring machine hardware...")

pkg/pve-node-driver/l10n/en-us.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ cluster:
5858
minimumMemory:
5959
label: Minimum memory (balloon target)
6060
tooltip: When set to 0, disables ballooning. When left empty, value from "Memory" is assigned as ballooning target.
61+
vmTags:
62+
header: VM Tags
63+
label: Tags
64+
tooltip: Comma-separated list of tags to assign to the VM
6165
ssh:
6266
header: SSH Connection
6367
username:

pkg/pve-node-driver/machine-config/pve.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default {
6060
memory: this.value.memory ? parseInt(this.value.memory) : "",
6161
memoryBalloon: this.value.memoryBalloon ? parseInt(this.value.memoryBalloon) : "",
6262
fullClone: this.value.fullClone ?? false,
63+
tags: this.value.tags ?? '',
6364
},
6465
}
6566
},
@@ -616,6 +617,23 @@ export default {
616617
</div>
617618
618619
<portal :to="`advanced-${uuid}`">
620+
<h3>
621+
<t k="cluster.machineConfig.pve.vmTags.header" />
622+
</h3>
623+
<div class="row mb-20">
624+
<div class="col span-12">
625+
<!-- VM Tags -->
626+
<LabeledInput
627+
type="text"
628+
:mode="mode"
629+
v-model:value="currentValue.tags"
630+
label-key="cluster.machineConfig.pve.vmTags.label"
631+
tooltip-key="cluster.machineConfig.pve.vmTags.tooltip"
632+
placeholder="tag1,tag2"
633+
/>
634+
</div>
635+
</div>
636+
619637
<h3>
620638
<t k="cluster.machineConfig.pve.memoryBalloon.header" />
621639
</h3>

0 commit comments

Comments
 (0)