本文整理汇总了Golang中github.com/lxc/lxd/shared.DefaultIdmapSet函数的典型用法代码示例。如果您正苦于以下问题:Golang DefaultIdmapSet函数的具体用法?Golang DefaultIdmapSet怎么用?Golang DefaultIdmapSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultIdmapSet函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: showDefaultMap
func showDefaultMap() {
set, err := shared.DefaultIdmapSet()
if err != nil {
fmt.Printf("Error reading default mapset: %q\n", err)
help(1)
}
fmt.Printf("Your current default allocation is:\n\n")
for _, m := range set.Idmap {
t := "uid"
if !m.Isuid {
t = "gid"
}
hmin := m.Hostid
hmax := m.Hostid + m.Maprange - 1
cmin := m.Nsid
cmax := m.Nsid + m.Maprange - 1
fmt.Printf("host %s %d - %d mapping to %d - %d in container\n",
t, hmin, hmax, cmin, cmax)
}
}
开发者ID:hallyn,项目名称:uidmapviz,代码行数:20,代码来源:mapviz.go
示例3: Init
//.........这里部分代码省略.........
/* Set container path */
d.lxcpath = shared.VarPath("containers")
/* Make sure all our directories are available */
if err := os.MkdirAll(shared.VarPath("containers"), 0711); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("devices"), 0711); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("devlxd"), 0755); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("images"), 0700); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("security"), 0700); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("shmounts"), 0711); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("snapshots"), 0700); err != nil {
return err
}
/* Detect the filesystem */
d.BackingFs, err = filesystemDetect(d.lxcpath)
if err != nil {
shared.Log.Error("Error detecting backing fs", log.Ctx{"err": err})
}
/* Read the uid/gid allocation */
d.IdmapSet, err = shared.DefaultIdmapSet()
if err != nil {
shared.Log.Warn("Error reading idmap", log.Ctx{"err": err.Error()})
shared.Log.Warn("Only privileged containers will be able to run")
} else {
shared.Log.Info("Default uid/gid map:")
for _, lxcmap := range d.IdmapSet.ToLxcString() {
shared.Log.Info(strings.TrimRight(" - "+lxcmap, "\n"))
}
}
/* Initialize the database */
err = initializeDbObject(d, shared.VarPath("lxd.db"))
if err != nil {
return err
}
/* Prune images */
d.pruneChan = make(chan bool)
go func() {
d.pruneExpiredImages()
for {
timer := time.NewTimer(24 * time.Hour)
timeChan := timer.C
select {
case <-timeChan:
/* run once per day */
d.pruneExpiredImages()
case <-d.pruneChan:
/* run when image.remote_cache_expiry is changed */
d.pruneExpiredImages()
timer.Stop()
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:67,代码来源:daemon.go
示例4: StartDaemon
// StartDaemon starts the shared daemon with the provided configuration.
func StartDaemon() (*Daemon, error) {
d := &Daemon{}
/* Setup logging */
if shared.Log == nil {
shared.SetLogger("", "", true, true)
}
shared.Log.Info("LXD is starting.")
/* Get the list of supported architectures */
var architectures = []int{}
uname := syscall.Utsname{}
if err := syscall.Uname(&uname); err != nil {
return nil, err
}
architectureName := ""
for _, c := range uname.Machine {
if c == 0 {
break
}
architectureName += string(byte(c))
}
architecture, err := shared.ArchitectureId(architectureName)
if err != nil {
return nil, err
}
architectures = append(architectures, architecture)
personalities, err := shared.ArchitecturePersonalities(architecture)
if err != nil {
return nil, err
}
for _, personality := range personalities {
architectures = append(architectures, personality)
}
d.architectures = architectures
/* Create required paths */
d.lxcpath = shared.VarPath("containers")
err = os.MkdirAll(d.lxcpath, 0755)
if err != nil {
return nil, err
}
// Create default directories
if err := os.MkdirAll(shared.VarPath("images"), 0700); err != nil {
return nil, err
}
if err := os.MkdirAll(shared.VarPath("snapshots"), 0700); err != nil {
return nil, err
}
if err := os.MkdirAll(shared.VarPath("devlxd"), 0755); err != nil {
return nil, err
}
/* Detect the filesystem */
d.BackingFs, err = filesystemDetect(d.lxcpath)
if err != nil {
shared.Log.Error("Error detecting backing fs", log.Ctx{"err": err})
}
/* Read the uid/gid allocation */
d.IdmapSet, err = shared.DefaultIdmapSet()
if err != nil {
shared.Log.Warn("error reading idmap", log.Ctx{"err": err.Error()})
shared.Log.Warn("operations requiring idmap will not be available")
} else {
shared.Log.Info("Default uid/gid map:")
for _, lxcmap := range d.IdmapSet.ToLxcString() {
shared.Log.Info(strings.TrimRight(" - "+lxcmap, "\n"))
}
}
/* Initialize the database */
err = initDb(d)
if err != nil {
return nil, err
}
/* Setup the TLS authentication */
certf, keyf, err := readMyCert()
if err != nil {
return nil, err
}
d.certf = certf
d.keyf = keyf
readSavedClientCAList(d)
tlsConfig, err := shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return nil, err
}
/* Setup /dev/lxd */
d.devlxd, err = createAndBindDevLxd()
//.........这里部分代码省略.........
开发者ID:crwloop,项目名称:lxd,代码行数:101,代码来源:daemon.go
示例5: Init
//.........这里部分代码省略.........
/* Make sure all our directories are available */
if err := os.MkdirAll(shared.VarPath("containers"), 0711); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("devices"), 0711); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("devlxd"), 0755); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("images"), 0700); err != nil {
return err
}
if err := os.MkdirAll(shared.LogPath(), 0700); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("security"), 0700); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("shmounts"), 0711); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("snapshots"), 0700); err != nil {
return err
}
/* Detect the filesystem */
d.BackingFs, err = filesystemDetect(d.lxcpath)
if err != nil {
shared.Log.Error("Error detecting backing fs", log.Ctx{"err": err})
}
/* Read the uid/gid allocation */
d.IdmapSet, err = shared.DefaultIdmapSet()
if err != nil {
shared.Log.Warn("Error reading idmap", log.Ctx{"err": err.Error()})
shared.Log.Warn("Only privileged containers will be able to run")
} else {
shared.Log.Info("Default uid/gid map:")
for _, lxcmap := range d.IdmapSet.ToLxcString() {
shared.Log.Info(strings.TrimRight(" - "+lxcmap, "\n"))
}
}
/* Initialize the database */
err = initializeDbObject(d, shared.VarPath("lxd.db"))
if err != nil {
return err
}
/* Setup the storage driver */
if !d.MockMode {
err = d.SetupStorageDriver()
if err != nil {
return fmt.Errorf("Failed to setup storage: %s", err)
}
}
/* Load all config values from the database */
_, err = d.ConfigValuesGet()
if err != nil {
return err
}
/* set the initial proxy function based on config values in the DB */
d.updateProxy()
开发者ID:jsavikko,项目名称:lxd,代码行数:67,代码来源:daemon.go
示例6: Init
//.........这里部分代码省略.........
if err != nil {
return err
}
for _, personality := range personalities {
architectures = append(architectures, personality)
}
d.architectures = architectures
/* Create required paths */
d.lxcpath = shared.VarPath("containers")
err = os.MkdirAll(d.lxcpath, 0755)
if err != nil {
return err
}
// Create default directories
if err := os.MkdirAll(shared.VarPath("images"), 0700); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("snapshots"), 0700); err != nil {
return err
}
if err := os.MkdirAll(shared.VarPath("devlxd"), 0755); err != nil {
return err
}
/* Detect the filesystem */
d.BackingFs, err = filesystemDetect(d.lxcpath)
if err != nil {
shared.Log.Error("Error detecting backing fs", log.Ctx{"err": err})
}
/* Read the uid/gid allocation */
d.IdmapSet, err = shared.DefaultIdmapSet()
if err != nil {
shared.Log.Warn("Error reading idmap", log.Ctx{"err": err.Error()})
shared.Log.Warn("Only privileged containers will be able to run")
} else {
shared.Log.Info("Default uid/gid map:")
for _, lxcmap := range d.IdmapSet.ToLxcString() {
shared.Log.Info(strings.TrimRight(" - "+lxcmap, "\n"))
}
}
/* Initialize the database */
err = initializeDbObject(d, shared.VarPath("lxd.db"))
if err != nil {
return err
}
/* Prune images */
d.pruneChan = make(chan bool)
go func() {
for {
expiryStr, err := dbImageExpiryGet(d.db)
var expiry int
if err != nil {
expiry = 10
} else {
expiry, err = strconv.Atoi(expiryStr)
if err != nil {
expiry = 10
}
if expiry <= 0 {
expiry = 1
}
开发者ID:achanda,项目名称:lxd,代码行数:67,代码来源:daemon.go
示例7: cmdActivateIfNeeded
func cmdActivateIfNeeded() error {
// Don't start a full daemon, we just need DB access
d := &Daemon{
imagesDownloading: map[string]chan bool{},
imagesDownloadingLock: sync.RWMutex{},
lxcpath: shared.VarPath("containers"),
}
if !shared.PathExists(shared.VarPath("lxd.db")) {
shared.LogDebugf("No DB, so no need to start the daemon now.")
return nil
}
err := initializeDbObject(d, shared.VarPath("lxd.db"))
if err != nil {
return err
}
/* Load all config values from the database */
err = daemonConfigInit(d.db)
if err != nil {
return err
}
// Look for network socket
value := daemonConfig["core.https_address"].Get()
if value != "" {
shared.LogDebugf("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 c.IsRunning() {
shared.LogDebugf("Daemon has running containers, activating...")
_, err := lxd.NewClient(&lxd.DefaultConfig, "local")
return err
}
if lastState == "RUNNING" || lastState == "Running" || shared.IsTrue(autoStart) {
shared.LogDebugf("Daemon has auto-started containers, activating...")
_, err := lxd.NewClient(&lxd.DefaultConfig, "local")
return err
}
}
shared.LogDebugf("No need to start the daemon now.")
return nil
}
开发者ID:akshaykarle,项目名称:lxd,代码行数:69,代码来源:main.go
示例8: StartDaemon
// StartDaemon starts the shared daemon with the provided configuration.
func StartDaemon(listenAddr string) (*Daemon, error) {
d := &Daemon{}
d.lxcpath = shared.VarPath("lxc")
err := os.MkdirAll(shared.VarPath("/"), 0755)
if err != nil {
return nil, err
}
err = os.MkdirAll(d.lxcpath, 0755)
if err != nil {
return nil, err
}
d.BackingFs, err = shared.GetFilesystem(d.lxcpath)
if err != nil {
shared.Debugf("Error detecting backing fs: %s\n", err)
}
certf, keyf, err := readMyCert()
if err != nil {
return nil, err
}
d.certf = certf
d.keyf = keyf
err = initDb(d)
if err != nil {
return nil, err
}
readSavedClientCAList(d)
d.mux = mux.NewRouter()
d.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
SyncResponse(true, []string{"/1.0"}).Render(w)
})
for _, c := range api10 {
d.createCmd("1.0", c)
}
d.mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
shared.Debugf("sending top level 404: %s", r.URL)
w.Header().Set("Content-Type", "application/json")
NotFound.Render(w)
})
d.IdmapSet, err = shared.DefaultIdmapSet()
if err != nil {
shared.Logf("error reading idmap: %s", err.Error())
shared.Logf("operations requiring idmap will not be available")
} else {
shared.Debugf("Default uid/gid map:")
for _, lxcmap := range d.IdmapSet.ToLxcString() {
shared.Debugf(" - " + lxcmap)
}
}
tlsConfig, err := shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return nil, err
}
listeners, err := activation.Listeners(false)
if err != nil {
return nil, err
}
var localSockets []net.Listener
var remoteSockets []net.Listener
if len(listeners) > 0 {
shared.Debugf("LXD is socket activated.\n")
for _, listener := range listeners {
if _, err := os.Stat(listener.Addr().String()); err == nil {
localSockets = append(localSockets, listener)
} else {
tlsListener := tls.NewListener(listener, tlsConfig)
remoteSockets = append(remoteSockets, tlsListener)
}
}
} else {
shared.Debugf("LXD isn't socket activated.\n")
localSocketPath := shared.VarPath("unix.socket")
// If the socket exists, let's try to connect to it and see if there's
// a lxd running.
if _, err := os.Stat(localSocketPath); err == nil {
c := &lxd.Config{Remotes: map[string]lxd.RemoteConfig{}}
_, err := lxd.NewClient(c, "")
if err != nil {
shared.Debugf("Detected old but dead unix socket, deleting it...")
// Connecting failed, so let's delete the socket and
// listen on it ourselves.
err = os.Remove(localSocketPath)
//.........这里部分代码省略.........
开发者ID:Ramzec,项目名称:lxd,代码行数:101,代码来源:daemon.go
注:本文中的github.com/lxc/lxd/shared.DefaultIdmapSet函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论