Skip to content
Snippets Groups Projects
Commit 30b05b36 authored by Neil Schark's avatar Neil Schark
Browse files

progress for export of SDN config

parent 1b1a11ab
Branches
No related tags found
2 merge requests!406Draft: Add backup script,!404Enable export and import of SDN configuration
Pipeline #124034 failed
This commit is part of merge request !404. Comments created here will be created in the context of that merge request.
...@@ -53,8 +53,9 @@ stores/*.json ...@@ -53,8 +53,9 @@ stores/*.json
configs/gosdn.toml configs/gosdn.toml
config/.gosdnc.toml config/.gosdnc.toml
# venv-manager
applications/venv-manager/*.clab.yaml applications/venv-manager/*.clab.yaml
applications/venv-manager/sdn_config.json
#debug #debug
__debug_bin __debug_bin
...@@ -15,17 +15,21 @@ func main() { ...@@ -15,17 +15,21 @@ func main() {
var dialConnectionURL string var dialConnectionURL string
var yamlFilepath string var yamlFilepath string
var customContainerRegistryURL string var customContainerRegistryURL string
var sdnConfigFilepath string
dialOption := grpc.WithTransportCredentials(insecure.NewCredentials()) dialOption := grpc.WithTransportCredentials(insecure.NewCredentials())
flag.StringVar(&dialConnectionURL, "controller", "localhost:55055", "") flag.StringVar(&dialConnectionURL, "controller", "localhost:55055", "")
flag.StringVar(&yamlFilepath, "file", "venv.clab.yaml", "") flag.StringVar(&yamlFilepath, "topology", "venv.clab.yaml", "")
flag.StringVar(&customContainerRegistryURL, "registry", "", "") flag.StringVar(&customContainerRegistryURL, "registry", "", "")
flag.StringVar(&sdnConfigFilepath, "sdnconfig", "sdn_config.json", "")
// 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("--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("--file 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("--registry string\n\t URL of the container registry to use. Keep in mind that cEOS images and prebuild linux images with the gnmi target are not available on dockerhub. (Default: dockerhub)") fmt.Println("--registry string\n\t URL of the container registry to use. Keep in mind that cEOS images and prebuild linux images with the gnmi target are not available on dockerhub. (Default: dockerhub)")
fmt.Println("--help\n\t Shows this help screen.") fmt.Println("--help\n\t Shows this help screen.")
} }
...@@ -34,7 +38,7 @@ func main() { ...@@ -34,7 +38,7 @@ func main() {
customContainerRegistryURL = ensureLastCharIsSlash(customContainerRegistryURL) customContainerRegistryURL = ensureLastCharIsSlash(customContainerRegistryURL)
fmt.Println("I will try to connect to goSDN located at", dialConnectionURL) fmt.Println("I will try to connect to goSDN located at", dialConnectionURL)
venvManager := venvmanager.NewVenvManager(dialConnectionURL, dialOption, yamlFilepath, customContainerRegistryURL) venvManager := venvmanager.NewVenvManager(dialConnectionURL, dialOption, yamlFilepath, sdnConfigFilepath, customContainerRegistryURL)
err := venvManager.TestConnection() err := venvManager.TestConnection()
if err != nil { if err != nil {
......
...@@ -31,16 +31,18 @@ type VenvManager struct { ...@@ -31,16 +31,18 @@ type VenvManager struct {
dialConnectionURL string dialConnectionURL string
dialOption grpc.DialOption dialOption grpc.DialOption
yamlFilepath string yamlFilepath string
sdnConfigFilepath string
containerRegistryURL string containerRegistryURL string
pnd string pnd string
} }
// NewVenvManager creates a new VenvManager to use. // NewVenvManager creates a new VenvManager to use.
func NewVenvManager(dialConnectionURL string, dialOption grpc.DialOption, yamlFilepath string, containerRegistryURL string) *VenvManager { func NewVenvManager(dialConnectionURL string, dialOption grpc.DialOption, yamlFilepath string, sdnConfigFilepath string, containerRegistryURL string) *VenvManager {
v := new(VenvManager) v := new(VenvManager)
v.dialConnectionURL = dialConnectionURL v.dialConnectionURL = dialConnectionURL
v.dialOption = dialOption v.dialOption = dialOption
v.yamlFilepath = yamlFilepath v.yamlFilepath = yamlFilepath
v.sdnConfigFilepath = sdnConfigFilepath
v.containerRegistryURL = containerRegistryURL v.containerRegistryURL = containerRegistryURL
return v return v
} }
...@@ -90,7 +92,10 @@ func (v *VenvManager) CreateSDNConfigFile() error { ...@@ -90,7 +92,10 @@ func (v *VenvManager) CreateSDNConfigFile() error {
return err return err
} }
fmt.Println(sdnConfigReponse) err = v.writeSDNConfigToFile(*sdnConfigReponse)
if err != nil {
return err
}
return nil return nil
} }
...@@ -123,6 +128,16 @@ func (v *VenvManager) getSDNConfigData() (*string, error) { ...@@ -123,6 +128,16 @@ func (v *VenvManager) getSDNConfigData() (*string, error) {
return &sdnConfigResponse.SdnConfig, nil return &sdnConfigResponse.SdnConfig, nil
} }
// writeSDNConfigToFile wriets the SDN configuration in a string to a file
func (v *VenvManager) writeSDNConfigToFile(sdnConfigToWrite string) error {
err := os.WriteFile(v.sdnConfigFilepath, []byte(sdnConfigToWrite), 0644)
if err != nil {
return err
}
return 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()
......
...@@ -41,10 +41,10 @@ func NewConfigurationManagementServer( ...@@ -41,10 +41,10 @@ func NewConfigurationManagementServer(
// SDNConfig is used to aprse the SDNConfig into JSON. // SDNConfig is used to aprse the SDNConfig into JSON.
type SDNConfig struct { type SDNConfig struct {
PndID string `json:"pndID"` PndID string `json:"pndID"`
NetworkElements []networkelement.NetworkElement `json:"networkelements"`
Nodes []nodes.Node `json:"nodes"` Nodes []nodes.Node `json:"nodes"`
Ports []ports.Port `json:"ports"` Ports []ports.Port `json:"ports"`
Links []links.Link `json:"links"` Links []links.Link `json:"links"`
NetworkElements []networkelement.NetworkElement `json:"networkelements"`
} }
// ExportSDNConfig returns the SDN configuration. // ExportSDNConfig returns the SDN configuration.
...@@ -72,14 +72,16 @@ func (c ConfigurationManagementServer) ExportSDNConfig(ctx context.Context, requ ...@@ -72,14 +72,16 @@ func (c ConfigurationManagementServer) ExportSDNConfig(ctx context.Context, requ
return nil, err return nil, err
} }
jsonSDNConfig, err := json.Marshal(sdnConfig) jsonSDNConfig, err := json.MarshalIndent(sdnConfig, "", " ")
if err != nil { if err != nil {
return nil, err return nil, err
} }
stringified := string(jsonSDNConfig)
return &cmpb.ExportSDNConfigResponse{ return &cmpb.ExportSDNConfigResponse{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
SdnConfig: string(jsonSDNConfig)}, nil SdnConfig: stringified}, nil
} }
// ImportSDNConfig receives an SDN configuration and imports it. // ImportSDNConfig receives an SDN configuration and imports it.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment