// CmdNetworkRm handles Network Delete UI
975597
func (cli *NetworkCli) CmdNetworkRm(chain string, args ...string) error {
	cmd := cli.Subcmd(chain, "rm", "NETWORK", "Deletes a network", false)
	cmd.Require(flag.Exact, 1)
	err := cmd.ParseFlags(args, true)
	if err != nil {
		return err
	}
	id, err := lookupNetworkID(cli, cmd.Arg(0))
	if err != nil {
		return err
	}
	_, _, err = readBody(cli.call("DELETE", "/networks/"+id, nil, nil))
	if err != nil {
		return err
	}
	return nil
}
522810
func (m *MockCommonAPIClient) NetworkRemove(ctx context.Context, networkID string) error {
	ret := m.ctrl.Call(m, "NetworkRemove", ctx, networkID)
	ret0, _ := ret[0].(error)
	return ret0
}
603755
func (c *Cluster) RemoveNetwork(input string) error {
	return c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
		network, err := getNetwork(ctx, state.controlClient, input)
		if err != nil {
			return err
		}

		_, err = state.controlClient.RemoveNetwork(ctx, &swarmapi.RemoveNetworkRequest{NetworkID: network.ID})
		return err
	})
}
1040562
func (_m *API) NetworkDisconnect(ctx context.Context, network string, target string, force bool) error {
	ret := _m.Called(ctx, network, target, force)

	var r0 error
	if rf, ok := ret.Get(0).(func(context.Context, string, string, bool) error); ok {
		r0 = rf(ctx, network, target, force)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
763865
func (c *CNIConfig) DelNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) error {
	var cachedResult types.Result

	// Cached result on DEL was added in CNI spec version 0.4.0 and higher
	if gtet, err := version.GreaterThanOrEqualTo(net.Network.CNIVersion, "0.4.0"); err != nil {
		return err
	} else if gtet {
		cachedResult, err = getCachedResult(net.Network.Name, net.Network.CNIVersion, rt)
		if err != nil {
			return fmt.Errorf("failed to get network %q cached result: %v", net.Network.Name, err)
		}
	}

	if err := c.delNetwork(ctx, net.Network.Name, net.Network.CNIVersion, net, cachedResult, rt); err != nil {
		return err
	}
	_ = delCachedResult(net.Network.Name, rt)
	return nil
}
636760
func (r *resourceAllocator) DetachNetwork(ctx context.Context, aID string) error {
	return r.agent.withSession(ctx, func(session *session) error {
		client := api.NewResourceAllocatorClient(session.conn.ClientConn)
		_, err := client.DetachNetwork(ctx, &api.DetachNetworkRequest{
			AttachmentID: aID,
		})

		return err
	})
}
818694
func GetNetworkByID(networkID string) (*HostComputeNetwork, error) {
	hcnQuery := defaultQuery()
	mapA := map[string]string{"ID": networkID}
	filter, err := json.Marshal(mapA)
	if err != nil {
		return nil, err
	}
	hcnQuery.Filter = string(filter)

	networks, err := ListNetworksQuery(hcnQuery)
	if err != nil {
		return nil, err
	}
	if len(networks) == 0 {
		return nil, NetworkNotFoundError{NetworkID: networkID}
	}
	return &networks[0], err
}
215632
func (s *NetworkACLService) DeleteNetworkACL(p *DeleteNetworkACLParams) (*DeleteNetworkACLResponse, error) {
	resp, err := s.cs.newRequest("deleteNetworkACL", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r DeleteNetworkACLResponse
	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
		}

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

	return &r, nil
}
592322
func (s *LoadBalancerService) NewDeleteNetscalerLoadBalancerParams(lbdeviceid string) *DeleteNetscalerLoadBalancerParams {
	p := &DeleteNetscalerLoadBalancerParams{}
	p.p = make(map[string]interface{})
	p.p["lbdeviceid"] = lbdeviceid
	return p
}
450384
func DeleteNetwork(tx Tx, id string) error {
	return tx.delete(tableNetwork, id)
}
669726
func DeleteNetworkID(stateDriver core.StateDriver, netID string) error {
	nwCfg := &mastercfg.CfgNetworkState{}
	nwCfg.StateDriver = stateDriver
	err := nwCfg.Read(netID)
	if err != nil {
		log.Errorf("network %s is not operational", netID)
		return err
	}

	// Will Skip docker network deletion for ACI fabric mode.
	aci, _ := IsAciConfigured()

	if nwCfg.NwType != "infra" {
		// For Infra nw, endpoint delete initiated by netplugin
		// Check if there are any active endpoints
		if hasActiveEndpoints(nwCfg) {
			return core.Errorf("Error: Network has active endpoints")
		}

		if GetClusterMode() == core.Docker && aci == false {
			// Delete the docker network
			err = docknet.DeleteDockNet(nwCfg.Tenant, nwCfg.NetworkName, "")
			if err != nil {
				log.Errorf("Error deleting network %s. Err: %v", netID, err)
				// DeleteDockNet will fail when network has active endpoints.
				// No damage is done yet. It is safe to fail.
				return err
			}
		}
	}

	gstate.GlobalMutex.Lock()
	defer gstate.GlobalMutex.Unlock()
	gCfg := &gstate.Cfg{}
	gCfg.StateDriver = stateDriver
	err = gCfg.Read("")
	if err != nil {
		log.Errorf("error reading tenant info for %q. Error: %s", nwCfg.Tenant, err)
		return err
	}

	// Free resource associated with the network
	err = freeNetworkResources(stateDriver, nwCfg, gCfg)
	if err != nil {
		// Error while freeing up vlan/vxlan/subnet/gateway resources
		// This can only happen because of defects in code
		// No need of any corrective handling here
		return err
	}

	err = nwCfg.Clear()
	if err != nil {
		log.Errorf("error writing nw config. Error: %s", err)
		return err
	}

	return err
}
521050
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
	cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false)
	flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network")
	flID := cmd.String([]string{"-id"}, "", "Network ID string")
	flOpts := cmd.String([]string{"o", "-opt"}, "", "Network options")
	flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal")
	flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network")
	flSubnet := cmd.String([]string{"-subnet"}, "", "Subnet option")
	flRange := cmd.String([]string{"-ip-range"}, "", "Range option")

	cmd.Require(flag.Exact, 1)
	err := cmd.ParseFlags(args, true)
	if err != nil {
		return err
	}
	networkOpts := make(map[string]string)
	if *flInternal {
		networkOpts[netlabel.Internal] = "true"
	}
	if *flIPv6 {
		networkOpts[netlabel.EnableIPv6] = "true"
	}

	driverOpts := make(map[string]string)
	if *flOpts != "" {
		opts := strings.Split(*flOpts, ",")
		for _, opt := range opts {
			driverOpts[netlabel.Key(opt)] = netlabel.Value(opt)
		}
	}

	var icList []ipamConf
	if *flSubnet != "" {
		ic := ipamConf{
			PreferredPool: *flSubnet,
		}

		if *flRange != "" {
			ic.SubPool = *flRange
		}

		icList = append(icList, ic)
	}

	// Construct network create request body
	nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, ID: *flID, IPv4Conf: icList, DriverOpts: driverOpts, NetworkOpts: networkOpts}
	obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
	if err != nil {
		return err
	}
	var replyID string
	err = json.Unmarshal(obj, &replyID)
	if err != nil {
		return err
	}
	fmt.Fprintf(cli.out, "%s\n", replyID)
	return nil
}
1232811
func (daemon *Daemon) GetNetworksByIDPrefix(partialID string) []libnetwork.Network {
	c := daemon.netController
	if c == nil {
		return nil
	}
	list := []libnetwork.Network{}
	l := func(nw libnetwork.Network) bool {
		if strings.HasPrefix(nw.ID(), partialID) {
			list = append(list, nw)
		}
		return false
	}
	c.WalkNetworks(l)

	return list
}
215403
func (d *driver) DeleteNetwork(nid string) error {
	defer osl.InitOSContext()()
	n := d.network(nid)
	if n == nil {
		return fmt.Errorf("network id %s not found", nid)
	}
	// if the driver created the slave interface, delete it, otherwise leave it
	if ok := n.config.CreatedSlaveLink; ok {
		// if the interface exists, only delete if it matches iface.vlan or dummy.net_id naming
		if ok := parentExists(n.config.Parent); ok {
			// only delete the link if it is named the net_id
			if n.config.Parent == getDummyName(stringid.TruncateID(nid)) {
				err := delDummyLink(n.config.Parent)
				if err != nil {
					logrus.Debugf("link %s was not deleted, continuing the delete network operation: %v",
						n.config.Parent, err)
				}
			} else {
				// only delete the link if it matches iface.vlan naming
				err := delVlanLink(n.config.Parent)
				if err != nil {
					logrus.Debugf("link %s was not deleted, continuing the delete network operation: %v",
						n.config.Parent, err)
				}
			}
		}
	}
	for _, ep := range n.endpoints {
		if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil {
			if err := ns.NlHandle().LinkDel(link); err != nil {
				logrus.WithError(err).Warnf("Failed to delete interface (%s)'s link on endpoint (%s) delete", ep.srcName, ep.id)
			}
		}

		if err := d.storeDelete(ep); err != nil {
			logrus.Warnf("Failed to remove ipvlan endpoint %.7s from store: %v", ep.id, err)
		}
	}
	// delete the *network
	d.deleteNetwork(nid)
	// delete the network record from persistent cache
	err := d.storeDelete(n.config)
	if err != nil {
		return fmt.Errorf("error deleting deleting id %s from datastore: %v", nid, err)
	}
	return nil
}
403841
func (ac *APIController) NetworkDelete(network *contivModel.Network) error {
	log.Infof("Received NetworkDelete: %+v", network)

	// Find the tenant
	tenant := contivModel.FindTenant(network.TenantName)
	if tenant == nil {
		return core.Errorf("Tenant not found")
	}

	// if the network has associated epgs, fail the delete
	epgCount := len(network.LinkSets.EndpointGroups)
	if epgCount != 0 {
		return core.Errorf("cannot delete %s has %d endpoint groups",
			network.NetworkName, epgCount)
	}

	svcCount := len(network.LinkSets.Servicelbs)
	if svcCount != 0 {
		return core.Errorf("cannot delete %s has %d services ",
			network.NetworkName, svcCount)
	}

	// In swarm-mode work-flow, if this is mapped to a docker network, reject delete
	if master.GetClusterMode() == core.SwarmMode {
		docknet, err := docknet.GetDocknetState(network.TenantName, network.NetworkName, "")
		if err == nil {
			return fmt.Errorf("cannot delete network %s mapped to docker network %s",
				network.NetworkName, docknet.DocknetUUID)
		}
		if !strings.Contains(strings.ToLower(err.Error()), "key not found") {
			log.Errorf("Error getting docknet state for %s.%s. (retval = %s)",
				network.TenantName, network.NetworkName, err.Error())
			return err
		}
		log.Infof("No docknet state for %s.%s. (retval = %s)",
			network.TenantName, network.NetworkName, err.Error())
	}

	// Remove link
	modeldb.RemoveLinkSet(&tenant.LinkSets.Networks, network)

	// Get the state driver
	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		return err
	}

	// Delete the network
	networkID := network.NetworkName + "." + network.TenantName
	err = master.DeleteNetworkID(stateDriver, networkID)
	if err != nil {
		log.Errorf("Error deleting network %s. Err: %v", network.NetworkName, err)
		return err
	}

	// Save the tenant too since we removed the links
	return tenant.Write()
}
225848
func (r Network_SecurityGroup) DetachNetworkComponents(networkComponentIds []int) (resp datatypes.Network_SecurityGroup_Request, err error) {
	params := []interface{}{
		networkComponentIds,
	}
	err = r.Session.DoRequest("SoftLayer_Network_SecurityGroup", "detachNetworkComponents", params, &r.Options, &resp)
	return
}
739756
func Network() (c *NetworkController) {
	return &NetworkController{
		List:       networkList,
		New:        networkNew,
		Create:     networkCreate,
		Delete:     networkDelete,
		Disconnect: networkDisconnect,
		Detail:     networkDetail,
		Raw:        networkRaw,
	}
}