本文整理汇总了Golang中github.com/docker/libnetwork.Sandbox类的典型用法代码示例。如果您正苦于以下问题:Golang Sandbox类的具体用法?Golang Sandbox怎么用?Golang Sandbox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sandbox类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: setNetworkNamespaceKey
// called from the libcontainer pre-start hook to set the network
// namespace configuration linkage to the libnetwork "sandbox" entity
func (daemon *Daemon) setNetworkNamespaceKey(containerID string, pid int) error {
path := fmt.Sprintf("/proc/%d/ns/net", pid)
var sandbox libnetwork.Sandbox
search := libnetwork.SandboxContainerWalker(&sandbox, containerID)
daemon.netController.WalkSandboxes(search)
if sandbox == nil {
return derr.ErrorCodeNoSandbox.WithArgs(containerID, "no sandbox found")
}
return sandbox.SetKey(path)
}
开发者ID:RockaLabs,项目名称:docker,代码行数:13,代码来源:container_unix.go
示例2: setNetworkNamespaceKey
// called from the libcontainer pre-start hook to set the network
// namespace configuration linkage to the libnetwork "sandbox" entity
func (daemon *Daemon) setNetworkNamespaceKey(containerID string, pid int) error {
path := fmt.Sprintf("/proc/%d/ns/net", pid)
var sandbox libnetwork.Sandbox
search := libnetwork.SandboxContainerWalker(&sandbox, containerID)
daemon.netController.WalkSandboxes(search)
if sandbox == nil {
return fmt.Errorf("error locating sandbox id %s: no sandbox found", containerID)
}
return sandbox.SetKey(path)
}
开发者ID:contiv,项目名称:docker,代码行数:13,代码来源:container_operations_unix.go
示例3: Join
// Join creates a new sandbox for the given container ID and populates the
// network resources allocated for the endpoint and joins the sandbox to
// the endpoint. It returns the sandbox key to the caller
func (e *remoteEndpoint) Join(sandbox libnetwork.Sandbox, options ...libnetwork.EndpointOption) error {
url := path.Join("/networks", e.networkID, "endpoints", e.er.ID, "containers")
//TODO: process options somehow
join := endpointJoin{
SandboxID: sandbox.ID(),
}
sk := ""
return e.rc.httpPost(url, join, &sk)
}
开发者ID:syeduguri,项目名称:netplugin,代码行数:14,代码来源:libnetClient.go
示例4: GetSandboxPortMapInfo
// GetSandboxPortMapInfo retrieves the current port-mapping programmed for the given sandbox
func GetSandboxPortMapInfo(sb libnetwork.Sandbox) nat.PortMap {
pm := nat.PortMap{}
if sb == nil {
return pm
}
for _, ep := range sb.Endpoints() {
pm, _ = getEndpointPortMapInfo(ep)
if len(pm) > 0 {
break
}
}
return pm
}
开发者ID:docker,项目名称:dockercraft,代码行数:15,代码来源:container.go
示例5: buildSandboxResource
func buildSandboxResource(sb libnetwork.Sandbox) *sandboxResource {
r := &sandboxResource{}
if sb != nil {
r.ID = sb.ID()
r.Key = sb.Key()
r.ContainerID = sb.ContainerID()
}
return r
}
开发者ID:noqcks,项目名称:docker,代码行数:9,代码来源:api.go
示例6: updateSandboxNetworkSettings
func (container *Container) updateSandboxNetworkSettings(sb libnetwork.Sandbox) error {
container.NetworkSettings.SandboxID = sb.ID()
container.NetworkSettings.SandboxKey = sb.Key()
return nil
}
开发者ID:RockaLabs,项目名称:docker,代码行数:5,代码来源:container_unix.go
示例7: runParallelTests
func runParallelTests(t *testing.T, thrNumber int) {
var (
ep libnetwork.Endpoint
sb libnetwork.Sandbox
err error
)
t.Parallel()
pTest := flag.Lookup("test.parallel")
if pTest == nil {
t.Skip("Skipped because test.parallel flag not set;")
}
numParallel, err := strconv.Atoi(pTest.Value.String())
if err != nil {
t.Fatal(err)
}
if numParallel < numThreads {
t.Skip("Skipped because t.parallel was less than ", numThreads)
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if thrNumber == first {
createGlobalInstance(t)
}
if thrNumber != first {
select {
case <-start:
}
thrdone := make(chan struct{})
done <- thrdone
defer close(thrdone)
if thrNumber == last {
defer close(done)
}
err = netns.Set(testns)
if err != nil {
t.Fatal(err)
}
}
defer netns.Set(origns)
net1, err := controller.NetworkByName("testhost")
if err != nil {
t.Fatal(err)
}
if net1 == nil {
t.Fatal("Could not find testhost")
}
net2, err := controller.NetworkByName("network2")
if err != nil {
t.Fatal(err)
}
if net2 == nil {
t.Fatal("Could not find network2")
}
epName := fmt.Sprintf("pep%d", thrNumber)
if thrNumber == first {
ep, err = net1.EndpointByName(epName)
} else {
ep, err = net2.EndpointByName(epName)
}
if err != nil {
t.Fatal(err)
}
if ep == nil {
t.Fatal("Got nil ep with no error")
}
cid := fmt.Sprintf("%drace", thrNumber)
controller.WalkSandboxes(libnetwork.SandboxContainerWalker(&sb, cid))
if sb == nil {
t.Fatalf("Got nil sandbox for container: %s", cid)
}
for i := 0; i < iterCnt; i++ {
parallelJoin(t, sb, ep, thrNumber)
parallelLeave(t, sb, ep, thrNumber)
}
debugf("\n")
err = ep.Delete()
if err != nil {
t.Fatal(err)
}
if thrNumber == first {
for thrdone := range done {
select {
//.........这里部分代码省略.........
开发者ID:hurrygeek,项目名称:libnetwork,代码行数:101,代码来源:libnetwork_test.go
示例8: ContainerRename
// ContainerRename changes the name of a container, using the oldName
// to find the container. An error is returned if newName is already
// reserved.
func (daemon *Daemon) ContainerRename(oldName, newName string) error {
var (
sid string
sb libnetwork.Sandbox
)
if oldName == "" || newName == "" {
return derr.ErrorCodeEmptyRename
}
container, err := daemon.GetContainer(oldName)
if err != nil {
return err
}
oldName = container.Name
container.Lock()
defer container.Unlock()
if newName, err = daemon.reserveName(container.ID, newName); err != nil {
return derr.ErrorCodeRenameTaken.WithArgs(err)
}
container.Name = newName
defer func() {
if err != nil {
container.Name = oldName
daemon.reserveName(container.ID, oldName)
daemon.containerGraphDB.Delete(newName)
}
}()
if err = daemon.containerGraphDB.Delete(oldName); err != nil {
return derr.ErrorCodeRenameDelete.WithArgs(oldName, err)
}
if err = container.ToDisk(); err != nil {
return err
}
if !container.Running {
daemon.LogContainerEvent(container, "rename")
return nil
}
defer func() {
if err != nil {
container.Name = oldName
if e := container.ToDisk(); e != nil {
logrus.Errorf("%s: Failed in writing to Disk on rename failure: %v", container.ID, e)
}
}
}()
sid = container.NetworkSettings.SandboxID
sb, err = daemon.netController.SandboxByID(sid)
if err != nil {
return err
}
err = sb.Rename(strings.TrimPrefix(container.Name, "/"))
if err != nil {
return err
}
daemon.LogContainerEvent(container, "rename")
return nil
}
开发者ID:DaveDaCoda,项目名称:docker,代码行数:72,代码来源:rename.go
示例9: ContainerRename
// ContainerRename changes the name of a container, using the oldName
// to find the container. An error is returned if newName is already
// reserved.
func (daemon *Daemon) ContainerRename(oldName, newName string) error {
var (
sid string
sb libnetwork.Sandbox
)
if oldName == "" || newName == "" {
return fmt.Errorf("Neither old nor new names may be empty")
}
if newName[0] != '/' {
newName = "/" + newName
}
container, err := daemon.GetContainer(oldName)
if err != nil {
return err
}
oldName = container.Name
oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
container.Lock()
defer container.Unlock()
if oldName == newName {
return fmt.Errorf("Renaming a container with the same name as its current name")
}
if newName, err = daemon.reserveName(container.ID, newName); err != nil {
return fmt.Errorf("Error when allocating new name: %v", err)
}
container.Name = newName
container.NetworkSettings.IsAnonymousEndpoint = false
defer func() {
if err != nil {
container.Name = oldName
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
daemon.reserveName(container.ID, oldName)
daemon.releaseName(newName)
}
}()
daemon.releaseName(oldName)
if err = container.ToDisk(); err != nil {
return err
}
attributes := map[string]string{
"oldName": oldName,
}
if !container.Running {
daemon.LogContainerEventWithAttributes(container, "rename", attributes)
return nil
}
defer func() {
if err != nil {
container.Name = oldName
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
if e := container.ToDisk(); e != nil {
logrus.Errorf("%s: Failed in writing to Disk on rename failure: %v", container.ID, e)
}
}
}()
sid = container.NetworkSettings.SandboxID
if daemon.netController != nil {
sb, err = daemon.netController.SandboxByID(sid)
if err != nil {
return err
}
err = sb.Rename(strings.TrimPrefix(container.Name, "/"))
if err != nil {
return err
}
}
daemon.LogContainerEventWithAttributes(container, "rename", attributes)
return nil
}
开发者ID:GoFrag,项目名称:docker,代码行数:88,代码来源:rename.go
示例10: ContainerRename
// ContainerRename changes the name of a container, using the oldName
// to find the container. An error is returned if newName is already
// reserved.
func (daemon *Daemon) ContainerRename(oldName, newName string) error {
var (
sid string
sb libnetwork.Sandbox
)
if oldName == "" || newName == "" {
return errors.New("Neither old nor new names may be empty")
}
if newName[0] != '/' {
newName = "/" + newName
}
container, err := daemon.GetContainer(oldName)
if err != nil {
return err
}
oldName = container.Name
oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
if oldName == newName {
return errors.New("Renaming a container with the same name as its current name")
}
container.Lock()
defer container.Unlock()
links := map[string]*dockercontainer.Container{}
for k, v := range daemon.linkIndex.children(container) {
if !strings.HasPrefix(k, oldName) {
return fmt.Errorf("Linked container %s does not match parent %s", k, oldName)
}
links[strings.TrimPrefix(k, oldName)] = v
}
if newName, err = daemon.reserveName(container.ID, newName); err != nil {
return fmt.Errorf("Error when allocating new name: %v", err)
}
for k, v := range links {
daemon.nameIndex.Reserve(newName+k, v.ID)
daemon.linkIndex.link(container, v, newName+k)
}
container.Name = newName
container.NetworkSettings.IsAnonymousEndpoint = false
defer func() {
if err != nil {
container.Name = oldName
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
daemon.reserveName(container.ID, oldName)
for k, v := range links {
daemon.nameIndex.Reserve(oldName+k, v.ID)
daemon.linkIndex.link(container, v, oldName+k)
daemon.linkIndex.unlink(newName+k, v, container)
daemon.nameIndex.Release(newName + k)
}
daemon.releaseName(newName)
}
}()
for k, v := range links {
daemon.linkIndex.unlink(oldName+k, v, container)
daemon.nameIndex.Release(oldName + k)
}
daemon.releaseName(oldName)
if err = container.ToDisk(); err != nil {
return err
}
attributes := map[string]string{
"oldName": oldName,
}
if !container.Running {
daemon.LogContainerEventWithAttributes(container, "rename", attributes)
return nil
}
defer func() {
if err != nil {
container.Name = oldName
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
if e := container.ToDisk(); e != nil {
logrus.Errorf("%s: Failed in writing to Disk on rename failure: %v", container.ID, e)
}
}
}()
sid = container.NetworkSettings.SandboxID
if daemon.netController != nil {
sb, err = daemon.netController.SandboxByID(sid)
if err != nil {
return err
//.........这里部分代码省略.........
开发者ID:docker,项目名称:docker,代码行数:101,代码来源:rename.go
注:本文中的github.com/docker/libnetwork.Sandbox类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论