-
Notifications
You must be signed in to change notification settings - Fork 45
/
Test_Config.go
123 lines (106 loc) · 3.53 KB
/
Test_Config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Proof of Concepts of CB-Spider.
// The CB-Spider is sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// This is a Cloud Driver Example for PoC Test.
//
// by devunet@mz.co.kr, 2019.08.
package TencentTestConfig
import (
"io/ioutil"
tdrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/tencent"
idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
cblog "github.com/cloud-barista/cb-log"
)
var cblogger *logrus.Logger
func init() {
// cblog is a global variable.
cblogger = cblog.GetLogger("Tencent Resource Test")
cblog.SetLevel("debug")
}
// 환경 설정 파일
type Config struct {
Tencent struct {
SecretId string `yaml:"tencent_secret_id"`
SecretKey string `yaml:"tencent_secret_key"`
Region string `yaml:"region"`
Zone string `yaml:"zone"`
} `yaml:"tencent"`
}
//환경 설정 파일 읽기
//환경변수 CBSPIDER_PATH 설정 후 해당 폴더 하위에 /config/configTencent.yaml 파일 생성해야 함.
func ReadConfigFile() Config {
// Set Environment Value of Project Root Path
// /mnt/d/Workspace/mcloud-barista-config/config/config.yaml
//testFilePath := os.Getenv("CBSPIDER_PATH") + "/config/configTencent.yaml" //혹시 모를 키 노출 대비 시스템 외부에 존재(개발용용)
testFilePath := "./conf/testConfigTencent.yaml"
cblogger.Debugf("Test Data 설정파일 : [%]", testFilePath)
data, err := ioutil.ReadFile(testFilePath)
if err != nil {
panic(err)
}
var config Config
err = yaml.Unmarshal(data, &config)
if err != nil {
panic(err)
}
cblogger.Info("Loaded ConfigFile...")
//spew.Dump(config)
//cblogger.Info(config)
cblogger.Debug(config.Tencent.SecretId, " ", config.Tencent.Region)
//cblogger.Debug(config.Tencent.Region)
return config
}
//handlerType : resources폴더의 xxxHandler.go에서 Handler이전까지의 문자열
//(예) ImageHandler.go -> "Image"
func GetResourceHandler(handlerType string) (interface{}, error) {
var cloudDriver idrv.CloudDriver
cloudDriver = new(tdrv.TencentDriver)
config := ReadConfigFile()
connectionInfo := idrv.ConnectionInfo{
CredentialInfo: idrv.CredentialInfo{
ClientId: config.Tencent.SecretId,
ClientSecret: config.Tencent.SecretKey,
},
RegionInfo: idrv.RegionInfo{
Region: config.Tencent.Region,
Zone: config.Tencent.Zone,
},
}
cloudConnection, errCon := cloudDriver.ConnectCloud(connectionInfo)
if errCon != nil {
return nil, errCon
}
var resourceHandler interface{}
var err error
switch handlerType {
case "Image":
resourceHandler, err = cloudConnection.CreateImageHandler()
//case "Publicip":
//resourceHandler, err = cloudConnection.CreatePublicIPHandler()
case "Security":
resourceHandler, err = cloudConnection.CreateSecurityHandler()
// case "VNetwork":
//resourceHandler, err = cloudConnection.CreateVNetworkHandler()
case "KeyPair":
resourceHandler, err = cloudConnection.CreateKeyPairHandler()
case "VPC":
resourceHandler, err = cloudConnection.CreateVPCHandler()
//case "VNic":
//resourceHandler, err = cloudConnection.CreateVNicHandler()
case "VMSpec":
resourceHandler, err = cloudConnection.CreateVMSpecHandler()
case "VM":
resourceHandler, err = cloudConnection.CreateVMHandler()
case "NLB":
resourceHandler, err = cloudConnection.CreateNLBHandler()
}
if err != nil {
return nil, err
}
return resourceHandler, nil
}