// listPhysicalHosts returns a slice of physical hosts in the database.
498150
func listPhysicalHosts(c context.Context, q database.QueryerContext, req *crimson.ListPhysicalHostsRequest) ([]*crimson.PhysicalHost, error) {
	mac48s, err := parseMAC48s(req.MacAddresses)
	if err != nil {
		return nil, err
	}
	ipv4s, err := parseIPv4s(req.Ipv4S)
	if err != nil {
		return nil, err
	}

	stmt := squirrel.Select(
		"hp.name",
		"hp.vlan_id",
		"m.name",
		"n.name",
		"n.mac_address",
		"o.name",
		"h.vm_slots",
		"h.virtual_datacenter",
		"h.description",
		"h.deployment_ticket",
		"i.ipv4",
		"m.state",
	)
	stmt = stmt.From("(physical_hosts h, hostnames hp, machines m, nics n, oses o, ips i)")
	if len(req.Datacenters) > 0 {
		stmt = stmt.Join("racks r ON m.rack_id = r.id")
		stmt = stmt.Join("datacenters d ON r.datacenter_id = d.id")
	} else if len(req.Racks) > 0 {
		stmt = stmt.Join("racks r ON m.rack_id = r.id")
	}
	if len(req.Platforms) > 0 {
		stmt = stmt.Join("platforms p ON m.platform_id = p.id")
	}
	stmt = stmt.Where("n.hostname_id = hp.id").
		Where("h.machine_id = m.id").
		Where("h.nic_id = n.id").
		Where("h.os_id = o.id").
		Where("i.hostname_id = hp.id")
	stmt = selectInString(stmt, "hp.name", req.Names)
	stmt = selectInInt64(stmt, "hp.vlan_id", req.Vlans)
	stmt = selectInString(stmt, "m.name", req.Machines)
	stmt = selectInString(stmt, "n.name", req.Nics)
	stmt = selectInUint64(stmt, "n.mac_address", mac48s)
	stmt = selectInString(stmt, "o.name", req.Oses)
	stmt = selectInString(stmt, "h.virtual_datacenter", req.VirtualDatacenters)
	stmt = selectInInt64(stmt, "i.ipv4", ipv4s)
	stmt = selectInState(stmt, "m.state", req.States)
	stmt = selectInString(stmt, "d.name", req.Datacenters)
	stmt = selectInString(stmt, "r.name", req.Racks)
	stmt = selectInString(stmt, "p.name", req.Platforms)
	query, args, err := stmt.ToSql()
	if err != nil {
		return nil, errors.Annotate(err, "failed to generate statement").Err()
	}

	rows, err := q.QueryContext(c, query, args...)
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch physical hosts").Err()
	}
	defer rows.Close()
	var hosts []*crimson.PhysicalHost
	for rows.Next() {
		h := &crimson.PhysicalHost{}
		var mac48 common.MAC48
		var ipv4 common.IPv4
		if err = rows.Scan(
			&h.Name,
			&h.Vlan,
			&h.Machine,
			&h.Nic,
			&mac48,
			&h.Os,
			&h.VmSlots,
			&h.VirtualDatacenter,
			&h.Description,
			&h.DeploymentTicket,
			&ipv4,
			&h.State,
		); err != nil {
			return nil, errors.Annotate(err, "failed to fetch physical host").Err()
		}
		h.MacAddress = mac48.String()
		h.Ipv4 = ipv4.String()
		hosts = append(hosts, h)
	}
	return hosts, nil
}
111132
func ListLoadBalancers() ([]HostComputeLoadBalancer, error) {
	hcnQuery := defaultQuery()
	loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
	if err != nil {
		return nil, err
	}
	return loadBalancers, nil
}
1076845
func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error) {
	dbKey := m.dbKey(dbID)
	if err := m.checkDBExists(dbKey); err != nil {
		return nil, errors.Trace(err)
	}

	res, err := m.txn.HGetAll(dbKey)
	if err != nil {
		return nil, errors.Trace(err)
	}

	tables := make([]*model.TableInfo, 0, len(res)/2)
	for _, r := range res {
		// only handle table meta
		tableKey := string(r.Field)
		if !strings.HasPrefix(tableKey, mTablePrefix) {
			continue
		}

		tbInfo := &model.TableInfo{}
		err = json.Unmarshal(r.Value, tbInfo)
		if err != nil {
			return nil, errors.Trace(err)
		}

		tables = append(tables, tbInfo)
	}

	return tables, nil
}
311562
func (db *ProtoWrapper) ListValues(key string) (keyval.ProtoKeyValIterator, error) {
	return listValuesProtoInternal(db.broker, db.serializer, key)
}
340371
func (k *kubernetesClient) listHostCloudRegions() (string, set.Strings, error) {
	// we only check 5 worker nodes as of now just run in the one region and
	// we are just looking for a running worker to sniff its region.
	nodes, err := k.client().CoreV1().Nodes().List(v1.ListOptions{Limit: 5})
	if err != nil {
		return "", nil, errors.Annotate(err, "listing nodes")
	}
	result := set.NewStrings()
	var cloudResult string
	for _, n := range nodes.Items {
		var nodeCloud, region string
		if nodeCloud, region = getCloudRegionFromNodeMeta(n); nodeCloud == "" {
			continue
		}
		cloudResult = nodeCloud
		result.Add(region)
	}
	return cloudResult, result, nil
}
351088
func (s *Connection) SetPhysicalConnectionRequirements(v *PhysicalConnectionRequirements) *Connection {
	s.PhysicalConnectionRequirements = v
	return s
}
252528
func (c *Host) ListJobs() (map[string]host.ActiveJob, error) {
	var jobs map[string]host.ActiveJob
	err := c.c.Get("/host/jobs", &jobs)
	return jobs, err
}
662541
func (c *Client) ListHostTags(p *ListHostTagsParameter) ([]*HostTag, error) {
	obj, err := c.Request("listHostTags", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.([]*HostTag), err
}
654273
func (jolokiaClient *JolokiaClient) ListProperties(domain string, properties []string) ([]string, error) {
	request := NewJolokiaRequest(READ, domain, properties, "")
	resp, requestErr := jolokiaClient.ExecuteRequest(request, "")
	if requestErr != nil {
		return nil, requestErr
	}
	ret := make([]string, 0, len(resp.Value))
	for key, _ := range resp.Value {
		ret = append(ret, key)
	}
	sort.Strings(ret)
	return ret, nil
}
835964
func listVMs(c context.Context, q database.QueryerContext, req *crimson.ListVMsRequest) ([]*crimson.VM, error) {
	ipv4s, err := parseIPv4s(req.Ipv4S)
	if err != nil {
		return nil, err
	}

	stmt := squirrel.Select(
		"hv.name",
		"hv.vlan_id",
		"hp.name",
		"hp.vlan_id",
		"o.name",
		"v.description",
		"v.deployment_ticket",
		"i.ipv4",
		"v.state",
	)
	stmt = stmt.From("vms v, hostnames hv, physical_hosts p, hostnames hp, oses o, ips i").
		Where("v.hostname_id = hv.id").
		Where("v.physical_host_id = p.id").
		Where("p.hostname_id = hp.id").
		Where("v.os_id = o.id").
		Where("i.hostname_id = hv.id")
	stmt = selectInString(stmt, "hv.name", req.Names)
	stmt = selectInInt64(stmt, "hv.vlan_id", req.Vlans)
	stmt = selectInInt64(stmt, "i.ipv4", ipv4s)
	stmt = selectInString(stmt, "hp.name", req.Hosts)
	stmt = selectInInt64(stmt, "hp.vlan_id", req.HostVlans)
	stmt = selectInString(stmt, "o.name", req.Oses)
	stmt = selectInState(stmt, "v.state", req.States)
	query, args, err := stmt.ToSql()
	if err != nil {
		return nil, errors.Annotate(err, "failed to generate statement").Err()
	}

	rows, err := q.QueryContext(c, query, args...)
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch VMs").Err()
	}
	defer rows.Close()
	var vms []*crimson.VM
	for rows.Next() {
		v := &crimson.VM{}
		var ipv4 common.IPv4
		if err = rows.Scan(
			&v.Name,
			&v.Vlan,
			&v.Host,
			&v.HostVlan,
			&v.Os,
			&v.Description,
			&v.DeploymentTicket,
			&ipv4,
			&v.State,
		); err != nil {
			return nil, errors.Annotate(err, "failed to fetch VM").Err()
		}
		v.Ipv4 = ipv4.String()
		vms = append(vms, v)
	}
	return vms, nil
}
150436
func (keys *LocalKeyClient) ListKeys(keysPath string, quiet bool, logger *logging.Logger) ([]string, error) {
	var result []string
	addrs, err := ioutil.ReadDir(keysPath)
	if err != nil {
		return nil, err
	}
	for _, addr := range addrs {
		result = append(result, addr.Name())
	}
	if !quiet {
		if len(addrs) == 0 {
			logger.InfoMsg("No keys found on host")
		} else {
			// First key.
			logger.InfoMsg("The keys on host", result)
		}
	}

	return result, nil
}
859621
func (api *InfraHostsAPI) GetHosts() (result *Hosts, err error) {
	uri := api.client.Endpoint + InfraHostsUrl
	res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
	if err != nil {
		return
	}

	result = &Hosts{}
	err = json.Unmarshal(res, result)
	return
}
433289
func listHosts(alias string) {
	conf, err := loadMcConfig()
	fatalIf(err.Trace(globalMCConfigVersion), "Unable to load config version `"+globalMCConfigVersion+"`.")

	// If specific alias is requested, look for it and print.
	if alias != "" {
		if v, ok := conf.Hosts[alias]; ok {
			printHosts(hostMessage{
				op:          "list",
				prettyPrint: false,
				Alias:       alias,
				URL:         v.URL,
				AccessKey:   v.AccessKey,
				SecretKey:   v.SecretKey,
				API:         v.API,
				Lookup:      v.Lookup,
			})
			return
		}
		fatalIf(errInvalidAliasedURL(alias), "No such alias `"+alias+"` found.")
	}

	var hosts []hostMessage
	for k, v := range conf.Hosts {
		hosts = append(hosts, hostMessage{
			op:          "list",
			prettyPrint: true,
			Alias:       k,
			URL:         v.URL,
			AccessKey:   v.AccessKey,
			SecretKey:   v.SecretKey,
			API:         v.API,
			Lookup:      v.Lookup,
		})
	}

	// Sort hosts by alias names lexically.
	sort.Sort(byAlias(hosts))

	// Display all the hosts.
	printHosts(hosts...)
}
607231
func (s *VPCService) ListStaticRoutes(p *ListStaticRoutesParams) (*ListStaticRoutesResponse, error) {
	resp, err := s.cs.newRequest("listStaticRoutes", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ListStaticRoutesResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
1160438
func (s *NetworkService) UpdatePhysicalNetwork(p *UpdatePhysicalNetworkParams) (*UpdatePhysicalNetworkResponse, error) {
	resp, err := s.cs.newRequest("updatePhysicalNetwork", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r UpdatePhysicalNetworkResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
620497
func (s *NetworkService) ListPhysicalNetworks(p *ListPhysicalNetworksParams) (*ListPhysicalNetworksResponse, error) {
	resp, err := s.cs.newRequest("listPhysicalNetworks", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ListPhysicalNetworksResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
492352
func (es *EnvironmentsService) List(ctx context.Context) (e *EnvironmentsResponse, resp *APIResponse, err error) {
	e = &EnvironmentsResponse{}
	_, resp, err = es.client.getAction(ctx, &APIClientRequest{
		Path:         "admin/environments",
		ResponseBody: e,
		APIVersion:   apiV2,
	})

	return
}