]>
git.proxmox.com Git - pve-network.git/blob - PVE/API2/Network/SDN/Zones.pm
a4478130a4eea1a172d5a30600f9e2f7658d6744
1 package PVE
::API2
::Network
::SDN
::Zones
;
7 use PVE
::Tools
qw(extract_param);
8 use PVE
::Cluster
qw(cfs_read_file cfs_write_file);
9 use PVE
::Network
::SDN
::Vnets
;
10 use PVE
::Network
::SDN
::Zones
;
11 use PVE
::Network
::SDN
::Zones
::Plugin
;
12 use PVE
::Network
::SDN
::Zones
::VlanPlugin
;
13 use PVE
::Network
::SDN
::Zones
::QinQPlugin
;
14 use PVE
::Network
::SDN
::Zones
::VxlanPlugin
;
15 use PVE
::Network
::SDN
::Zones
::EvpnPlugin
;
16 use PVE
::Network
::SDN
::Zones
::FaucetPlugin
;
18 use Storable
qw(dclone);
19 use PVE
::JSONSchema
qw(get_standard_option);
20 use PVE
::RPCEnvironment
;
24 use base
qw(PVE::RESTHandler);
26 my $sdn_zones_type_enum = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup_types();
28 my $api_sdn_zones_config = sub {
31 my $scfg = dclone
(PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id));
33 $scfg->{digest
} = $cfg->{digest
};
38 __PACKAGE__-
>register_method ({
42 description
=> "SDN zones index.",
44 description
=> "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/cluster/sdn/zones/<zone>'",
48 additionalProperties
=> 0,
51 description
=> "Only list sdn zones of specific type",
53 enum
=> $sdn_zones_type_enum,
62 properties
=> { zone
=> { type
=> 'string'},
63 type
=> { type
=> 'string'},
66 links
=> [ { rel
=> 'child', href
=> "{zone}" } ],
71 my $rpcenv = PVE
::RPCEnvironment
::get
();
72 my $authuser = $rpcenv->get_user();
75 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
77 my @sids = PVE
::Network
::SDN
::Zones
::sdn_zones_ids
($cfg);
79 foreach my $id (@sids) {
80 # my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
81 # next if !$rpcenv->check_any($authuser, "/cluster/sdn/zones/$id", $privs, 1);
83 my $scfg = &$api_sdn_zones_config($cfg, $id);
84 next if $param->{type
} && $param->{type
} ne $scfg->{type
};
86 my $plugin_config = $cfg->{ids
}->{$id};
87 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($plugin_config->{type
});
94 __PACKAGE__-
>register_method ({
98 description
=> "Read sdn zone configuration.",
100 # check => ['perm', '/cluster/sdn/zones/{zone}', ['SDN.Allocate']],
104 additionalProperties
=> 0,
106 zone
=> get_standard_option
('pve-sdn-zone-id'),
109 returns
=> { type
=> 'object' },
113 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
115 return &$api_sdn_zones_config($cfg, $param->{zone
});
118 __PACKAGE__-
>register_method ({
123 description
=> "Create a new sdn zone object.",
125 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
127 parameters
=> PVE
::Network
::SDN
::Zones
::Plugin-
>createSchema(),
128 returns
=> { type
=> 'null' },
132 my $type = extract_param
($param, 'type');
133 my $id = extract_param
($param, 'zone');
135 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($type);
136 my $opts = $plugin->check_config($id, $param, 1, 1);
138 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
141 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
144 if ($scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id, 1)) {
145 die "sdn zone object ID '$id' already defined\n";
148 $cfg->{ids
}->{$id} = $opts;
149 $plugin->on_update_hook($id, $cfg);
151 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
153 }, "create sdn zone object failed");
158 __PACKAGE__-
>register_method ({
159 name
=> 'apply_configuration',
163 description
=> "Apply sdn zone changes.",
165 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
168 additionalProperties
=> 0,
170 returns
=> { type
=> 'null' },
174 die "no sdn zone changes to apply" if !-e
"/etc/pve/sdn/zones.cfg.new";
175 rename("/etc/pve/sdn/zones.cfg.new", "/etc/pve/sdn/zones.cfg")
176 || die "applying sdn/zones.cfg changes failed - $!\n";
182 __PACKAGE__-
>register_method ({
183 name
=> 'revert_configuration',
187 description
=> "Revert sdn zone changes.",
189 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
192 additionalProperties
=> 0,
194 returns
=> { type
=> 'null' },
198 die "no sdn zones changes to revert" if !-e
"/etc/pve/sdn/zones.cfg.new";
199 unlink "/etc/pve/sdn/zones.cfg.new";
204 __PACKAGE__-
>register_method ({
209 description
=> "Update sdn zone object configuration.",
211 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
213 parameters
=> PVE
::Network
::SDN
::Zones
::Plugin-
>updateSchema(),
214 returns
=> { type
=> 'null' },
218 my $id = extract_param
($param, 'zone');
219 my $digest = extract_param
($param, 'digest');
221 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
224 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
226 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
228 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id);
230 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
231 my $opts = $plugin->check_config($id, $param, 0, 1);
233 foreach my $k (%$opts) {
234 $scfg->{$k} = $opts->{$k};
237 $plugin->on_update_hook($id, $cfg);
239 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
241 }, "update sdn zone object failed");
246 __PACKAGE__-
>register_method ({
251 description
=> "Delete sdn zone object configuration.",
253 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
256 additionalProperties
=> 0,
258 zone
=> get_standard_option
('pve-sdn-zone-id', {
259 completion
=> \
&PVE
::Network
::SDN
::Zones
::complete_sdn_zones
,
263 returns
=> { type
=> 'null' },
267 my $id = extract_param
($param, 'zone');
269 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
272 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
274 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id);
276 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
278 my $vnet_cfg = PVE
::Network
::SDN
::Vnets
::config
();
280 $plugin->on_delete_hook($id, $vnet_cfg);
282 delete $cfg->{ids
}->{$id};
283 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
285 }, "delete sdn zone object failed");