-
Notifications
You must be signed in to change notification settings - Fork 47
/
CommonIbmFunc.go
56 lines (48 loc) · 1.5 KB
/
CommonIbmFunc.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
package resources
import (
"fmt"
cblog "github.com/cloud-barista/cb-log"
call "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/call-log"
idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces"
"github.com/sirupsen/logrus"
"math/rand"
"strconv"
"sync"
"time"
)
const (
CBDefaultVmUserName string = "cb-user"
CBCloudInitFilePath string = "/cloud-driver-libs/.cloud-init-ibm/cloud-init"
)
var once sync.Once
var cblogger *logrus.Logger
var calllogger *logrus.Logger
func InitLog() {
once.Do(func() {
// cblog is a global variable.
cblogger = cblog.GetLogger("CB-SPIDER")
calllogger = call.GetLogger("HISCALL")
})
}
func LoggingError(hiscallInfo call.CLOUDLOGSCHEMA, err error) {
hiscallInfo.ErrorMSG = err.Error()
calllogger.Info(call.String(hiscallInfo))
}
func LoggingInfo(hiscallInfo call.CLOUDLOGSCHEMA, start time.Time) {
hiscallInfo.ElapsedTime = call.Elapsed(start)
calllogger.Info(call.String(hiscallInfo))
}
func GetCallLogScheme(region idrv.RegionInfo, resourceType call.RES_TYPE, resourceName string, apiName string) call.CLOUDLOGSCHEMA {
cblogger.Info(fmt.Sprintf("Call %s %s", call.IBM, apiName))
return call.CLOUDLOGSCHEMA{
CloudOS: call.IBM,
RegionZone: region.Region,
ResourceType: resourceType,
ResourceName: resourceName,
CloudOSAPI: apiName,
}
}
func generateRandName(prefix string) string {
rand.Seed(time.Now().UnixNano())
return fmt.Sprintf("%s-%s", prefix, strconv.FormatInt(rand.Int63n(1000000), 10))
}