// ClosePorts implements Firewaller interface.
182767
func (c *neutronFirewaller) ClosePorts(ctx context.ProviderCallContext, rules []network.IngressRule) error {
	err := c.closePorts(ctx, c.closePortsInGroup, rules)
	if err != nil {
		common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
		return errors.Trace(err)
	}
	return nil
}
538858
func (c *Client) Close() error {
	if cl, ok := c.sto.(io.Closer); ok {
		return cl.Close()
	}
	if c := c.HTTPClient(); c != nil {
		switch t := c.Transport.(type) {
		case *http.Transport:
			t.CloseIdleConnections()
		case *http2.Transport:
			t.CloseIdleConnections()
		}
	}
	return nil
}
456029
func (i sigmaInstance) OpenPorts(ctx context.ProviderCallContext, machineID string, ports []network.IngressRule) error {
	return errors.NotImplementedf("OpenPorts")
}
472908
func (m *model) closeConns(devs []protocol.DeviceID, err error) {
	conns := make([]connections.Connection, 0, len(devs))
	m.pmut.Lock()
	for _, dev := range devs {
		if conn, ok := m.conn[dev]; ok {
			conns = append(conns, conn)
		}
	}
	m.pmut.Unlock()
	for _, conn := range conns {
		conn.Close(err)
	}
}
83760
func (lxd *lxdInstance) OpenPorts(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error {
	return fmt.Errorf("not implemented")
}
820832
func (s *InstanceNetworking) SetPorts(v []*InstancePortInfo) *InstanceNetworking {
	s.Ports = v
	return s
}
1132848
func (fw *Firewaller) flushGlobalPorts(rawOpen, rawClose []network.IngressRule) error {
	// Filter which ports are really to open or close.
	var toOpen, toClose []network.IngressRule
	for _, rule := range rawOpen {
		ruleName := rule.String()
		if fw.globalIngressRuleRef[ruleName] == 0 {
			toOpen = append(toOpen, rule)
		}
		fw.globalIngressRuleRef[ruleName]++
	}
	for _, rule := range rawClose {
		ruleName := rule.String()
		fw.globalIngressRuleRef[ruleName]--
		if fw.globalIngressRuleRef[ruleName] == 0 {
			toClose = append(toClose, rule)
			delete(fw.globalIngressRuleRef, ruleName)
		}
	}
	// Open and close the ports.
	if len(toOpen) > 0 {
		if err := fw.environFirewaller.OpenPorts(fw.cloudCallContext, toOpen); err != nil {
			// TODO(mue) Add local retry logic.
			return err
		}
		network.SortIngressRules(toOpen)
		logger.Infof("opened port ranges %v in environment", toOpen)
	}
	if len(toClose) > 0 {
		if err := fw.environFirewaller.ClosePorts(fw.cloudCallContext, toClose); err != nil {
			// TODO(mue) Add local retry logic.
			return err
		}
		network.SortIngressRules(toClose)
		logger.Infof("closed port ranges %v in environment", toClose)
	}
	return nil
}
555946
func (p *Ports) OpenPorts(portRange PortRange) (err error) {
	defer errors.DeferredAnnotatef(&err, "cannot open ports %s", portRange)

	if err = portRange.Validate(); err != nil {
		return errors.Trace(err)
	}
	ports := Ports{st: p.st, doc: p.doc, areNew: p.areNew}

	buildTxn := func(attempt int) ([]txn.Op, error) {
		if attempt > 0 {
			if err := checkModelActive(p.st); err != nil {
				return nil, errors.Trace(err)
			}
			if err := p.verifySubnetAliveWhenSet(); err != nil {
				return nil, errors.Trace(err)
			}
			if err = ports.Refresh(); errors.IsNotFound(err) {
				// No longer exists, we'll create it.
				if !ports.areNew {
					ports.areNew = true
				}
			} else if err != nil {
				return nil, errors.Trace(err)
			} else if ports.areNew {
				// Already created, we'll update it.
				ports.areNew = false
			}
		}

		// Check for conflicts with existing ports.
		for _, existingPorts := range p.doc.Ports {
			if err := existingPorts.CheckConflicts(portRange); err != nil {
				return nil, errors.Trace(err)
			} else if existingPorts == portRange {
				// Trying to open the same range for the same unit is
				// ignored, as we don't need to change the document
				// and hence its txn-revno and trigger unnecessary
				// watcher notifications.
				return nil, statetxn.ErrNoOperations
			}
		}

		ops := []txn.Op{
			assertModelActiveOp(p.st.ModelUUID()),
		}
		if ports.areNew {
			// Create a new document.
			assert := txn.DocMissing
			ops = append(ops, addPortsDocOps(p.st, &ports.doc, assert, portRange)...)
		} else {
			// Update an existing document.
			assert := bson.D{{"txn-revno", ports.doc.TxnRevno}}
			ops = append(ops, updatePortsDocOps(p.st, ports.doc, assert, portRange)...)
		}
		return ops, nil
	}
	// Run the transaction using the state transaction runner.
	if err = p.st.db().Run(buildTxn); err != nil {
		return errors.Trace(err)
	}
	// Mark object as created.
	p.areNew = false
	p.doc.Ports = append(p.doc.Ports, portRange)
	return nil
}
1267193
func RevertPorts(replacementPortsMap, originalPortsMap map[LocalPort]Closeable) {
	for k, v := range replacementPortsMap {
		// Only close newly opened local ports - leave ones that were open before this update
		if originalPortsMap[k] == nil {
			klog.V(2).Infof("Closing local port %s", k.String())
			v.Close()
		}
	}
}
1268285
func (c *Conn) Close() error {
	return c.opError(opClose, c.fd.Close())
}
1198588
func (f Firewall) ClosePortsOnInstance(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error {
	// fetch the group name based on the machine id provided
	groupName := f.machineGroupName(machineId)
	return f.closePortsOnList(ctx, f.client.ComposeName(groupName), rules)
}
390104
func (s *SocketHub) Close() {
	if s.closed {
		return
	}
	s.closed = true
	close(s.closer)
}
1127117
func (cl *Client) Close() {
	cl.lock()
	defer cl.unlock()
	cl.closed.Set()
	cl.eachDhtServer(func(s *dht.Server) { s.Close() })
	cl.closeSockets()
	for _, t := range cl.torrents {
		t.close()
	}
	for _, f := range cl.onClose {
		f()
	}
	cl.event.Broadcast()
}
1296157
func (memif *Memif) closeQueues() {
	log.WithFields(logger.Fields{
		"ifName":   memif.IfName,
		"Rx-count": len(memif.rxQueueBufs),
		"Tx-count": len(memif.txQueueBufs),
	}).Debug("Closing Rx/Tx queues.")

	// Close interrupt channels.
	for _, ch := range memif.queueIntCh {
		close(ch)
	}
	memif.queueIntCh = nil

	// Deallocate Rx/Tx packet buffers.
	for _, pb := range memif.rxQueueBufs {
		C.free(unsafe.Pointer(pb.buffers))
	}
	memif.rxQueueBufs = nil
	for _, pb := range memif.txQueueBufs {
		C.free(unsafe.Pointer(pb.buffers))
	}
	memif.txQueueBufs = nil
}
1236801
func Close() {
	mu.Lock()
	defer mu.Unlock()

	if portfile != "" {
		os.Remove(portfile)
		portfile = ""
	}
	if listener != nil {
		listener.Close()
	}
}
978526
func (t *UdpTransport) Close() error {
	close(t.requestQueue)
	err := t.conn.Close()
	if err != nil {
		return err
	}
	return nil
}
1048893
func (inst *environInstance) OpenPorts(ctx context.ProviderCallContext, machineID string, rules []network.IngressRule) error {
	return inst.changeIngressRules(ctx, true, rules)
}