// extractPortsIDParts parses the given ports global key and extracts
// its parts.
327815
func extractPortsIDParts(globalKey string) ([]string, error) {
	if parts := portsIDRe.FindStringSubmatch(globalKey); len(parts) == 3 {
		return parts, nil
	}
	return nil, errors.NotValidf("ports document key %q", globalKey)
}
1240211
func (e *ADLDAPInterface) ExtractMembers(ldapGroupUID string) ([]*ldap.Entry, error) {
	// if we already have it cached, return the cached value
	if members, present := e.ldapGroupToLDAPMembers[ldapGroupUID]; present {
		return members, nil
	}

	// This happens in cases where we did not list out every group.  In that case, we're going to be asked about specific groups.
	usersInGroup := []*ldap.Entry{}

	// check for all users with ldapGroupUID in any of the allowed member attributes
	for _, currAttribute := range e.groupMembershipAttributes {
		currQuery := ldaputil.LDAPQueryOnAttribute{LDAPQuery: e.userQuery, QueryAttribute: currAttribute}

		searchRequest, err := currQuery.NewSearchRequest(ldapGroupUID, e.requiredUserAttributes())
		if err != nil {
			return nil, err
		}

		currEntries, err := ldaputil.QueryForEntries(e.clientConfig, searchRequest)
		if err != nil {
			return nil, err
		}

		for _, currEntry := range currEntries {
			if !isEntryPresent(usersInGroup, currEntry) {
				usersInGroup = append(usersInGroup, currEntry)
			}
		}
	}

	e.ldapGroupToLDAPMembers[ldapGroupUID] = usersInGroup

	return usersInGroup, nil
}
1315519
func (container *Container) ServicePortIndex(port int) (int, error) {
	if container.PortMappings == nil || len(*container.PortMappings) == 0 {
		return 0, errors.New("The container does not contain any port mappings to search")
	}

	// step: iterate and find the port
	for index, containerPort := range *container.PortMappings {
		if containerPort.ContainerPort == port {
			return index, nil
		}
	}

	// step: we didn't find the port in the mappings
	return 0, fmt.Errorf("The container port %d was not found in the container port mappings", port)
}
955935
func (f Firewall) ClosePorts(ctx context.ProviderCallContext, rules []network.IngressRule) error {
	groupName := f.globalGroupName()
	return f.closePortsOnList(ctx, f.client.ComposeName(groupName), rules)
}
292874
func splitPort(port string) (local, remote string) {
	parts := strings.Split(port, ":")
	if len(parts) == 2 {
		return parts[0], parts[1]
	}

	return parts[0], parts[0]
}
908983
func ParsePort(s string) (p Port, err error) {
	if strings.Contains(s, ":") {
		return portFromHostContainer(s)
	}

	var port int
	port, err = toPort(s)
	if err != nil {
		return
	}
	p.Host = port
	p.Container = port
	return
}
51277
func extractHexAddresses(s string) ([]string, []uint64) {
	hexStrings := hexNumberRE.FindAllString(s, -1)
	var ids []uint64
	for _, s := range hexStrings {
		if id, err := strconv.ParseUint(s, 0, 64); err == nil {
			ids = append(ids, id)
		} else {
			// Do not expect any parsing failures due to the regexp matching.
			panic("failed to parse hex value:" + s)
		}
	}
	return hexStrings, ids
}
248444
func (r Resources) Ports() []string {
	if r.PortRanges == "" || r.PortRanges == "[]" {
		return []string{}
	}

	rhs := strings.Split(r.PortRanges, "[")[1]
	lhs := strings.Split(rhs, "]")[0]

	yports := []string{}

	mports := strings.Split(lhs, ",")
	for _, port := range mports {
		tmp := strings.TrimSpace(port)
		pz := strings.Split(tmp, "-")
		lo, err := strconv.Atoi(pz[0])
		if err != nil {
			logging.Error.Println(err)
			continue
		}
		hi, err := strconv.Atoi(pz[1])
		if err != nil {
			logging.Error.Println(err)
			continue
		}

		for t := lo; t <= hi; t++ {
			yports = append(yports, strconv.Itoa(t))
		}
	}
	return yports
}
901794
func (m *Machine) OpenedPorts(subnetID string) (*Ports, error) {
	ports, err := getPorts(m.st, m.Id(), subnetID)
	if err != nil && !errors.IsNotFound(err) {
		return nil, errors.Trace(err)
	}
	return ports, nil
}
1357905
func AllContainerPorts(containers ...corev1.Container) []corev1.ContainerPort {
	var ports []corev1.ContainerPort
	for _, container := range containers {
		ports = append(ports, container.Ports...)
	}
	sort.Sort(sortablePorts(ports))
	return ports
}
721265
func (p *podRouter) getPortMappings(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	env, err := p.backend.CmdListPortMappings(vars["id"])
	if err != nil {
		return err
	}

	return env.WriteJSON(w, http.StatusOK)
}
1276074
func (zk *zkf) RemoveTenantExports(tenantID string) error {
	logger := plog.WithField("tenantid", tenantID)

	// get the root-based connection to delete the service endpoints
	rootconn, err := zzk.GetLocalConnection("/")
	if err != nil {
		logger.WithError(err).Debug("Could not acquire a root-based connection to delete the tenant's exported endpoints in zookeeper")
		return err
	}

	// delete the exports
	if err := zkr.DeleteExports(rootconn, tenantID); err != nil {
		logger.WithError(err).Debug("Could not delete the tenant's exported endpoints in zookeeper")
		return err
	}
	logger.Debug("Deleted the tenant's exported endpoints in zookeeper")
	return nil
}
1298688
func (docker *Docker) ServicePortIndex(port int) (int, error) {
	if docker.PortMappings == nil || len(*docker.PortMappings) == 0 {
		return 0, errors.New("The docker does not contain any port mappings to search")
	}

	// step: iterate and find the port
	for index, containerPort := range *docker.PortMappings {
		if containerPort.ContainerPort == port {
			return index, nil
		}
	}

	// step: we didn't find the port in the mappings
	return 0, fmt.Errorf("The docker port %d was not found in the container port mappings", port)
}
1175760
func (o *RedundancyGroup) VsgRedundantPorts(info *bambou.FetchingInfo) (VsgRedundantPortsList, *bambou.Error) {

	var list VsgRedundantPortsList
	err := bambou.CurrentSession().FetchChildren(o, VsgRedundantPortIdentity, &list, info)
	return list, err
}
127252
func infinibandPorts(infinibandPath, device string) ([]string, error) {
	ports, err := filepath.Glob(filepath.Join(infinibandPath, device, "ports/*"))
	if err != nil {
		return nil, err
	}

	if len(ports) < 1 {
		log.Debugf("Unable to detect ports for %s", device)
		err = errInfinibandNoPortsFound
		return nil, err
	}

	// Extract just the filenames which equates to the port numbers.
	for i, port := range ports {
		ports[i] = filepath.Base(port)
	}

	return ports, nil
}
390277
func (c *Client) GetPorts(ctx context.Context) ([]int, error) {
	var ports []int

	req, err := c.NewRequest("GET", portsPath, nil, nil)
	if err != nil {
		return nil, err
	}

	if err := c.Do(ctx, req, &ports); err != nil {
		return nil, err
	}

	return ports, nil
}
264960
func ExtractHostname(addr string) (string, error) {
	u, err := url.Parse(addr)
	if err != nil {
		return "", err
	}
	return stripPort(u.Host), nil
}