-
Notifications
You must be signed in to change notification settings - Fork 2
/
driver.go
117 lines (88 loc) · 3.64 KB
/
driver.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
// gRPC Runtime of CB-Spider.
// The CB-Spider is a 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
//
// by CB-Spider Team, 2020.09.
package service
import (
"context"
gc "github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/common"
"github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/logger"
pb "github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/stub/cbspider"
dim "github.com/cloud-barista/poc-cicd-spider/cloud-info-manager/driver-info-manager"
)
// ===== [ Constants and Variables ] =====
// ===== [ Types ] =====
// ===== [ Implementations ] =====
// CreateCloudDriver - Cloud Driver 생성
func (s *CIMService) CreateCloudDriver(ctx context.Context, req *pb.CloudDriverInfoRequest) (*pb.CloudDriverInfoResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling CIMService.CreateCloudDriver()")
// GRPC 메시지에서 CIM 객체로 복사
var cimObj dim.CloudDriverInfo
err := gc.CopySrcToDest(&req.Item, &cimObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.CreateCloudDriver()")
}
drvInfo, err := dim.RegisterCloudDriverInfo(cimObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.CreateCloudDriver()")
}
// CIM 객체에서 GRPC 메시지로 복사
var grpcObj pb.CloudDriverInfo
err = gc.CopySrcToDest(&drvInfo, &grpcObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.CreateCloudDriver()")
}
resp := &pb.CloudDriverInfoResponse{Item: &grpcObj}
return resp, nil
}
// ListCloudDriver -Cloud Driver 목록
func (s *CIMService) ListCloudDriver(ctx context.Context, req *pb.Empty) (*pb.ListCloudDriverInfoResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling CIMService.ListCloudDriver()")
infoList, err := dim.ListCloudDriver()
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.ListCloudDriver()")
}
// CIM 객체에서 GRPC 메시지로 복사
var grpcObj []*pb.CloudDriverInfo
err = gc.CopySrcToDest(&infoList, &grpcObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.ListCloudDriver()")
}
resp := &pb.ListCloudDriverInfoResponse{Items: grpcObj}
return resp, nil
}
// GetCloudDriver - Cloud Driver 조회
func (s *CIMService) GetCloudDriver(ctx context.Context, req *pb.CloudDriverQryRequest) (*pb.CloudDriverInfoResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling CIMService.GetCloudDriver()")
drvInfo, err := dim.GetCloudDriver(req.DriverName)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.GetCloudDriver()")
}
// CIM 객체에서 GRPC 메시지로 복사
var grpcObj pb.CloudDriverInfo
err = gc.CopySrcToDest(&drvInfo, &grpcObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.GetCloudDriver()")
}
resp := &pb.CloudDriverInfoResponse{Item: &grpcObj}
return resp, nil
}
// DeleteCloudDriver - Cloud Driver 삭제
func (s *CIMService) DeleteCloudDriver(ctx context.Context, req *pb.CloudDriverQryRequest) (*pb.BooleanResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling CIMService.DeleteCloudDriver()")
result, err := dim.UnRegisterCloudDriver(req.DriverName)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.DeleteCloudDriver()")
}
resp := &pb.BooleanResponse{Result: result}
return resp, nil
}
// ===== [ Private Functions ] =====
// ===== [ Public Functions ] =====