// validateNICForCreation validates a NIC for creation.
193275
func validateNICForCreation(n *crimson.NIC) error {
	switch {
	case n == nil:
		return status.Error(codes.InvalidArgument, "NIC specification is required")
	case n.Name == "":
		return status.Error(codes.InvalidArgument, "NIC name is required and must be non-empty")
	case n.Machine == "":
		return status.Error(codes.InvalidArgument, "machine is required and must be non-empty")
	case n.Switch == "":
		return status.Error(codes.InvalidArgument, "switch is required and must be non-empty")
	case n.Switchport < 1:
		return status.Error(codes.InvalidArgument, "switchport must be positive")
	default:
		// If hostname or IPv4 address is specified, require both.
		if n.Hostname != "" || n.Ipv4 != "" {
			if n.Hostname == "" {
				return status.Errorf(codes.InvalidArgument, "if IPv4 is specified then hostname is required and must be non-empty")
			}
			if n.Ipv4 == "" {
				return status.Errorf(codes.InvalidArgument, "if hostname is specified then IPv4 address is required and must be non-empty")
			}
			_, err := common.ParseIPv4(n.Ipv4)
			if err != nil {
				return status.Errorf(codes.InvalidArgument, "invalid IPv4 address %q", n.Ipv4)
			}
		}
		_, err := common.ParseMAC48(n.MacAddress)
		if err != nil {
			return status.Errorf(codes.InvalidArgument, "invalid MAC-48 address %q", n.MacAddress)
		}
		return nil
	}
}
394559
func ValidateInitialization(plugin Interface) error {
	if validater, ok := plugin.(InitializationValidator); ok {
		err := validater.ValidateInitialization()
		if err != nil {
			return err
		}
	}
	return nil
}
585557
func getHostnameForNIC(c context.Context, q database.QueryerContext, name, machine string) (*int64, error) {
	rows, err := q.QueryContext(c, `
		SELECT h.id FROM nics n, machines m, hostnames h
		WHERE n.machine_id = m.id AND n.hostname_id = h.id AND n.name = ? AND m.name = ?
	`, name, machine)
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch associated hostname").Err()
	}
	defer rows.Close()
	if rows.Next() {
		var hostnameId int64
		if err = rows.Scan(&hostnameId); err != nil {
			return nil, errors.Annotate(err, "failed to fetch hostname").Err()
		}
		return &hostnameId, nil
	}
	return nil, nil
}
1263883
func CreateNoError(t *testing.T, ctx context.Context, client client.APIClient, name string, ops ...func(*types.NetworkCreate)) string { // nolint: golint
	t.Helper()

	name, err := createNetwork(ctx, client, name, ops...)
	assert.NilError(t, err)
	return name
}
123945
func SetValidationFunc(name string, vf ValidationFunc) error {
	return defaultValidator.SetValidationFunc(name, vf)
}
491748
func ValidateNetNamespace(netnamespace *networkapi.NetNamespace) field.ErrorList {
	allErrs := validation.ValidateObjectMeta(&netnamespace.ObjectMeta, false, path.ValidatePathSegmentName, field.NewPath("metadata"))

	if netnamespace.NetName != netnamespace.Name {
		allErrs = append(allErrs, field.Invalid(field.NewPath("netname"), netnamespace.NetName, fmt.Sprintf("must be the same as metadata.name: %q", netnamespace.Name)))
	}

	if err := ValidVNID(netnamespace.NetID); err != nil {
		allErrs = append(allErrs, field.Invalid(field.NewPath("netid"), netnamespace.NetID, err.Error()))
	}

	for i, ip := range netnamespace.EgressIPs {
		if _, err := validateIPv4(ip); err != nil {
			allErrs = append(allErrs, field.Invalid(field.NewPath("egressIPs").Index(i), ip, err.Error()))
		}
	}

	return allErrs
}
770078
func (s *Service) IdentityProviderCreateByOrganization(ctx context.Context, organizationName string, o IdentityProviderCreateByOrganizationOpts) (*IdentityProvider, error) {
	var identityProvider IdentityProvider
	return &identityProvider, s.Post(ctx, &identityProvider, fmt.Sprintf("/organizations/%v/identity-providers", organizationName), o)
}
456944
func createNIC(c context.Context, n *crimson.NIC) error {
	if err := validateNICForCreation(n); err != nil {
		return err
	}
	mac, _ := common.ParseMAC48(n.MacAddress)
	tx, err := database.Begin(c)
	if err != nil {
		return errors.Annotate(err, "failed to begin transaction").Err()
	}
	defer tx.MaybeRollback(c)

	var hostnameId sql.NullInt64
	if n.Hostname != "" {
		ip, _ := common.ParseIPv4(n.Ipv4)
		id, err := model.AssignHostnameAndIP(c, tx, n.Hostname, ip)
		if err != nil {
			return err
		}
		hostnameId.Int64 = id
		hostnameId.Valid = true
	}

	// By setting nics.machine_id NOT NULL when setting up the database, we can avoid checking if the given machine is
	// valid. MySQL will turn up NULL for its column values which will be rejected as an error.
	_, err = tx.ExecContext(c, `
		INSERT INTO nics (name, machine_id, mac_address, switch_id, switchport, hostname_id)
		VALUES (?, (SELECT id FROM machines WHERE name = ?), ?, (SELECT id FROM switches WHERE name = ?), ?, ?)
	`, n.Name, n.Machine, mac, n.Switch, n.Switchport, hostnameId)
	if err != nil {
		switch e, ok := err.(*mysql.MySQLError); {
		case !ok:
			// Type assertion failed.
		case e.Number == mysqlerr.ER_DUP_ENTRY && strings.Contains(e.Message, "'name'"):
			// e.g. "Error 1062: Duplicate entry 'eth0-machineId' for key 'name'".
			return status.Errorf(codes.AlreadyExists, "duplicate NIC %q for machine %q", n.Name, n.Machine)
		case e.Number == mysqlerr.ER_DUP_ENTRY && strings.Contains(e.Message, "'mac_address'"):
			// e.g. "Error 1062: Duplicate entry '1234567890' for key 'mac_address'".
			return status.Errorf(codes.AlreadyExists, "duplicate MAC address %q", n.MacAddress)
		case e.Number == mysqlerr.ER_BAD_NULL_ERROR && strings.Contains(e.Message, "'machine_id'"):
			// e.g. "Error 1048: Column 'machine_id' cannot be null".
			return status.Errorf(codes.NotFound, "machine %q does not exist", n.Machine)
		case e.Number == mysqlerr.ER_BAD_NULL_ERROR && strings.Contains(e.Message, "'switch_id'"):
			// e.g. "Error 1048: Column 'switch_id' cannot be null".
			return status.Errorf(codes.NotFound, "switch %q does not exist", n.Switch)
		}
		return errors.Annotate(err, "failed to create NIC").Err()
	}

	if err := tx.Commit(); err != nil {
		return errors.Annotate(err, "failed to commit transaction").Err()
	}
	return nil
}
652374
func (*Service) UpdateNIC(c context.Context, req *crimson.UpdateNICRequest) (*crimson.NIC, error) {
	return updateNIC(c, req.Nic, req.UpdateMask)
}
1111080
func (_m *APIClient) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
	ret := _m.Called(ctx, name, options)

	var r0 types.NetworkCreateResponse
	if rf, ok := ret.Get(0).(func(context.Context, string, types.NetworkCreate) types.NetworkCreateResponse); ok {
		r0 = rf(ctx, name, options)
	} else {
		r0 = ret.Get(0).(types.NetworkCreateResponse)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(context.Context, string, types.NetworkCreate) error); ok {
		r1 = rf(ctx, name, options)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
588118
func (r User_Customer_External_Binding_Verisign) ValidateCredentialId(userId *int, externalId *string) (resp bool, err error) {
	params := []interface{}{
		userId,
		externalId,
	}
	err = r.Session.DoRequest("SoftLayer_User_Customer_External_Binding_Verisign", "validateCredentialId", params, &r.Options, &resp)
	return
}
1204655
func (t *WorkItemLinkType) CheckValidForCreation() error {
	if t.Name == "" {
		return errors.NewBadParameterError("name", t.Name)
	}
	if t.ForwardName == "" {
		return errors.NewBadParameterError("forward_name", t.ForwardName)
	}
	if t.ReverseName == "" {
		return errors.NewBadParameterError("reverse_name", t.ReverseName)
	}
	if err := t.Topology.CheckValid(); err != nil {
		return errs.WithStack(err)
	}
	if t.SpaceTemplateID == uuid.Nil {
		return errors.NewBadParameterError("space_template_id", t.SpaceTemplateID)
	}
	return nil
}
598169
func validateDRACForCreation(d *crimson.DRAC) error {
	switch {
	case d == nil:
		return status.Error(codes.InvalidArgument, "DRAC specification is required")
	case d.Name == "":
		return status.Error(codes.InvalidArgument, "hostname is required and must be non-empty")
	case d.Machine == "":
		return status.Error(codes.InvalidArgument, "machine is required and must be non-empty")
	case d.Switch == "":
		return status.Error(codes.InvalidArgument, "switch is required and must be non-empty")
	case d.Switchport < 1:
		return status.Error(codes.InvalidArgument, "switchport must be positive")
	case d.Vlan != 0:
		return status.Error(codes.InvalidArgument, "VLAN must not be specified, use IP address instead")
	default:
		_, err := common.ParseIPv4(d.Ipv4)
		if err != nil {
			return status.Errorf(codes.InvalidArgument, "invalid IPv4 address %q", d.Ipv4)
		}
		_, err = common.ParseMAC48(d.MacAddress)
		if err != nil {
			return status.Errorf(codes.InvalidArgument, "invalid MAC-48 address %q", d.MacAddress)
		}
		return nil
	}
}
484074
func (vm *VM) deleteNic(authorizer autorest.Authorizer) error {
	interfaceClient := network.NewInterfacesClient(vm.Creds.SubscriptionID)
	interfaceClient.Authorizer = authorizer

	_, errc := interfaceClient.Delete(vm.ResourceGroup, vm.Nic, nil)
	return <-errc
}
599016
func ValidateNewModelCredential(backend PersistentBackend, callCtx context.ProviderCallContext, credentialTag names.CloudCredentialTag, credential *cloud.Credential) (params.ErrorResults, error) {
	openParams, err := buildOpenParams(backend, credentialTag, credential)
	if err != nil {
		return params.ErrorResults{}, errors.Trace(err)
	}
	model, err := backend.Model()
	if err != nil {
		return params.ErrorResults{}, errors.Trace(err)
	}
	switch model.Type() {
	case state.ModelTypeCAAS:
		return checkCAASModelCredential(openParams)
	case state.ModelTypeIAAS:
		return checkIAASModelCredential(openParams, backend, callCtx)
	default:
		return params.ErrorResults{}, errors.NotSupportedf("model type %q", model.Type())
	}
}
677629
func NewValidationAssertion() (Assertion, Failures) {
	vf := &validationFailer{
		offset:  2,
		details: []FailureDetail{},
		errs:    []error{},
	}
	return NewAssertion(vf), vf
}
990693
func (e *Exists) ValidateInitialization() error {
	if e.namespaceLister == nil {
		return fmt.Errorf("missing namespaceLister")
	}
	if e.client == nil {
		return fmt.Errorf("missing client")
	}
	return nil
}