本文整理匯總了Golang中github.com/dotcloud/docker/graph.NewGraph函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewGraph函數的具體用法?Golang NewGraph怎麽用?Golang NewGraph使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewGraph函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: tempGraph
func tempGraph(t *testing.T) (*graph.Graph, graphdriver.Driver) {
tmp, err := ioutil.TempDir("", "docker-graph-")
if err != nil {
t.Fatal(err)
}
driver, err := graphdriver.New(tmp, nil)
if err != nil {
t.Fatal(err)
}
graph, err := graph.NewGraph(tmp, driver)
if err != nil {
t.Fatal(err)
}
return graph, driver
}
示例2: NewDaemonFromDirectory
func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*Daemon, error) {
if !config.EnableSelinuxSupport {
selinux.SetDisabled()
}
// Create the root directory if it doesn't exists
if err := os.MkdirAll(config.Root, 0700); err != nil && !os.IsExist(err) {
return nil, err
}
// Set the default driver
graphdriver.DefaultDriver = config.GraphDriver
// Load storage driver
driver, err := graphdriver.New(config.Root)
if err != nil {
return nil, err
}
utils.Debugf("Using graph driver %s", driver)
if err := remountPrivate(config.Root); err != nil {
return nil, err
}
daemonRepo := path.Join(config.Root, "containers")
if err := os.MkdirAll(daemonRepo, 0700); err != nil && !os.IsExist(err) {
return nil, err
}
// Migrate the container if it is aufs and aufs is enabled
if err = migrateIfAufs(driver, config.Root); err != nil {
return nil, err
}
utils.Debugf("Creating images graph")
g, err := graph.NewGraph(path.Join(config.Root, "graph"), driver)
if err != nil {
return nil, err
}
// We don't want to use a complex driver like aufs or devmapper
// for volumes, just a plain filesystem
volumesDriver, err := graphdriver.GetDriver("vfs", config.Root)
if err != nil {
return nil, err
}
utils.Debugf("Creating volumes graph")
volumes, err := graph.NewGraph(path.Join(config.Root, "volumes"), volumesDriver)
if err != nil {
return nil, err
}
utils.Debugf("Creating repository list")
repositories, err := graph.NewTagStore(path.Join(config.Root, "repositories-"+driver.String()), g)
if err != nil {
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
}
if !config.DisableNetwork {
job := eng.Job("init_networkdriver")
job.SetenvBool("EnableIptables", config.EnableIptables)
job.SetenvBool("InterContainerCommunication", config.InterContainerCommunication)
job.SetenvBool("EnableIpForward", config.EnableIpForward)
job.Setenv("BridgeIface", config.BridgeIface)
job.Setenv("BridgeIP", config.BridgeIP)
job.Setenv("DefaultBindingIP", config.DefaultIp.String())
if err := job.Run(); err != nil {
return nil, err
}
}
graphdbPath := path.Join(config.Root, "linkgraph.db")
graph, err := graphdb.NewSqliteConn(graphdbPath)
if err != nil {
return nil, err
}
localCopy := path.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", dockerversion.VERSION))
sysInitPath := utils.DockerInitPath(localCopy)
if sysInitPath == "" {
return nil, fmt.Errorf("Could not locate dockerinit: This usually means docker was built incorrectly. See http://docs.docker.io/en/latest/contributing/devenvironment for official build instructions.")
}
if sysInitPath != localCopy {
// When we find a suitable dockerinit binary (even if it's our local binary), we copy it into config.Root at localCopy for future use (so that the original can go away without that being a problem, for example during a package upgrade).
if err := os.Mkdir(path.Dir(localCopy), 0700); err != nil && !os.IsExist(err) {
return nil, err
}
if _, err := utils.CopyFile(sysInitPath, localCopy); err != nil {
return nil, err
}
if err := os.Chmod(localCopy, 0700); err != nil {
return nil, err
}
sysInitPath = localCopy
}
sysInfo := sysinfo.New(false)
//.........這裏部分代碼省略.........
示例3: main
func main() {
flag.Parse()
maxProcs := runtime.NumCPU()
prevMaxProcs := runtime.GOMAXPROCS(maxProcs)
log.Println("set GOMAXPROCS to", maxProcs, "was", prevMaxProcs)
if *binPath == "" {
log.Fatalln("must specify -bin with linux backend")
}
if *depotPath == "" {
log.Fatalln("must specify -depot with linux backend")
}
if *rootFSPath == "" {
log.Fatalln("must specify -rootfs with linux backend")
}
uidPool := uid_pool.New(uint32(*uidPoolStart), uint32(*uidPoolSize))
_, ipNet, err := net.ParseCIDR(*networkPool)
if err != nil {
log.Fatalln("error parsing CIDR:", err)
}
networkPool := network_pool.New(ipNet)
// TODO: use /proc/sys/net/ipv4/ip_local_port_range by default (end + 1)
portPool := port_pool.New(uint32(*portPoolStart), uint32(*portPoolSize))
runner := linux_command_runner.New(*debug)
quotaManager, err := quota_manager.New(*depotPath, *binPath, runner)
if err != nil {
log.Fatalln("error creating quota manager:", err)
}
if *disableQuotas {
quotaManager.Disable()
}
graphDriver, err := graphdriver.New(*graphRoot)
if err != nil {
log.Fatalln("error constructing graph driver:", err)
}
graph, err := graph.NewGraph(*graphRoot, graphDriver)
if err != nil {
log.Fatalln("error constructing graph:", err)
}
reg, err := registry.NewRegistry(nil, nil, *dockerRegistry)
if err != nil {
log.Fatalln(err)
}
pool := container_pool.New(
*binPath,
*depotPath,
*rootFSPath,
repository_fetcher.Retryable{repository_fetcher.New(reg, graph)},
graphDriver,
uidPool,
networkPool,
portPool,
strings.Split(*denyNetworks, ","),
strings.Split(*allowNetworks, ","),
runner,
quotaManager,
)
systemInfo := system_info.NewProvider(*depotPath)
backend := linux_backend.New(pool, systemInfo, *snapshotsPath)
log.Println("setting up backend")
err = backend.Setup()
if err != nil {
log.Fatalln("failed to set up backend:", err)
}
log.Println("starting server; listening with", *listenNetwork, "on", *listenAddr)
graceTime := *containerGraceTime
wardenServer := server.New(*listenNetwork, *listenAddr, graceTime, backend)
err = wardenServer.Start()
if err != nil {
log.Fatalln("failed to start:", err)
}
signals := make(chan os.Signal, 1)
go func() {
<-signals
log.Println("stopping...")
//.........這裏部分代碼省略.........
示例4: NewRuntimeFromDirectory
func NewRuntimeFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*Runtime, error) {
// Set the default driver
graphdriver.DefaultDriver = config.GraphDriver
// Load storage driver
driver, err := graphdriver.New(config.Root)
if err != nil {
return nil, err
}
utils.Debugf("Using graph driver %s", driver)
runtimeRepo := path.Join(config.Root, "containers")
if err := os.MkdirAll(runtimeRepo, 0700); err != nil && !os.IsExist(err) {
return nil, err
}
if ad, ok := driver.(*aufs.Driver); ok {
utils.Debugf("Migrating existing containers")
if err := ad.Migrate(config.Root, graph.SetupInitLayer); err != nil {
return nil, err
}
}
utils.Debugf("Creating images graph")
g, err := graph.NewGraph(path.Join(config.Root, "graph"), driver)
if err != nil {
return nil, err
}
// We don't want to use a complex driver like aufs or devmapper
// for volumes, just a plain filesystem
volumesDriver, err := graphdriver.GetDriver("vfs", config.Root)
if err != nil {
return nil, err
}
utils.Debugf("Creating volumes graph")
volumes, err := graph.NewGraph(path.Join(config.Root, "volumes"), volumesDriver)
if err != nil {
return nil, err
}
utils.Debugf("Creating repository list")
repositories, err := graph.NewTagStore(path.Join(config.Root, "repositories-"+driver.String()), g)
if err != nil {
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
}
if !config.DisableNetwork {
job := eng.Job("init_networkdriver")
job.SetenvBool("EnableIptables", config.EnableIptables)
job.SetenvBool("InterContainerCommunication", config.InterContainerCommunication)
job.SetenvBool("EnableIpForward", config.EnableIpForward)
job.Setenv("BridgeIface", config.BridgeIface)
job.Setenv("BridgeIP", config.BridgeIP)
job.Setenv("DefaultBindingIP", config.DefaultIp.String())
if err := job.Run(); err != nil {
return nil, err
}
}
graphdbPath := path.Join(config.Root, "linkgraph.db")
graph, err := graphdb.NewSqliteConn(graphdbPath)
if err != nil {
return nil, err
}
localCopy := path.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", dockerversion.VERSION))
sysInitPath := utils.DockerInitPath(localCopy)
if sysInitPath == "" {
return nil, fmt.Errorf("Could not locate dockerinit: This usually means docker was built incorrectly. See http://docs.docker.io/en/latest/contributing/devenvironment for official build instructions.")
}
if sysInitPath != localCopy {
// When we find a suitable dockerinit binary (even if it's our local binary), we copy it into config.Root at localCopy for future use (so that the original can go away without that being a problem, for example during a package upgrade).
if err := os.Mkdir(path.Dir(localCopy), 0700); err != nil && !os.IsExist(err) {
return nil, err
}
if _, err := utils.CopyFile(sysInitPath, localCopy); err != nil {
return nil, err
}
if err := os.Chmod(localCopy, 0700); err != nil {
return nil, err
}
sysInitPath = localCopy
}
var (
ed execdriver.Driver
sysInfo = sysinfo.New(false)
)
switch config.ExecDriver {
case "lxc":
// we want to five the lxc driver the full docker root because it needs
// to access and write config and template files in /var/lib/docker/containers/*
// to be backwards compatible
ed, err = lxc.NewDriver(config.Root, sysInfo.AppArmor)
//.........這裏部分代碼省略.........