]>
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
};
36 $scfg->{nodes
} = PVE
::Storage
::Plugin-
>encode_value($scfg->{type
}, 'nodes', $scfg->{nodes
});
42 __PACKAGE__-
>register_method ({
46 description
=> "SDN zones index.",
48 description
=> "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/cluster/sdn/zones/<zone>'",
52 additionalProperties
=> 0,
55 description
=> "Only list sdn zones of specific type",
57 enum
=> $sdn_zones_type_enum,
66 properties
=> { zone
=> { type
=> 'string'},
67 type
=> { type
=> 'string'},
70 links
=> [ { rel
=> 'child', href
=> "{zone}" } ],
75 my $rpcenv = PVE
::RPCEnvironment
::get
();
76 my $authuser = $rpcenv->get_user();
79 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
81 my @sids = PVE
::Network
::SDN
::Zones
::sdn_zones_ids
($cfg);
83 foreach my $id (@sids) {
84 # my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
85 # next if !$rpcenv->check_any($authuser, "/cluster/sdn/zones/$id", $privs, 1);
87 my $scfg = &$api_sdn_zones_config($cfg, $id);
88 next if $param->{type
} && $param->{type
} ne $scfg->{type
};
90 my $plugin_config = $cfg->{ids
}->{$id};
91 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($plugin_config->{type
});
98 __PACKAGE__-
>register_method ({
102 description
=> "Read sdn zone configuration.",
104 # check => ['perm', '/cluster/sdn/zones/{zone}', ['SDN.Allocate']],
108 additionalProperties
=> 0,
110 zone
=> get_standard_option
('pve-sdn-zone-id'),
113 returns
=> { type
=> 'object' },
117 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
119 return &$api_sdn_zones_config($cfg, $param->{zone
});
122 __PACKAGE__-
>register_method ({
127 description
=> "Create a new sdn zone object.",
129 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
131 parameters
=> PVE
::Network
::SDN
::Zones
::Plugin-
>createSchema(),
132 returns
=> { type
=> 'null' },
136 my $type = extract_param
($param, 'type');
137 my $id = extract_param
($param, 'zone');
139 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($type);
140 my $opts = $plugin->check_config($id, $param, 1, 1);
142 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
145 my $zone_cfg = PVE
::Network
::SDN
::Zones
::config
();
146 my $controller_cfg = PVE
::Network
::SDN
::Controllers
::config
();
149 if ($scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($zone_cfg, $id, 1)) {
150 die "sdn zone object ID '$id' already defined\n";
153 $zone_cfg->{ids
}->{$id} = $opts;
154 $plugin->on_update_hook($id, $zone_cfg, $controller_cfg);
156 PVE
::Network
::SDN
::Zones
::write_config
($zone_cfg);
158 }, "create sdn zone object failed");
163 __PACKAGE__-
>register_method ({
164 name
=> 'revert_configuration',
168 description
=> "Revert sdn zone changes.",
170 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
173 additionalProperties
=> 0,
175 returns
=> { type
=> 'null' },
179 die "no sdn zones changes to revert" if !-e
"/etc/pve/sdn/zones.cfg.new";
180 unlink "/etc/pve/sdn/zones.cfg.new";
185 __PACKAGE__-
>register_method ({
190 description
=> "Update sdn zone object configuration.",
192 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
194 parameters
=> PVE
::Network
::SDN
::Zones
::Plugin-
>updateSchema(),
195 returns
=> { type
=> 'null' },
199 my $id = extract_param
($param, 'zone');
200 my $digest = extract_param
($param, 'digest');
202 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
205 my $zone_cfg = PVE
::Network
::SDN
::Zones
::config
();
206 my $controller_cfg = PVE
::Network
::SDN
::Controllers
::config
();
208 PVE
::SectionConfig
::assert_if_modified
($zone_cfg, $digest);
210 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($zone_cfg, $id);
212 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
213 my $opts = $plugin->check_config($id, $param, 0, 1);
215 foreach my $k (%$opts) {
216 $scfg->{$k} = $opts->{$k};
219 $plugin->on_update_hook($id, $zone_cfg, $controller_cfg);
221 PVE
::Network
::SDN
::Zones
::write_config
($zone_cfg);
223 }, "update sdn zone object failed");
228 __PACKAGE__-
>register_method ({
233 description
=> "Delete sdn zone object configuration.",
235 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
238 additionalProperties
=> 0,
240 zone
=> get_standard_option
('pve-sdn-zone-id', {
241 completion
=> \
&PVE
::Network
::SDN
::Zones
::complete_sdn_zones
,
245 returns
=> { type
=> 'null' },
249 my $id = extract_param
($param, 'zone');
251 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
254 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
256 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id);
258 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
260 my $vnet_cfg = PVE
::Network
::SDN
::Vnets
::config
();
262 $plugin->on_delete_hook($id, $vnet_cfg);
264 delete $cfg->{ids
}->{$id};
265 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
267 }, "delete sdn zone object failed");