]>
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);
10 use PVE
::Network
::SDN
::Zones
;
11 use PVE
::Network
::SDN
::Zones
::Plugin
;
12 use PVE
::Network
::SDN
::Vnets
;
13 use PVE
::Network
::SDN
::VnetPlugin
;
15 use Storable
qw(dclone);
16 use PVE
::JSONSchema
qw(get_standard_option);
17 use PVE
::RPCEnvironment
;
21 use base
qw(PVE::RESTHandler);
23 my $api_sdn_vnets_config = sub {
26 my $scfg = dclone
(PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id));
28 $scfg->{digest
} = $cfg->{digest
};
33 __PACKAGE__-
>register_method ({
37 description
=> "SDN vnets index.",
39 description
=> "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/vnets/<vnet>'",
43 additionalProperties
=> 0,
51 links
=> [ { rel
=> 'child', href
=> "{vnet}" } ],
56 my $rpcenv = PVE
::RPCEnvironment
::get
();
57 my $authuser = $rpcenv->get_user();
60 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
62 my @sids = PVE
::Network
::SDN
::Vnets
::sdn_vnets_ids
($cfg);
64 foreach my $id (@sids) {
65 my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
66 next if !$rpcenv->check_any($authuser, "/sdn/vnets/$id", $privs, 1);
68 my $scfg = &$api_sdn_vnets_config($cfg, $id);
75 __PACKAGE__-
>register_method ({
79 description
=> "Read sdn vnet configuration.",
81 check
=> ['perm', '/sdn/vnets/{vnet}', ['SDN.Allocate']],
85 additionalProperties
=> 0,
87 vnet
=> get_standard_option
('pve-sdn-vnet-id', {
88 completion
=> \
&PVE
::Network
::SDN
::Vnets
::complete_sdn_vnets
,
92 returns
=> { type
=> 'object' },
96 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
98 return &$api_sdn_vnets_config($cfg, $param->{vnet
});
101 __PACKAGE__-
>register_method ({
106 description
=> "Create a new sdn vnet object.",
108 check
=> ['perm', '/sdn/vnets', ['SDN.Allocate']],
110 parameters
=> PVE
::Network
::SDN
::VnetPlugin-
>createSchema(),
111 returns
=> { type
=> 'null' },
115 my $type = extract_param
($param, 'type');
116 my $id = extract_param
($param, 'vnet');
118 # create /etc/pve/sdn directory
119 PVE
::Cluster
::check_cfs_quorum
();
120 mkdir("/etc/pve/sdn");
122 PVE
::Network
::SDN
::lock_sdn_config
(
125 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
126 my $opts = PVE
::Network
::SDN
::VnetPlugin-
>check_config($id, $param, 1, 1);
129 if ($scfg = PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id, 1)) {
130 die "sdn vnet object ID '$id' already defined\n";
133 $cfg->{ids
}->{$id} = $opts;
135 my $zone_cfg = PVE
::Network
::SDN
::Zones
::config
();
136 my $zoneid = $cfg->{ids
}->{$id}->{zone
};
137 my $plugin_config = $zone_cfg->{ids
}->{$zoneid};
138 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($plugin_config->{type
});
139 $plugin->verify_tag($opts->{tag
});
141 PVE
::Network
::SDN
::VnetPlugin-
>on_update_hook($id, $cfg);
143 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
145 PVE
::Network
::SDN
::increase_version
();
148 }, "create sdn vnet object failed");
153 __PACKAGE__-
>register_method ({
158 description
=> "Update sdn vnet object configuration.",
160 check
=> ['perm', '/sdn/vnets', ['SDN.Allocate']],
162 parameters
=> PVE
::Network
::SDN
::VnetPlugin-
>updateSchema(),
163 returns
=> { type
=> 'null' },
167 my $id = extract_param
($param, 'vnet');
168 my $digest = extract_param
($param, 'digest');
170 PVE
::Network
::SDN
::lock_sdn_config
(
173 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
175 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
177 my $opts = PVE
::Network
::SDN
::VnetPlugin-
>check_config($id, $param, 0, 1);
178 $cfg->{ids
}->{$id} = $opts;
180 my $zone_cfg = PVE
::Network
::SDN
::Zones
::config
();
181 my $zoneid = $cfg->{ids
}->{$id}->{zone
};
182 my $plugin_config = $zone_cfg->{ids
}->{$zoneid};
183 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($plugin_config->{type
});
184 $plugin->verify_tag($opts->{tag
});
186 PVE
::Network
::SDN
::VnetPlugin-
>on_update_hook($id, $cfg);
188 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
190 PVE
::Network
::SDN
::increase_version
();
192 }, "update sdn vnet object failed");
197 __PACKAGE__-
>register_method ({
202 description
=> "Delete sdn vnet object configuration.",
204 check
=> ['perm', '/sdn/vnets', ['SDN.Allocate']],
207 additionalProperties
=> 0,
209 vnet
=> get_standard_option
('pve-sdn-vnet-id', {
210 completion
=> \
&PVE
::Network
::SDN
::Vnets
::complete_sdn_vnets
,
214 returns
=> { type
=> 'null' },
218 my $id = extract_param
($param, 'vnet');
220 PVE
::Network
::SDN
::lock_sdn_config
(
223 my $cfg = PVE
::Network
::SDN
::Vnets
::config
();
225 my $scfg = PVE
::Network
::SDN
::Vnets
::sdn_vnets_config
($cfg, $id);
227 my $vnet_cfg = PVE
::Network
::SDN
::Vnets
::config
();
229 PVE
::Network
::SDN
::VnetPlugin-
>on_delete_hook($id, $vnet_cfg);
231 delete $cfg->{ids
}->{$id};
232 PVE
::Network
::SDN
::Vnets
::write_config
($cfg);
234 PVE
::Network
::SDN
::increase_version
();
236 }, "delete sdn vnet object failed");