// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
5642
func (pc *PCCloud) InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error) {
	return false, cloudprovider.NotImplemented
}
570091
func fetchExistingInstances(c context.Context, keys []*datastore.Key) ([]*Instance, error) {
	instances := make([]*Instance, len(keys))
	for i, k := range keys {
		instances[i] = &Instance{
			InstanceID: k.StringID(),
			Package:    k.Parent(),
		}
	}

	err := datastore.Get(c, instances)
	if err == nil {
		return instances, nil
	}

	merr, ok := err.(errors.MultiError)
	if !ok {
		return nil, errors.Annotate(err, "failed to fetch instances").Tag(transient.Tag).Err()
	}

	existing := instances[:0]
	for i, inst := range instances {
		switch err := merr[i]; {
		case err == nil:
			existing = append(existing, inst)
		case err != datastore.ErrNoSuchEntity:
			return nil, errors.Annotate(err, "failed to fetch instance %q", inst.InstanceID).Tag(transient.Tag).Err()
		}
	}
	return existing, nil
}
50521
func (k *kubernetesClient) OperatorExists(appName string) (caas.OperatorState, error) {
	var result caas.OperatorState

	statefulsets := k.client().AppsV1().StatefulSets(k.namespace)
	operator, err := statefulsets.Get(k.operatorName(appName), v1.GetOptions{IncludeUninitialized: true})
	if k8serrors.IsNotFound(err) {
		return result, nil
	}
	if err != nil {
		return result, errors.Trace(err)
	}
	result.Exists = true
	result.Terminating = operator.DeletionTimestamp != nil
	return result, nil
}
239846
func (vm *VM) serviceExist(services []hostedservice.HostedService) bool {
	for _, srv := range services {
		if srv.ServiceName == vm.ServiceName {
			return true
		}
	}

	return false
}
1227791
func splitProviderID(providerID string) (project, zone, instance string, err error) {
	matches := providerIDRE.FindStringSubmatch(providerID)
	if len(matches) != 4 {
		return "", "", "", errors.New("error splitting providerID")
	}
	return matches[1], matches[2], matches[3], nil
}
224246
func (c *Cloud) InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error) {
	instanceID, err := KubernetesInstanceID(providerID).MapToAWSInstanceID()
	if err != nil {
		return false, err
	}

	request := &ec2.DescribeInstancesInput{
		InstanceIds: []*string{instanceID.awsString()},
	}

	instances, err := c.ec2.DescribeInstances(request)
	if err != nil {
		return false, err
	}
	if len(instances) == 0 {
		return false, nil
	}
	if len(instances) > 1 {
		return false, fmt.Errorf("multiple instances found for instance: %s", instanceID)
	}

	state := instances[0].State.Name
	if *state == ec2.InstanceStateNameTerminated {
		klog.Warningf("the instance %s is terminated", instanceID)
		return false, nil
	}

	return true, nil
}
1201908
func (m *metadata) InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error) {
	return false, cloudprovider.NotImplemented
}
27176
func (instanceApi *InstanceApi) Exists(id string) (bool, error) {
	_, err := instanceApi.Get(id)
	if err != nil {
		if ccaError, ok := err.(api.CcaErrorResponse); ok && ccaError.StatusCode == 404 {
			return false, nil
		}
		return false, err
	}
	return true, nil
}
474299
func (os *OpenStack) GetZoneByProviderID(ctx context.Context, providerID string) (cloudprovider.Zone, error) {
	instanceID, err := instanceIDFromProviderID(providerID)
	if err != nil {
		return cloudprovider.Zone{}, err
	}

	compute, err := os.NewComputeV2()
	if err != nil {
		return cloudprovider.Zone{}, err
	}

	srv, err := servers.Get(compute, instanceID).Extract()
	if err != nil {
		return cloudprovider.Zone{}, err
	}

	zone := cloudprovider.Zone{
		FailureDomain: srv.Metadata[availabilityZone],
		Region:        os.region,
	}
	klog.V(4).Infof("The instance %s in zone %v", srv.Name, zone)
	return zone, nil
}
1359806
func columnPrivEntryExists(ctx sessionctx.Context, name string, host string, db string, tbl string, col string) (bool, error) {
	sql := fmt.Sprintf(`SELECT * FROM %s.%s WHERE User='%s' AND Host='%s' AND DB='%s' AND Table_name='%s' AND Column_name='%s';`, mysql.SystemDB, mysql.ColumnPrivTable, name, host, db, tbl, col)
	return recordExists(ctx, sql)
}
410065
func (indom *PCPInstanceDomain) HasInstance(name string) bool {
	_, present := indom.instances[name]
	return present
}
1021159
func imageExists(reg registry.Registry, imageID image.Ref) (bool, error) {
	_, err := reg.GetImage(imageID)
	if err != nil {
		return false, nil
	}
	return true, nil
}
778279
func CheckInstanceExists(c context.Context, inst *Instance) error {
	switch err := datastore.Get(c, inst); {
	case err == datastore.ErrNoSuchEntity:
		// Maybe the package is missing completely?
		if err := CheckPackageExists(c, inst.Package.StringID()); err != nil {
			return err
		}
		return errors.Reason("no such instance").Tag(grpcutil.NotFoundTag).Err()
	case err != nil:
		return errors.Annotate(err, "failed to check the instance presence").Tag(transient.Tag).Err()
	default:
		return nil
	}
}
758699
func (az *Cloud) IsNodeUnmanagedByProviderID(providerID string) bool {
	return !azureNodeProviderIDRE.Match([]byte(providerID))
}
242203
func IsProviderIDNotUniqueError(err interface{}) bool {
	if err == nil {
		return false
	}
	// In case of a wrapped error, check the cause first.
	value := err
	cause := errors.Cause(err.(error))
	if cause != nil {
		value = cause
	}
	_, ok := value.(*ErrProviderIDNotUnique)
	return ok
}
1370053
func (r *globalProviderRegistry) UnregisterProvider(providerType string) {
	delete(r.providers, providerType)
	for a, p := range r.aliases {
		if p == providerType {
			delete(r.aliases, a)
		}
	}
}
1193864
func (d *driver) InstanceID(
	ctx types.Context,
	opts types.Store) (*types.InstanceID, error) {

	iid := &types.InstanceID{Driver: vfs.Name}
	hostName, err := utils.HostName()
	if err != nil {
		return nil, err
	}

	if ok, _ := strconv.ParseBool(os.Getenv("VFS_INSTANCEID_USE_FIELDS")); ok {
		iid.ID = hostName
		iid.Fields = map[string]string{"region": "east"}
		return iid, nil
	}

	if err := iid.MarshalMetadata(hostName); err != nil {
		return nil, err
	}
	return iid, nil
}