Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
opentrafficshaper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eezysol
opentrafficshaper
Commits
c40c72a5
Commit
c40c72a5
authored
11 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
Moved configuration management to a core module
parent
ff195d7d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentrafficshaper/plugins/configmanager.pm
+118
-0
118 additions, 0 deletions
opentrafficshaper/plugins/configmanager.pm
opentrafficshaperd
+19
-27
19 additions, 27 deletions
opentrafficshaperd
with
137 additions
and
27 deletions
opentrafficshaper/plugins/configmanager.pm
0 → 100644
+
118
−
0
View file @
c40c72a5
# OpenTrafficShaper configuration manager
# Copyright (C) 2007-2013, AllWorldIT
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
package
opentrafficshaper::plugins::
configmanager
;
use
strict
;
use
warnings
;
use
POE
;
use
opentrafficshaper::
logger
;
# Exporter stuff
require
Exporter
;
our
(
@ISA
,
@EXPORT
,
@EXPORT_OK
);
@ISA
=
qw(Exporter)
;
@EXPORT
=
qw(
)
;
@EXPORT_OK
=
qw(
)
;
use
constant
{
VERSION
=>
'
0.0.1
',
};
# Plugin info
our
$pluginInfo
=
{
Name
=>
"
Config Manager
",
Version
=>
VERSION
,
Init
=>
\
&init
,
};
# Copy of system globals
my
$globals
;
my
$logger
;
# Initialize plugin
sub
init
{
$globals
=
shift
;
# Setup our environment
$logger
=
$globals
->
{'
logger
'};
# This is our configuration processing session
POE::
Session
->
create
(
inline_states
=>
{
_start
=>
\
&session_init
,
tick
=>
\
&session_tick
,
process_change
=>
\
&process_change
,
}
);
$logger
->
log
(
LOG_NOTICE
,"
[CONFIGMANAGER] OpenTrafficShaper Config Manager v
"
.
VERSION
.
"
- Copyright (c) 2013, AllWorldIT
")
}
# Initialize config manager
sub
session_init
{
my
$kernel
=
$_
[
KERNEL
];
# Set our alias
$kernel
->
alias_set
("
configmanager
");
# Set delay on config updates
$kernel
->
delay
(
tick
=>
5
);
}
# Time ticker for processing changes
sub
session_tick
{
my
$kernel
=
$_
[
KERNEL
];
print
STDERR
"
tick at
",
time
(),
"
: users =
"
.
(
keys
%
{
$globals
->
{'
users
'}})
.
"
\n
";
# Reset tick
$kernel
->
delay
(
tick
=>
5
);
};
# Read event for server
sub
process_change
{
my
(
$kernel
,
$user
)
=
@_
[
KERNEL
,
ARG0
];
print
STDERR
"
We were asked to process an update for
$user
->{'Username'}
\n
";
}
1
;
# vim: ts=4
This diff is collapsed.
Click to expand it.
opentrafficshaperd
+
19
−
27
View file @
c40c72a5
...
@@ -42,35 +42,13 @@ my $globals;
...
@@ -42,35 +42,13 @@ my $globals;
my
$logger
=
new
opentrafficshaper::
logger
;
my
$logger
=
new
opentrafficshaper::
logger
;
#
# Process basically starts here
# MAIN
#
$logger
->
log
(
LOG_NOTICE
,"
[MAIN] OpenTrafficShaper v
"
.
VERSION
.
"
- Copyright (c) 2007-2013, AllWorldIT
");
$logger
->
log
(
LOG_NOTICE
,"
[MAIN] OpenTrafficShaper v
"
.
VERSION
.
"
- Copyright (c) 2007-2013, AllWorldIT
");
parseCfgCmdLine
();
parseCfgCmdLine
();
init
();
init
();
# This is our configuration processing session
# TODO: Current just a trigger
POE::
Session
->
create
(
inline_states
=>
{
_start
=>
sub
{
$_
[
KERNEL
]
->
delay
(
tick
=>
5
);
},
tick
=>
sub
{
print
STDERR
"
tick at
",
time
(),
"
: users =
"
.
(
keys
%
{
$globals
->
{'
users
'}})
.
"
\n
";
$_
[
KERNEL
]
->
delay
(
tick
=>
5
);
},
}
);
#
# MAIN
#
$logger
->
log
(
LOG_NOTICE
,"
[MAIN] Starting...
");
$logger
->
log
(
LOG_NOTICE
,"
[MAIN] Starting...
");
POE::
Kernel
->
run
();
POE::
Kernel
->
run
();
exit
;
exit
;
...
@@ -250,6 +228,19 @@ sub init
...
@@ -250,6 +228,19 @@ sub init
$globals->{
'
radius
'
}->{
'
dictionary
'
} = $dict;
$globals->{
'
radius
'
}->{
'
dictionary
'
} = $dict;
# Core configuration manager
$logger->log(LOG_INFO,"[MAIN] Initializing config manager...");
my $res = eval("
use opentrafficshaper::plugins::configmanager;
plugin_register(\$globals,\"configmanager\",\$opentrafficshaper::plugins::configmanager::pluginInfo);
");
if ($@ || (defined($res) && $res != 0)) {
$logger->log(LOG_WARN,"[MAIN] Error loading config manager, things WILL BREAK! ($@)");
} else {
$logger->log(LOG_DEBUG,"[MAIN] Config manager initialized.");
}
# Load plugins
# Load plugins
$logger->log(LOG_INFO,"[MAIN] Initializing plugins...");
$logger->log(LOG_INFO,"[MAIN] Initializing plugins...");
foreach my $plugin (@{$globals->{
'
config
'
}->{
'
plugin_list
'
}}) {
foreach my $plugin (@{$globals->{
'
config
'
}->{
'
plugin_list
'
}}) {
...
@@ -259,13 +250,14 @@ sub init
...
@@ -259,13 +250,14 @@ sub init
plugin_register(\$globals,\"${plugin}\",\$opentrafficshaper::plugins::${plugin}::pluginInfo);
plugin_register(\$globals,\"${plugin}\",\$opentrafficshaper::plugins::${plugin}::pluginInfo);
");
");
if ($@ || (defined($res) && $res != 0)) {
if ($@ || (defined($res) && $res != 0)) {
$logger->log(LOG_WARN,"[MAIN] Error loading plugin $plugin ($@)");
$logger->log(LOG_WARN,"[MAIN] Error loading plugin
'
$plugin
'
($@)");
} else {
} else {
$logger->log(LOG_DEBUG,"[MAIN] Plugin
'
$plugin
'
loaded.");
$logger->log(LOG_DEBUG,"[MAIN] Plugin
'
$plugin
'
loaded.");
}
}
}
}
$logger->log(LOG_INFO,"[MAIN] Plugins initialized.");
$logger->log(LOG_INFO,"[MAIN] Plugins initialized.");
}
}
# Register plugin info
# Register plugin info
sub plugin_register {
sub plugin_register {
my ($globals,$plugin,$info) = @_;
my ($globals,$plugin,$info) = @_;
...
@@ -279,7 +271,7 @@ sub plugin_register {
...
@@ -279,7 +271,7 @@ sub plugin_register {
# Set real module name & save
# Set real module name & save
$info->{
'
Plugin
'
} = $plugin;
$info->{
'
Plugin
'
} = $plugin;
#
push(@{$lo
gger->{
'
module_list
'
}},$info);
push(@{$
g
lo
bals->{
'
plugins
'
}},$info);
# If we should, init the module
# If we should, init the module
if (defined($info->{
'
Init
'
})) {
if (defined($info->{
'
Init
'
})) {
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment