Ejemplo n.º 1
0
// ContainerTypeFromId returns the container type if machineId is a container id, or ""
// if machineId is not for a container.
func ContainerTypeFromId(machineId string) instance.ContainerType {
	idParts := strings.Split(machineId, "/")
	if len(idParts) < 3 {
		return instance.ContainerType("")
	}
	return instance.ContainerType(idParts[len(idParts)-2])
}
Ejemplo n.º 2
0
func (s *InstanceSuite) TestParseSupportedContainerTypeOrNone(c *C) {
	ctype, err := instance.ParseSupportedContainerTypeOrNone("lxc")
	c.Assert(err, IsNil)
	c.Assert(ctype, Equals, instance.ContainerType("lxc"))
	ctype, err = instance.ParseSupportedContainerTypeOrNone("none")
	c.Assert(err, IsNil)
	c.Assert(ctype, Equals, instance.ContainerType("none"))
}
Ejemplo n.º 3
0
// SetYAML is required to unmarshall 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) SetYAML(tag string, value interface{}) bool {
	values := value.(map[interface{}]interface{})
	for k, val := range values {
		vstr := fmt.Sprintf("%v", val)
		var err error
		switch k {
		case "arch":
			v.Arch = &vstr
		case "container":
			ctype := instance.ContainerType(vstr)
			v.Container = &ctype
		case "cpu-cores":
			v.CpuCores, err = parseUint64(vstr)
		case "cpu-power":
			v.CpuPower, err = parseUint64(vstr)
		case "mem":
			v.Mem, err = parseUint64(vstr)
		default:
			return false
		}
		if err != nil {
			return false
		}
	}
	return true
}
Ejemplo n.º 4
0
func (v *Value) setContainer(str string) error {
	if v.Container != nil {
		return fmt.Errorf("already set")
	}
	if str == "" {
		ctype := instance.ContainerType("")
		v.Container = &ctype
	} else {
		ctype, err := instance.ParseSupportedContainerTypeOrNone(str)
		if err != nil {
			return err
		}
		v.Container = &ctype
	}
	return nil
}
Ejemplo n.º 5
0
// ContainerType returns the type of container hosting this machine.
func (m *Machine) ContainerType() instance.ContainerType {
	return instance.ContainerType(m.doc.ContainerType)
}
Ejemplo n.º 6
0
func ctypep(ctype string) *instance.ContainerType {
	res := instance.ContainerType(ctype)
	return &res
}