]>
git.proxmox.com Git - pve-network.git/blob - PVE/API2/Network/Vnet.pm
74f59fccf44c86235f12cea02aaf0f0a57ab53a9
1 package PVE
::API2
::Network
::Vnet
;
7 use PVE
::Tools
qw(extract_param);
8 use PVE
::Cluster
qw(cfs_read_file cfs_write_file);
9 use PVE
::Network
::Vnet
;
10 use PVE
::Network
::Vnet
::Plugin
;
11 use Storable
qw(dclone);
12 use PVE
::JSONSchema
qw(get_standard_option);
13 use PVE
::RPCEnvironment
;
17 use base
qw(PVE::RESTHandler);
19 my $api_vnet_config = sub {
20 my ($cfg, $vnetid) = @_;
22 my $scfg = dclone
(PVE
::Network
::Vnet
::vnet_config
($cfg, $vnetid));
23 $scfg->{vnet
} = $vnetid;
24 $scfg->{digest
} = $cfg->{digest
};
29 __PACKAGE__-
>register_method ({
33 description
=> "Vnet index.",
35 description
=> "Only list entries where you have 'NetworkVnet.Audit' or 'NetworkVnet.Allocate' permissions on '/cluster/network/vnet/<vnet>'",
39 additionalProperties
=> 0,
42 description
=> "Only list vnet of specific type",
52 properties
=> { vnet
=> { type
=> 'string'} },
54 links
=> [ { rel
=> 'child', href
=> "{vnet}" } ],
59 my $rpcenv = PVE
::RPCEnvironment
::get
();
60 my $authuser = $rpcenv->get_user();
63 my $cfg = PVE
::Network
::Vnet
::config
();
65 my @sids = PVE
::Network
::Vnet
::vnets_ids
($cfg);
67 foreach my $vnetid (@sids) {
68 # my $privs = [ 'NetworkVnet.Audit', 'NetworkVnet.Allocate' ];
69 # next if !$rpcenv->check_any($authuser, "/cluster/network/vnet/$vnetid", $privs, 1);
71 my $scfg = &$api_vnet_config($cfg, $vnetid);
72 next if $param->{type
} && $param->{type
} ne $scfg->{type
};
79 __PACKAGE__-
>register_method ({
83 description
=> "Read vnet configuration.",
85 # check => ['perm', '/cluster/network/vnet/{vnet}', ['NetworkVnet.Allocate']],
89 additionalProperties
=> 0,
91 vnet
=> get_standard_option
('pve-vnet-id'),
94 returns
=> { type
=> 'object' },
98 my $cfg = PVE
::Network
::Vnet
::config
();
100 return &$api_vnet_config($cfg, $param->{vnet
});
103 __PACKAGE__-
>register_method ({
108 description
=> "Create a new network vnet.",
110 # check => ['perm', '/cluster/network/vnet', ['NetworkVnet.Allocate']],
112 parameters
=> PVE
::Network
::Vnet
::Plugin-
>createSchema(),
113 returns
=> { type
=> 'null' },
117 my $vnetid = extract_param
($param, 'vnet');
119 my $plugin = PVE
::Network
::Vnet
::Plugin-
>lookup($type);
120 my $opts = $plugin->check_config($vnetid, $param, 1, 1);
122 PVE
::Network
::Vnet
::lock_vnet_config
(
125 my $cfg = PVE
::Network
::Vnet
::config
();
127 if (my $scfg = PVE
::Network
::Vnet
::vnet_config
($cfg, $vnetid, 1)) {
128 die "network vnet ID '$vnetid' already defined\n";
131 $cfg->{ids
}->{$vnetid} = $opts;
133 PVE
::Network
::Vnet
::write_config
($cfg);
135 }, "create network vnet failed");
140 __PACKAGE__-
>register_method ({
145 description
=> "Update network vnet configuration.",
147 # check => ['perm', '/cluster/network/vnet', ['NetworkVnet.Allocate']],
149 parameters
=> PVE
::Network
::Vnet
::Plugin-
>updateSchema(),
150 returns
=> { type
=> 'null' },
154 my $vnetid = extract_param
($param, 'vnet');
155 my $digest = extract_param
($param, 'digest');
157 PVE
::Network
::Vnet
::lock_vnet_config
(
160 my $cfg = PVE
::Network
::Vnet
::config
();
162 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
164 my $scfg = PVE
::Network
::Vnet
::vnet_config
($cfg, $vnetid);
165 my $plugin = PVE
::Network
::Vnet
::Plugin-
>lookup($scfg->{type
});
166 my $opts = $plugin->check_config($vnetid, $param, 0, 1);
168 foreach my $k (%$opts) {
169 $scfg->{$k} = $opts->{$k};
171 PVE
::Network
::Vnet
::write_config
($cfg);
173 }, "update network vnet failed");
178 __PACKAGE__-
>register_method ({
181 path
=> '{vnet}', # /networkvnets/{vnet}
183 description
=> "Delete network vnet configuration.",
185 # check => ['perm', '/networkvnets', ['NetworkVnet.Allocate']],
188 additionalProperties
=> 0,
190 vnet
=> get_standard_option
('pve-vnet-id', {
191 completion
=> \
&PVE
::Network
::Vnet
::complete_vnet
,
195 returns
=> { type
=> 'null' },
199 my $vnetid = extract_param
($param, 'vnet');
201 PVE
::Network
::Vnet
::lock_vnet_config
(
204 my $cfg = PVE
::Network
::Vnet
::config
();
206 my $scfg = PVE
::Network
::Vnet
::vnet_config
($cfg, $vnetid);
208 delete $cfg->{ids
}->{$vnetid};
210 PVE
::Network
::Vnet
::write_config
($cfg);
212 }, "delete network vnet failed");