本文整理匯總了Golang中github.com/samalba/dockerclient.VolumeCreateRequest.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang VolumeCreateRequest.Name方法的具體用法?Golang VolumeCreateRequest.Name怎麽用?Golang VolumeCreateRequest.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/samalba/dockerclient.VolumeCreateRequest
的用法示例。
在下文中一共展示了VolumeCreateRequest.Name方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CreateVolume
// CreateVolume creates a volume in the cluster
func (c *Cluster) CreateVolume(request *dockerclient.VolumeCreateRequest) (*cluster.Volume, error) {
var (
wg sync.WaitGroup
volume *cluster.Volume
err error
parts = strings.SplitN(request.Name, "/", 2)
node = ""
)
if request.Name == "" {
request.Name = stringid.GenerateRandomID()
} else if len(parts) == 2 {
node = parts[0]
request.Name = parts[1]
}
if node == "" {
c.RLock()
for _, e := range c.engines {
wg.Add(1)
go func(engine *cluster.Engine) {
defer wg.Done()
v, er := engine.CreateVolume(request)
if v != nil {
volume = v
err = nil
}
if er != nil && volume == nil {
err = er
}
}(e)
}
c.RUnlock()
wg.Wait()
} else {
config := cluster.BuildContainerConfig(dockerclient.ContainerConfig{Env: []string{"constraint:node==" + parts[0]}})
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config)
if err != nil {
return nil, err
}
if nodes != nil {
v, er := c.engines[nodes[0].ID].CreateVolume(request)
if v != nil {
volume = v
err = nil
}
if er != nil && volume == nil {
err = er
}
}
}
return volume, err
}
示例2: CreateVolume
// CreateVolume creates a volume in the cluster
func (c *Cluster) CreateVolume(request *dockerclient.VolumeCreateRequest) (*cluster.Volume, error) {
var (
wg sync.WaitGroup
volume *cluster.Volume
err error
)
if request.Name == "" {
request.Name = stringid.GenerateRandomID()
}
c.RLock()
for _, e := range c.engines {
wg.Add(1)
go func(engine *cluster.Engine) {
defer wg.Done()
v, er := engine.CreateVolume(request)
if v != nil {
volume = v
err = nil
}
if er != nil && volume == nil {
err = er
}
}(e)
}
c.RUnlock()
wg.Wait()
return volume, err
}