Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Commits
36a8a272
Commit
36a8a272
authored
4 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
client config now in clients.toml. also some shutdown simplification
parent
aad7e9a3
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!51
Resolve "Read RESTCONF Client from config.toml"
,
!18
Develop
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
clients.toml
+3
-0
3 additions, 0 deletions
clients.toml
nucleus/controller.go
+52
-25
52 additions, 25 deletions
nucleus/controller.go
nucleus/nucleus-core.go
+2
-4
2 additions, 4 deletions
nucleus/nucleus-core.go
with
57 additions
and
29 deletions
clients.toml
0 → 100644
+
3
−
0
View file @
36a8a272
[[client]]
identifier
=
"ciena-mcp"
endpoint
=
"141.100.70.170:8080"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
nucleus/controller.go
+
52
−
25
View file @
36a8a272
...
...
@@ -18,6 +18,13 @@ type controllerConfig struct {
ConfigPath
string
}
type
clientConfig
struct
{
identifier
string
endpoint
string
username
string
password
string
}
type
Core
struct
{
//Assert type with clients[key].(*MCPClient)
clients
map
[
string
]
interfaces
.
Client
...
...
@@ -26,33 +33,22 @@ type Core struct {
IsRunning
chan
bool
}
func
(
c
*
Core
)
Init
(
socket
,
configfile
string
,
IsRunningChannel
chan
bool
)
{
if
configfile
==
""
{
configfile
=
"gosdn.toml"
}
_
,
err
:=
os
.
Stat
(
configfile
)
if
err
!=
nil
{
log
.
Fatal
(
"Config file is missing: "
,
configfile
)
}
c
.
config
=
controllerConfig
{}
if
_
,
err
:=
toml
.
DecodeFile
(
configfile
,
&
c
.
config
);
err
!=
nil
{
func
(
c
*
Core
)
Init
(
socket
,
configFileController
,
configFileClient
string
,
IsRunningChannel
chan
bool
)
{
if
err
:=
c
.
readControllerConfig
(
configFileController
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
if
socket
!=
"localhost:55055"
{
c
.
config
.
CliSocket
=
socket
}
if
c
.
config
.
ConfigPath
==
""
{
c
.
config
.
ConfigPath
=
configfile
}
c
.
AttachDatabase
()
c
.
IsRunning
=
IsRunningChannel
//TODO: Create client config/CLI adapter
c
.
clients
[
"ciena-mcp"
]
=
ciena
.
NewMCPClient
(
"141.100.70.170:8080"
,
""
,
""
,
&
c
.
database
)
if
err
:=
c
.
readClientConfig
(
configFileClient
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
func
(
c
*
Core
)
AttachDatabase
()
{
...
...
@@ -61,13 +57,8 @@ func (c *Core) AttachDatabase() {
func
(
c
*
Core
)
Shutdown
()
{
stopIt
:=
<-
c
.
IsRunning
if
!
stopIt
{
log
.
Debug
(
"Shutdown() received action to shutdown"
)
}
else
{
log
.
Debug
(
"Shutdown() received something else."
)
}
<-
c
.
IsRunning
log
.
Info
(
"Received shutdown signal. Shutting down"
)
f
,
err
:=
os
.
Create
(
c
.
config
.
ConfigPath
)
if
err
!=
nil
{
...
...
@@ -77,6 +68,42 @@ func (c *Core) Shutdown() {
if
err
:=
enc
.
Encode
(
c
.
config
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
log
.
Info
(
"Shutdown complete"
)
os
.
Exit
(
0
)
}
func
(
c
*
Core
)
readControllerConfig
(
configFileController
string
)
error
{
if
configFileController
==
""
{
configFileController
=
"gosdn.toml"
}
if
_
,
err
:=
os
.
Stat
(
configFileController
);
err
!=
nil
{
return
err
}
c
.
config
=
controllerConfig
{}
if
_
,
err
:=
toml
.
DecodeFile
(
configFileController
,
&
c
.
config
);
err
!=
nil
{
return
err
}
if
c
.
config
.
ConfigPath
==
""
{
c
.
config
.
ConfigPath
=
configFileController
}
return
nil
}
func
(
c
*
Core
)
readClientConfig
(
configFileClient
string
)
error
{
if
configFileClient
==
""
{
configFileClient
=
"clients.toml"
}
if
_
,
err
:=
os
.
Stat
(
configFileClient
);
err
!=
nil
{
return
err
}
clients
:=
make
([]
clientConfig
,
0
)
if
_
,
err
:=
toml
.
DecodeFile
(
configFileClient
,
&
clients
);
err
!=
nil
{
return
err
}
for
_
,
client
:=
range
clients
{
c
.
clients
[
client
.
identifier
]
=
ciena
.
NewMCPClient
(
client
.
endpoint
,
client
.
username
,
client
.
password
,
&
c
.
database
)
}
return
nil
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
nucleus/nucleus-core.go
+
2
−
4
View file @
36a8a272
...
...
@@ -17,7 +17,7 @@ func StartAndRun(socket, filename string, IsRunningChannel chan bool) {
clients
:
make
(
map
[
string
]
interfaces
.
Client
),
database
:
database
.
Database
{},
}
core
.
Init
(
socket
,
filename
,
IsRunningChannel
)
core
.
Init
(
socket
,
filename
,
""
,
IsRunningChannel
)
// Start the GRCP CLI
go
getCLIGoing
(
&
core
)
go
core
.
Shutdown
()
...
...
@@ -25,10 +25,8 @@ func StartAndRun(socket, filename string, IsRunningChannel chan bool) {
log
.
Info
(
"and ready for take off"
)
//Just to produce some signs of vitality...
for
(
true
)
{
for
{
time
.
Sleep
(
10
*
time
.
Second
)
log
.
Debug
(
"Still alive..."
)
}
log
.
Info
(
"Good bye....!"
)
}
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