本文整理汇总了Golang中Logger.Logger.Debugf方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Debugf方法的具体用法?Golang Logger.Debugf怎么用?Golang Logger.Debugf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Logger.Logger
的用法示例。
在下文中一共展示了Logger.Debugf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunGetVmHostPoolInfo
//get vm pool info
func RunGetVmHostPoolInfo(repo model.Repo, logger logger.Logger, conf *config.Config, deviceId uint) (string, error) {
device, err := repo.GetDeviceById(deviceId)
if err != nil {
return "", err
}
storage := conf.Vm.Storage
if storage == "" {
storage = "guest_images_lvm"
}
var cmdFormat = `LANG=C virsh --connect qemu+ssh://[email protected]%s/system pool-info %s`
var cmd = fmt.Sprintf(cmdFormat,
device.Ip,
storage)
logger.Debugf("get vm host pool info:%s", cmd)
var runResult = "执行脚本:\n" + cmd
bytes, err := util.ExecScript(cmd)
logger.Debugf("result:%s", string(bytes))
runResult += "\n\n" + "执行结果:\n" + string(bytes)
if err != nil {
logger.Errorf("error:%s", err.Error())
runResult += "\n\n" + "错误信息:\n" + err.Error()
return "", errors.New(runResult)
}
return string(bytes), nil
}
示例2: RunGetVmInfo
//get vm info
func RunGetVmInfo(repo model.Repo, logger logger.Logger, vmDeviceId uint) (string, error) {
vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
if err != nil {
return "", err
}
device, err := repo.GetDeviceById(vmDevice.DeviceID)
if err != nil {
return "", err
}
var cmdFormat = `LANG=C virsh --connect qemu+ssh://[email protected]%s/system dominfo %s`
var cmd = fmt.Sprintf(cmdFormat,
device.Ip,
vmDevice.Hostname)
logger.Debugf("get vm info:%s", cmd)
var runResult = "执行脚本:\n" + cmd
bytes, err := util.ExecScript(cmd)
logger.Debugf("result:%s", string(bytes))
runResult += "\n\n" + "执行结果:\n" + string(bytes)
if err != nil {
logger.Errorf("error:%s", err.Error())
runResult += "\n\n" + "错误信息:\n" + err.Error()
return "", errors.New(runResult)
}
return string(bytes), nil
}
示例3: RunTestConnectVmHost
//test connect vm host
func RunTestConnectVmHost(repo model.Repo, logger logger.Logger, deviceId uint) (string, error) {
device, err := repo.GetDeviceById(deviceId)
if err != nil {
return "", err
}
var cmdFormat = `LANG=C ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=3 [email protected]%s 'w'`
var cmd = fmt.Sprintf(cmdFormat,
device.Ip)
logger.Debugf("test connect vm host:%s", cmd)
var runResult = "执行脚本:\n" + cmd
bytes, err := util.ExecScript(cmd)
logger.Debugf("result:%s", string(bytes))
runResult += "\n\n" + "执行结果:\n" + string(bytes)
if err != nil {
logger.Errorf("error:%s", err.Error())
runResult += "\n\n" + "错误信息:\n" + err.Error()
return "", errors.New(runResult)
}
return string(bytes), nil
}
示例4: GetCidrInfo
func GetCidrInfo(network string, logger logger.Logger) (map[string]string, error) {
network = strings.TrimSpace(network)
result := make(map[string]string)
list := strings.Split(network, "/")
if len(list) != 2 {
return result, errors.New("网段格式不正确")
}
isValidate, err := regexp.MatchString("^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$", list[0])
if err != nil {
return result, err
}
if !isValidate {
return result, errors.New("IP格式不正确")
}
logger.Debugf("get network info:%s", network)
minIp, maxIp := GetCidrIpRange(network)
logger.Debugf("get ip range:%s~%s", minIp, maxIp)
result["MinIP"] = minIp
result["MaxIP"] = maxIp
mask, err := strconv.Atoi(list[1])
if err != nil {
return result, err
}
logger.Debugf("get mask:%d", mask)
if mask <= 0 || mask >= 32 {
logger.Error("掩码位不正确!")
return result, errors.New("掩码位不正确!")
}
result["Mask"] = GetCidrIpMask(mask)
result["IPNum"] = fmt.Sprintf("%d", GetCidrHostNum(mask))
logger.Debugf("ip nums:%s", result["IPNum"])
return result, nil
}
示例5: RunDeleteVmNoVncTokenFile
//delete noVNC token file
func RunDeleteVmNoVncTokenFile(repo model.Repo, logger logger.Logger, vmDeviceId uint) error {
vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
if err != nil {
return err
}
var dir = "/etc/cloudboot-server/novnc-tokens"
var file = vmDevice.Hostname
logger.Debugf("delete vm novnc token file:%s", dir+"/"+file)
if util.FileExist(dir + "/" + file) {
err := os.Remove(dir + "/" + file)
if err != nil {
logger.Errorf("error:%s", err.Error())
return err
}
}
return nil
}
示例6: RunCreateVmNoVncTokenFile
//create noVNC token file
func RunCreateVmNoVncTokenFile(repo model.Repo, logger logger.Logger, vmDeviceId uint) error {
vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
if err != nil {
return err
}
device, err := repo.GetDeviceById(vmDevice.DeviceID)
if err != nil {
return err
}
var newHostname = strings.Replace(vmDevice.Hostname, ":", "_", -1)
var strFormat = `%s: %s:%s`
var str = fmt.Sprintf(strFormat,
newHostname,
device.Ip,
vmDevice.VncPort)
var dir = "/etc/cloudboot-server/novnc-tokens"
var file = vmDevice.Hostname
if !util.FileExist(dir) {
err := os.MkdirAll(dir, 0777)
if err != nil {
return err
}
}
//文件已存在,先删除
if util.FileExist(dir + "/" + file) {
err := os.Remove(dir + "/" + file)
if err != nil {
return err
}
}
logger.Debugf("create vm novnc token file %s:%s", dir+"/"+file, str)
bytes := []byte(str)
errCreate := ioutil.WriteFile(dir+"/"+file, bytes, 0644)
if errCreate != nil {
logger.Errorf("error:%s", errCreate.Error())
return errCreate
}
return nil
}