本文整理汇总了Golang中github.com/lxc/lxd/shared.Debugf函数的典型用法代码示例。如果您正苦于以下问题:Golang Debugf函数的具体用法?Golang Debugf怎么用?Golang Debugf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debugf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: eventsSocket
func eventsSocket(r *http.Request, w http.ResponseWriter) error {
listener := eventListener{}
typeStr := r.FormValue("type")
if typeStr == "" {
typeStr = "logging,operation"
}
c, err := shared.WebsocketUpgrader.Upgrade(w, r, nil)
if err != nil {
return err
}
listener.active = make(chan bool, 1)
listener.connection = c
listener.id = uuid.NewRandom().String()
listener.messageTypes = strings.Split(typeStr, ",")
eventsLock.Lock()
eventListeners[listener.id] = &listener
eventsLock.Unlock()
shared.Debugf("New events listener: %s", listener.id)
<-listener.active
eventsLock.Lock()
delete(eventListeners, listener.id)
eventsLock.Unlock()
listener.connection.Close()
shared.Debugf("Disconnected events listener: %s", listener.id)
return nil
}
开发者ID:jameinel,项目名称:lxd,代码行数:35,代码来源:events.go
示例2: ConnStateHandler
func (m *ConnPidMapper) ConnStateHandler(conn net.Conn, state http.ConnState) {
unixConn := conn.(*net.UnixConn)
switch state {
case http.StateNew:
pid, err := getPid(unixConn)
if err != nil {
shared.Debugf("Error getting pid for conn %s", err)
} else {
m.m[unixConn] = pid
}
case http.StateActive:
return
case http.StateIdle:
return
case http.StateHijacked:
/*
* The "Hijacked" state indicates that the connection has been
* taken over from net/http. This is useful for things like
* developing websocket libraries, who want to upgrade the
* connection to a websocket one, and not use net/http any
* more. Whatever the case, we want to forget about it since we
* won't see it either.
*/
delete(m.m, unixConn)
case http.StateClosed:
delete(m.m, unixConn)
default:
shared.Debugf("Unknown state for connection %s", state)
}
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:30,代码来源:devlxd.go
示例3: verifyAdminPwd
func (d *Daemon) verifyAdminPwd(password string) bool {
value, err := dbPasswordGet(d.db)
if err != nil {
shared.Debugf("verifyAdminPwd: %s", err)
return false
}
buff, err := hex.DecodeString(value)
if err != nil {
shared.Debugf("hex decode failed")
return false
}
salt := buff[0:PW_SALT_BYTES]
hash, err := scrypt.Key([]byte(password), salt, 1<<14, 8, 1, PW_HASH_BYTES)
if err != nil {
shared.Debugf("failed to create hash to check")
return false
}
if !bytes.Equal(hash, buff[PW_SALT_BYTES:]) {
shared.Debugf("Bad password received")
return false
}
shared.Debugf("Verified the admin password")
return true
}
开发者ID:joker042,项目名称:lxd,代码行数:27,代码来源:certificates.go
示例4: untar
func untar(tarball string, path string) error {
extractArgs, _, err := detectCompression(tarball)
if err != nil {
return err
}
command := "tar"
args := []string{}
if !canMknod {
// if we are running in a userns where we cannot mknod,
// then run with a seccomp filter which turns mknod into a
// a noop. The container config had better know how to bind
// mount the devices in at container start.
args = append(args, "--exclude=dev/*")
}
args = append(args, "-C", path, "--numeric-owner")
args = append(args, extractArgs...)
args = append(args, tarball)
output, err := exec.Command(command, args...).CombinedOutput()
if err != nil {
shared.Debugf("Unpacking failed")
shared.Debugf(string(output))
return err
}
return nil
}
开发者ID:KorayAgaya,项目名称:lxd,代码行数:28,代码来源:images.go
示例5: Connect
func (op *operation) Connect(r *http.Request, w http.ResponseWriter) (chan error, error) {
if op.class != operationClassWebsocket {
return nil, fmt.Errorf("Only websocket operations can be connected")
}
if op.status != shared.Running {
return nil, fmt.Errorf("Only running operations can be connected")
}
chanConnect := make(chan error, 1)
op.lock.Lock()
go func(op *operation, chanConnect chan error) {
err := op.onConnect(op, r, w)
if err != nil {
chanConnect <- err
shared.Debugf("Failed to handle %s operation: %s: %s", op.class.String(), op.id, err)
return
}
chanConnect <- nil
shared.Debugf("Handled %s operation: %s", op.class.String(), op.id)
}(op, chanConnect)
op.lock.Unlock()
shared.Debugf("Connected %s operation: %s", op.class.String(), op.id)
return chanConnect, nil
}
开发者ID:ccsblueboy,项目名称:lxd,代码行数:32,代码来源:operations.go
示例6: main
func main() {
if err := run(); err != nil {
// The action we take depends on the error we get.
switch t := err.(type) {
case *url.Error:
shared.Debugf("url.Error caught in main(). Op: %s, URL: %s, Err: %s\n", t.Op, t.URL, t.Err)
switch u := t.Err.(type) {
case *net.OpError:
shared.Debugf("Inner error type is a net.OpError: Op: %s Net: %s Addr: %s Err: %T", u.Op, u.Net, u.Addr, u.Err)
if u.Op == "dial" && u.Net == "unix" {
// The unix socket we are trying to conect to is refusing our connection attempt. Perhaps the server is not running?
// Let's at least tell the user about it, since it's hard to get information on wether something is actually listening.
fmt.Fprintf(os.Stderr, fmt.Sprintf(gettext.Gettext("Cannot connect to unix socket at %s Is the server running?\n"), u.Addr))
os.Exit(1)
}
default:
shared.Debugf("url.Error's inner Err type is %T", u)
}
default:
shared.Debugf("Error caught in main: %T\n", t)
}
fmt.Fprintf(os.Stderr, gettext.Gettext("error: %v\n"), err)
os.Exit(1)
}
}
开发者ID:kostyll,项目名称:lxd,代码行数:26,代码来源:main.go
示例7: RsyncSend
// RsyncSend sets up the sending half of an rsync, to recursively send the
// directory pointed to by path over the websocket.
func RsyncSend(path string, conn *websocket.Conn) error {
cmd, dataSocket, stderr, err := rsyncSendSetup(path)
if dataSocket != nil {
defer dataSocket.Close()
}
if err != nil {
return err
}
readDone, writeDone := shared.WebsocketMirror(conn, dataSocket, dataSocket)
output, err := ioutil.ReadAll(stderr)
if err != nil {
shared.Debugf("problem reading rsync stderr %s", err)
}
if err := cmd.Wait(); err != nil {
shared.Debugf("problem with rsync send of %s: %s: %s", path, err, string(output))
}
<-readDone
<-writeDone
return err
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:27,代码来源:rsync.go
示例8: removeImgWorkdir
func removeImgWorkdir(d *Daemon, builddir string) {
vgname, _, err := getServerConfigValue(d, "core.lvm_vg_name")
if err != nil {
shared.Debugf("Error checking server config: %v", err)
}
matches, _ := filepath.Glob(fmt.Sprintf("%s/*.lv", builddir))
if len(matches) > 0 {
if len(matches) > 1 {
shared.Debugf("Unexpected - more than one .lv file in builddir. using first: %v", matches)
}
lvsymlink := matches[0]
if lvpath, err := os.Readlink(lvsymlink); err != nil {
shared.Debugf("Error reading target of symlink '%s'", lvsymlink)
} else {
err = shared.LVMRemoveLV(vgname, filepath.Base(lvpath))
if err != nil {
shared.Debugf("Error removing LV '%s': %v", lvpath, err)
}
}
}
if d.BackingFs == "btrfs" {
/* cannot rm -rf /a if /a/b is a subvolume, so first delete subvolumes */
/* todo: find the .btrfs file under dir */
fnamelist, _ := shared.ReadDir(builddir)
for _, fname := range fnamelist {
subvol := filepath.Join(builddir, fname)
btrfsDeleteSubvol(subvol)
}
}
if remErr := os.RemoveAll(builddir); remErr != nil {
shared.Debugf("Error deleting temporary directory: %s", remErr)
}
}
开发者ID:joker042,项目名称:lxd,代码行数:35,代码来源:images.go
示例9: untar
func untar(tarball string, path string) error {
extractArgs, _, err := detectCompression(tarball)
if err != nil {
return err
}
command := "tar"
args := []string{}
if runningInUserns {
args = append(args, "--wildcards")
args = append(args, "--exclude=dev/*")
args = append(args, "--exclude=./dev/*")
args = append(args, "--exclude=rootfs/dev/*")
args = append(args, "--exclude=rootfs/./dev/*")
}
args = append(args, "-C", path, "--numeric-owner")
args = append(args, extractArgs...)
args = append(args, tarball)
output, err := exec.Command(command, args...).CombinedOutput()
if err != nil {
shared.Debugf("Unpacking failed")
shared.Debugf(string(output))
return err
}
return nil
}
开发者ID:djibi2,项目名称:lxd,代码行数:28,代码来源:images.go
示例10: rsyncWebsocket
func rsyncWebsocket(cmd *exec.Cmd, conn *websocket.Conn) error {
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
shared.WebsocketMirror(conn, stdin, stdout)
data, err2 := ioutil.ReadAll(stderr)
if err2 != nil {
shared.Debugf("error reading rsync stderr: %s", err2)
return err2
}
shared.Debugf("Stderr from rsync: %s", data)
err = cmd.Wait()
if err != nil {
shared.Debugf("rsync recv error %s: %s", err, string(data))
}
return err
}
开发者ID:rockstar,项目名称:lxd,代码行数:35,代码来源:rsync.go
示例11: untarImage
func untarImage(imagefname string, destpath string) error {
compression, _, err := detectCompression(imagefname)
if err != nil {
return err
}
args := []string{"-C", destpath, "--numeric-owner"}
switch compression {
case COMPRESSION_TAR:
args = append(args, "-xf")
case COMPRESSION_GZIP:
args = append(args, "-zxf")
case COMPRESSION_BZ2:
args = append(args, "--jxf")
case COMPRESSION_LZMA:
args = append(args, "--lzma", "-xf")
default:
args = append(args, "-Jxf")
}
args = append(args, imagefname)
output, err := exec.Command("tar", args...).CombinedOutput()
if err != nil {
shared.Debugf("image unpacking failed\n")
shared.Debugf(string(output))
return err
}
return nil
}
开发者ID:Ramzec,项目名称:lxd,代码行数:30,代码来源:images.go
示例12: deviceTaskScheduler
func deviceTaskScheduler(d *Daemon) {
chHotplug, err := deviceMonitorProcessors()
if err != nil {
shared.Log.Error("scheduler: couldn't setup uevent watcher, no automatic re-balance")
return
}
shared.Debugf("Scheduler: doing initial balance")
deviceTaskBalance(d)
for {
select {
case e := <-chHotplug:
if len(e) != 2 {
shared.Log.Error("Scheduler: received an invalid hotplug event")
continue
}
shared.Debugf("Scheduler: %s is now %s: re-balancing", e[0], e[1])
deviceTaskBalance(d)
case e := <-deviceSchedRebalance:
if len(e) != 3 {
shared.Log.Error("Scheduler: received an invalid rebalance event")
continue
}
shared.Debugf("Scheduler: %s %s %s: re-balancing", e[0], e[1], e[2])
deviceTaskBalance(d)
}
}
}
开发者ID:czl349095941,项目名称:lxd,代码行数:29,代码来源:devices.go
示例13: verifyAdminPwd
func (d *Daemon) verifyAdminPwd(password string) bool {
q := "SELECT value FROM config WHERE key=\"core.trust_password\""
value := ""
argIn := []interface{}{}
argOut := []interface{}{&value}
err := dbQueryRowScan(d.db, q, argIn, argOut)
if err != nil || value == "" {
shared.Debugf("verifyAdminPwd: no password is set")
return false
}
buff, err := hex.DecodeString(value)
if err != nil {
shared.Debugf("hex decode failed")
return false
}
salt := buff[0:PW_SALT_BYTES]
hash, err := scrypt.Key([]byte(password), salt, 1<<14, 8, 1, PW_HASH_BYTES)
if err != nil {
shared.Debugf("failed to create hash to check")
return false
}
if !bytes.Equal(hash, buff[PW_SALT_BYTES:]) {
shared.Debugf("Bad password received")
return false
}
shared.Debugf("Verified the admin password")
return true
}
开发者ID:kostyll,项目名称:lxd,代码行数:31,代码来源:certificates.go
示例14: deviceEventListener
func deviceEventListener(d *Daemon) {
chNetlink, err := deviceNetlinkListener()
if err != nil {
shared.Log.Error("scheduler: couldn't setup netlink listener")
return
}
for {
select {
case e := <-chNetlink:
if len(e) != 3 {
shared.Log.Error("Scheduler: received an invalid hotplug event")
continue
}
if e[0] == "cpu" {
shared.Debugf("Scheduler: %s: %s is now %s: re-balancing", e[0], e[1], e[2])
deviceTaskBalance(d)
}
if e[0] == "net" && e[2] == "add" {
shared.Debugf("Scheduler: %s: %s has been added: updating network priorities", e[0], e[1])
deviceNetworkPriority(d, e[1])
}
case e := <-deviceSchedRebalance:
if len(e) != 3 {
shared.Log.Error("Scheduler: received an invalid rebalance event")
continue
}
shared.Debugf("Scheduler: %s %s %s: re-balancing", e[0], e[1], e[2])
deviceTaskBalance(d)
}
}
}
开发者ID:nehaljwani,项目名称:lxd,代码行数:34,代码来源:devices.go
示例15: pruneExpiredImages
func pruneExpiredImages(d *Daemon) {
shared.Debugf("Pruning expired images")
expiry, err := d.ConfigValueGet("images.remote_cache_expiry")
if err != nil {
shared.Log.Error("Unable to read the images.remote_cache_expiry key")
return
}
if expiry == "" {
expiry = "10"
}
expiryInt, err := strconv.Atoi(expiry)
if err != nil {
shared.Log.Error("Invalid value for images.remote_cache_expiry", log.Ctx{"err": err})
return
}
images, err := dbImagesGetExpired(d.db, expiryInt)
if err != nil {
shared.Log.Error("Unable to retrieve the list of expired images", log.Ctx{"err": err})
return
}
for _, fp := range images {
if err := doDeleteImage(d, fp); err != nil {
shared.Log.Error("Error deleting image", log.Ctx{"err": err, "fp": fp})
}
}
shared.Debugf("Done pruning expired images")
}
开发者ID:jameinel,项目名称:lxd,代码行数:31,代码来源:images.go
示例16: containersPost
func containersPost(d *Daemon, r *http.Request) Response {
shared.Debugf("Responding to container create")
req := containerPostReq{}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return BadRequest(err)
}
if req.Name == "" {
req.Name = strings.ToLower(petname.Generate(2, "-"))
shared.Debugf("No name provided, creating %s", req.Name)
}
if strings.Contains(req.Name, shared.SnapshotDelimiter) {
return BadRequest(fmt.Errorf("Invalid container name: '%s' is reserved for snapshots", shared.SnapshotDelimiter))
}
switch req.Source.Type {
case "image":
return createFromImage(d, &req)
case "none":
return createFromNone(d, &req)
case "migration":
return createFromMigration(d, &req)
case "copy":
return createFromCopy(d, &req)
default:
return BadRequest(fmt.Errorf("unknown source type %s", req.Source.Type))
}
}
开发者ID:destitutus,项目名称:lxd,代码行数:31,代码来源:containers_post.go
示例17: containersPost
func containersPost(d *Daemon, r *http.Request) Response {
shared.Debugf("responding to create")
if d.IdmapSet == nil {
return BadRequest(fmt.Errorf("shared's user has no subuids"))
}
req := containerPostReq{}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return BadRequest(err)
}
if req.Name == "" {
req.Name = strings.ToLower(petname.Generate(2, "-"))
shared.Debugf("no name provided, creating %s", req.Name)
}
switch req.Source.Type {
case "image":
return createFromImage(d, &req)
case "none":
return createFromNone(d, &req)
case "migration":
return createFromMigration(d, &req)
case "copy":
return createFromCopy(d, &req)
default:
return BadRequest(fmt.Errorf("unknown source type %s", req.Source.Type))
}
}
开发者ID:joker042,项目名称:lxd,代码行数:31,代码来源:containers_post.go
示例18: imageDelete
func imageDelete(d *Daemon, r *http.Request) Response {
fingerprint := mux.Vars(r)["fingerprint"]
imgInfo, err := dbImageGet(d.db, fingerprint, false)
if err != nil {
return SmartError(err)
}
fname := shared.VarPath("images", imgInfo.Fingerprint)
err = os.Remove(fname)
if err != nil {
shared.Debugf("Error deleting image file %s: %s\n", fname, err)
}
fmetaname := shared.VarPath("images", imgInfo.Fingerprint+".rootfs")
if shared.PathExists(fmetaname) {
err = os.Remove(fmetaname)
if err != nil {
shared.Debugf("Error deleting image file %s: %s\n", fmetaname, err)
}
}
vgname, vgnameIsSet, err := getServerConfigValue(d, "core.lvm_vg_name")
if err != nil {
return InternalError(fmt.Errorf("Error checking server config: %v", err))
}
if vgnameIsSet {
err = shared.LVMRemoveLV(vgname, imgInfo.Fingerprint)
if err != nil {
return InternalError(fmt.Errorf("Failed to remove deleted image LV: %v", err))
}
lvsymlink := fmt.Sprintf("%s.lv", fname)
err = os.Remove(lvsymlink)
if err != nil {
return InternalError(fmt.Errorf("Failed to remove symlink to deleted image LV: '%s': %v", lvsymlink, err))
}
} else if d.BackingFs == "btrfs" {
subvol := fmt.Sprintf("%s.btrfs", fname)
btrfsDeleteSubvol(subvol)
}
tx, err := dbBegin(d.db)
if err != nil {
return InternalError(err)
}
_, _ = tx.Exec("DELETE FROM images_aliases WHERE image_id=?", imgInfo.Id)
_, _ = tx.Exec("DELETE FROM images_properties WHERE image_id?", imgInfo.Id)
_, _ = tx.Exec("DELETE FROM images WHERE id=?", imgInfo.Id)
if err := txCommit(tx); err != nil {
return InternalError(err)
}
return EmptySyncResponse
}
开发者ID:joker042,项目名称:lxd,代码行数:58,代码来源:images.go
示例19: ExportToTar
/*
* Export the container to a unshifted tarfile containing:
* dir/
* metadata.yaml
* rootfs/
*/
func (c *containerLXD) ExportToTar(snap string, w io.Writer) error {
if snap == "" && c.IsRunning() {
return fmt.Errorf("Cannot export a running container as image")
}
idmap, err := c.LastIdmapSetGet()
if err != nil {
return err
}
if idmap != nil {
if err := idmap.UnshiftRootfs(c.RootfsPathGet()); err != nil {
return err
}
defer idmap.ShiftRootfs(c.RootfsPathGet())
}
tw := tar.NewWriter(w)
// keep track of the first path we saw for each path with nlink>1
linkmap := map[uint64]string{}
cDir := c.PathGet("")
// Path inside the tar image is the pathname starting after cDir
offset := len(cDir) + 1
writeToTar := func(path string, fi os.FileInfo, err error) error {
if err := c.tarStoreFile(linkmap, offset, tw, path, fi); err != nil {
shared.Debugf("Error tarring up %s: %s", path, err)
return err
}
return nil
}
fnam := filepath.Join(cDir, "metadata.yaml")
if shared.PathExists(fnam) {
fi, err := os.Lstat(fnam)
if err != nil {
shared.Debugf("Error statting %s during exportToTar", fnam)
tw.Close()
return err
}
if err := c.tarStoreFile(linkmap, offset, tw, fnam, fi); err != nil {
shared.Debugf("Error writing to tarfile: %s", err)
tw.Close()
return err
}
}
fnam = filepath.Join(cDir, "rootfs")
filepath.Walk(fnam, writeToTar)
fnam = filepath.Join(cDir, "templates")
if shared.PathExists(fnam) {
filepath.Walk(fnam, writeToTar)
}
return tw.Close()
}
开发者ID:Skarlso,项目名称:lxd,代码行数:64,代码来源:container.go
示例20: activateIfNeeded
func activateIfNeeded() error {
// Don't start a full daemon, we just need DB access
d := &Daemon{
IsMock: false,
imagesDownloading: map[string]chan bool{},
imagesDownloadingLock: sync.RWMutex{},
}
err := initializeDbObject(d, shared.VarPath("lxd.db"))
if err != nil {
return err
}
// Look for network socket
value, err := d.ConfigValueGet("core.https_address")
if err != nil {
return err
}
if value != "" {
shared.Debugf("Daemon has core.https_address set, activating...")
_, err := lxd.NewClient(&lxd.DefaultConfig, "local")
return err
}
// Look for auto-started or previously started containers
d.IdmapSet, err = shared.DefaultIdmapSet()
if err != nil {
return err
}
result, err := dbContainersList(d.db, cTypeRegular)
if err != nil {
return err
}
for _, name := range result {
c, err := containerLoadByName(d, name)
if err != nil {
return err
}
config := c.ExpandedConfig()
lastState := config["volatile.last_state.power"]
autoStart := config["boot.autostart"]
if lastState == "RUNNING" || lastState == "Running" || autoStart == "true" {
shared.Debugf("Daemon has auto-started containers, activating...")
_, err := lxd.NewClient(&lxd.DefaultConfig, "local")
return err
}
}
shared.Debugf("No need to start the daemon now.")
return nil
}
开发者ID:jameinel,项目名称:lxd,代码行数:56,代码来源:main.go
注:本文中的github.com/lxc/lxd/shared.Debugf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论