本文整理匯總了Golang中github.com/docker/engine-api/types.NetworkCreate類的典型用法代碼示例。如果您正苦於以下問題:Golang NetworkCreate類的具體用法?Golang NetworkCreate怎麽用?Golang NetworkCreate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了NetworkCreate類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CreateNetwork
// CreateNetwork creates a network in the cluster
func (c *Cluster) CreateNetwork(request *types.NetworkCreate) (*types.NetworkCreateResponse, error) {
var (
parts = strings.SplitN(request.Name, "/", 2)
config = &cluster.ContainerConfig{}
)
if len(parts) == 2 {
// a node was specified, create the container only on this node
request.Name = parts[1]
config = cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:node==" + parts[0]}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{})
}
c.scheduler.Lock()
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config)
c.scheduler.Unlock()
if err != nil {
return nil, err
}
if nodes == nil {
return nil, errors.New("cannot find node to create network")
}
n := nodes[0]
s, ok := c.agents[n.ID]
if !ok {
return nil, fmt.Errorf("Unable to create network on agent %q", n.ID)
}
resp, err := s.engine.CreateNetwork(request)
c.refreshNetworks()
return resp, err
}
示例2: CreateNetwork
// CreateNetwork creates a network in the cluster
func (c *Cluster) CreateNetwork(request *types.NetworkCreate) (response *types.NetworkCreateResponse, err error) {
var (
parts = strings.SplitN(request.Name, "/", 2)
config = &cluster.ContainerConfig{}
)
if len(parts) == 2 {
// a node was specified, create the container only on this node
request.Name = parts[1]
config = cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:node==" + parts[0]}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{})
}
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config)
if err != nil {
return nil, err
}
if nodes != nil {
resp, err := c.engines[nodes[0].ID].CreateNetwork(request)
if err == nil {
if network := c.engines[nodes[0].ID].Networks().Get(resp.ID); network != nil && network.Scope == "global" {
for id, engine := range c.engines {
if id != nodes[0].ID {
engine.AddNetwork(network)
}
}
}
}
return resp, err
}
return nil, nil
}
示例3: postNetworksCreate
// POST /networks/create
func postNetworksCreate(c *context, w http.ResponseWriter, r *http.Request) {
var request apitypes.NetworkCreate
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
httpError(w, err.Error(), http.StatusBadRequest)
return
}
if request.Driver == "" {
request.Driver = "overlay"
}
response, err := c.cluster.CreateNetwork(&request)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(response)
}