diff options
| author | Thomas Lamprecht <t.lamprecht@proxmox.com> | 2023-05-25 18:10:14 +0200 | 
|---|---|---|
| committer | Thomas Lamprecht <t.lamprecht@proxmox.com> | 2023-05-25 18:18:57 +0200 | 
| commit | 6029cbb071c3722c717eebbafaf1b373f3edaadc (patch) | |
| tree | 456d7aff44d2ae220d1671f77da7528174d53fe6 /src/PVE/API2/Network/SDN.pm | |
| parent | cead0f28af4aceee83af6636d4f5ffb2d2f6c6b1 (diff) | |
separate packaging and source build system
like almost all of our repos do nowadays, modern git can detect such
things on rebase so in development stuff should be hopefully not too
much affected by this.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Diffstat (limited to 'src/PVE/API2/Network/SDN.pm')
| -rw-r--r-- | src/PVE/API2/Network/SDN.pm | 144 | 
1 files changed, 144 insertions, 0 deletions
diff --git a/src/PVE/API2/Network/SDN.pm b/src/PVE/API2/Network/SDN.pm new file mode 100644 index 0000000..f129d60 --- /dev/null +++ b/src/PVE/API2/Network/SDN.pm @@ -0,0 +1,144 @@ +package PVE::API2::Network::SDN; + +use strict; +use warnings; + +use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file); +use PVE::Exception qw(raise_param_exc); +use PVE::JSONSchema qw(get_standard_option); +use PVE::RESTHandler; +use PVE::RPCEnvironment; +use PVE::SafeSyslog; +use PVE::Tools qw(run_command); +use PVE::Network::SDN; + +use PVE::API2::Network::SDN::Controllers; +use PVE::API2::Network::SDN::Vnets; +use PVE::API2::Network::SDN::Zones; +use PVE::API2::Network::SDN::Ipams; +use PVE::API2::Network::SDN::Dns; + +use base qw(PVE::RESTHandler); + +__PACKAGE__->register_method ({ +    subclass => "PVE::API2::Network::SDN::Vnets", +    path => 'vnets', +}); + +__PACKAGE__->register_method ({ +    subclass => "PVE::API2::Network::SDN::Zones", +    path => 'zones', +}); + +__PACKAGE__->register_method ({ +    subclass => "PVE::API2::Network::SDN::Controllers", +    path => 'controllers', +}); + +__PACKAGE__->register_method ({ +    subclass => "PVE::API2::Network::SDN::Ipams", +    path => 'ipams', +}); + +__PACKAGE__->register_method ({ +    subclass => "PVE::API2::Network::SDN::Dns", +    path => 'dns', +}); + +__PACKAGE__->register_method({ +    name => 'index', +    path => '', +    method => 'GET', +    description => "Directory index.", +    permissions => { +	check => ['perm', '/', [ 'SDN.Audit' ]], +    }, +    parameters => { +    	additionalProperties => 0, +	properties => {}, +    }, +    returns => { +	type => 'array', +	items => { +	    type => "object", +	    properties => { +		id => { type => 'string' }, +	    }, +	}, +	links => [ { rel => 'child', href => "{id}" } ], +    }, +    code => sub { +	my ($param) = @_; + +	my $res = [ +	    { id => 'vnets' }, +	    { id => 'zones' }, +	    { id => 'controllers' }, +	    { id => 'ipams' }, +	    { id => 'dns' }, +	]; + +	return $res; +    }}); + +my $create_reload_network_worker = sub { +    my ($nodename) = @_; + +    # FIXME: how to proxy to final node ? +    my $upid; +    run_command(['pvesh', 'set', "/nodes/$nodename/network"], outfunc => sub { +	my $line = shift; +	if ($line =~ /^["']?(UPID:[^\s"']+)["']?$/) { +	    $upid = $1; +	} +    }); +    #my $upid = PVE::API2::Network->reload_network_config(node => $nodename}); +    my $res = PVE::Tools::upid_decode($upid); + +    return $res->{pid}; +}; + +__PACKAGE__->register_method ({ +    name => 'reload', +    protected => 1, +    path => '', +    method => 'PUT', +    description => "Apply sdn controller changes && reload.", +    permissions => { +       check => ['perm', '/sdn', ['SDN.Allocate']], +    }, +    parameters => { +        additionalProperties => 0, +    }, +    returns => { +        type => 'string', +    }, +    code => sub { +        my ($param) = @_; + +        my $rpcenv = PVE::RPCEnvironment::get(); +        my $authuser = $rpcenv->get_user(); + +	PVE::Network::SDN::commit_config(); + +        my $code = sub { +            $rpcenv->{type} = 'priv'; # to start tasks in background +	    PVE::Cluster::check_cfs_quorum(); +	    my $nodelist = PVE::Cluster::get_nodelist(); +	    for my $node (@$nodelist) { +		my $pid = eval { $create_reload_network_worker->($node) }; +		warn $@ if $@; +	    } + +	    # FIXME: use libpve-apiclient (like in cluster join) to create +	    # tasks and moitor the tasks. + +	    return; +        }; + +        return $rpcenv->fork_worker('reloadnetworkall', undef, $authuser, $code); + +    }}); + + +1;  | 
