2 * Copyright 2018 NEC Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 "github.com/BurntSushi/toml"
22 "github.com/go-redis/redis"
23 libvirt "github.com/libvirt/libvirt-go"
24 "github.com/opnfv/barometer/src/dma/pkg/common"
29 var infoPool common.RedisPool
34 InfoFetch InfoFetchConfig
37 // CommonConfig is ...
38 type CommonConfig struct {
39 RedisHost string `toml:"redis_host"`
40 RedisPort string `toml:"redis_port"`
41 RedisPassword string `toml:"redis_password"`
42 RedisDB int `toml:"redis_db"`
45 // InfoFetchConfig is ...
46 type InfoFetchConfig struct {
47 OSUsername string `toml:"os_username"`
48 OSUserDomainName string `toml:"os_user_domain_name"`
49 OSProjectDomainName string `toml:"os_project_domain_name"`
50 OSProjectName string `toml:"os_project_name"`
51 OSPassword string `toml:"os_password"`
52 OSAuthURL string `toml:"os_auth_url"`
58 _, err := toml.DecodeFile("/etc/barometer-dma/config.toml", &config)
60 log.Println("Read error of config file")
63 var waitgroup sync.WaitGroup
64 libvirt.EventRegisterDefaultImpl()
66 redisClient := redis.NewClient(&redis.Options{
67 Addr: config.Common.RedisHost + ":" + config.Common.RedisPort,
68 Password: config.Common.RedisPassword,
69 DB: config.Common.RedisDB,
71 infoPool = common.RedisPool{Client: redisClient}
72 // Initialize redis db...
75 conn, err := libvirt.NewConnect("qemu:///system")
77 log.Fatalln("libvirt connect error")
81 vmIfInfoChan := make(chan string)
83 ctx := context.Background()
86 RunNeutronInfoFetch(ctx, &config, vmIfInfoChan)
92 GetActiveDomain(conn, vmIfInfoChan)
94 ctx := context.Background()
97 RunVirshEventLoop(ctx, conn, vmIfInfoChan)