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
c80f603b
Commit
c80f603b
authored
2 years ago
by
Neil Schark
Browse files
Options
Downloads
Patches
Plain Diff
read and send sdn config
parent
f3eb93b2
Branches
Branches containing commit
No related tags found
1 merge request
!404
Enable export and import of SDN configuration
Pipeline
#124508
failed
2 years ago
Stage: build
Stage: test
Stage: analyze
Stage: integration-test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
applications/venv-manager/main.go
+35
-15
35 additions, 15 deletions
applications/venv-manager/main.go
applications/venv-manager/venv-manager/venv-manager.go
+57
-6
57 additions, 6 deletions
applications/venv-manager/venv-manager/venv-manager.go
with
92 additions
and
21 deletions
applications/venv-manager/main.go
+
35
−
15
View file @
c80f603b
...
@@ -16,9 +16,11 @@ func main() {
...
@@ -16,9 +16,11 @@ func main() {
var
yamlFilepath
string
var
yamlFilepath
string
var
customContainerRegistryURL
string
var
customContainerRegistryURL
string
var
sdnConfigFilepath
string
var
sdnConfigFilepath
string
var
mode
string
dialOption
:=
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
())
dialOption
:=
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
())
flag
.
StringVar
(
&
mode
,
"mode"
,
"extract"
,
""
)
flag
.
StringVar
(
&
dialConnectionURL
,
"controller"
,
"localhost:55055"
,
""
)
flag
.
StringVar
(
&
dialConnectionURL
,
"controller"
,
"localhost:55055"
,
""
)
flag
.
StringVar
(
&
yamlFilepath
,
"topology"
,
"venv.clab.yaml"
,
""
)
flag
.
StringVar
(
&
yamlFilepath
,
"topology"
,
"venv.clab.yaml"
,
""
)
flag
.
StringVar
(
&
customContainerRegistryURL
,
"registry"
,
""
,
""
)
flag
.
StringVar
(
&
customContainerRegistryURL
,
"registry"
,
""
,
""
)
...
@@ -27,6 +29,7 @@ func main() {
...
@@ -27,6 +29,7 @@ func main() {
// Define own output of --help and parsing error, as some library also uses the flags library and adds there flags to ours, which is not intended.
// Define own output of --help and parsing error, as some library also uses the flags library and adds there flags to ours, which is not intended.
flag
.
Usage
=
func
()
{
flag
.
Usage
=
func
()
{
fmt
.
Printf
(
"Usable flags of the venv-manager:
\n\n
"
)
fmt
.
Printf
(
"Usable flags of the venv-manager:
\n\n
"
)
fmt
.
Println
(
"--mode string
\n\t
The mode of the venv-manager. use either 'extract' or 'deploy'. (Default: 'extract')"
)
fmt
.
Println
(
"--controller string
\n\t
Controller URL and Port. (Default: 'localhost:55055')"
)
fmt
.
Println
(
"--controller string
\n\t
Controller URL and Port. (Default: 'localhost:55055')"
)
fmt
.
Println
(
"--topology string
\n\t
Filename of the resulting topology file. (Default: 'venv.clab.yaml')"
)
fmt
.
Println
(
"--topology string
\n\t
Filename of the resulting topology file. (Default: 'venv.clab.yaml')"
)
fmt
.
Println
(
"--sdnconfig string
\n\t
Filename of the resulting SDN configuration file. (Default: 'sdn_config.json')"
)
fmt
.
Println
(
"--sdnconfig string
\n\t
Filename of the resulting SDN configuration file. (Default: 'sdn_config.json')"
)
...
@@ -37,23 +40,34 @@ func main() {
...
@@ -37,23 +40,34 @@ func main() {
customContainerRegistryURL
=
ensureLastCharIsSlash
(
customContainerRegistryURL
)
customContainerRegistryURL
=
ensureLastCharIsSlash
(
customContainerRegistryURL
)
fmt
.
Println
(
"I will try to connect to goSDN located at"
,
dialConnectionURL
)
if
mode
==
"extract"
{
venvManager
:=
venvmanager
.
NewVenvManager
(
dialConnectionURL
,
dialOption
,
yamlFilepath
,
sdnConfigFilepath
,
customContainerRegistryURL
)
fmt
.
Println
(
"I will try to connect to goSDN located at"
,
dialConnectionURL
)
venvManager
:=
venvmanager
.
NewVenvManager
(
dialConnectionURL
,
dialOption
,
yamlFilepath
,
sdnConfigFilepath
,
customContainerRegistryURL
)
fmt
.
Println
(
"Generating topology file..."
)
fmt
.
Println
(
"Generating topology file..."
)
err
:=
venvManager
.
CreateTopologyFile
()
err
:=
venvManager
.
CreateTopologyFile
()
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
printErrAndAbort
(
err
)
fmt
.
Println
(
"An error occurred, exiting."
)
}
os
.
Exit
(
1
)
}
fmt
.
Println
(
"Generating SDN configuration file..."
)
err
=
venvManager
.
CreateSDNConfigFile
()
if
err
!=
nil
{
printErrAndAbort
(
err
)
}
}
else
if
mode
==
"deploy"
{
fmt
.
Println
(
"I will try to connect to goSDN located at"
,
dialConnectionURL
)
venvManager
:=
venvmanager
.
NewVenvManager
(
dialConnectionURL
,
dialOption
,
yamlFilepath
,
sdnConfigFilepath
,
customContainerRegistryURL
)
//TODO: read topology file and tell containerlab to start environment.
fmt
.
Println
(
"Generating SDN configuration file..."
)
err
:=
venvManager
.
ReadAndSendSDNConfig
()
err
=
venvManager
.
CreateSDNConfigFile
()
if
err
!=
nil
{
if
err
!=
nil
{
printErrAndAbort
(
err
)
fmt
.
Println
(
err
)
}
fmt
.
Println
(
"An error occurred, exiting."
)
os
.
Exit
(
1
)
}
else
{
fmt
.
Println
(
"No valid mode selected. Choose either 'extract' or 'deploy'."
)
}
}
fmt
.
Println
(
"All done!"
)
fmt
.
Println
(
"All done!"
)
...
@@ -72,3 +86,9 @@ func ensureLastCharIsSlash(inputString string) string {
...
@@ -72,3 +86,9 @@ func ensureLastCharIsSlash(inputString string) string {
return
inputString
+
"/"
return
inputString
+
"/"
}
}
func
printErrAndAbort
(
err
error
)
{
fmt
.
Println
(
err
)
fmt
.
Println
(
"An error occurred, exiting."
)
os
.
Exit
(
1
)
}
This diff is collapsed.
Click to expand it.
applications/venv-manager/venv-manager/venv-manager.go
+
57
−
6
View file @
c80f603b
...
@@ -49,7 +49,6 @@ func NewVenvManager(dialConnectionURL string, dialOption grpc.DialOption, yamlFi
...
@@ -49,7 +49,6 @@ func NewVenvManager(dialConnectionURL string, dialOption grpc.DialOption, yamlFi
func
(
v
*
VenvManager
)
createConnection
()
(
*
grpc
.
ClientConn
,
error
)
{
func
(
v
*
VenvManager
)
createConnection
()
(
*
grpc
.
ClientConn
,
error
)
{
conn
,
err
:=
grpc
.
Dial
(
v
.
dialConnectionURL
,
v
.
dialOption
)
conn
,
err
:=
grpc
.
Dial
(
v
.
dialConnectionURL
,
v
.
dialOption
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -59,12 +58,54 @@ func (v *VenvManager) createConnection() (*grpc.ClientConn, error) {
...
@@ -59,12 +58,54 @@ func (v *VenvManager) createConnection() (*grpc.ClientConn, error) {
func
(
v
*
VenvManager
)
closeConnection
(
conn
*
grpc
.
ClientConn
)
{
func
(
v
*
VenvManager
)
closeConnection
(
conn
*
grpc
.
ClientConn
)
{
err
:=
conn
.
Close
()
err
:=
conn
.
Close
()
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
}
}
// ReadAndSendSDNConfig gets the SDN config data and sends it to the controller.
func
(
v
*
VenvManager
)
ReadAndSendSDNConfig
()
error
{
sdnConfigData
,
err
:=
v
.
readSDNConfigFile
()
if
err
!=
nil
{
return
err
}
err
=
v
.
sendSDNConfigData
(
&
sdnConfigData
)
if
err
!=
nil
{
return
err
}
return
nil
}
// getSDNConfigData gets the sDN configuration data.
func
(
v
*
VenvManager
)
sendSDNConfigData
(
sdnConfigData
*
string
)
error
{
conn
,
err
:=
v
.
createConnection
()
if
err
!=
nil
{
return
err
}
defer
v
.
closeConnection
(
conn
)
ctx
:=
context
.
Background
()
//get PND, might remove later because we won't support PND in the future and it gets infored everywhere
coreService
:=
corePb
.
NewCoreServiceClient
(
conn
)
pndRes
,
err
:=
coreService
.
GetPndList
(
ctx
,
&
corePb
.
GetPndListRequest
{
Timestamp
:
getTimestamp
()})
if
err
!=
nil
{
return
err
}
v
.
pnd
=
pndRes
.
Pnd
[
0
]
.
Id
configMgmtService
:=
configMgmtPb
.
NewConfigurationManagementServiceClient
(
conn
)
_
,
err
=
configMgmtService
.
ImportSDNConfig
(
ctx
,
&
configMgmtPb
.
ImportSDNConfigRequest
{
Timestamp
:
getTimestamp
(),
Pid
:
v
.
pnd
,
SdnConfigData
:
*
sdnConfigData
})
if
err
!=
nil
{
return
err
}
return
nil
}
// CreateSDNConfigFile creates the SDN configuration file.
// CreateSDNConfigFile creates the SDN configuration file.
func
(
v
*
VenvManager
)
CreateSDNConfigFile
()
error
{
func
(
v
*
VenvManager
)
CreateSDNConfigFile
()
error
{
sdnConfigReponse
,
err
:=
v
.
getSDNConfigData
()
sdnConfigReponse
,
err
:=
v
.
getSDNConfigData
()
...
@@ -72,7 +113,7 @@ func (v *VenvManager) CreateSDNConfigFile() error {
...
@@ -72,7 +113,7 @@ func (v *VenvManager) CreateSDNConfigFile() error {
return
err
return
err
}
}
err
=
v
.
writeSDNConfig
To
File
(
*
sdnConfigReponse
)
err
=
v
.
writeSDNConfigFile
(
*
sdnConfigReponse
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -105,11 +146,11 @@ func (v *VenvManager) getSDNConfigData() (*string, error) {
...
@@ -105,11 +146,11 @@ func (v *VenvManager) getSDNConfigData() (*string, error) {
return
nil
,
err
return
nil
,
err
}
}
return
&
sdnConfigResponse
.
SdnConfig
,
nil
return
&
sdnConfigResponse
.
SdnConfig
Data
,
nil
}
}
// writeSDNConfig
To
File wri
e
ts the SDN configuration in a string to a file.
// writeSDNConfigFile writ
e
s the SDN configuration in a string to a file.
func
(
v
*
VenvManager
)
writeSDNConfig
To
File
(
sdnConfigToWrite
string
)
error
{
func
(
v
*
VenvManager
)
writeSDNConfigFile
(
sdnConfigToWrite
string
)
error
{
err
:=
os
.
WriteFile
(
v
.
sdnConfigFilepath
,
[]
byte
(
sdnConfigToWrite
),
0644
)
err
:=
os
.
WriteFile
(
v
.
sdnConfigFilepath
,
[]
byte
(
sdnConfigToWrite
),
0644
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -118,6 +159,16 @@ func (v *VenvManager) writeSDNConfigToFile(sdnConfigToWrite string) error {
...
@@ -118,6 +159,16 @@ func (v *VenvManager) writeSDNConfigToFile(sdnConfigToWrite string) error {
return
nil
return
nil
}
}
// readSDNConfigToFile reads the SDN configuration from a file to a string.
func
(
v
*
VenvManager
)
readSDNConfigFile
()
(
string
,
error
)
{
content
,
err
:=
os
.
ReadFile
(
v
.
sdnConfigFilepath
)
if
err
!=
nil
{
return
""
,
err
}
return
string
(
content
),
nil
}
// CreateTopologyFile creates the topology file.
// CreateTopologyFile creates the topology file.
func
(
v
*
VenvManager
)
CreateTopologyFile
()
error
{
func
(
v
*
VenvManager
)
CreateTopologyFile
()
error
{
topologyData
,
err
:=
v
.
getTopologyData
()
topologyData
,
err
:=
v
.
getTopologyData
()
...
...
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