]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/Network/VnetPlugin.pm
b255691c102aded0ea98dc763d1c1732b9b1dcf9
1 package PVE
::Network
::Network
::VnetPlugin
;
5 use PVE
::Network
::Network
::Plugin
;
7 use base
('PVE::Network::Network::Plugin');
11 # dynamically include PVE::QemuServer and PVE::LXC
12 # to avoid dependency problems
15 require PVE
::QemuServer
;
16 require PVE
::QemuConfig
;
17 $have_qemu_server = 1;
23 require PVE
::LXC
::Config
;
38 description
=> "transportzone id",
42 description
=> "vlan or vxlan id",
46 description
=> "alias name of the vnet",
55 description
=> "Anycast router ipv4 address.",
56 type
=> 'string', format
=> 'ipv4',
60 description
=> "Anycast router ipv6 address.",
61 type
=> 'string', format
=> 'ipv6',
66 description
=> "Anycast router mac address",
74 transportzone
=> { optional
=> 0},
75 tag
=> { optional
=> 0},
76 alias
=> { optional
=> 1 },
77 ipv4
=> { optional
=> 1 },
78 ipv6
=> { optional
=> 1 },
79 mtu
=> { optional
=> 1 },
84 my ($class, $networkid, $network_cfg) = @_;
86 # verify than no vm or ct have interfaces in this bridge
87 my $vmdata = read_cluster_vm_config
();
89 foreach my $vmid (sort keys %{$vmdata->{qemu
}}) {
90 my $conf = $vmdata->{qemu
}->{$vmid};
91 foreach my $netid (sort keys %$conf) {
92 next if $netid !~ m/^net(\d+)$/;
93 my $net = PVE
::QemuServer
::parse_net
($conf->{$netid});
94 die "vnet $networkid is used by vm $vmid" if $net->{bridge
} eq $networkid;
98 foreach my $vmid (sort keys %{$vmdata->{lxc
}}) {
99 my $conf = $vmdata->{lxc
}->{$vmid};
100 foreach my $netid (sort keys %$conf) {
101 next if $netid !~ m/^net(\d+)$/;
102 my $net = PVE
::LXC
::Config-
>parse_lxc_network($conf->{$netid});
103 die "vnet $networkid is used by ct $vmid" if $net->{bridge
} eq $networkid;
110 my ($class, $networkid, $network_cfg) = @_;
111 # verify that tag is not already defined in another vnet
112 if (defined($network_cfg->{ids
}->{$networkid}->{tag
})) {
113 my $tag = $network_cfg->{ids
}->{$networkid}->{tag
};
114 foreach my $id (keys %{$network_cfg->{ids
}}) {
115 next if $id eq $networkid;
116 my $network = $network_cfg->{ids
}->{$id};
117 if ($network->{type
} eq 'vnet' && defined($network->{tag
})) {
118 die "tag $tag already exist in vnet $id" if $tag eq $network->{tag
};
124 sub read_cluster_vm_config
{
129 my $vmdata = { qemu
=> $qemu, lxc
=> $lxc };
131 my $vmlist = PVE
::Cluster
::get_vmlist
();
132 return $vmdata if !$vmlist || !$vmlist->{ids
};
133 my $ids = $vmlist->{ids
};
135 foreach my $vmid (keys %$ids) {
137 my $d = $ids->{$vmid};
139 if ($d->{type
} eq 'qemu' && $have_qemu_server) {
140 my $cfspath = PVE
::QemuConfig-
>cfs_config_path($vmid);
141 if (my $conf = PVE
::Cluster
::cfs_read_file
($cfspath)) {
142 $qemu->{$vmid} = $conf;
144 } elsif ($d->{type
} eq 'lxc' && $have_lxc) {
145 my $cfspath = PVE
::LXC
::Config-
>cfs_config_path($vmid);
146 if (my $conf = PVE
::Cluster
::cfs_read_file
($cfspath)) {
147 $lxc->{$vmid} = $conf;