diff --git a/controller/config/config.go b/controller/config/config.go index dded01cadf31958c52211ffb211c6c19aab5d9dc..55161e10c7a598d4aca9ba4ac755ac7ad8f3c4c4 100644 --- a/controller/config/config.go +++ b/controller/config/config.go @@ -21,6 +21,7 @@ const ( jwtDurationKey = "defaultJWTDuration" defaultJWTDuration = time.Hour * 24 jwtSecretKey = "jwtSecret" + gNMISubscriptionsFilePathKey = "gNMISubscriptionsPath" // RabbitMQ Broker amqpPrefixKey = "amqpPrefix" @@ -72,6 +73,9 @@ var AMQPHost string // AMQPPort is the amqp port var AMQPPort string +// GNMISubscriptionsFilePath is the path to the file used for automated subscriptions +var GNMISubscriptionsFilePath string + // Init gets called on module import func Init() { err := InitializeConfig() @@ -125,6 +129,8 @@ func InitializeConfig() error { JWTSecret = viper.GetString(jwtSecretKey) + GNMISubscriptionsFilePath = getStringFromViper(gNMISubscriptionsFilePathKey) + loadAMQPConfig() if err := viper.WriteConfig(); err != nil { diff --git a/controller/config/gnmiSubscriptionConfig.go b/controller/config/gnmiSubscriptionConfig.go index fa433e3d8fce96733c4b0f55d5fc99b3ed47396b..53e1b32571f9793cfe2596fe018a04ca45357351 100644 --- a/controller/config/gnmiSubscriptionConfig.go +++ b/controller/config/gnmiSubscriptionConfig.go @@ -16,12 +16,18 @@ var gnmiSubscriptionPaths [][]string // ReadGnmiSubscriptionPaths reads the paths the watcher should subscribe to provided in a file. func ReadGnmiSubscriptionPaths() error { - currentDir, err := os.Getwd() - if err != nil { - return err - } + var filePath string - filePath := filepath.Join(currentDir, defaultGnmiSubscriptionFilePath) + if GNMISubscriptionsFilePath != "" { + filePath = GNMISubscriptionsFilePath + } else { + currentDir, err := os.Getwd() + if err != nil { + return err + } + + filePath = filepath.Join(currentDir, defaultGnmiSubscriptionFilePath) + } f, err := os.Open(filePath) if err != nil { diff --git a/controller/configs/containerlab-gosdn.toml.example b/controller/configs/containerlab-gosdn.toml.example index 6f52b353c6594ed1e91f06d9b769e974a857841e..abe7167bd009908b37d4b35ea8e5ab6a8cad6da8 100644 --- a/controller/configs/containerlab-gosdn.toml.example +++ b/controller/configs/containerlab-gosdn.toml.example @@ -11,6 +11,8 @@ pnduuid = "bf8160d4-4659-4a1b-98fd-f409a04111ec" socket = ":55055" databaseConnection = "mongodb://root:example@clab-gosdn_csbi_arista_base-mongodb:27017" filesystemPathToStores = "stores" +gNMISubscriptionsPath = "controller/configs/gNMISubscriptions.txt" + amqpPrefix = "amqp://" amqpUser = "guest" diff --git a/controller/configs/development-gosdn.toml.example b/controller/configs/development-gosdn.toml.example index b1cf52c3a1548b582a5ff48a6d836c51880c3bb9..820c76f130e7cbf8c9a48edd9eb577d97266ecad 100644 --- a/controller/configs/development-gosdn.toml.example +++ b/controller/configs/development-gosdn.toml.example @@ -11,7 +11,7 @@ pnduuid = "bf8160d4-4659-4a1b-98fd-f409a04111ec" socket = ":55055" databaseConnection = "mongodb://root:example@localhost:27017" filesystemPathToStores = "stores" - +gNMISubscriptionsPath = "controller/configs/gNMISubscriptions.txt" amqpPrefix = "amqp://" amqpUser = "guest" diff --git a/controller/controller.go b/controller/controller.go index 5eb24da68c0e07da11df4e35ac4a0d39610e5122..a79d4cea9bdbcd6480636b9abf32bbd429007135 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -112,8 +112,6 @@ func initialize() error { } c.deviceWatcher = nucleus.NewDeviceWatcher(c.pndStore) - // TODO: udpate with actual paths to subscribe when using template/config - fmt.Println(config.GetGnmiSubscriptionPaths()) c.deviceWatcher.SubToDevices(config.GetGnmiSubscriptionPaths(), nil) err = ensureDefaultRoleExists()