// CreateFabricNetwork creates a new fabric network
// See API docs: https://apidocs.joyent.com/cloudapi/#CreateFabricNetwork
160070
func (c *Client) CreateFabricNetwork(vlanID int16, opts CreateFabricNetworkOpts) (*FabricNetwork, error) {
	var resp FabricNetwork
	req := request{
		method:         client.POST,
		url:            makeURL(apiFabricVLANs, strconv.Itoa(int(vlanID)), apiFabricNetworks),
		reqValue:       opts,
		resp:           &resp,
		expectedStatus: http.StatusCreated,
	}
	if _, err := c.sendRequest(req); err != nil {
		return nil, errors.Newf(err, "failed to create fabric network %s on vlan %d", opts.Name, vlanID)
	}
	return &resp, nil
}
1008184
func (c *containerConfig) createNetworkingConfig(b executorpkg.Backend) *network.NetworkingConfig {
	var networks []*api.NetworkAttachment
	if c.task.Spec.GetContainer() != nil || c.task.Spec.GetAttachment() != nil {
		networks = c.task.Networks
	}

	epConfig := make(map[string]*network.EndpointSettings)
	if len(networks) > 0 {
		epConfig[networks[0].Network.Spec.Annotations.Name] = getEndpointConfig(networks[0], b)
	}

	return &network.NetworkingConfig{EndpointsConfig: epConfig}
}
904950
func (c *CloudAPI) ListFabricVLANs() ([]cloudapi.FabricVLAN, error) {
	out := []cloudapi.FabricVLAN{}
	for _, vlan := range c.fabricVLANs {
		out = append(out, vlan.FabricVLAN)
	}

	return out, nil
}
940239
func (o *Enterprise) CreateNetworkMacroGroup(child *NetworkMacroGroup) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1216290
func (c *Client) CreateNetwork(p *CreateNetworkParameter) (*Network, error) {
	obj, err := c.Request("createNetwork", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Network), err
}
27817
func (f *DockerFactory) Create(projectName string, networkConfigs map[string]*config.NetworkConfig, serviceConfigs *config.ServiceConfigs, networkEnabled bool) (project.Networks, error) {
	cli := f.ClientFactory.Create(nil)
	return NetworksFromServices(cli, projectName, networkConfigs, serviceConfigs, networkEnabled)
}
1065999
func (s *NetworkFrameworkAttributes) SetFabric(v *NetworkFabricAttributes) *NetworkFrameworkAttributes {
	s.Fabric = v
	return s
}
911304
func NetworkCreate(info *model.NetworkCreateInfo) error {
	return mgr.Do(func(ctx context.Context, cli *client.Client) (err error) {
		var (
			resp    types.NetworkCreateResponse
			options = types.NetworkCreate{
				Internal:   info.Internal,
				Attachable: info.Attachable,
				IPAM:       &network.IPAM{},
				EnableIPv6: info.IPV6.Enabled,
				Options:    info.Options.ToMap(),
				Labels:     info.Labels.ToMap(),
			}
		)

		if info.Driver == "other" {
			options.Driver = info.CustomDriver
		} else {
			options.Driver = info.Driver
		}

		if info.IPV4.Subnet != "" || info.IPV4.Gateway != "" || info.IPV4.IPRange != "" {
			cfg := network.IPAMConfig{
				Subnet:  info.IPV4.Subnet,
				Gateway: info.IPV4.Gateway,
				IPRange: info.IPV4.IPRange,
			}
			options.IPAM.Config = append(options.IPAM.Config, cfg)
		}

		if info.IPV6.Enabled && (info.IPV6.Subnet != "" || info.IPV6.Gateway != "") {
			cfg := network.IPAMConfig{
				Subnet:  info.IPV6.Subnet,
				Gateway: info.IPV6.Gateway,
			}
			options.IPAM.Config = append(options.IPAM.Config, cfg)
		}

		resp, err = cli.NetworkCreate(ctx, info.Name, options)
		if err == nil && resp.Warning != "" {
			mgr.Logger().Warnf("network %s was created but got warning: %s", info.Name, resp.Warning)
		}
		return
	})
}
1343846
func Create(ctx context.Context, client client.APIClient, name string, ops ...func(*types.NetworkCreate)) (string, error) {
	return createNetwork(ctx, client, name, ops...)
}
850751
func (o *NetconfManager) CreateNetconfSession(child *NetconfSession) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
563325
func CreateChainFromBlock(cb *common.Block, ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider) error {
	cid, err := utils.GetChainIDFromBlock(cb)
	if err != nil {
		return err
	}

	var l ledger.PeerLedger
	if l, err = ledgermgmt.CreateLedger(cb); err != nil {
		return errors.WithMessage(err, "cannot create ledger from genesis block")
	}

	return createChain(cid, l, cb, ccp, sccp, pluginMapper)
}
399868
func setupNetwork(config *initConfig) error {
	for _, config := range config.Networks {
		strategy, err := getStrategy(config.Type)
		if err != nil {
			return err
		}
		if err := strategy.initialize(config); err != nil {
			return err
		}
	}
	return nil
}
440053
func (s *NetworkACLService) NewCreateNetworkACLParams(protocol string) *CreateNetworkACLParams {
	p := &CreateNetworkACLParams{}
	p.p = make(map[string]interface{})
	p.p["protocol"] = protocol
	return p
}
861597
func (d *Driver) createNetwork() error {
	conn, err := getConnection()
	if err != nil {
		return errors.Wrap(err, "getting libvirt connection")
	}
	defer conn.Close()

	// network: default
	// It is assumed that the libvirt/kvm installation has already created this network

	// network: private

	// Only create the private network if it does not already exist
	if _, err := conn.LookupNetworkByName(d.PrivateNetwork); err != nil {
		// create the XML for the private network from our networkTmpl
		tmpl := template.Must(template.New("network").Parse(networkTmpl))
		var networkXML bytes.Buffer
		if err := tmpl.Execute(&networkXML, d); err != nil {
			return errors.Wrap(err, "executing network template")
		}

		// define the network using our template
		network, err := conn.NetworkDefineXML(networkXML.String())
		if err != nil {
			return errors.Wrapf(err, "defining network from xml: %s", networkXML.String())
		}

		// and finally create it
		if err := network.Create(); err != nil {
			return errors.Wrapf(err, "creating network %s", d.PrivateNetwork)
		}
	}

	return nil
}
1294231
func (s *MemberFrameworkConfiguration) SetFabric(v *MemberFabricConfiguration) *MemberFrameworkConfiguration {
	s.Fabric = v
	return s
}
621699
func (s *NetworkService) CreatePhysicalNetwork(p *CreatePhysicalNetworkParams) (*CreatePhysicalNetworkResponse, error) {
	resp, err := s.cs.newRequest("createPhysicalNetwork", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r CreatePhysicalNetworkResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
997450
func CreateDockNet(tenantName, networkName, serviceName string, nwCfg *mastercfg.CfgNetworkState) error {
	var nwID string
	var subnetCIDRv6 = ""

	if nwCfg.IPv6Subnet != "" {
		subnetCIDRv6 = fmt.Sprintf("%s/%d", nwCfg.IPv6Subnet, nwCfg.IPv6SubnetLen)
	}

	// Trim default tenant name
	docknetName := GetDocknetName(tenantName, networkName, serviceName)

	// connect to docker
	defaultHeaders := map[string]string{"User-Agent": "Docker-Client/" + dockerversion.Version + " (" + runtime.GOOS + ")"}
	docker, err := dockerclient.NewClient("unix:///var/run/docker.sock", "v1.23", nil, defaultHeaders)
	if err != nil {
		log.Errorf("Unable to connect to docker. Error %v", err)
		return fmt.Errorf("Unable to connect to docker: %s", err.Error())
	}

	// Check if the network already exists
	nw, err := docker.NetworkInspect(context.Background(), docknetName)
	if err == nil && nw.Driver == netDriverName {
		log.Infof("docker network: %s already exists", docknetName)
		nwID = nw.ID
	} else if err == nil && nw.Driver != netDriverName {
		log.Errorf("Network name %s used by another driver %s", docknetName, nw.Driver)
		return errors.New("network name used by another driver")
	} else if err != nil {
		// plugin options to be sent to docker
		netPluginOptions := make(map[string]string)
		netPluginOptions["tenant"] = nwCfg.Tenant
		netPluginOptions["encap"] = nwCfg.PktTagType
		if nwCfg.PktTagType == "vxlan" {
			netPluginOptions["pkt-tag"] = strconv.Itoa(nwCfg.ExtPktTag)
		} else {
			netPluginOptions["pkt-tag"] = strconv.Itoa(nwCfg.PktTag)
		}

		subnetCIDR := fmt.Sprintf("%s/%d", nwCfg.SubnetIP, nwCfg.SubnetLen)

		var ipams []network.IPAMConfig
		var IPAMv4 = network.IPAMConfig{
			Subnet:  subnetCIDR,
			Gateway: nwCfg.Gateway,
		}
		ipams = append(ipams, IPAMv4)
		var IPAMv6 network.IPAMConfig
		if subnetCIDRv6 != "" {
			IPAMv6 = network.IPAMConfig{
				Subnet:  subnetCIDRv6,
				Gateway: nwCfg.IPv6Gateway,
			}
			ipams = append(ipams, IPAMv6)
		}
		ipamOptions := make(map[string]string)
		ipamOptions["tenant"] = nwCfg.Tenant
		ipamOptions["network"] = nwCfg.NetworkName
		if len(serviceName) > 0 {
			ipamOptions["group"] = serviceName
		}

		ipamCfg := network.IPAM{
			Driver:  ipamDriverName,
			Config:  ipams,
			Options: ipamOptions,
		}
		// Build network parameters
		nwCreate := types.NetworkCreate{
			CheckDuplicate: true,
			Driver:         netDriverName,
			IPAM:           &ipamCfg,
			Options:        netPluginOptions,
			Attachable:     true,
			EnableIPv6:     (subnetCIDRv6 != ""),
		}

		log.Infof("Creating docker network: %+v", nwCreate)
		log.Infof("         docker ipam config: %+v", *nwCreate.IPAM)

		// Create network
		resp, err := docker.NetworkCreate(context.Background(), docknetName, nwCreate)
		if err != nil {
			log.Errorf("Error creating network %s. Err: %v", docknetName, err)
			return err
		}

		nwID = resp.ID
	}

	return CreateDockNetState(tenantName, networkName, serviceName, nwID)
}