// checkInstanceType is used to ensure the the provided constraints
// specify a recognized instance type.
556682
func checkInstanceType(cons constraints.Value) bool {
	// Constraint has an instance-type constraint so let's see if it is valid.
	for _, itype := range allInstanceTypes {
		if itype.Name == *cons.InstanceType {
			return true
		}
	}
	return false
}
12843
func (s *ResourceConfig) SetInstanceType(v string) *ResourceConfig {
	s.InstanceType = &v
	return s
}
902471
func (s *InstanceTypeSpecification) SetInstanceType(v string) *InstanceTypeSpecification {
	s.InstanceType = &v
	return s
}
787669
func (b *backend) validateInstance(ctx context.Context, s logical.Storage, instanceID, region, accountID string) (*ec2.Instance, error) {
	// Create an EC2 client to pull the instance information
	ec2Client, err := b.clientEC2(ctx, s, region, accountID)
	if err != nil {
		return nil, err
	}

	status, err := ec2Client.DescribeInstances(&ec2.DescribeInstancesInput{
		InstanceIds: []*string{
			aws.String(instanceID),
		},
	})
	if err != nil {
		errW := errwrap.Wrapf(fmt.Sprintf("error fetching description for instance ID %q: {{err}}", instanceID), err)
		return nil, errwrap.Wrap(errW, awsutil.CheckAWSError(err))
	}
	if status == nil {
		return nil, fmt.Errorf("nil output from describe instances")
	}
	if len(status.Reservations) == 0 {
		return nil, fmt.Errorf("no reservations found in instance description")

	}
	if len(status.Reservations[0].Instances) == 0 {
		return nil, fmt.Errorf("no instance details found in reservations")
	}
	if *status.Reservations[0].Instances[0].InstanceId != instanceID {
		return nil, fmt.Errorf("expected instance ID not matching the instance ID in the instance description")
	}
	if status.Reservations[0].Instances[0].State == nil {
		return nil, fmt.Errorf("instance state in instance description is nil")
	}
	if *status.Reservations[0].Instances[0].State.Name != "running" {
		return nil, fmt.Errorf("instance is not in 'running' state")
	}
	return status.Reservations[0].Instances[0], nil
}
1181792
func (f *FakeCloud) InstanceType(ctx context.Context, instance types.NodeName) (string, error) {
	f.addCall("instance-type")
	return f.InstanceTypes[instance], nil
}
512618
func (s *ServerLaunchConfiguration) SetInstanceType(v string) *ServerLaunchConfiguration {
	s.InstanceType = &v
	return s
}
1160299
func (env *environ) InstanceTypes(ctx context.ProviderCallContext, c constraints.Value) (instances.InstanceTypesWithCostMetadata, error) {
	reg, err := env.Region()
	if err != nil {
		return instances.InstanceTypesWithCostMetadata{}, errors.Trace(err)
	}
	zones, err := env.gce.AvailabilityZones(reg.Region)
	if err != nil {
		return instances.InstanceTypesWithCostMetadata{}, google.HandleCredentialError(errors.Trace(err), ctx)
	}
	resultUnique := map[string]instances.InstanceType{}

	for _, z := range zones {
		if !z.Available() {
			continue
		}
		machines, err := env.gce.ListMachineTypes(z.Name())
		if err != nil {
			return instances.InstanceTypesWithCostMetadata{}, google.HandleCredentialError(errors.Trace(err), ctx)
		}
		for _, m := range machines {
			i := instances.InstanceType{
				Id:       strconv.FormatUint(m.Id, 10),
				Name:     m.Name,
				CpuCores: uint64(m.GuestCpus),
				Mem:      uint64(m.MemoryMb),
				Arches:   []string{arch.AMD64},
				VirtType: &virtType,
			}
			resultUnique[m.Name] = i
		}
	}

	result := make([]instances.InstanceType, len(resultUnique))
	i := 0
	for _, it := range resultUnique {
		result[i] = it
		i++
	}
	result, err = instances.MatchingInstanceTypes(result, "", c)
	if err != nil {
		return instances.InstanceTypesWithCostMetadata{}, errors.Trace(err)
	}
	return instances.InstanceTypesWithCostMetadata{InstanceTypes: result}, nil
}
376318
func CheckInstance(endpoint string) InstanceStatus {
	if inst, exist := connectionPool[endpoint]; exist {
		if inst.connection.Ping() == nil {
			return InstanceOK
		}
		return InstanceERROR
	}
	return InstanceUnregistered
}
1321600
func ensureInType(outType reflect.Type) error {
	switch outType.Kind() {
	case reflect.Slice:
		fallthrough
	case reflect.Array:
		return nil
	}
	return fmt.Errorf("cannot use " + outType.String() + ", only slice or array supported")
}
585064
func (s *ContainerProperties) SetInstanceType(v string) *ContainerProperties {
	s.InstanceType = &v
	return s
}
884630
func (s *ReservedElasticsearchInstance) SetElasticsearchInstanceType(v string) *ReservedElasticsearchInstance {
	s.ElasticsearchInstanceType = &v
	return s
}
706057
func InstanceTypes(cons instanceTypeConstraints) (params.InstanceTypesResult, error) {
	instanceTypes, err := cons.environ.InstanceTypes(cons.context, cons.constraints)
	if err != nil {
		return params.InstanceTypesResult{}, errors.Trace(err)
	}

	return params.InstanceTypesResult{
		InstanceTypes: toParamsInstanceTypeResult(instanceTypes.InstanceTypes),
		CostUnit:      instanceTypes.CostUnit,
		CostCurrency:  instanceTypes.CostCurrency,
		CostDivisor:   instanceTypes.CostDivisor,
	}, 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
	}
}
98368
func (ms *modelSpec) checkModelType(model Model) error {
	if reflect.TypeOf(model) != ms.typ {
		return fmt.Errorf("model was the wrong type. Expected %s but got %T", ms.typ.String(), model)
	}
	return nil
}
457384
func (s *InstanceFleet) SetInstanceFleetType(v string) *InstanceFleet {
	s.InstanceFleetType = &v
	return s
}
543115
func (c *awsCloudImplementation) DefaultInstanceType(cluster *kops.Cluster, ig *kops.InstanceGroup) (string, error) {
	var candidates []string

	switch ig.Spec.Role {
	case kops.InstanceGroupRoleMaster:
		// Some regions do not (currently) support the m3 family; the c4 large is the cheapest non-burstable instance
		// (us-east-2, ca-central-1, eu-west-2, ap-northeast-2).
		// Also some accounts are no longer supporting m3 in us-east-1 zones
		candidates = []string{"m3.medium", "c4.large"}

	case kops.InstanceGroupRoleNode:
		candidates = []string{"t2.medium"}

	case kops.InstanceGroupRoleBastion:
		candidates = []string{"t2.micro"}

	default:
		return "", fmt.Errorf("unhandled role %q", ig.Spec.Role)
	}

	// Find the AZs the InstanceGroup targets
	igZones, err := model.FindZonesForInstanceGroup(cluster, ig)
	if err != nil {
		return "", err
	}
	igZonesSet := sets.NewString(igZones...)

	// TODO: Validate that instance type exists in all AZs, but skip AZs that don't support any VPC stuff
	for _, instanceType := range candidates {
		zones, err := c.zonesWithInstanceType(instanceType)
		if err != nil {
			return "", err
		}
		if zones.IsSuperset(igZonesSet) {
			return instanceType, nil
		} else {
			glog.V(2).Infof("can't use instance type %q, available in zones %v but need %v", instanceType, zones, igZones)
		}
	}

	return "", fmt.Errorf("could not find a suitable supported instance type for the instance group %q (type %q) in region %q", ig.Name, ig.Spec.Role, c.region)
}
13785
func (e *environ) InstanceTypes(ctx context.ProviderCallContext, c constraints.Value) (instances.InstanceTypesWithCostMetadata, error) {
	iTypes, err := e.supportedInstanceTypes(ctx)
	if err != nil {
		return instances.InstanceTypesWithCostMetadata{}, errors.Trace(err)
	}
	iTypes, err = instances.MatchingInstanceTypes(iTypes, "", c)
	if err != nil {
		return instances.InstanceTypesWithCostMetadata{}, errors.Trace(err)
	}
	return instances.InstanceTypesWithCostMetadata{
		InstanceTypes: iTypes,
		CostUnit:      "$USD/hour",
		CostDivisor:   1000,
		CostCurrency:  "USD"}, nil
}