本文整理汇总了Golang中github.com/juju/juju/instance.ContainerType函数的典型用法代码示例。如果您正苦于以下问题:Golang ContainerType函数的具体用法?Golang ContainerType怎么用?Golang ContainerType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ContainerType函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ContainerTypeFromId
// 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])
}
示例2: makeMachineDoc
func (i *importer) makeMachineDoc(m description.Machine) (*machineDoc, error) {
id := m.Id()
supported, supportedSet := m.SupportedContainers()
supportedContainers := make([]instance.ContainerType, len(supported))
for j, c := range supported {
supportedContainers[j] = instance.ContainerType(c)
}
jobs, err := i.makeMachineJobs(m.Jobs())
if err != nil {
return nil, errors.Trace(err)
}
return &machineDoc{
DocID: i.st.docID(id),
Id: id,
ModelUUID: i.st.ModelUUID(),
Nonce: m.Nonce(),
Series: m.Series(),
ContainerType: m.ContainerType(),
Principals: nil, // TODO
Life: Alive,
Tools: i.makeTools(m.Tools()),
Jobs: jobs,
NoVote: true, // State servers can't be migrated yet.
HasVote: false, // State servers can't be migrated yet.
PasswordHash: m.PasswordHash(),
Clean: true, // check this later
Addresses: i.makeAddresses(m.ProviderAddresses()),
MachineAddresses: i.makeAddresses(m.MachineAddresses()),
PreferredPrivateAddress: i.makeAddress(m.PreferredPrivateAddress()),
PreferredPublicAddress: i.makeAddress(m.PreferredPublicAddress()),
SupportedContainersKnown: supportedSet,
SupportedContainers: supportedContainers,
Placement: m.Placement(),
}, nil
}
示例3: constraints
func (i *importer) constraints(cons description.Constraints) constraints.Value {
var result constraints.Value
if cons == nil {
return result
}
if arch := cons.Architecture(); arch != "" {
result.Arch = &arch
}
if container := instance.ContainerType(cons.Container()); container != "" {
result.Container = &container
}
if cores := cons.CpuCores(); cores != 0 {
result.CpuCores = &cores
}
if power := cons.CpuPower(); power != 0 {
result.CpuPower = &power
}
if inst := cons.InstanceType(); inst != "" {
result.InstanceType = &inst
}
if mem := cons.Memory(); mem != 0 {
result.Mem = &mem
}
if disk := cons.RootDisk(); disk != 0 {
result.RootDisk = &disk
}
if spaces := cons.Spaces(); len(spaces) > 0 {
result.Spaces = &spaces
}
if tags := cons.Tags(); len(tags) > 0 {
result.Tags = &tags
}
return result
}
示例4: TestNewContainerManager
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, nil)
if test.valid {
c.Assert(err, jc.ErrorIsNil)
c.Assert(manager, gc.NotNil)
} else {
c.Assert(err, gc.ErrorMatches, `unknown container type: ".*"`)
c.Assert(manager, gc.IsNil)
}
}
}
示例5: watchOneMachineContainers
func (p *ProvisionerAPI) watchOneMachineContainers(arg params.WatchContainer) (params.StringsWatchResult, error) {
nothing := params.StringsWatchResult{}
canAccess, err := p.getAuthFunc()
if err != nil {
return nothing, common.ErrPerm
}
tag, err := names.ParseMachineTag(arg.MachineTag)
if err != nil {
return nothing, common.ErrPerm
}
if !canAccess(tag) {
return nothing, common.ErrPerm
}
machine, err := p.st.Machine(tag.Id())
if err != nil {
return nothing, err
}
var watch state.StringsWatcher
if arg.ContainerType != "" {
watch = machine.WatchContainers(instance.ContainerType(arg.ContainerType))
} else {
watch = machine.WatchAllContainers()
}
// Consume the initial event and forward it to the result.
if changes, ok := <-watch.Changes(); ok {
return params.StringsWatchResult{
StringsWatcherId: p.resources.Register(watch),
Changes: changes,
}, nil
}
return nothing, watcher.EnsureErr(watch)
}
示例6: UnmarshalYAML
// 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 {
// 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 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 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
default:
return errors.Errorf("unknown constraint value: %v", k)
}
if err != nil {
return errors.Trace(err)
}
}
return nil
}
示例7: UnmarshalYAML
// 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)
}
for k, val := range values {
vstr := fmt.Sprintf("%v", val)
switch k {
case Arch:
v.Arch = &vstr
case Container:
ctype := instance.ContainerType(vstr)
v.Container = &ctype
case InstanceType:
v.InstanceType = &vstr
case CpuCores:
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 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 Networks:
var networks *[]string
networks, err = parseYamlStrings("networks", val)
if err != nil {
return errors.Trace(err)
}
err = v.validateNetworks(networks)
if err == nil {
v.Networks = networks
}
case VirtType:
v.VirtType = &vstr
default:
return errors.Errorf("unknown constraint value: %v", k)
}
if err != nil {
return errors.Trace(err)
}
}
return nil
}
示例8: SetYAML
// 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, ok := value.(map[interface{}]interface{})
if !ok {
return false
}
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 InstanceType:
v.InstanceType = &vstr
case CpuCores:
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 Tags:
v.Tags, err = parseYamlStrings("tags", val)
case Spaces:
var spaces *[]string
spaces, err = parseYamlStrings("spaces", val)
if err != nil {
return false
}
err = v.validateSpaces(spaces)
if err == nil {
v.Spaces = spaces
}
case Networks:
var networks *[]string
networks, err = parseYamlStrings("networks", val)
if err != nil {
return false
}
err = v.validateNetworks(networks)
if err == nil {
v.Networks = networks
}
default:
return false
}
if err != nil {
return false
}
}
return true
}
示例9: setContainer
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.ParseContainerTypeOrNone(str)
if err != nil {
return err
}
v.Container = &ctype
}
return nil
}
示例10: TestNewContainerManager
func (*factorySuite) TestNewContainerManager(c *gc.C) {
for _, test := range []struct {
containerType instance.ContainerType
valid bool
}{{
containerType: instance.LXD,
valid: true,
}, {
containerType: instance.LXD,
valid: true,
}, {
containerType: instance.KVM,
valid: true,
}, {
containerType: instance.NONE,
valid: false,
}, {
containerType: instance.ContainerType("other"),
valid: false,
}} {
/* LXD isn't available in go 1.2 */
if test.containerType == instance.LXD && !lxd.HasLXDSupport() {
continue
}
conf := container.ManagerConfig{container.ConfigModelUUID: testing.ModelTag.Id()}
manager, err := factory.NewContainerManager(test.containerType, conf)
if test.valid {
c.Assert(err, jc.ErrorIsNil)
c.Assert(manager, gc.NotNil)
} else {
c.Assert(err, gc.ErrorMatches, `unknown container type: ".*"`)
c.Assert(manager, gc.IsNil)
}
}
}
示例11: ContainerType
// ContainerType returns the type of container hosting this machine.
func (m *Machine) ContainerType() instance.ContainerType {
return instance.ContainerType(m.doc.ContainerType)
}
示例12: ctypep
func ctypep(ctype string) *instance.ContainerType {
res := instance.ContainerType(ctype)
return &res
}
示例13: container
func (c *environConfig) container() instance.ContainerType {
return instance.ContainerType(c.attrs[ContainerKey].(string))
}