// ListInstances implements the corresponding RPC method, see the proto doc.
199040
func (impl *repoImpl) ListInstances(c context.Context, r *api.ListInstancesRequest) (resp *api.ListInstancesResponse, err error) {
	defer func() { err = grpcutil.GRPCifyAndLogErr(c, err) }()

	result, nextPage, err := impl.paginatedQuery(c, paginatedQueryOpts{
		Package:   r.Package,
		PageSize:  r.PageSize,
		PageToken: r.PageToken,
		Handler: func(cur datastore.Cursor, pageSize int32) ([]*model.Instance, datastore.Cursor, error) {
			return model.ListInstances(c, r.Package, pageSize, cur)
		},
	})
	if err != nil {
		return nil, err
	}

	return &api.ListInstancesResponse{
		Instances:     result,
		NextPageToken: nextPage,
	}, nil
}
254844
func (s *Store) Instances(service string) ([]*discoverd.Instance, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	return s.instances(service), nil
}
1332833
func (c Client) GetInstances(appName, serviceName, partitionName string) (*InstanceItemsPage, error) {
	var aggregateInstanceItemsPages InstanceItemsPage
	var continueToken string
	for {
		basePath := "Applications/" + appName + "/$/GetServices/" + serviceName + "/$/GetPartitions/" + partitionName + "/$/GetReplicas"
		res, err := c.getHTTP(basePath, withContinue(continueToken))
		if err != nil {
			return nil, err
		}

		var instanceItemsPage InstanceItemsPage
		err = json.Unmarshal(res, &instanceItemsPage)
		if err != nil {
			return nil, fmt.Errorf("could not deserialise JSON response: %+v", err)
		}

		aggregateInstanceItemsPages.Items = append(aggregateInstanceItemsPages.Items, instanceItemsPage.Items...)

		continueToken = getString(instanceItemsPage.ContinuationToken)
		if continueToken == "" {
			break
		}
	}
	return &aggregateInstanceItemsPages, nil
}
1180881
func (*Instances) List(c context.Context, req *instances.ListRequest) (*instances.ListResponse, error) {
	if req.GetPrefix() == "" {
		return nil, status.Errorf(codes.InvalidArgument, "prefix is required")
	}
	rsp := &instances.ListResponse{}
	// TODO(smut): Handle page tokens.
	if req.GetPageToken() != "" {
		return rsp, nil
	}
	q := datastore.NewQuery(model.VMKind).Eq("prefix", req.Prefix)
	if err := datastore.Run(c, q, func(vm *model.VM, f datastore.CursorCB) error {
		rsp.Instances = append(rsp.Instances, toInstance(vm))
		return nil
	}); err != nil {
		return nil, errors.Annotate(err, "failed to fetch instances").Err()
	}
	return rsp, nil
}
410485
func (g *Cloud) getInstancesByNames(names []string) ([]*gceInstance, error) {
	ctx, cancel := cloud.ContextWithCallTimeout()
	defer cancel()

	found := map[string]*gceInstance{}
	remaining := len(names)

	nodeInstancePrefix := g.nodeInstancePrefix
	for _, name := range names {
		name = canonicalizeInstanceName(name)
		if !strings.HasPrefix(name, g.nodeInstancePrefix) {
			klog.Warningf("Instance %q does not conform to prefix %q, removing filter", name, g.nodeInstancePrefix)
			nodeInstancePrefix = ""
		}
		found[name] = nil
	}

	for _, zone := range g.managedZones {
		if remaining == 0 {
			break
		}
		instances, err := g.c.Instances().List(ctx, zone, filter.Regexp("name", nodeInstancePrefix+".*"))
		if err != nil {
			return nil, err
		}
		for _, inst := range instances {
			if remaining == 0 {
				break
			}
			if _, ok := found[inst.Name]; !ok {
				continue
			}
			if found[inst.Name] != nil {
				klog.Errorf("Instance name %q was duplicated (in zone %q and %q)", inst.Name, zone, found[inst.Name].Zone)
				continue
			}
			found[inst.Name] = &gceInstance{
				Zone:  zone,
				Name:  inst.Name,
				ID:    inst.Id,
				Disks: inst.Disks,
				Type:  lastComponent(inst.MachineType),
			}
			remaining--
		}
	}

	if remaining > 0 {
		var failed []string
		for k := range found {
			if found[k] == nil {
				failed = append(failed, k)
			}
		}
		klog.Errorf("Failed to retrieve instances: %v", failed)
		return nil, cloudprovider.InstanceNotFound
	}

	var ret []*gceInstance
	for _, instance := range found {
		ret = append(ret, instance)
	}

	return ret, nil
}
1148923
func ListManagedInstances(c GCECloud, igm *compute.InstanceGroupManager) ([]*compute.ManagedInstance, error) {
	ctx := context.Background()
	project := c.Project()

	zoneName := LastComponent(igm.Zone)

	// TODO: Only select a subset of fields
	//	req.Fields(
	//		googleapi.Field("items/selfLink"),
	//		googleapi.Field("items/metadata/items[key='cluster-name']"),
	//		googleapi.Field("items/metadata/items[key='instance-template']"),
	//	)

	var instances []*compute.ManagedInstance
	err := c.Compute().InstanceGroupManagers.ListManagedInstances(project, zoneName, igm.Name).Pages(ctx,
		func(page *compute.InstanceGroupManagersListManagedInstancesResponse) error {
			instances = append(instances, page.ManagedInstances...)
			return nil
		})
	if err != nil {
		return nil, fmt.Errorf("error listing ManagedInstances in %s: %v", igm.Name, err)
	}

	return instances, nil
}
1173384
func listKeys(db keyval.ProtoBroker) {
	resp, err := db.ListKeys(phonebook.EtcdPath())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("list keys:")
	for {
		key, _, stop := resp.GetNext()
		if stop {
			break
		}

		fmt.Printf("- %s\n", key)

	}
}
371050
func (s *VMGroupService) NewListInstanceGroupsParams() *ListInstanceGroupsParams {
	p := &ListInstanceGroupsParams{}
	p.p = make(map[string]interface{})
	return p
}
972527
func (s *Service) ServiceInstances() []ServiceInstance {
	svcs := s.services.Load().([]ServiceInstance)
	ret := make([]ServiceInstance, len(svcs))
	copy(ret, svcs)
	sort.Sort(serviceInstanceList(ret))
	return ret
}
1198193
func (instanceApi *InstanceApi) ListWithOptions(options map[string]string) ([]Instance, error) {
	data, err := instanceApi.entityService.List(options)
	if err != nil {
		return nil, err
	}
	return parseInstanceList(data), nil
}
746180
func (env *environ) AllInstances(ctx context.ProviderCallContext) ([]instances.Instance, error) {
	instances, err := getInstances(env, ctx)
	return instances, errors.Trace(err)
}
1183793
func (gce *Cloud) ListInstancesInInstanceGroup(name string, zone string, state string) (*compute.InstanceGroupsListInstances, error) {
	// TODO: use PageToken to list all not just the first 500
	return gce.service.InstanceGroups.ListInstances(
		gce.projectID, zone, name,
		&compute.InstanceGroupsListInstancesRequest{InstanceState: state}).Do()
}
1304945
func (o *OracleEnviron) AllInstances(ctx context.ProviderCallContext) ([]envinstance.Instance, error) {
	tagFilter := tagValue{tags.JujuModel, o.Config().UUID()}
	all, err := o.allInstances(tagFilter)
	if err != nil {
		return nil, err
	}

	ret := make([]envinstance.Instance, len(all))
	for i, val := range all {
		ret[i] = val
	}
	return ret, nil
}
841084
func (broker *lxdBroker) AllInstances(ctx context.ProviderCallContext) (result []instances.Instance, err error) {
	return broker.manager.ListContainers()
}
1220567
func (e *manualEnviron) Instances(ctx context.ProviderCallContext, ids []instance.Id) ([]instances.Instance, error) {
	result := make([]instances.Instance, len(ids))
	var found bool
	var err error
	for i, id := range ids {
		if id == BootstrapInstanceId {
			result[i] = manualBootstrapInstance{e.host}
			found = true
		} else {
			err = environs.ErrPartialInstances
		}
	}
	if !found {
		err = environs.ErrNoInstances
	}
	return result, err
}
777364
func (e *Environ) AllInstances(ctx envcontext.ProviderCallContext) ([]instances.Instance, error) {
	tags := map[string]string{
		tags.JujuModel: e.Config().UUID(),
	}
	allInstances, err := e.allInstances(ctx, tags)
	if err != nil {
		providerCommon.HandleCredentialError(err, ctx)
		return nil, errors.Trace(err)
	}

	ret := []instances.Instance{}
	for _, val := range allInstances {
		ret = append(ret, val)
	}
	return ret, nil
}
782198
func (p *AuroraSchedulerManagerClient) AddInstances(ctx context.Context, key *InstanceKey, count int32) (r *Response, err error) {
  var _args143 AuroraSchedulerManagerAddInstancesArgs
  _args143.Key = key
  _args143.Count = count
  var _result144 AuroraSchedulerManagerAddInstancesResult
  if err = p.Client_().Call(ctx, "addInstances", &_args143, &_result144); err != nil {
    return
  }
  return _result144.GetSuccess(), nil
}