// DeleteExports deletes all export data for a tenant id
964561
func DeleteExports(conn client.Connection, tenantID string) error {
	pth := path.Join("/net/export", tenantID)
	logger := plog.WithFields(log.Fields{
		"tenantid": tenantID,
		"zkpath":   pth,
	})

	if err := conn.Delete(pth); err == client.ErrNoNode {
		logger.Debug("No exports for tenant id")
		return nil
	} else if err != nil {
		logger.WithError(err).Debug("Could not delete exports for tenant id")
		return err
	}

	logger.Debug("Removed exports for tenant id")
	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()
}
1277970
func (m *ExpirationManager) deleteEntry(ctx context.Context, le *leaseEntry) error {
	view := m.leaseView(le.namespace)
	if err := view.Delete(ctx, le.LeaseID); err != nil {
		return errwrap.Wrapf("failed to delete lease entry: {{err}}", err)
	}
	return nil
}
858640
func (c Client) DeleteTransmission(age int64, status contract.TransmissionStatus) error {
	conn := c.Pool.Get()
	defer conn.Close()

	currentTime := db.MakeTimestamp()
	end := currentTime - age

	objects, err := getObjectsByRangeFilter(conn, db.Transmission+":modified", db.Transmission+":status:"+fmt.Sprintf("%s", status), 0, int(end))
	if err != nil {
		return err
	}
	transmissions, err := unmarshalTransmissions(objects)
	if err != nil {
		return err
	}

	for _, transmission := range transmissions {
		err = deleteTransmission(conn, transmission.ID)
		if err != nil {
			return err
		}
	}
	return err
}
421701
func (i *Instance) DeletePortFromPortSet(contextID string, port string) error {
	portSetName := i.getPortSet(contextID)
	if portSetName == "" {
		return fmt.Errorf("unable to get portset for contextID %s", contextID)
	}

	ips := ipset.IPSet{
		Name: portSetName,
	}

	if _, err := strconv.Atoi(port); err != nil {
		return fmt.Errorf("invalid port: %s", err)
	}

	if err := ips.Del(port); err != nil {
		return fmt.Errorf("unable to delete port from portset: %s", err)
	}

	return nil
}
625405
func (cli *Client) ContainerExport(ctx context.Context, containerID string) (io.ReadCloser, error) {
	serverResp, err := cli.get(ctx, "/containers/"+containerID+"/export", url.Values{}, nil)
	if err != nil {
		return nil, err
	}

	return serverResp.body, nil
}
1331379
func DeleteExtension(tx Tx, id string) error {
	e := tx.get(tableExtension, id)
	if e == nil {
		return ErrNotExist
	}

	resources, err := FindResources(tx, ByKind(e.(extensionEntry).Annotations.Name))
	if err != nil {
		return err
	}

	if len(resources) != 0 {
		return errors.New("cannot delete extension because objects of this type exist in the data store")
	}

	return tx.delete(tableExtension, id)
}
1149500
func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceEndpoint) {
	for _, epSvcPair := range connectionMap {
		if svcInfo, ok := proxier.serviceMap[epSvcPair.ServicePortName]; ok && svcInfo.GetProtocol() == v1.ProtocolUDP {
			endpointIP := utilproxy.IPPart(epSvcPair.Endpoint)
			nodePort := svcInfo.GetNodePort()
			var err error
			if nodePort != 0 {
				err = conntrack.ClearEntriesForPortNAT(proxier.exec, endpointIP, nodePort, v1.ProtocolUDP)
			} else {
				err = conntrack.ClearEntriesForNAT(proxier.exec, svcInfo.ClusterIPString(), endpointIP, v1.ProtocolUDP)
			}
			if err != nil {
				klog.Errorf("Failed to delete %s endpoint connections, error: %v", epSvcPair.ServicePortName.String(), err)
			}
			for _, extIP := range svcInfo.ExternalIPStrings() {
				err := conntrack.ClearEntriesForNAT(proxier.exec, extIP, endpointIP, v1.ProtocolUDP)
				if err != nil {
					klog.Errorf("Failed to delete %s endpoint connections for externalIP %s, error: %v", epSvcPair.ServicePortName.String(), extIP, err)
				}
			}
			for _, lbIP := range svcInfo.LoadBalancerIPStrings() {
				err := conntrack.ClearEntriesForNAT(proxier.exec, lbIP, endpointIP, v1.ProtocolUDP)
				if err != nil {
					klog.Errorf("Failed to delete %s endpoint connections for LoabBalancerIP %s, error: %v", epSvcPair.ServicePortName.String(), lbIP, err)
				}
			}
		}
	}
}
96140
func (c *Client) IsExported(
	ctx context.Context, name string) (bool, int, error) {

	export, err := c.GetExportByName(ctx, name)
	if err != nil {
		return false, 0, err
	}
	if export == nil {
		return false, 0, nil
	}
	return true, export.ID, nil
}
754638
func (n *upnpNAT) DeletePortMapping(protocol string, externalPort, internalPort int) (err error) {

	message := "<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">\r\n" +
		"<NewRemoteHost></NewRemoteHost><NewExternalPort>" + strconv.Itoa(externalPort) +
		"</NewExternalPort><NewProtocol>" + strings.ToUpper(protocol) + "</NewProtocol>" +
		"</u:DeletePortMapping>"

	response, err := soapRequest(n.serviceURL, "DeletePortMapping", message)
	if err != nil {
		return
	}

	// TODO: check response to see if the port was deleted
	// log.Println(message, response)
	_ = response
	return
}
227372
func (vrsConnection *VRSConnection) RemovePortFromAlubr0(portName string) error {

	condition := libovsdb.NewCondition("name", "==", portName)
	selectOp := libovsdb.Operation{
		Op:    "select",
		Table: "Port",
		Where: []interface{}{condition},
	}

	selectOperation := []libovsdb.Operation{selectOp}
	reply, err := vrsConnection.ovsdbClient.Transact(OvsDBName, selectOperation...)
	if err != nil || len(reply) != 1 || len(reply[0].Rows) != 1 {
		return fmt.Errorf("Problem selecting row in the OVSDB Port table for alubr0")
	}

	// Obtain Port table OVSDB row corresponding to the port name
	ovsdbRow := reply[0].Rows[0]
	portUUID := ovsdbRow["_uuid"]
	portUUIDStr := fmt.Sprintf("%v", portUUID)
	portUUIDNew := util.SplitUUIDString(portUUIDStr)

	condition = libovsdb.NewCondition("name", "==", portName)
	deleteOp := libovsdb.Operation{
		Op:    "delete",
		Table: "Port",
		Where: []interface{}{condition},
	}

	// Deleting a Bridge row in Bridge table requires mutating the open_vswitch table.
	mutateUUID := []libovsdb.UUID{libovsdb.UUID{portUUIDNew}}
	mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
	mutation := libovsdb.NewMutation("ports", "delete", mutateSet)
	condition = libovsdb.NewCondition("name", "==", bridgeName)

	// simple mutate operation
	mutateOp := libovsdb.Operation{
		Op:        "mutate",
		Table:     "Bridge",
		Mutations: []interface{}{mutation},
		Where:     []interface{}{condition},
	}

	operations := []libovsdb.Operation{deleteOp, mutateOp}
	reply, err = vrsConnection.ovsdbClient.Transact(OvsDBName, operations...)
	if err != nil || len(reply) < len(operations) {
		return fmt.Errorf("Problem mutating row in the OVSDB Bridge table for alubr0")
	}

	return nil
}
1069869
func (u *UPnP) DeletePortMapping(port uint16) error {
	u.forwardedPortsMtx.Lock()
	defer u.forwardedPortsMtx.Unlock()

	if _, exists := u.forwardedPorts[port]; !exists {
		return fmt.Errorf("port %d is not being forwarded", port)
	}

	if err := u.device.Clear(port); err != nil {
		return err
	}

	delete(u.forwardedPorts, port)

	return nil
}
654189
func (s *DescribeContinuousExportsInput) SetExportIds(v []*string) *DescribeContinuousExportsInput {
	s.ExportIds = v
	return s
}
1078325
func (sw *OvsSwitch) DeletePort(epOper *drivers.OperEndpointState, skipVethPair bool) error {

	if epOper.VtepIP != "" {
		return nil
	}

	// Get the OVS port name
	ovsPortName := getOvsPortName(epOper.PortName, skipVethPair)

	// Get the openflow port number for the interface and remove from ofnet
	ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName)
	if err == nil {
		if sw.ofnetAgent != nil {
			err = sw.ofnetAgent.RemoveLocalEndpoint(ofpPort)
		}
	} else {
		if sw.ofnetAgent != nil {
			var tenantName string
			netParts := strings.Split(epOper.NetID, ".")
			if len(netParts) == 2 {
				tenantName = netParts[1]
			} else {
				tenantName = "default"
			}
			epID := sw.ofnetAgent.GetEndpointIdByIpVrf(net.ParseIP(epOper.IPAddress), tenantName)
			err = sw.ofnetAgent.RemoveLocalEndpointByID(epID)
		}
	}
	if err != nil {
		log.Errorf("Error removing endpoint %+v from ofnet. Err: %v", epOper, err)
		// continue with further cleanup
	}

	// Delete it from ovsdb
	err = sw.ovsdbDriver.DeletePort(ovsPortName)
	if err != nil {
		log.Errorf("Error deleting port %s from OVS. Err: %v", ovsPortName, err)
		// continue with further cleanup
	}

	// Delete the Veth pairs if required
	if useVethPair && !skipVethPair {
		// Delete a Veth pair
		verr := deleteVethPair(ovsPortName, epOper.PortName)
		if verr != nil {
			log.Errorf("Error deleting veth pairs. Err: %v", verr)
			return verr
		}
	}

	return err
}
1359416
func RemoveExtensions(migrationsDir string, db *sqlx.DB) error {
	extensions, err := getExtensions(migrationsDir)
	if err != nil {
		return err
	}
	var retErr error
	for _, extension := range extensions {
		_, err := db.Exec(fmt.Sprintf("DROP EXTENSION IF EXISTS %v", extension))
		if err != nil && retErr == nil {
			retErr = err
		}
	}
	return retErr
}
711098
func (s *UsageService) NewDeleteTrafficTypeParams(id string) *DeleteTrafficTypeParams {
	p := &DeleteTrafficTypeParams{}
	p.p = make(map[string]interface{})
	p.p["id"] = id
	return p
}
751300
func (c *Client) SetExportClientsByID(
	ctx context.Context, id int, clients ...string) error {

	return api.ExportUpdate(ctx, c.API, &api.Export{ID: id, Clients: &clients})
}