本文整理匯總了Golang中hyper/lib/glog.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CreateVolume
func CreateVolume(poolName, volName, dev_id string, size int, restore bool) error {
glog.Infof("/dev/mapper/%s", volName)
if _, err := os.Stat("/dev/mapper/" + volName); err == nil {
return nil
}
if restore == false {
parms := fmt.Sprintf("dmsetup message /dev/mapper/%s 0 \"create_thin %s\"", poolName, dev_id)
if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil {
glog.Error(string(res))
return fmt.Errorf(string(res))
}
}
parms := fmt.Sprintf("dmsetup create %s --table \"0 %d thin /dev/mapper/%s %s\"", volName, size/512, poolName, dev_id)
if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil {
glog.Error(string(res))
return fmt.Errorf(string(res))
}
if restore == false {
parms = fmt.Sprintf("mkfs.ext4 \"/dev/mapper/%s\"", volName)
if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil {
glog.Error(string(res))
return fmt.Errorf(string(res))
}
}
return nil
}
示例2: waitConsoleOutput
func waitConsoleOutput(ctx *VmContext) {
conn, err := unixSocketConnect(ctx.consoleSockName)
if err != nil {
glog.Error("failed to connected to ", ctx.consoleSockName, " ", err.Error())
return
}
glog.V(1).Info("connected to ", ctx.consoleSockName)
tc, err := telnet.NewConn(conn)
if err != nil {
glog.Error("fail to init telnet connection to ", ctx.consoleSockName, ": ", err.Error())
return
}
glog.V(1).Infof("connected %s as telnet mode.", ctx.consoleSockName)
cout := make(chan string, 128)
go ttyLiner(tc, cout)
for {
line, ok := <-cout
if ok {
glog.V(1).Info("[console] ", line)
} else {
glog.Info("console output end")
break
}
}
}
示例3: waitInitReady
func waitInitReady(ctx *VmContext) {
conn, err := UnixSocketConnect(ctx.HyperSockName)
if err != nil {
glog.Error("Cannot connect to hyper socket ", err.Error())
ctx.Hub <- &InitFailedEvent{
Reason: "Cannot connect to hyper socket " + err.Error(),
}
return
}
glog.Info("Wating for init messages...")
msg, err := readVmMessage(conn.(*net.UnixConn))
if err != nil {
glog.Error("read init message failed... ", err.Error())
ctx.Hub <- &InitFailedEvent{
Reason: "read init message failed... " + err.Error(),
}
conn.Close()
} else if msg.code == INIT_READY {
glog.Info("Get init ready message")
ctx.Hub <- &InitConnectedEvent{conn: conn.(*net.UnixConn)}
go waitCmdToInit(ctx, conn.(*net.UnixConn))
} else {
glog.Warningf("Get init message %d", msg.code)
ctx.Hub <- &InitFailedEvent{
Reason: fmt.Sprintf("Get init message %d", msg.code),
}
conn.Close()
}
}
示例4: InitNetwork
func InitNetwork(bIface, bIP string) error {
if bIface == "" {
BridgeIface = defaultBridgeIface
} else {
BridgeIface = bIface
}
if bIP == "" {
BridgeIP = defaultBridgeIP
} else {
BridgeIP = bIP
}
addr, err := GetIfaceAddr(BridgeIface)
if err != nil {
glog.V(1).Infof("create bridge %s, ip %s", BridgeIface, BridgeIP)
// No Bridge existent, create one
// If the iface is not found, try to create it
if err := configureBridge(BridgeIP, BridgeIface); err != nil {
glog.Error("create bridge failed")
return err
}
addr, err = GetIfaceAddr(BridgeIface)
if err != nil {
glog.Error("get iface addr failed\n")
return err
}
bridgeIPv4Net = addr.(*net.IPNet)
} else {
glog.V(1).Info("bridge exist\n")
// Validate that the bridge ip matches the ip specified by BridgeIP
bridgeIPv4Net = addr.(*net.IPNet)
if BridgeIP != "" {
bip, _, err := net.ParseCIDR(BridgeIP)
if err != nil {
return err
}
if !bridgeIPv4Net.Contains(bip) {
return fmt.Errorf("Bridge ip (%s) does not match existing bridge configuration %s", addr, bip)
}
}
}
err = setupIPTables(addr)
if err != nil {
return err
}
ipAllocator.RequestIP(bridgeIPv4Net, bridgeIPv4Net.IP)
return nil
}
示例5: launchQemu
// launchQemu run qemu and wait it's quit, includes
func launchQemu(ctx *VmContext) {
qemu, err := exec.LookPath("qemu-system-x86_64")
if err != nil {
ctx.hub <- &QemuExitEvent{message: "can not find qemu executable"}
return
}
args := ctx.QemuArguments()
if glog.V(1) {
glog.Info("cmdline arguments: ", strings.Join(args, " "))
}
go waitConsoleOutput(ctx)
pipe := make([]int, 2)
err = syscall.Pipe(pipe)
if err != nil {
glog.Error("fail to create pipe")
ctx.hub <- &QemuExitEvent{message: "fail to create pipe"}
return
}
err = daemon(qemu, append([]string{"qemu-system-x86_64"}, args...), pipe[1])
if err != nil {
//fail to daemonize
glog.Error("try to start qemu failed")
ctx.hub <- &QemuExitEvent{message: "try to start qemu failed"}
return
}
buf := make([]byte, 4)
nr, err := syscall.Read(pipe[0], buf)
if err != nil || nr != 4 {
glog.Error("try to start qemu failed")
ctx.hub <- &QemuExitEvent{message: "try to start qemu failed"}
return
}
syscall.Close(pipe[1])
syscall.Close(pipe[0])
pid := binary.BigEndian.Uint32(buf[:nr])
glog.V(1).Infof("starting daemon with pid: %d", pid)
err = ctx.watchPid(int(pid))
if err != nil {
glog.Error("watch qemu process failed")
ctx.hub <- &QemuExitEvent{message: "watch qemu process failed"}
return
}
}
示例6: launchQemu
// launchQemu run qemu and wait it's quit, includes
func launchQemu(qc *QemuContext, ctx *hypervisor.VmContext) {
qemu := qc.driver.executable
if qemu == "" {
ctx.Hub <- &hypervisor.VmStartFailEvent{Message: "can not find qemu executable"}
return
}
args := qc.arguments(ctx)
if glog.V(1) {
glog.Info("cmdline arguments: ", strings.Join(args, " "))
}
pipe := make([]int, 2)
err := syscall.Pipe(pipe)
if err != nil {
glog.Error("fail to create pipe")
ctx.Hub <- &hypervisor.VmStartFailEvent{Message: "fail to create pipe"}
return
}
err = daemon(qemu, append([]string{"qemu-system-x86_64"}, args...), pipe[1])
if err != nil {
//fail to daemonize
glog.Error("try to start qemu failed")
ctx.Hub <- &hypervisor.VmStartFailEvent{Message: "try to start qemu failed"}
return
}
buf := make([]byte, 4)
nr, err := syscall.Read(pipe[0], buf)
if err != nil || nr != 4 {
glog.Error("try to start qemu failed")
ctx.Hub <- &hypervisor.VmStartFailEvent{Message: "try to start qemu failed"}
return
}
syscall.Close(pipe[1])
syscall.Close(pipe[0])
pid := binary.BigEndian.Uint32(buf[:nr])
glog.V(1).Infof("starting daemon with pid: %d", pid)
err = ctx.DCtx.(*QemuContext).watchPid(int(pid), ctx.Hub)
if err != nil {
glog.Error("watch qemu process failed")
ctx.Hub <- &hypervisor.VmStartFailEvent{Message: "watch qemu process failed"}
return
}
}
示例7: CreateNewDevice
func CreateNewDevice(containerId, devPrefix, rootPath string) error {
var metadataPath = fmt.Sprintf("%s/metadata/", rootPath)
// Get device id from the metadata file
idMetadataFile := path.Join(metadataPath, containerId)
if _, err := os.Stat(idMetadataFile); err != nil && os.IsNotExist(err) {
return err
}
jsonData, err := ioutil.ReadFile(idMetadataFile)
if err != nil {
return err
}
var dat jsonMetadata
if err := json.Unmarshal(jsonData, &dat); err != nil {
return err
}
deviceId := dat.Device_id
deviceSize := dat.Size
// Activate the device for that device ID
devName := fmt.Sprintf("%s-%s", devPrefix, containerId)
poolName := fmt.Sprintf("/dev/mapper/%s-pool", devPrefix)
createDeviceCmd := fmt.Sprintf("dmsetup create %s --table \"0 %d thin %s %d\"", devName, deviceSize/512, poolName, deviceId)
createDeviceCommand := exec.Command("/bin/sh", "-c", createDeviceCmd)
output, err := createDeviceCommand.Output()
if err != nil {
glog.Error(output)
return err
}
return nil
}
示例8: DeleteVolumeId
func (daemon *Daemon) DeleteVolumeId(podId string) error {
key := fmt.Sprintf("vol-%s", podId)
iter := (daemon.db).NewIterator(util.BytesPrefix([]byte(key)), nil)
for iter.Next() {
value := iter.Key()
if string(value)[4:18] == podId {
fields := strings.Split(string(iter.Value()), ":")
dev_id, _ := strconv.Atoi(fields[1])
if err := dm.DeleteVolume(daemon.Storage.DmPoolData, dev_id); err != nil {
glog.Error(err.Error())
return err
}
}
err := (daemon.db).Delete(value, nil)
if err != nil {
return err
}
}
iter.Release()
err := iter.Error()
if err != nil {
return err
}
return nil
}
示例9: initContext
func initContext(id string, hub chan QemuEvent, client chan *types.QemuResponse, boot *BootConfig) (*VmContext, error) {
var err error = nil
qmpChannel := make(chan QmpInteraction, 128)
vmChannel := make(chan *DecodedMessage, 128)
defer func() {
if err != nil {
close(qmpChannel)
close(vmChannel)
}
}()
//dir and sockets:
homeDir := BaseDir + "/" + id + "/"
qmpSockName := homeDir + QmpSockName
hyperSockName := homeDir + HyperSockName
ttySockName := homeDir + TtySockName
consoleSockName := homeDir + ConsoleSockName
shareDir := homeDir + ShareDirTag
err = os.MkdirAll(shareDir, 0755)
if err != nil {
glog.Error("cannot make dir", shareDir, err.Error())
return nil, err
}
defer func() {
if err != nil {
os.RemoveAll(homeDir)
}
}()
return &VmContext{
Id: id,
Boot: boot,
pciAddr: PciAddrFrom,
scsiId: 0,
attachId: 1,
hub: hub,
client: client,
qmp: qmpChannel,
vm: vmChannel,
wdt: make(chan string, 16),
ptys: newPts(),
ttySessions: make(map[string]uint64),
qmpSockName: qmpSockName,
hyperSockName: hyperSockName,
ttySockName: ttySockName,
consoleSockName: consoleSockName,
shareDir: shareDir,
timer: nil,
process: nil,
handler: stateInit,
userSpec: nil,
vmSpec: nil,
devices: newDeviceMap(),
progress: newProcessingList(),
lock: &sync.Mutex{},
}, nil
}
示例10: initFailureHandler
func initFailureHandler(ctx *VmContext, ev QemuEvent) bool {
processed := true
switch ev.Event() {
case ERROR_INIT_FAIL: // Qemu connection Failure
reason := ev.(*InitFailedEvent).reason
glog.Error(reason)
case ERROR_QMP_FAIL: // Device allocate and insert Failure
reason := "QMP protocol exception"
if ev.(*DeviceFailed).session != nil {
reason = "QMP protocol exception: failed while waiting " + EventString(ev.(*DeviceFailed).session.Event())
}
glog.Error(reason)
default:
processed = false
}
return processed
}
示例11: poweroffVM
func (ctx *VmContext) poweroffVM(err bool, msg string) {
if err {
ctx.reportVmFault(msg)
glog.Error("Shutting down because of an exception: ", msg)
}
qmpQemuQuit(ctx)
ctx.timedKill(10)
}
示例12: shutdownVM
func (ctx *VmContext) shutdownVM(err bool, msg string) {
if err {
ctx.reportVmFault(msg)
glog.Error("Shutting down because of an exception: ", msg)
}
ctx.setTimeout(10)
ctx.vm <- &DecodedMessage{code: INIT_DESTROYPOD, message: []byte{}}
}
示例13: DeleteVolume
func DeleteVolume(dm *DeviceMapper, dev_id int) error {
var parms string
// Delete the thin pool for test
parms = fmt.Sprintf("dmsetup message /dev/mapper/%s 0 \"delete %d\"", dm.PoolName, dev_id)
if res, err := exec.Command("/bin/sh", "-c", parms).CombinedOutput(); err != nil {
glog.Error(string(res))
return fmt.Errorf(string(res))
}
return nil
}
示例14: InitContext
func InitContext(dr HypervisorDriver, id string, hub chan VmEvent, client chan *types.QemuResponse, dc DriverContext, boot *BootConfig) (*VmContext, error) {
var err error = nil
vmChannel := make(chan *DecodedMessage, 128)
//dir and sockets:
homeDir := BaseDir + "/" + id + "/"
hyperSockName := homeDir + HyperSockName
ttySockName := homeDir + TtySockName
consoleSockName := homeDir + ConsoleSockName
shareDir := homeDir + ShareDirTag
if dc == nil {
dc = dr.InitContext(homeDir)
}
err = os.MkdirAll(shareDir, 0755)
if err != nil {
glog.Error("cannot make dir", shareDir, err.Error())
return nil, err
}
defer func() {
if err != nil {
os.Remove(homeDir)
}
}()
return &VmContext{
Id: id,
Boot: boot,
pciAddr: PciAddrFrom,
scsiId: 0,
attachId: 1,
Hub: hub,
client: client,
DCtx: dc,
vm: vmChannel,
ptys: newPts(),
ttySessions: make(map[string]uint64),
HomeDir: homeDir,
HyperSockName: hyperSockName,
TtySockName: ttySockName,
ConsoleSockName: consoleSockName,
ShareDir: shareDir,
timer: nil,
handler: stateInit,
userSpec: nil,
vmSpec: nil,
devices: newDeviceMap(),
progress: newProcessingList(),
lock: &sync.Mutex{},
wait: false,
}, nil
}
示例15: RestartPod
// The caller must make sure that the restart policy and the status is right to restart
func (daemon *Daemon) RestartPod(mypod *Pod) error {
// Remove the pod
// The pod is stopped, the vm is gone
for _, c := range mypod.Containers {
glog.V(1).Infof("Ready to rm container: %s", c.Id)
if _, _, err := daemon.dockerCli.SendCmdDelete(c.Id); err != nil {
glog.V(1).Infof("Error to rm container: %s", err.Error())
}
}
daemon.RemovePod(mypod.Id)
daemon.DeletePodContainerFromDB(mypod.Id)
daemon.DeleteVolumeId(mypod.Id)
podData, err := daemon.GetPodByName(mypod.Id)
vmId := fmt.Sprintf("vm-%s", pod.RandStr(10, "alpha"))
// Start the pod
_, _, err = daemon.StartPod(mypod.Id, vmId, string(podData))
if err != nil {
daemon.KillVm(vmId)
glog.Error(err.Error())
return err
}
if err := daemon.WritePodAndContainers(mypod.Id); err != nil {
glog.Error("Found an error while saving the Containers info")
return err
}
userPod, err := pod.ProcessPodBytes(podData)
if err != nil {
return err
}
vm := &Vm{
Id: vmId,
Pod: daemon.podList[mypod.Id],
Status: types.S_VM_ASSOCIATED,
Cpu: userPod.Resource.Vcpu,
Mem: userPod.Resource.Memory,
}
daemon.podList[mypod.Id].Vm = vmId
daemon.AddVm(vm)
return nil
}