blob: 030134bc6f416d502b4a6ee7dcde4303bbc3cd87 [file] [log] [blame]
Stephane Barbariea75791c2019-01-24 10:58:06 -05001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package config
17
18import (
19 "flag"
20 "fmt"
21 "github.com/opencord/voltha-go/common/log"
22 "os"
23)
24
25// RO Core service default constants
26const (
27 ConsulStoreName = "consul"
28 EtcdStoreName = "etcd"
29 default_InstanceID = "rocore001"
30 default_GrpcPort = 50057
31 default_GrpcHost = ""
32 default_KVStoreType = EtcdStoreName
33 default_KVStoreTimeout = 5 //in seconds
34 default_KVStoreHost = "127.0.0.1"
35 default_KVStorePort = 2379 // Consul = 8500; Etcd = 2379
36 default_KVTxnKeyDelTime = 60
37 default_LogLevel = 0
38 default_Banner = false
David K. Bainbridgef430cd52019-05-28 15:00:35 -070039 default_DisplayVersionOnly = false
Stephane Barbariea75791c2019-01-24 10:58:06 -050040 default_CoreTopic = "rocore"
41 default_ROCoreEndpoint = "rocore"
42 default_ROCoreKey = "pki/voltha.key"
43 default_ROCoreCert = "pki/voltha.crt"
44 default_ROCoreCA = "pki/voltha-CA.pem"
45 default_Affinity_Router_Topic = "affinityRouter"
46)
47
48// ROCoreFlags represents the set of configurations used by the read-only core service
49type ROCoreFlags struct {
50 // Command line parameters
51 InstanceID string
52 ROCoreEndpoint string
53 GrpcHost string
54 GrpcPort int
55 KVStoreType string
56 KVStoreTimeout int // in seconds
57 KVStoreHost string
58 KVStorePort int
59 KVTxnKeyDelTime int
60 CoreTopic string
61 LogLevel int
62 Banner bool
David K. Bainbridgef430cd52019-05-28 15:00:35 -070063 DisplayVersionOnly bool
Stephane Barbariea75791c2019-01-24 10:58:06 -050064 ROCoreKey string
65 ROCoreCert string
66 ROCoreCA string
67 AffinityRouterTopic string
68}
69
70func init() {
71 log.AddPackage(log.JSON, log.WarnLevel, nil)
72}
73
74// NewROCoreFlags returns a new ROCore config
75func NewROCoreFlags() *ROCoreFlags {
76 var roCoreFlag = ROCoreFlags{ // Default values
77 InstanceID: default_InstanceID,
78 ROCoreEndpoint: default_ROCoreEndpoint,
79 GrpcHost: default_GrpcHost,
80 GrpcPort: default_GrpcPort,
81 KVStoreType: default_KVStoreType,
82 KVStoreTimeout: default_KVStoreTimeout,
83 KVStoreHost: default_KVStoreHost,
84 KVStorePort: default_KVStorePort,
85 KVTxnKeyDelTime: default_KVTxnKeyDelTime,
86 CoreTopic: default_CoreTopic,
87 LogLevel: default_LogLevel,
88 Banner: default_Banner,
David K. Bainbridgef430cd52019-05-28 15:00:35 -070089 DisplayVersionOnly: default_DisplayVersionOnly,
Stephane Barbariea75791c2019-01-24 10:58:06 -050090 ROCoreKey: default_ROCoreKey,
91 ROCoreCert: default_ROCoreCert,
92 ROCoreCA: default_ROCoreCA,
93 AffinityRouterTopic: default_Affinity_Router_Topic,
94 }
95 return &roCoreFlag
96}
97
98// ParseCommandArguments parses the arguments when running read-only core service
99func (cf *ROCoreFlags) ParseCommandArguments() {
100
101 var help string
102
103 help = fmt.Sprintf("RO core endpoint address")
104 flag.StringVar(&(cf.ROCoreEndpoint), "vcore-endpoint", default_ROCoreEndpoint, help)
105
106 help = fmt.Sprintf("GRPC server - host")
107 flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help)
108
109 help = fmt.Sprintf("GRPC server - port")
110 flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help)
111
112 help = fmt.Sprintf("RO Core topic")
113 flag.StringVar(&(cf.CoreTopic), "ro_core_topic", default_CoreTopic, help)
114
115 help = fmt.Sprintf("Affinity Router topic")
116 flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", default_Affinity_Router_Topic, help)
117
118 help = fmt.Sprintf("KV store type")
119 flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help)
120
121 help = fmt.Sprintf("The default timeout when making a kv store request")
122 flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
123
124 help = fmt.Sprintf("KV store host")
125 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
126
127 help = fmt.Sprintf("KV store port")
128 flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help)
129
130 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
131 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", default_KVTxnKeyDelTime, help)
132
133 help = fmt.Sprintf("Log level")
134 flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help)
135
136 help = fmt.Sprintf("Show startup banner log lines")
137 flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
138
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700139 help = fmt.Sprintf("Show version information and exit")
140 flag.BoolVar(&cf.DisplayVersionOnly, "version", default_DisplayVersionOnly, help)
141
Stephane Barbariea75791c2019-01-24 10:58:06 -0500142 flag.Parse()
143
144 containerName := getContainerInfo()
145 if len(containerName) > 0 {
146 cf.InstanceID = containerName
147 }
148
149}
150
151func getContainerInfo() string {
152 return os.Getenv("HOSTNAME")
153}