func (v *Value) UnmarshalYAML(unmarshal func(interface{}) error) error {
	values := map[interface{}]interface{}{}
	err := unmarshal(&values)
	if err != nil {
		return errors.Trace(err)
	}
	canonicals := map[string]string{}
	for k, val := range values {
		vstr := fmt.Sprintf("%v", val)
		key, ok := k.(string)
		if !ok {
			return errors.Errorf("unexpected non-string key: %#v", k)
		}
		canonical := resolveAlias(key)
		if v, ok := canonicals[canonical]; ok {
			// duplicate entry
			return errors.Errorf("constraint %q duplicates constraint %q", key, v)
		}
		canonicals[canonical] = key
		switch canonical {
		case Arch:
			v.Arch = &vstr
		case Container:
			ctype := instance.ContainerType(vstr)
			v.Container = &ctype
		case InstanceRole:
			v.InstanceRole = &vstr
		case InstanceType:
			v.InstanceType = &vstr
		case Cores:
			v.CpuCores, err = parseUint64(vstr)
		case CpuPower:
			v.CpuPower, err = parseUint64(vstr)
		case Mem:
			v.Mem, err = parseUint64(vstr)
		case RootDisk:
			v.RootDisk, err = parseUint64(vstr)
		case RootDiskSource:
			v.RootDiskSource = &vstr
		case Tags:
			v.Tags, err = parseYamlStrings("tags", val)
		case Spaces:
			var spaces *[]string
			spaces, err = parseYamlStrings("spaces", val)
			if err != nil {
				return errors.Trace(err)
			}
			err = v.validateSpaces(spaces)
			if err == nil {
				v.Spaces = spaces
			}
		case VirtType:
			v.VirtType = &vstr
		case Zones:
			v.Zones, err = parseYamlStrings("zones", val)
		case AllocatePublicIP:
			v.AllocatePublicIP, err = parseBool(vstr)
		default:
			return errors.Errorf("unknown constraint value: %v", k)
		}
		if err != nil {
			return errors.Trace(err)
		}
	}
	return nil
}
// UnmarshalYAML is required to unmarshal a constraints.Value object
// to ensure the container attribute is correctly handled when it is empty.
// Because ContainerType is an alias for string, Go's reflect logic used in the
// YAML decode determines that *string and *ContainerType are not assignable so
// the container value of "" in the YAML is ignored.
UnmarshalYAML is required to unmarshal a constraints.Value object
to ensure the container attribute is correctly handled when it is empty.
Because ContainerType is an alias for string, Go's reflect logic used in the
YAML decode determines that *string and *ContainerType are not assignable so
the container value of "" in the YAML is ignored.
// UnmarshalYAML is required to unmarshal a constraints . Value object // to ensure the container attribute is correctly handled when it is empty . // Because ContainerType is an alias for string Go ' s reflect logic used in the // YAML decode determines that * string and * ContainerType are not assignable so // the container value of " " in the YAML is ignored .
func (v *Value) UnmarshalYAML(unmarshal func(interface{}) error) error {
	values := map[interface{}]interface{}{}
	err := unmarshal(&values)
	if err != nil {
		return errors.Trace(err)
	}
	canonicals := map[string]string{}
	for k, val := range values {
		vstr := fmt.Sprintf("%v", val)
		key, ok := k.(string)
		if !ok {
			return errors.Errorf("unexpected non-string key: %#v", k)
		}
		canonical := resolveAlias(key)
		if v, ok := canonicals[canonical]; ok {
			return errors.Errorf("constraint %q duplicates constraint %q", key, v)
		}
		canonicals[canonical] = key
		switch canonical {
		case Arch:
			v.Arch = &vstr
		case Container:
			ctype := instance.ContainerType(vstr)
			v.Container = &ctype
		case InstanceRole:
			v.InstanceRole = &vstr
		case InstanceType:
			v.InstanceType = &vstr
		case Cores:
			v.CpuCores, err = parseUint64(vstr)
		case CpuPower:
			v.CpuPower, err = parseUint64(vstr)
		case Mem:
			v.Mem, err = parseUint64(vstr)
		case RootDisk:
			v.RootDisk, err = parseUint64(vstr)
		case RootDiskSource:
			v.RootDiskSource = &vstr
		case Tags:
			v.Tags, err = parseYamlStrings("tags", val)
		case Spaces:
			var spaces *[]string
			spaces, err = parseYamlStrings("spaces", val)
			if err != nil {
				return errors.Trace(err)
			}
			err = v.validateSpaces(spaces)
			if err == nil {
				v.Spaces = spaces
			}
		case VirtType:
			v.VirtType = &vstr
		case Zones:
			v.Zones, err = parseYamlStrings("zones", val)
		case AllocatePublicIP:
			v.AllocatePublicIP, err = parseBool(vstr)
		default:
			return errors.Errorf("unknown constraint value: %v", k)
		}
		if err != nil {
			return errors.Trace(err)
		}
	}
	return nil
}
func ( v * Value ) UnmarshalYAML ( unmarshal func ( interface { } ) error ) error { values := map [ interface { } ] interface { } { } err := unmarshal ( & values ) if err != nil { return errors . Trace ( err ) } canonicals := map [ string ] string { } for k , val := range values { vstr := fmt . Sprintf ( " " , val ) key , ok := k . ( string ) if ! ok { return errors . Errorf ( " " , k ) } canonical := resolveAlias ( key ) if v , ok := canonicals [ canonical ] ; ok { return errors . Errorf ( " " , key , v ) } canonicals [ canonical ] = key switch canonical { case Arch : v . Arch = & vstr case Container : ctype := instance . ContainerType ( vstr ) v . Container = & ctype case InstanceRole : v . InstanceRole = & vstr case InstanceType : v . InstanceType = & vstr case Cores : v . CpuCores , err = parseUint64 ( vstr ) case CpuPower : v . CpuPower , err = parseUint64 ( vstr ) case Mem : v . Mem , err = parseUint64 ( vstr ) case RootDisk : v . RootDisk , err = parseUint64 ( vstr ) case RootDiskSource : v . RootDiskSource = & vstr case Tags : v . Tags , err = parseYamlStrings ( " " , val ) case Spaces : var spaces * [ ] string spaces , err = parseYamlStrings ( " " , val ) if err != nil { return errors . Trace ( err ) } err = v . validateSpaces ( spaces ) if err == nil { v . Spaces = spaces } case VirtType : v . VirtType = & vstr case Zones : v . Zones , err = parseYamlStrings ( " " , val ) case AllocatePublicIP : v . AllocatePublicIP , err = parseBool ( vstr ) default : return errors . Errorf ( " " , k ) } if err != nil { return errors . Trace ( err ) } } return nil }
UnmarshalYAML is required to unmarshal a constraints.Value object
to ensure the container attribute is correctly handled when it is empty.
UnmarshalYAML is required to unmarshal a constraints . Value object to ensure the container attribute is correctly handled when it is empty .
// duplicate entry