// GetServiceImports retrieves service endpoints whose purpose is "import"
342640
func (s *Service) GetServiceImports() []ServiceEndpoint {
	result := []ServiceEndpoint{}

	if s.Endpoints != nil {
		for _, ep := range s.Endpoints {
			if ep.Purpose == "import" || ep.Purpose == "import_all" {
				result = append(result, ep)
			}
		}
	}

	return result
}
274447
func getServices(e encoder, adapter PanamaxAdapter) (int, string) {
	data, err := adapter.GetServices()
	if err != nil {
		return sanitizeErrorCode(err.Code), err.Message
	}

	return http.StatusOK, e.Encode(data)
}
940764
func parseAccountImports(v interface{}, acc *Account, errors, warnings *[]error) ([]*importStream, []*importService, error) {
	// This should be an array of objects/maps.
	tk, v := unwrapValue(v)
	ims, ok := v.([]interface{})
	if !ok {
		return nil, nil, &configErr{tk, fmt.Sprintf("Imports should be an array, got %T", v)}
	}

	var services []*importService
	var streams []*importStream

	for _, v := range ims {
		// Should have stream or service
		stream, service, err := parseImportStreamOrService(v, errors, warnings)
		if err != nil {
			*errors = append(*errors, err)
			continue
		}
		if service != nil {
			service.acc = acc
			services = append(services, service)
		}
		if stream != nil {
			stream.acc = acc
			streams = append(streams, stream)
		}
	}
	return streams, services, nil
}
1023301
func (r Resource_Metadata) GetServiceResources() (resp []datatypes.Container_Resource_Metadata_ServiceResource, err error) {
	err = r.Session.DoRequest("SoftLayer_Resource_Metadata", "getServiceResources", nil, &r.Options, &resp)
	return
}
1149475
func (c *Client) GetExports(ctx context.Context) (ExportList, error) {
	return api.ExportsList(ctx, c.API)
}
837647
func syncServicePublicPorts(conn client.Connection, tx client.Transaction, request ServiceRegistrySyncRequest) error {
	logger := plog.WithField("serviceid", request.ServiceID)
	pth := "/net/pub"

	for _, pubKey := range request.PortsToDelete {
		addrpth := path.Join(pth, pubKey.HostID, pubKey.PortAddress)
		addrLogger := logger.WithFields(log.Fields{
			"hostid":      pubKey.HostID,
			"portaddress": pubKey.PortAddress,
			"zkpath":      addrpth,
		})
		tx.Delete(addrpth)
		addrLogger.Debug("Deleted public port address")
	}

	// Build a list of unique parent directory paths which need to be created
	pathsToBuild := map[string]string{}
	for pubKey, _ := range request.PortsToPublish {
		if _, ok := pathsToBuild[pubKey.HostID]; ok {
			continue
		}
		hostpth := path.Join(pth, pubKey.HostID)
		ok, err := conn.Exists(hostpth)
		if err != nil {
			return &RegistryError{
				Action:  "sync",
				Path:    hostpth,
				Message: "could not read parent path for public port address",
			}
		} else if !ok {
			pathsToBuild[pubKey.HostID] = hostpth
		}
	}

	// Build any missing parent directory paths
	if err := buildParentPaths(logger, conn, pathsToBuild); err != nil {
		err.Message = "could not register public port address"
		return err
	}

	for pubKey, pubValue := range request.PortsToPublish {
		addrpth := path.Join(pth, pubKey.HostID, pubKey.PortAddress)
		addrLogger := logger.WithFields(log.Fields{
			"hostid":      pubKey.HostID,
			"portaddress": pubKey.PortAddress,
			"zkpath":      addrpth,
		})

		ok, err := conn.Exists(addrpth)
		if err != nil {
			addrLogger.WithError(err).Debug("skipped public port address because of an unexpected error")
			return &RegistryError{
				Action:  "sync",
				Path:   addrpth,
				Message: "could not register public port address",
			}
		}

		publicPort := pubValue
		if !ok {
			publicPort.SetVersion(nil)
			tx.Create(addrpth, &publicPort)
			addrLogger.Debug("Created public port address")
		} else {
			existingPub := &PublicPort{}
			if err := conn.Get(addrpth, existingPub); err != nil {
				return &RegistryError{
					Action:  "sync",
					Path:    addrpth,
					Message: "could not read current public port address",
				}
			}
			publicPort.SetVersion(existingPub.Version())
			tx.Set(addrpth, &publicPort)
			addrLogger.Debug("Updated public port address")
		}
	}

	logger.Debug("Updated transaction to sync public ports for service")
	return nil
}
851929
func (s *Server) GetServiceTemplates(unused struct{}, response *map[string]servicetemplate.ServiceTemplate) error  {
	templates, err := s.f.GetServiceTemplates(s.context())
	if err != nil {
		return err
	}
	*response = templates
	return nil
}
967084
func getService(lbClientPort string, serviceID string, instanceID int) (*service.Service, string, string, error) {
	client, err := node.NewLBClient(lbClientPort)
	if err != nil {
		glog.Errorf("Could not create a client to endpoint: %s, %s", lbClientPort, err)
		return nil, "", "", err
	}
	defer client.Close()

	var evaluatedServiceResponse node.EvaluateServiceResponse
	err = client.GetEvaluatedService(node.EvaluateServiceRequest{serviceID, instanceID}, &evaluatedServiceResponse)

	if err != nil {
		glog.Errorf("Error getting service %s  error: %s", serviceID, err)
		return nil, "", "", err
	}

	glog.V(2).Infof("getService: serviceID=%s, tenantID=%s, serviceNamePath=%s: %+v", serviceID, evaluatedServiceResponse.TenantID, evaluatedServiceResponse.ServiceNamePath, evaluatedServiceResponse.Service)
	return &evaluatedServiceResponse.Service, evaluatedServiceResponse.TenantID, evaluatedServiceResponse.ServiceNamePath, 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
}
726405
func (r Network_LoadBalancer_VirtualIpAddress) GetServices() (resp []datatypes.Network_LoadBalancer_Service, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_LoadBalancer_VirtualIpAddress", "getServices", nil, &r.Options, &resp)
	return
}
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)
}
1036813
func (a *api) GetServiceTemplates() ([]template.ServiceTemplate, error) {
	client, err := a.connectMaster()
	if err != nil {
		return nil, err
	}

	templateMap, err := client.GetServiceTemplates()
	if err != nil {
			return nil, err
	}
	templates := make([]template.ServiceTemplate, len(templateMap))
	i := 0
	for id, t := range templateMap {
		t.ID = id
		templates[i] = t
		i++
	}

	return templates, nil
}
308849
func (s *Server) GetServiceEndpoints(request *EndpointRequest, reply *[]applicationendpoint.EndpointReport) error {
	endpoints, err := s.f.GetServiceEndpoints(s.context(), request.ServiceIDs[0], request.ReportImports, request.ReportExports, request.Validate)
	if err != nil {
		return err
	}

	*reply = endpoints
	return nil
}
1099918
func getEndpointsFromState(state zkservice.State, reportImports, reportExports bool) []applicationendpoint.ApplicationEndpoint {
	var endpoints []applicationendpoint.ApplicationEndpoint
	if reportImports {
		for _, ep := range state.Imports {
			endpoint := applicationendpoint.ApplicationEndpoint{
				ServiceID:      state.ServiceID,
				Application:    ep.Application,
				Purpose:        ep.Purpose,
				ContainerID:    state.ContainerID,
				ContainerIP:    state.PrivateIP,
				ContainerPort:  ep.PortNumber,
				HostID:         state.HostID,
				VirtualAddress: ep.VirtualAddress,
				InstanceID:     state.InstanceID,
			}
			endpoints = append(endpoints, endpoint)
		}
	}

	if reportExports {
		for _, ep := range state.Exports {
			endpoint := applicationendpoint.ApplicationEndpoint{
				ServiceID:     state.ServiceID,
				Application:   ep.Application,
				Protocol:      ep.Protocol,
				Purpose:       "export",
				ContainerID:   state.ContainerID,
				ContainerIP:   state.PrivateIP,
				ContainerPort: ep.PortNumber,
				HostID:        state.HostID,
				HostIP:        state.HostIP,
				InstanceID:    state.InstanceID,
			}
			endpoints = append(endpoints, endpoint)
		}
	}

	return endpoints
}
348294
func translateServicePortToTargetPort(ports []string, svc corev1.Service, pod corev1.Pod) ([]string, error) {
	var translated []string
	for _, port := range ports {
		localPort, remotePort := splitPort(port)

		portnum, err := strconv.Atoi(remotePort)
		if err != nil {
			svcPort, err := util.LookupServicePortNumberByName(svc, remotePort)
			if err != nil {
				return nil, err
			}
			portnum = int(svcPort)

			if localPort == remotePort {
				localPort = strconv.Itoa(portnum)
			}
		}
		containerPort, err := util.LookupContainerPortNumberByServicePort(svc, pod, int32(portnum))
		if err != nil {
			// can't resolve a named port, or Service did not declare this port, return an error
			return nil, err
		}

		if int32(portnum) != containerPort {
			translated = append(translated, fmt.Sprintf("%s:%d", localPort, containerPort))
		} else {
			translated = append(translated, port)
		}
	}
	return translated, nil
}
587486
func (_m *ClientInterface) GetServiceTemplates() (map[string]servicetemplate.ServiceTemplate, error) {
	ret := _m.Called()

	var r0 map[string]servicetemplate.ServiceTemplate
	if rf, ok := ret.Get(0).(func() map[string]servicetemplate.ServiceTemplate); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(map[string]servicetemplate.ServiceTemplate)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1264954
func getEndpointsAndPort(endpoints []string) (endpointsR []string, portR int, err error) {
	var resultEndpoints []string
	var resultPort int

	if len(endpoints) > 1 {
		return nil, 0, ErrInvalidEndpointConfig
	}

	if len(endpoints[0]) > 0 {
		v := endpoints[0]

		if !strings.Contains(v, ":") {
			return nil, 0, ErrInvalidEndpointConfig
		}

		if strings.Contains(v, ",") {
			endpointsAndPort := strings.Split(v, ",")
			for _, val := range endpointsAndPort {
				endpointAndPort := strings.Split(val, ":")
				resultEndpoints = append(resultEndpoints, endpointAndPort[0])
				resultPort, err = strconv.Atoi(endpointAndPort[1])
				if err != nil {
					return nil, 0, err
				}
			}

		} else {
			endpointAndPort := strings.Split(v, ":")
			resultEndpoints = append(resultEndpoints, endpointAndPort[0])
			resultPort, err = strconv.Atoi(endpointAndPort[1])
			if err != nil {
				return nil, 0, err
			}
		}
	} else {
		return nil, 0, ErrInvalidEndpointConfig
	}

	return resultEndpoints, resultPort, nil
}