// RunExport exports a Docker context
179805
func RunExport(dockerCli command.Cli, opts *ExportOptions) error {
	if err := validateContextName(opts.ContextName); err != nil && opts.ContextName != command.DefaultContextName {
		return err
	}
	ctxMeta, err := dockerCli.ContextStore().GetMetadata(opts.ContextName)
	if err != nil {
		return err
	}
	if !opts.Kubeconfig {
		reader := store.Export(opts.ContextName, dockerCli.ContextStore())
		defer reader.Close()
		return writeTo(dockerCli, reader, opts.Dest)
	}
	kubernetesEndpointMeta := kubernetes.EndpointFromContext(ctxMeta)
	if kubernetesEndpointMeta == nil {
		return fmt.Errorf("context %q has no kubernetes endpoint", opts.ContextName)
	}
	kubernetesEndpoint, err := kubernetesEndpointMeta.WithTLSData(dockerCli.ContextStore(), opts.ContextName)
	if err != nil {
		return err
	}
	kubeConfig := kubernetesEndpoint.KubernetesConfig()
	rawCfg, err := kubeConfig.RawConfig()
	if err != nil {
		return err
	}
	data, err := clientcmd.Write(rawCfg)
	if err != nil {
		return err
	}
	return writeTo(dockerCli, bytes.NewBuffer(data), opts.Dest)
}
371818
func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store) hyperimage.Exporter {
	return &tarexporter{
		is: is,
		ls: ls,
		rs: rs,
	}
}
598455
func (f *NWFilterBinding) GetPortDev() (string, error) {
	if C.LIBVIR_VERSION_NUMBER < 4005000 {
		return "", makeNotImplementedError("virNWFilterBindingGetPortDev")
	}
	var err C.virError
	result := C.virNWFilterBindingGetPortDevWrapper(f.ptr, &err)
	if result == nil {
		return "", makeError(&err)
	}
	name := C.GoString(result)
	C.free(unsafe.Pointer(result))
	return name, nil
}
2151
func (op *DTGPIOModuleOpenPin) gpioUnexport() error {
	s := strconv.FormatInt(int64(op.gpioLogical), 10)
	e := WriteStringToFile("/sys/class/gpio/unexport", s)
	if e != nil {
		return e
	}

	return nil
}
1246930
func (o *oracleInstance) OpenPorts(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error {
	if o.env.Config().FirewallMode() != config.FwInstance {
		return errors.Errorf(
			"invalid firewall mode %q for opening ports on instance",
			o.env.Config().FirewallMode(),
		)
	}

	return o.env.OpenPortsOnInstance(ctx, machineId, rules)
}
839932
func NewExportCommand(dockerCli command.Cli) *cobra.Command {
	var opts exportOptions

	cmd := &cobra.Command{
		Use:   "export [OPTIONS] CONTAINER",
		Short: "Export a container's filesystem as a tar archive",
		Args:  cli.ExactArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			opts.container = args[0]
			return runExport(dockerCli, opts)
		},
	}

	flags := cmd.Flags()

	flags.StringVarP(&opts.output, "output", "o", "", "Write to a file, instead of STDOUT")

	return cmd
}
639591
func processPorts(app marathon.Application, task marathon.Task, serverPort string) (int, error) {
	if len(serverPort) > 0 && !strings.HasPrefix(serverPort, "index:") {
		port, err := strconv.Atoi(serverPort)
		if err != nil {
			return 0, err
		}

		if port <= 0 {
			return 0, fmt.Errorf("explicitly specified port %d must be greater than zero", port)
		} else if port > 0 {
			return port, nil
		}
	}

	ports := retrieveAvailablePorts(app, task)
	if len(ports) == 0 {
		return 0, errors.New("no port found")
	}

	portIndex := 0
	if strings.HasPrefix(serverPort, "index:") {
		split := strings.SplitN(serverPort, ":", 2)
		index, err := strconv.Atoi(split[1])
		if err != nil {
			return 0, err
		}

		if index < 0 || index > len(ports)-1 {
			return 0, fmt.Errorf("index %d must be within range (0, %d)", index, len(ports)-1)
		}
		portIndex = index
	}
	return ports[portIndex], nil
}
621087
func (b UDP) SetSourcePort(port uint16) {
	binary.BigEndian.PutUint16(b[udpSrcPort:], port)
}
835056
func WithPort(port string) NewServerOpt {
	return func(srv *http.Server) {
		srv.Addr = ":" + port
	}
}
1048893
func (inst *environInstance) OpenPorts(ctx context.ProviderCallContext, machineID string, rules []network.IngressRule) error {
	return inst.changeIngressRules(ctx, true, rules)
}
207888
func (r DockerImageReference) RegistryHostPort(insecure bool) (string, string) {
	registryHost := r.AsV2().DockerClientDefaults().Registry
	if strings.Contains(registryHost, ":") {
		hostname, port, _ := net.SplitHostPort(registryHost)
		return hostname, port
	}
	if insecure {
		return registryHost, "80"
	}
	return registryHost, "443"
}
933409
func (container *Container) ExposePort(portMapping PortMapping) *Container {
	if container.PortMappings == nil {
		container.EmptyPortMappings()
	}

	portMappings := *container.PortMappings
	portMappings = append(portMappings, portMapping)
	container.PortMappings = &portMappings

	return container
}
1033816
func ParsePorts(ssport string) ([]ListenTarget, error) {
	ret := []ListenTarget{}
	for _, pairstring := range strings.Split(ssport, ";") {
		pair := strings.Split(pairstring, "=")
		port, err := strconv.ParseUint(pair[1], 10, 0)
		if err != nil {
			return nil, fmt.Errorf("error: Failed to parse '%s'", pairstring)
		}
		ret = append(ret, ListenTarget{pair[0], uintptr(port)})
	}
	return ret, nil
}
1038503
func (s *SQL) runExecer() (interface{}, error) {
	ctx := context.Background()
	result, err := s.Config.Execer.ExecContext(ctx, s.Config.Query, s.Config.Params...)
	if err != nil {
		return nil, err
	}

	ok, err := s.Config.ExecerResultHandler(result)
	if err != nil {
		return nil, err
	}

	if !ok {
		return nil, fmt.Errorf("userland exec result handler returned false")
	}

	return nil, nil
}
166954
func ProjectPort(p project.APIProject, c *cli.Context) error {
	if len(c.Args()) != 2 {
		return cli.NewExitError("Please pass arguments in the form: SERVICE PORT", 1)
	}

	index := c.Int("index")
	protocol := c.String("protocol")
	serviceName := c.Args()[0]
	privatePort := c.Args()[1]

	port, err := p.Port(context.Background(), index, protocol, serviceName, privatePort)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	fmt.Println(port)
	return nil
}
1287739
func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
	if len(args) != 1 {
		return cmdutil.UsageError(cmd, "We accept only this format: explain RESOURCE")
	}

	client, err := f.Client()
	if err != nil {
		return err
	}

	recursive := cmdutil.GetFlagBool(cmd, "recursive")
	apiV := cmdutil.GetFlagString(cmd, "api-version")

	mapper, _ := f.Object()
	// TODO: After we figured out the new syntax to separate group and resource, allow
	// the users to use it in explain (kubectl explain <group><syntax><resource>).
	// Refer to issue #16039 for why we do this. Refer to PR #15808 that used "/" syntax.
	inModel, fieldsPath, err := kubectl.SplitAndParseResourceRequest(args[0], mapper)
	if err != nil {
		return err
	}

	// TODO: We should deduce the group for a resource by discovering the supported resources at server.
	gvk, err := mapper.KindFor(inModel)
	if err != nil {
		return err
	}

	if len(apiV) == 0 {
		groupMeta, err := latest.Group(gvk.Group)
		if err != nil {
			return err
		}
		apiV = groupMeta.GroupVersion.String()
	}
	swagSchema, err := kubectl.GetSwaggerSchema(apiV, client)
	if err != nil {
		return err
	}

	return kubectl.PrintModelDescription(inModel, fieldsPath, out, swagSchema, recursive)
}
631453
func (n *Network) PeerPort(p *Peer, portName PortName) uint16 {
	peerPorts := n.PortsByPeerID[p.ID()]
	Expect(peerPorts).NotTo(BeNil())
	return peerPorts[portName]
}