// 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]) }
func (*factorySuite) TestNewContainerManager(c *gc.C) { for _, test := range []struct { containerType instance.ContainerType valid bool }{{ containerType: instance.LXC, valid: true, }, { containerType: instance.KVM, valid: true, }, { containerType: instance.NONE, valid: false, }, { containerType: instance.ContainerType("other"), valid: false, }} { conf := container.ManagerConfig{container.ConfigName: "test"} manager, err := factory.NewContainerManager(test.containerType, conf) if test.valid { c.Assert(err, gc.IsNil) c.Assert(manager, gc.NotNil) } else { c.Assert(err, gc.ErrorMatches, `unknown container type: ".*"`) c.Assert(manager, gc.IsNil) } } }
// ContainerType returns the type of container hosting this machine. func (m *Machine) ContainerType() instance.ContainerType { return instance.ContainerType(m.doc.ContainerType) }
func (c *environConfig) container() instance.ContainerType { return instance.ContainerType(c.attrs["container"].(string)) }