]>
git.proxmox.com Git - pve-network.git/blob - PVE/API2/Network/SDN/Zones.pm
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
=> 'revert_configuration',
163 description
=> "Revert sdn zone changes.",
165 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
168 additionalProperties
=> 0,
170 returns
=> { type
=> 'null' },
174 die "no sdn zones changes to revert" if !-e
"/etc/pve/sdn/zones.cfg.new";
175 unlink "/etc/pve/sdn/zones.cfg.new";
180 __PACKAGE__-
>register_method ({
185 description
=> "Update sdn zone object configuration.",
187 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
189 parameters
=> PVE
::Network
::SDN
::Zones
::Plugin-
>updateSchema(),
190 returns
=> { type
=> 'null' },
194 my $id = extract_param
($param, 'zone');
195 my $digest = extract_param
($param, 'digest');
197 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
200 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
202 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
204 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id);
206 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
207 my $opts = $plugin->check_config($id, $param, 0, 1);
209 foreach my $k (%$opts) {
210 $scfg->{$k} = $opts->{$k};
213 $plugin->on_update_hook($id, $cfg);
215 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
217 }, "update sdn zone object failed");
222 __PACKAGE__-
>register_method ({
227 description
=> "Delete sdn zone object configuration.",
229 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
232 additionalProperties
=> 0,
234 zone
=> get_standard_option
('pve-sdn-zone-id', {
235 completion
=> \
&PVE
::Network
::SDN
::Zones
::complete_sdn_zones
,
239 returns
=> { type
=> 'null' },
243 my $id = extract_param
($param, 'zone');
245 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
248 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
250 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id);
252 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
254 my $vnet_cfg = PVE
::Network
::SDN
::Vnets
::config
();
256 $plugin->on_delete_hook($id, $vnet_cfg);
258 delete $cfg->{ids
}->{$id};
259 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
261 }, "delete sdn zone object failed");