[pve-devel] [PATCH guest-common 1/4] fix #5900: add helper function
Daniel Herzig
d.herzig at proxmox.com
Mon Dec 16 09:38:58 CET 2024
Hi Stefan,
thanks for the feedback.
Thanks for hinting at ~PVE::LXC::Config::parse_lxc_network~. I oversaw
that and did not want to pull ~PVE::QemuServer::parse_net~ into LXC's
deps.
Stefan Hanreich <s.hanreich at proxmox.com> writes:
> On 12/5/24 17:33, Daniel Herzig wrote:
>> This patch adds a small helper function to retrieve the bridge name
>> from the netN parameter string of a container or VM configuration.
>>
>> Signed-off-by: Daniel Herzig <d.herzig at proxmox.com>
>> ---
>> src/PVE/GuestHelpers.pm | 11 +++++++++++
>> 1 file changed, 11 insertions(+)
>>
>> diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm
>> index 592b4a8..c6006ba 100644
>> --- a/src/PVE/GuestHelpers.pm
>> +++ b/src/PVE/GuestHelpers.pm
>> @@ -450,4 +450,15 @@ sub abort_guest_tasks {
>> return $aborted_tasks;
>> }
>>
>> +sub get_bridge {
>> + my $net_params = shift;
>> + my $param_array = [ split(/,/, $net_params) ];
>> + my $bridge;
>> + for my $net_param (@$param_array) {
>> + $bridge = $net_param if ($net_param =~ /bridge\=/);
>> + $bridge =~ s|bridge\=|| if (defined($bridge));
>> + }
>> + return $bridge;
>> +}
>> +
>> 1;
>
> net is a property string, if you want to parse it there are helpers for
> that in PVE::JSONSchema.
>
> For VMs as well as CTs we already have helpers for parsing the network
> property string defined:
>
> PVE::QemuServer::parse_net
> PVE::LXC::Config::parse_lxc_network
More information about the pve-devel
mailing list