diff --git a/.gitignore b/.gitignore index fc66c8dcc06e289f00294b8e06f01eb2d13a8723..18f778fa72f8964aa66b521c56c75f00a0c9da5b 100644 --- a/.gitignore +++ b/.gitignore @@ -53,8 +53,9 @@ stores/*.json configs/gosdn.toml config/.gosdnc.toml +# venv-manager applications/venv-manager/*.clab.yaml - +applications/venv-manager/sdn_config.json #debug __debug_bin diff --git a/applications/venv-manager/main.go b/applications/venv-manager/main.go index 81c4cc10070f5d1ed119ce1f1eede272ba97b8fa..4fd254fadaab08025d5b8b11a6edba98a8a2d972 100644 --- a/applications/venv-manager/main.go +++ b/applications/venv-manager/main.go @@ -15,17 +15,21 @@ func main() { var dialConnectionURL string var yamlFilepath string var customContainerRegistryURL string + var sdnConfigFilepath string + dialOption := grpc.WithTransportCredentials(insecure.NewCredentials()) 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(&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. flag.Usage = func() { 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("--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("--help\n\t Shows this help screen.") } @@ -34,7 +38,7 @@ func main() { customContainerRegistryURL = ensureLastCharIsSlash(customContainerRegistryURL) 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() if err != nil { diff --git a/applications/venv-manager/venv-manager/venv-manager.go b/applications/venv-manager/venv-manager/venv-manager.go index c4c613548428d9c9dec79bacbda185bbda0eea0d..f82c2cd665600c64b6f78d485c2d3050b2a19204 100644 --- a/applications/venv-manager/venv-manager/venv-manager.go +++ b/applications/venv-manager/venv-manager/venv-manager.go @@ -31,16 +31,18 @@ type VenvManager struct { dialConnectionURL string dialOption grpc.DialOption yamlFilepath string + sdnConfigFilepath string containerRegistryURL string pnd string } // 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.dialConnectionURL = dialConnectionURL v.dialOption = dialOption v.yamlFilepath = yamlFilepath + v.sdnConfigFilepath = sdnConfigFilepath v.containerRegistryURL = containerRegistryURL return v } @@ -90,7 +92,10 @@ func (v *VenvManager) CreateSDNConfigFile() error { return err } - fmt.Println(sdnConfigReponse) + err = v.writeSDNConfigToFile(*sdnConfigReponse) + if err != nil { + return err + } return nil } @@ -123,6 +128,16 @@ func (v *VenvManager) getSDNConfigData() (*string, error) { 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. func (v *VenvManager) CreateTopologyFile() error { topologyData, err := v.getTopologyData() diff --git a/controller/northbound/server/configurationmanagement.go b/controller/northbound/server/configurationmanagement.go index 09564acddec380412b43171e0c716aca035d1d9e..96e0034a47499a8dda3e59397c48192eb1dc797d 100644 --- a/controller/northbound/server/configurationmanagement.go +++ b/controller/northbound/server/configurationmanagement.go @@ -41,10 +41,10 @@ func NewConfigurationManagementServer( // SDNConfig is used to aprse the SDNConfig into JSON. type SDNConfig struct { PndID string `json:"pndID"` - NetworkElements []networkelement.NetworkElement `json:"networkelements"` Nodes []nodes.Node `json:"nodes"` Ports []ports.Port `json:"ports"` Links []links.Link `json:"links"` + NetworkElements []networkelement.NetworkElement `json:"networkelements"` } // ExportSDNConfig returns the SDN configuration. @@ -72,14 +72,16 @@ func (c ConfigurationManagementServer) ExportSDNConfig(ctx context.Context, requ return nil, err } - jsonSDNConfig, err := json.Marshal(sdnConfig) + jsonSDNConfig, err := json.MarshalIndent(sdnConfig, "", " ") if err != nil { return nil, err } + stringified := string(jsonSDNConfig) + return &cmpb.ExportSDNConfigResponse{ Timestamp: time.Now().UnixNano(), - SdnConfig: string(jsonSDNConfig)}, nil + SdnConfig: stringified}, nil } // ImportSDNConfig receives an SDN configuration and imports it.