]>
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 $cfg = PVE
::Network
::SDN
::Zones
::config
();
148 if ($scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id, 1)) {
149 die "sdn zone object ID '$id' already defined\n";
152 $cfg->{ids
}->{$id} = $opts;
153 $plugin->on_update_hook($id, $cfg);
155 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
157 }, "create sdn zone object failed");
162 __PACKAGE__-
>register_method ({
163 name
=> 'revert_configuration',
167 description
=> "Revert sdn zone changes.",
169 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
172 additionalProperties
=> 0,
174 returns
=> { type
=> 'null' },
178 die "no sdn zones changes to revert" if !-e
"/etc/pve/sdn/zones.cfg.new";
179 unlink "/etc/pve/sdn/zones.cfg.new";
184 __PACKAGE__-
>register_method ({
189 description
=> "Update sdn zone object configuration.",
191 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
193 parameters
=> PVE
::Network
::SDN
::Zones
::Plugin-
>updateSchema(),
194 returns
=> { type
=> 'null' },
198 my $id = extract_param
($param, 'zone');
199 my $digest = extract_param
($param, 'digest');
201 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
204 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
206 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
208 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id);
210 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
211 my $opts = $plugin->check_config($id, $param, 0, 1);
213 foreach my $k (%$opts) {
214 $scfg->{$k} = $opts->{$k};
217 $plugin->on_update_hook($id, $cfg);
219 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
221 }, "update sdn zone object failed");
226 __PACKAGE__-
>register_method ({
231 description
=> "Delete sdn zone object configuration.",
233 # check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
236 additionalProperties
=> 0,
238 zone
=> get_standard_option
('pve-sdn-zone-id', {
239 completion
=> \
&PVE
::Network
::SDN
::Zones
::complete_sdn_zones
,
243 returns
=> { type
=> 'null' },
247 my $id = extract_param
($param, 'zone');
249 PVE
::Network
::SDN
::Zones
::lock_sdn_zones_config
(
252 my $cfg = PVE
::Network
::SDN
::Zones
::config
();
254 my $scfg = PVE
::Network
::SDN
::Zones
::sdn_zones_config
($cfg, $id);
256 my $plugin = PVE
::Network
::SDN
::Zones
::Plugin-
>lookup($scfg->{type
});
258 my $vnet_cfg = PVE
::Network
::SDN
::Vnets
::config
();
260 $plugin->on_delete_hook($id, $vnet_cfg);
262 delete $cfg->{ids
}->{$id};
263 PVE
::Network
::SDN
::Zones
::write_config
($cfg);
265 }, "delete sdn zone object failed");