]>
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 '/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, "/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', '/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', '/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 # create /etc/pve/sdn directory
116 PVE
::Cluster
::check_cfs_quorum
();
117 mkdir("/etc/pve/sdn");
119 PVE
::Network
::SDN
::Vnets
::lock_sdn_vnets_config
(
122 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
123 my $opts = PVE
::Network
::SDN
::VnetPlugin-
>check_config($id, $param, 1, 1);
126 if ($scfg = PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id, 1)) {
127 die "sdn vnet object ID '$id' already defined\n";
130 $cfg->{ids
}->{$id} = $opts;
131 PVE
::Network
::SDN
::VnetPlugin-
>on_update_hook($id, $cfg);
133 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
135 }, "create sdn vnet object failed");
140 __PACKAGE__-
>register_method ({
145 description
=> "Update sdn vnet object configuration.",
147 check
=> ['perm', '/sdn/vnets', ['SDN.Allocate']],
149 parameters
=> PVE
::Network
::SDN
::VnetPlugin-
>updateSchema(),
150 returns
=> { type
=> 'null' },
154 my $id = extract_param
($param, 'vnet');
155 my $digest = extract_param
($param, 'digest');
157 PVE
::Network
::SDN
::Vnets
::lock_sdn_vnets_config
(
160 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
162 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
164 my $opts = PVE
::Network
::SDN
::VnetPlugin-
>check_config($id, $param, 0, 1);
165 $cfg->{ids
}->{$id} = $opts;
167 PVE
::Network
::SDN
::VnetPlugin-
>on_update_hook($id, $cfg);
169 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
171 }, "update sdn vnet object failed");
176 __PACKAGE__-
>register_method ({
181 description
=> "Delete sdn vnet object configuration.",
183 check
=> ['perm', '/sdn/vnets', ['SDN.Allocate']],
186 additionalProperties
=> 0,
188 vnet
=> get_standard_option
('pve-sdn-vnet-id', {
189 completion
=> \
&PVE
::Network
::SDN
::Vnets
::complete_sdn_vnets
,
193 returns
=> { type
=> 'null' },
197 my $id = extract_param
($param, 'vnet');
199 PVE
::Network
::SDN
::Vnets
::lock_sdn_vnets_config
(
202 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
204 my $scfg = PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id);
206 my $vnet_cfg = PVE
::Network
::SDN
::Vnets
::config
();
208 PVE
::Network
::SDN
::VnetPlugin-
>on_delete_hook($id, $vnet_cfg);
210 delete $cfg->{ids
}->{$id};
211 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
213 }, "delete sdn vnet object failed");