]>
git.proxmox.com Git - pve-network.git/blob - PVE/API2/Network/SDN/Vnets.pm
1 package PVE
::API2
::Network
::SDN
::Vnets
;
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
::VnetPlugin
;
12 use Storable
qw(dclone);
13 use PVE
::JSONSchema
qw(get_standard_option);
14 use PVE
::RPCEnvironment
;
18 use base
qw(PVE::RESTHandler);
20 my $api_sdn_vnets_config = sub {
23 my $scfg = dclone
(PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id));
25 $scfg->{digest
} = $cfg->{digest
};
30 __PACKAGE__-
>register_method ({
34 description
=> "SDN vnets index.",
36 description
=> "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/cluster/sdn/vnets/<vnet>'",
40 additionalProperties
=> 0,
48 links
=> [ { rel
=> 'child', href
=> "{vnet}" } ],
53 my $rpcenv = PVE
::RPCEnvironment
::get
();
54 my $authuser = $rpcenv->get_user();
57 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
59 my @sids = PVE
::Network
::SDN
::Vnets
::sdn_vnets_ids
($cfg);
61 foreach my $id (@sids) {
62 # my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
63 # next if !$rpcenv->check_any($authuser, "/cluster/sdn/vnets/$id", $privs, 1);
65 my $scfg = &$api_sdn_vnets_config($cfg, $id);
72 __PACKAGE__-
>register_method ({
76 description
=> "Read sdn vnet configuration.",
78 # check => ['perm', '/cluster/sdn/vnets/{vnet}', ['SDN.Allocate']],
82 additionalProperties
=> 0,
84 vnet
=> get_standard_option
('pve-sdn-vnet-id', {
85 completion
=> \
&PVE
::Network
::SDN
::Vnets
::complete_sdn_vnets
,
89 returns
=> { type
=> 'object' },
93 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
95 return &$api_sdn_vnets_config($cfg, $param->{vnet
});
98 __PACKAGE__-
>register_method ({
103 description
=> "Create a new sdn vnet object.",
105 # check => ['perm', '/cluster/sdn/vnets', ['SDN.Allocate']],
107 parameters
=> PVE
::Network
::SDN
::VnetPlugin-
>createSchema(),
108 returns
=> { type
=> 'null' },
112 my $type = extract_param
($param, 'type');
113 my $id = extract_param
($param, 'vnet');
115 PVE
::Network
::SDN
::Vnets
::lock_sdn_vnets_config
(
118 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
119 my $opts = PVE
::Network
::SDN
::VnetPlugin-
>check_config($id, $param, 1, 1);
122 if ($scfg = PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id, 1)) {
123 die "sdn vnet object ID '$id' already defined\n";
126 $cfg->{ids
}->{$id} = $opts;
127 PVE
::Network
::SDN
::VnetPlugin-
>on_update_hook($id, $cfg);
129 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
131 }, "create sdn vnet object failed");
136 __PACKAGE__-
>register_method ({
137 name
=> 'apply_configuration',
141 description
=> "Apply sdn vnet changes.",
143 # check => ['perm', '/cluster/sdn/vnets', ['SDN.Allocate']],
146 additionalProperties
=> 0,
148 returns
=> { type
=> 'null' },
152 die "no sdn vnet changes to apply" if !-e
"/etc/pve/sdn/vnets.cfg.new";
153 rename("/etc/pve/sdn/vnets.cfg.new", "/etc/pve/sdn/vnets.cfg")
154 || die "applying sdn/vnets.cfg changes failed - $!\n";
160 __PACKAGE__-
>register_method ({
161 name
=> 'revert_configuration',
165 description
=> "Revert sdn vnet changes.",
167 # check => ['perm', '/cluster/sdn/vnets', ['SDN.Allocate']],
170 additionalProperties
=> 0,
172 returns
=> { type
=> 'null' },
176 die "no sdn vnets changes to revert" if !-e
"/etc/pve/sdn/vnets.cfg.new";
177 unlink "/etc/pve/sdn/vnets.cfg.new";
182 __PACKAGE__-
>register_method ({
187 description
=> "Update sdn vnet object configuration.",
189 # check => ['perm', '/cluster/sdn/vnets', ['SDN.Allocate']],
191 parameters
=> PVE
::Network
::SDN
::VnetPlugin-
>updateSchema(),
192 returns
=> { type
=> 'null' },
196 my $id = extract_param
($param, 'vnet');
197 my $digest = extract_param
($param, 'digest');
199 PVE
::Network
::SDN
::Vnets
::lock_sdn_vnets_config
(
202 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
204 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
206 my $scfg = PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id);
207 my $opts = PVE
::Network
::SDN
::VnetPlugin-
>check_config($id, $param, 0, 1);
209 foreach my $k (%$opts) {
210 $scfg->{$k} = $opts->{$k};
213 PVE
::Network
::SDN
::VnetPlugin-
>on_update_hook($id, $cfg);
215 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
217 }, "update sdn vnet object failed");
222 __PACKAGE__-
>register_method ({
227 description
=> "Delete sdn vnet object configuration.",
229 # check => ['perm', '/cluster/sdn/vnets', ['SDN.Allocate']],
232 additionalProperties
=> 0,
234 vnet
=> get_standard_option
('pve-sdn-vnet-id', {
235 completion
=> \
&PVE
::Network
::SDN
::Vnets
::complete_sdn_vnets
,
239 returns
=> { type
=> 'null' },
243 my $id = extract_param
($param, 'vnet');
245 PVE
::Network
::SDN
::Vnets
::lock_sdn_vnets_config
(
248 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
250 my $scfg = PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id);
252 my $vnet_cfg = PVE
::Network
::SDN
::Vnets
::config
();
254 PVE
::Network
::SDN
::VnetPlugin-
>on_delete_hook($id, $vnet_cfg);
256 delete $cfg->{ids
}->{$id};
257 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
259 }, "delete sdn vnet object failed");