You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: environs.go
    path of file: ./repos/juju/provider/dummy
    
    the code of the file until where you have to start completion: // Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package dummy

import (
	stdcontext "context"
	"crypto/tls"
	"fmt"
	"net"
	"net/http/httptest"
	"os"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"time"

	"github.com/juju/clock"
	"github.com/juju/errors"
	"github.com/juju/jsonschema"
	"github.com/juju/loggo"
	mgotesting "github.com/juju/mgo/v3/testing"
	"github.com/juju/names/v5"
	"github.com/juju/pubsub/v2"
	"github.com/juju/retry"
	"github.com/juju/schema"
	gitjujutesting "github.com/juju/testing"
	jc "github.com/juju/testing/checkers"
	"github.com/juju/version/v2"
	"github.com/juju/worker/v
    
func (inst *dummyInstance) ClosePorts(ctx context.ProviderCallContext, machineId string, rules firewall.IngressRules) error {
	defer delay()
	if inst.firewallMode != config.FwInstance {
		return fmt.Errorf("invalid firewall mode %q for closing ports on instance",
			inst.firewallMode)
	}
	if inst.machineId != machineId {
		panic(fmt.Errorf("ClosePorts with mismatched machine id, expected %s got %s", inst.machineId, machineId))
	}
	inst.state.mu.Lock()
	defer inst.state.mu.Unlock()
	if err := inst.checkBroken("ClosePorts"); err != nil {
		return err
	}
	inst.state.ops <- OpClosePorts{
		Env:        inst.state.name,
		MachineId:  machineId,
		InstanceId: inst.Id(),
		Rules:      rules,
	}

	var updatedRules firewall.IngressRules

nextRule:
	for _, existingRule := range inst.rules {
		for _, removeRule := range rules {
			if removeRule.PortRange != existingRule.PortRange {
				continue // port not matched
			}

			existingRule.SourceCIDRs = existingRule.SourceCIDRs.Difference(removeRule.SourceCIDRs)

			// If the rule is empty, OR the entry to be removed
			// has no CIDRs, drop the rule.
			if len(existingRule.SourceCIDRs) == 0 || len(removeRule.SourceCIDRs) == 0 {
				continue nextRule // drop existing rule
			}
		}

		updatedRules = append(updatedRules, existingRule)
	}
	inst.rules = updatedRules
	return nil
}