本文整理匯總了Golang中hyper/lib/glog.Errorf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Errorf函數的具體用法?Golang Errorf怎麽用?Golang Errorf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Errorf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: useDirperm
// useDirperm checks dirperm1 mount option can be used with the current
// version of aufs.
func useDirperm() bool {
enableDirpermLock.Do(func() {
base, err := ioutil.TempDir("", "docker-aufs-base")
if err != nil {
glog.Errorf("error checking dirperm1: %s", err.Error())
return
}
defer os.RemoveAll(base)
union, err := ioutil.TempDir("", "docker-aufs-union")
if err != nil {
glog.Errorf("error checking dirperm1: %s", err.Error())
return
}
defer os.RemoveAll(union)
opts := fmt.Sprintf("br:%s,dirperm1,xino=/dev/shm/aufs.xino", base)
if err := syscall.Mount("none", union, "aufs", 0, opts); err != nil {
return
}
enableDirperm = true
if err := aufsUnmount(union); err != nil {
glog.Errorf("error checking dirperm1: failed to unmount %s", err.Error())
}
})
return enableDirperm
}
示例2: Run
// Run executes the job and blocks until the job completes.
// If the job fails it returns an error
func (job *Job) Run() (err error) {
defer func() {
// Wait for all background tasks to complete
if job.closeIO {
if err := job.Stdout.Close(); err != nil {
glog.Errorf("%s\n", err)
}
if err := job.Stderr.Close(); err != nil {
glog.Errorf("%s\n", err)
}
if err := job.Stdin.Close(); err != nil {
glog.Errorf("%s\n", err)
}
}
}()
if job.Eng.IsShutdown() && !job.GetenvBool("overrideShutdown") {
return fmt.Errorf("engine is shutdown")
}
// FIXME: this is a temporary workaround to avoid Engine.Shutdown
// waiting 5 seconds for server/api.ServeApi to complete (which it never will)
// everytime the daemon is cleanly restarted.
// The permanent fix is to implement Job.Stop and Job.OnStop so that
// ServeApi can cooperate and terminate cleanly.
if job.Name != "serveapi" {
job.Eng.l.Lock()
job.Eng.tasks.Add(1)
job.Eng.l.Unlock()
defer job.Eng.tasks.Done()
}
// FIXME: make this thread-safe
// FIXME: implement wait
if !job.end.IsZero() {
return fmt.Errorf("%s: job has already completed", job.Name)
}
// Log beginning and end of the job
if job.Eng.Logging {
glog.V(0).Infof("+job %s\n", job.CallString())
defer func() {
okerr := "OK"
if err != nil {
okerr = fmt.Sprintf("ERR: %s", err)
}
glog.V(0).Infof("-job %s %s\n", job.CallString(), okerr)
}()
}
if job.handler == nil {
return fmt.Errorf("%s: command not found\n", job.Name)
}
var errorMessage = bytes.NewBuffer(nil)
job.Stderr.Add(errorMessage)
err = job.handler(job)
job.end = time.Now()
return
}
示例3: configureBridge
// create and setup network bridge
func configureBridge(bridgeIP, bridgeIface string) error {
var ifaceAddr string
if len(bridgeIP) != 0 {
_, _, err := net.ParseCIDR(bridgeIP)
if err != nil {
glog.Errorf("%s parsecidr failed\n", bridgeIP)
return err
}
ifaceAddr = bridgeIP
}
if ifaceAddr == "" {
return fmt.Errorf("Could not find a free IP address range for interface '%s'. Please configure its address manually", bridgeIface, bridgeIface)
}
if err := CreateBridgeIface(bridgeIface); err != nil {
// The bridge may already exist, therefore we can ignore an "exists" error
if !os.IsExist(err) {
glog.Errorf("CreateBridgeIface failed %s %s\n", bridgeIface, ifaceAddr)
return err
}
}
iface, err := net.InterfaceByName(bridgeIface)
if err != nil {
return err
}
ipAddr, ipNet, err := net.ParseCIDR(ifaceAddr)
if err != nil {
return err
}
if ipAddr.Equal(ipNet.IP) {
ipAddr, err = ipAllocator.RequestIP(ipNet, nil)
} else {
ipAddr, err = ipAllocator.RequestIP(ipNet, ipAddr)
}
if err != nil {
return err
}
glog.V(3).Infof("Allocate IP Address %s for bridge %s\n", ipAddr, bridgeIface)
if err := NetworkLinkAddIp(iface, ipAddr, ipNet); err != nil {
return fmt.Errorf("Unable to add private network: %s", err)
}
if err := NetworkLinkUp(iface); err != nil {
return fmt.Errorf("Unable to start network bridge: %s", err)
}
return nil
}
示例4: makeHttpHandler
func makeHttpHandler(eng *engine.Engine, logging bool, localMethod string, localRoute string, handlerFunc HttpApiFunc, corsHeaders string, dockerVersion version.Version) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// log the request
glog.V(0).Infof("Calling %s %s\n", localMethod, localRoute)
if logging {
glog.V(1).Infof("%s %s\n", r.Method, r.RequestURI)
}
if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") {
userAgent := strings.Split(r.Header.Get("User-Agent"), "/")
if len(userAgent) == 2 && !dockerVersion.Equal(version.Version(userAgent[1])) {
glog.Warningf("client and server don't have the same version (client: %s, server: %s)", userAgent[1], dockerVersion)
}
}
version := version.Version(mux.Vars(r)["version"])
if version == "" {
version = utils.APIVERSION
}
if corsHeaders != "" {
writeCorsHeaders(w, r, corsHeaders)
}
if version.GreaterThan(utils.APIVERSION) {
http.Error(w, fmt.Errorf("client and server don't have same version (client API version: %s, server API version: %s)", version, utils.APIVERSION).Error(), http.StatusNotFound)
return
}
if err := handlerFunc(eng, version, w, r, mux.Vars(r)); err != nil {
glog.Errorf("Handler for %s %s returned error: %s", localMethod, localRoute, err)
httpError(w, err)
}
}
}
示例5: httpError
func httpError(w http.ResponseWriter, err error) {
statusCode := http.StatusInternalServerError
// FIXME: this is brittle and should not be necessary.
// If we need to differentiate between different possible error types, we should
// create appropriate error types with clearly defined meaning.
errStr := strings.ToLower(err.Error())
if strings.Contains(errStr, "no such") {
statusCode = http.StatusNotFound
} else if strings.Contains(errStr, "bad parameter") {
statusCode = http.StatusBadRequest
} else if strings.Contains(errStr, "conflict") {
statusCode = http.StatusConflict
} else if strings.Contains(errStr, "impossible") {
statusCode = http.StatusNotAcceptable
} else if strings.Contains(errStr, "wrong login/password") {
statusCode = http.StatusUnauthorized
} else if strings.Contains(errStr, "hasn't been activated") {
statusCode = http.StatusForbidden
}
if err != nil {
glog.Errorf("HTTP Error: statusCode=%d %v", statusCode, err)
http.Error(w, err.Error(), statusCode)
}
}
示例6: Release
// Release an interface for a select ip
func Release(releasedIP string, maps []pod.UserContainerPort, file *os.File) error {
file.Close()
if err := ipAllocator.ReleaseIP(bridgeIPv4Net, net.ParseIP(releasedIP)); err != nil {
return err
}
if err := ReleasePortMaps(releasedIP, maps); err != nil {
glog.Errorf("fail to release port map %s", err)
return err
}
return nil
}
示例7: RemoveNic
func (xc *XenContext) RemoveNic(ctx *hypervisor.VmContext, device, mac string, callback hypervisor.VmEvent) {
go func() {
res := HyperxlNicRemove(xc.driver.Ctx, (uint32)(xc.domId), mac)
if res == 0 {
glog.V(1).Infof("nic %s remove succeeded", device)
ctx.Hub <- callback
return
}
glog.Errorf("nic %s remove failed", device)
ctx.Hub <- &hypervisor.DeviceFailed{
Session: callback,
}
}()
}
示例8: GenRandomMac
func GenRandomMac() (string, error) {
const alphanum = "0123456789abcdef"
var bytes = make([]byte, 8)
_, err := rand.Read(bytes)
if err != nil {
glog.Errorf("get random number faild")
return "", err
}
for i, b := range bytes {
bytes[i] = alphanum[b%byte(len(alphanum))]
}
tmp := []string{"52:54", string(bytes[0:2]), string(bytes[2:4]), string(bytes[4:6]), string(bytes[6:8])}
return strings.Join(tmp, ":"), nil
}
示例9: AddNic
func (xc *XenContext) AddNic(ctx *hypervisor.VmContext, host *hypervisor.HostNicInfo, guest *hypervisor.GuestNicInfo) {
go func() {
callback := &hypervisor.NetDevInsertedEvent{
Index: guest.Index,
DeviceName: guest.Device,
Address: guest.Busaddr,
}
glog.V(1).Infof("allocate nic %s for dom %d", host.Mac, xc.domId)
hw, err := net.ParseMAC(host.Mac)
if err == nil {
//dev := fmt.Sprintf("vif%d.%d", xc.domId, guest.Index)
dev := host.Device
glog.V(1).Infof("add network for %d - ip: %s, br: %s, gw: %s, dev: %s, hw: %s", xc.domId, guest.Ipaddr,
host.Bridge, host.Bridge, dev, hw.String())
res := HyperxlNicAdd(xc.driver.Ctx, (uint32)(xc.domId), guest.Ipaddr, host.Bridge, host.Bridge, dev, []byte(hw))
if res == 0 {
glog.V(1).Infof("nic %s insert succeeded", guest.Device)
err = network.UpAndAddToBridge(fmt.Sprintf("vif%d.%d", xc.domId, guest.Index))
if err != nil {
glog.Error("fail to add vif to bridge: ", err.Error())
ctx.Hub <- &hypervisor.DeviceFailed{
Session: callback,
}
HyperxlNicRemove(xc.driver.Ctx, (uint32)(xc.domId), host.Mac)
return
}
ctx.Hub <- callback
return
}
glog.V(1).Infof("nic %s insert succeeded [faked] ", guest.Device)
ctx.Hub <- callback
return
}
glog.Errorf("nic %s insert failed", guest.Device)
ctx.Hub <- &hypervisor.DeviceFailed{
Session: callback,
}
}()
}
示例10: ServeApi
// ServeApi loops through all of the protocols sent in to docker and spawns
// off a go routine to setup a serving http.Server for each.
func ServeApi(job *engine.Job) error {
if len(job.Args) == 0 {
return fmt.Errorf("usage: %s PROTO://ADDR [PROTO://ADDR ...]", job.Name)
}
var (
protoAddrs = job.Args
chErrors = make(chan error, len(protoAddrs))
)
activationLock = make(chan struct{})
for _, protoAddr := range protoAddrs {
protoAddrParts := strings.SplitN(protoAddr, "://", 2)
if len(protoAddrParts) != 2 {
return fmt.Errorf("usage: %s PROTO://ADDR [PROTO://ADDR ...]", job.Name)
}
go func() {
glog.V(0).Infof("Listening for HTTP on %s (%s)", protoAddrParts[0], protoAddrParts[1])
srv, err := NewServer(protoAddrParts[0], protoAddrParts[1], job)
if err != nil {
chErrors <- err
return
}
job.Eng.OnShutdown(func() {
if err := srv.Close(); err != nil {
glog.Errorf("%s\n", err)
}
})
if err = srv.Serve(); err != nil && strings.Contains(err.Error(), "use of closed network connection") {
err = nil
}
chErrors <- err
}()
}
for i := 0; i < len(protoAddrs); i++ {
err := <-chErrors
if err != nil {
return err
}
}
return nil
}
示例11: ReleaseMap
func (p *PortMapper) ReleaseMap(protocol string, hostPort int) error {
p.mutex.Lock()
defer p.mutex.Unlock()
var pset PortSet
if strings.EqualFold(protocol, "udp") {
pset = p.udpMap
} else {
pset = p.tcpMap
}
_, ok := pset[hostPort]
if !ok {
glog.Errorf("Host port %d has not been used", hostPort)
}
delete(pset, hostPort)
return nil
}
示例12: diskRoutine
func diskRoutine(add bool, xc *XenContext, ctx *hypervisor.VmContext,
name, sourceType, filename, format string, id int, callback hypervisor.VmEvent) {
backend := LIBXL_DISK_BACKEND_TAP
if strings.HasPrefix(filename, "/dev/") {
backend = LIBXL_DISK_BACKEND_PHY
}
dfmt := LIBXL_DISK_FORMAT_RAW
if format == "qcow" || format == "qcow2" {
dfmt = LIBXL_DISK_FORMAT_QCOW2
}
devName := xvdId2Name(id)
var res int
var op string = "insert"
if add {
res = HyperxlDiskAdd(xc.driver.Ctx, uint32(xc.domId), filename, devName, LibxlDiskBackend(backend), LibxlDiskFormat(dfmt))
callback = &hypervisor.BlockdevInsertedEvent{
Name: name,
SourceType: sourceType,
DeviceName: devName,
ScsiId: id,
}
} else {
op = "remove"
res = HyperxlDiskRemove(xc.driver.Ctx, uint32(xc.domId), filename, devName, LibxlDiskBackend(backend), LibxlDiskFormat(dfmt))
}
if res == 0 {
glog.V(1).Infof("Disk %s (%s) %s succeeded", devName, filename, op)
ctx.Hub <- callback
return
}
glog.Errorf("Disk %s (%s) insert %s failed", devName, filename, op)
ctx.Hub <- &hypervisor.DeviceFailed{
Session: callback,
}
}
示例13: UpAndAddToBridge
func UpAndAddToBridge(name string) error {
inf, err := net.InterfaceByName(name)
if err != nil {
glog.Error("cannot find network interface ", name)
return err
}
brg, err := net.InterfaceByName(BridgeIface)
if err != nil {
glog.Error("cannot find bridge interface ", BridgeIface)
return err
}
err = AddToBridge(inf, brg)
if err != nil {
glog.Errorf("cannot add %s to %s ", name, BridgeIface)
return err
}
err = NetworkLinkUp(inf)
if err != nil {
glog.Error("cannot up interface ", name)
return err
}
return nil
}
示例14: AssociateAllVms
// This function will only be invoked during daemon start
func (daemon *Daemon) AssociateAllVms() error {
for _, mypod := range daemon.podList {
if mypod.Vm == "" {
continue
}
data, err := daemon.GetPodByName(mypod.Id)
if err != nil {
continue
}
userPod, err := pod.ProcessPodBytes(data)
if err != nil {
continue
}
glog.V(1).Infof("Associate the POD(%s) with VM(%s)", mypod.Id, mypod.Vm)
var (
qemuPodEvent = make(chan hypervisor.VmEvent, 128)
qemuStatus = make(chan *types.QemuResponse, 128)
subQemuStatus = make(chan *types.QemuResponse, 128)
)
data, err = daemon.GetVmData(mypod.Vm)
if err != nil {
continue
}
glog.V(1).Infof("The data for vm(%s) is %v", mypod.Vm, data)
go hypervisor.VmAssociate(hypervisorDriver, mypod.Vm, qemuPodEvent,
qemuStatus, mypod.Wg, data)
ass := <-qemuStatus
if ass.Code != types.E_OK {
glog.Errorf("cannot associate with vm: %s, error status %d (%s)", mypod.Vm, ass.Code, ass.Cause)
return errors.New("load vm status failed")
}
if err := daemon.SetQemuChan(mypod.Vm, qemuPodEvent, qemuStatus, subQemuStatus); err != nil {
glog.V(1).Infof("SetQemuChan error: %s", err.Error())
return err
}
vm := &Vm{
Id: mypod.Vm,
Pod: mypod,
Status: types.S_VM_ASSOCIATED,
Cpu: userPod.Resource.Vcpu,
Mem: userPod.Resource.Memory,
}
daemon.AddVm(vm)
daemon.SetContainerStatus(mypod.Id, types.S_POD_RUNNING)
mypod.Status = types.S_POD_RUNNING
go func(interface{}) {
for {
podId := mypod.Id
qemuResponse := <-qemuStatus
subQemuStatus <- qemuResponse
if qemuResponse.Code == types.E_POD_FINISHED {
data := qemuResponse.Data.([]uint32)
daemon.SetPodContainerStatus(podId, data)
} else if qemuResponse.Code == types.E_VM_SHUTDOWN {
if daemon.podList[mypod.Id].Status == types.S_POD_RUNNING {
daemon.podList[mypod.Id].Status = types.S_POD_SUCCEEDED
daemon.SetContainerStatus(podId, types.S_POD_SUCCEEDED)
}
daemon.podList[mypod.Id].Vm = ""
daemon.RemoveVm(mypod.Vm)
daemon.DeleteQemuChan(mypod.Vm)
if mypod.Type == "kubernetes" {
switch mypod.Status {
case types.S_POD_SUCCEEDED:
if mypod.RestartPolicy == "always" {
daemon.RestartPod(mypod)
} else {
daemon.DeletePodFromDB(podId)
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(podId)
daemon.DeletePodContainerFromDB(podId)
daemon.DeleteVolumeId(podId)
}
break
case types.S_POD_FAILED:
if mypod.RestartPolicy != "never" {
daemon.RestartPod(mypod)
} else {
daemon.DeletePodFromDB(podId)
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(podId)
daemon.DeletePodContainerFromDB(podId)
daemon.DeleteVolumeId(podId)
}
break
default:
break
}
}
//.........這裏部分代碼省略.........
示例15: StartPod
func (daemon *Daemon) StartPod(podId, vmId, podArgs string) (int, string, error) {
var (
fstype string
poolName string
volPoolName string
devPrefix string
storageDriver string
rootPath string
devFullName string
rootfs string
containerInfoList = []*hypervisor.ContainerInfo{}
volumuInfoList = []*hypervisor.VolumeInfo{}
cli = daemon.dockerCli
qemuPodEvent = make(chan hypervisor.VmEvent, 128)
qemuStatus = make(chan *types.QemuResponse, 128)
subQemuStatus = make(chan *types.QemuResponse, 128)
sharedDir = path.Join(hypervisor.BaseDir, vmId, hypervisor.ShareDirTag)
podData []byte
mypod *Pod
wg *sync.WaitGroup
err error
uid string
gid string
)
if podArgs == "" {
mypod = daemon.podList[podId]
if mypod == nil {
return -1, "", fmt.Errorf("Can not find the POD instance of %s", podId)
}
podData, err = daemon.GetPodByName(podId)
if err != nil {
return -1, "", err
}
wg = mypod.Wg
} else {
podData = []byte(podArgs)
}
userPod, err := pod.ProcessPodBytes(podData)
if err != nil {
return -1, "", err
}
vm := daemon.vmList[vmId]
if vm == nil {
glog.V(1).Infof("The config: kernel=%s, initrd=%s", daemon.kernel, daemon.initrd)
var (
cpu = 1
mem = 128
)
if userPod.Resource.Vcpu > 0 {
cpu = userPod.Resource.Vcpu
}
if userPod.Resource.Memory > 0 {
mem = userPod.Resource.Memory
}
b := &hypervisor.BootConfig{
CPU: cpu,
Memory: mem,
Kernel: daemon.kernel,
Initrd: daemon.initrd,
Bios: daemon.bios,
Cbfs: daemon.cbfs,
}
go hypervisor.VmLoop(hypervisorDriver, vmId, qemuPodEvent, qemuStatus, b)
if err := daemon.SetQemuChan(vmId, qemuPodEvent, qemuStatus, subQemuStatus); err != nil {
glog.V(1).Infof("SetQemuChan error: %s", err.Error())
return -1, "", err
}
} else {
ret1, ret2, ret3, err := daemon.GetQemuChan(vmId)
if err != nil {
return -1, "", err
}
qemuPodEvent = ret1.(chan hypervisor.VmEvent)
qemuStatus = ret2.(chan *types.QemuResponse)
subQemuStatus = ret3.(chan *types.QemuResponse)
}
if podArgs != "" {
wg = new(sync.WaitGroup)
if err := daemon.CreatePod(podArgs, podId, wg); err != nil {
glog.Error(err.Error())
return -1, "", err
}
mypod = daemon.podList[podId]
}
storageDriver = daemon.Storage.StorageType
if storageDriver == "devicemapper" {
poolName = daemon.Storage.PoolName
fstype = daemon.Storage.Fstype
volPoolName = "hyper-volume-pool"
devPrefix = poolName[:strings.Index(poolName, "-pool")]
rootPath = "/var/lib/docker/devicemapper"
rootfs = "/rootfs"
} else if storageDriver == "aufs" {
rootPath = daemon.Storage.RootPath
fstype = daemon.Storage.Fstype
rootfs = ""
} else if storageDriver == "overlay" {
//.........這裏部分代碼省略.........