lxd/config/map.go
func (m *Map) Change(changes map[string]interface{}) (map[string]string, error) {
	values := make(map[string]string, len(m.schema))

	errors := ErrorList{}
	for name, change := range changes {
		key, ok := m.schema[name]

		// When a hidden value is set to "true" in the change set, it
		// means "keep it unchanged", so we replace it with our current
		// value.
		if ok && key.Hidden && change == true {
			change = m.GetRaw(name)
		}

		// A nil object means the empty string.
		if change == nil {
			change = ""
		}

		// Sanity check that we were actually passed a string.
		s := reflect.ValueOf(change)
		if s.Kind() != reflect.String {
			errors.add(name, nil, fmt.Sprintf("invalid type %s", s.Kind()))
			continue
		}

		values[name] = change.(string)
	}

	if errors.Len() > 0 {
		return nil, errors
	}

	// Any key not explicitly set, is considered unset.
	for name, key := range m.schema {
		_, ok := values[name]
		if !ok {
			values[name] = key.Default
		}
	}

	names, err := m.update(values)

	changed := map[string]string{}
	for _, name := range names {
		changed[name] = m.GetRaw(name)
	}
	return changed, err
}
func (m *Map) Change(changes map[string]interface{}) (map[string]string, error) {
	values := make(map[string]string, len(m.schema))

	errors := ErrorList{}
	for name, change := range changes {
		key, ok := m.schema[name]

		// When a hidden value is set to "true" in the change set, it
		// means "keep it unchanged", so we replace it with our current
		// value.
		if ok && key.Hidden && change == true {
			change = m.GetRaw(name)
		}

		// A nil object means the empty string.
		if change == nil {
			change = ""
		}

		// Sanity check that we were actually passed a string.
		s := reflect.ValueOf(change)
		if s.Kind() != reflect.String {
			errors.add(name, nil, fmt.Sprintf("invalid type %s", s.Kind()))
			continue
		}

		values[name] = change.(string)
	}

	if errors.Len() > 0 {
		return nil, errors
	}

	// Any key not explicitly set, is considered unset.
	for name, key := range m.schema {
		_, ok := values[name]
		if !ok {
			values[name] = key.Default
		}
	}

	names, err := m.update(values)

	changed := map[string]string{}
	for _, name := range names {
		changed[name] = m.GetRaw(name)
	}
	return changed, err
}
func ( m * Map ) Change ( changes map [ string ] interface { } ) ( map [ string ] string , error ) { values := make ( map [ string ] string , len ( m . schema ) ) errors := ErrorList { } for name , change := range changes { key , ok := m . schema [ name ] // When a hidden value is set to "true" in the change set, it // means "keep it unchanged", so we replace it with our current // value. if ok && key . Hidden && change == true { change = m . GetRaw ( name ) } // A nil object means the empty string. if change == nil { change = " " } // Sanity check that we were actually passed a string. s := reflect . ValueOf ( change ) if s . Kind ( ) != reflect . String { errors . add ( name , nil , fmt . Sprintf ( " " , s . Kind ( ) ) ) continue } values [ name ] = change . ( string ) } if errors . Len ( ) > 0 { return nil , errors } // Any key not explicitly set, is considered unset. for name , key := range m . schema { _ , ok := values [ name ] if ! ok { values [ name ] = key . Default } } names , err := m . update ( values ) changed := map [ string ] string { } for _ , name := range names { changed [ name ] = m . GetRaw ( name ) } return changed , err }
// Change the values of this configuration Map.
//
// Return a map of key/value pairs that were actually changed. If some keys
// fail to apply, details are included in the returned ErrorList.
Change the values of this configuration Map . Return a map of key / value pairs that were actually changed . If some keys fail to apply details are included in the returned ErrorList .