]>
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);
10 use PVE
::Network
::SDN
::Vnets
;
11 use PVE
::Network
::SDN
::Zones
;
12 use PVE
::Network
::SDN
::Zones
::Plugin
;
13 use PVE
::Network
::SDN
::Zones
::VlanPlugin
;
14 use PVE
::Network
::SDN
::Zones
::QinQPlugin
;
15 use PVE
::Network
::SDN
::Zones
::VxlanPlugin
;
16 use PVE
::Network
::SDN
::Zones
::EvpnPlugin
;
17 use PVE
::Network
::SDN
::Zones
::FaucetPlugin
;
18 use PVE
::Network
::SDN
::Zones
::SimplePlugin
;
20 use Storable
qw(dclone);
21 use PVE
::JSONSchema
qw(get_standard_option);
22 use PVE
::RPCEnvironment
;
26 use base
qw(PVE::RESTHandler);
28 my $sdn_zones_type_enum = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup_types();
30 my $api_sdn_zones_config = sub {
33 my $scfg = dclone
(PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id));
35 $scfg->{digest
} = $cfg->{digest
};
38 $scfg->{nodes
} = PVE
::Network
::SDN
::Zones
::Plugin-
>encode_value($scfg->{type
}, 'nodes', $scfg->{nodes
});
44 __PACKAGE__-
>register_method ({
48 description
=> "SDN zones index.",
50 description
=> "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>'",
54 additionalProperties
=> 0,
57 description
=> "Only list sdn zones of specific type",
59 enum
=> $sdn_zones_type_enum,
68 properties
=> { zone
=> { type
=> 'string'},
69 type
=> { type
=> 'string'},
72 links
=> [ { rel
=> 'child', href
=> "{zone}" } ],
77 my $rpcenv = PVE
::RPCEnvironment
::get
();
78 my $authuser = $rpcenv->get_user();
81 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
83 my @sids = PVE
::Network
::SDN
::Zones
::sdn_zones_ids
($cfg);
85 foreach my $id (@sids) {
86 my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
87 next if !$rpcenv->check_any($authuser, "/sdn/zones/$id", $privs, 1);
89 my $scfg = &$api_sdn_zones_config($cfg, $id);
90 next if $param->{type
} && $param->{type
} ne $scfg->{type
};
92 my $plugin_config = $cfg->{ids
}->{$id};
93 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($plugin_config->{type
});
100 __PACKAGE__-
>register_method ({
104 description
=> "Read sdn zone configuration.",
106 check
=> ['perm', '/sdn/zones/{zone}', ['SDN.Allocate']],
110 additionalProperties
=> 0,
112 zone
=> get_standard_option
('pve-sdn-zone-id'),
115 returns
=> { type
=> 'object' },
119 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
121 return &$api_sdn_zones_config($cfg, $param->{zone
});
124 __PACKAGE__-
>register_method ({
129 description
=> "Create a new sdn zone object.",
131 check
=> ['perm', '/sdn/zones', ['SDN.Allocate']],
133 parameters
=> PVE
::Network
::SDN
::Zones
::Plugin-
>createSchema(),
134 returns
=> { type
=> 'null' },
138 my $type = extract_param
($param, 'type');
139 my $id = extract_param
($param, 'zone');
141 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($type);
142 my $opts = $plugin->check_config($id, $param, 1, 1);
144 # create /etc/pve/sdn directory
145 PVE
::Cluster
::check_cfs_quorum
();
146 mkdir("/etc/pve/sdn");
148 PVE
::Network
::SDN
::lock_sdn_config
(
151 my $zone_cfg = PVE
::Network
::SDN
::Zones
::config
();
152 my $controller_cfg = PVE
::Network
::SDN
::Controllers
::config
();
155 if ($scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($zone_cfg, $id, 1)) {
156 die "sdn zone object ID '$id' already defined\n";
159 $zone_cfg->{ids
}->{$id} = $opts;
160 $plugin->on_update_hook($id, $zone_cfg, $controller_cfg);
162 PVE
::Network
::SDN
::Zones
::write_config
($zone_cfg);
164 }, "create sdn zone object failed");
169 __PACKAGE__-
>register_method ({
174 description
=> "Update sdn zone object configuration.",
176 check
=> ['perm', '/sdn/zones', ['SDN.Allocate']],
178 parameters
=> PVE
::Network
::SDN
::Zones
::Plugin-
>updateSchema(),
179 returns
=> { type
=> 'null' },
183 my $id = extract_param
($param, 'zone');
184 my $digest = extract_param
($param, 'digest');
186 PVE
::Network
::SDN
::lock_sdn_config
(
189 my $zone_cfg = PVE
::Network
::SDN
::Zones
::config
();
190 my $controller_cfg = PVE
::Network
::SDN
::Controllers
::config
();
192 PVE
::SectionConfig
::assert_if_modified
($zone_cfg, $digest);
194 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($zone_cfg, $id);
196 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
197 my $opts = $plugin->check_config($id, $param, 0, 1);
199 foreach my $k (%$opts) {
200 $scfg->{$k} = $opts->{$k};
203 $plugin->on_update_hook($id, $zone_cfg, $controller_cfg);
205 PVE
::Network
::SDN
::Zones
::write_config
($zone_cfg);
207 }, "update sdn zone object failed");
212 __PACKAGE__-
>register_method ({
217 description
=> "Delete sdn zone object configuration.",
219 check
=> ['perm', '/sdn/zones', ['SDN.Allocate']],
222 additionalProperties
=> 0,
224 zone
=> get_standard_option
('pve-sdn-zone-id', {
225 completion
=> \
&PVE
::Network
::SDN
::Zones
::complete_sdn_zones
,
229 returns
=> { type
=> 'null' },
233 my $id = extract_param
($param, 'zone');
235 PVE
::Network
::SDN
::lock_sdn_config
(
238 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
240 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id);
242 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
244 my $vnet_cfg = PVE
::Network
::SDN
::Vnets
::config
();
246 $plugin->on_delete_hook($id, $vnet_cfg);
248 delete $cfg->{ids
}->{$id};
249 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
251 }, "delete sdn zone object failed");