• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang instance.ContainerType函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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])
}
开发者ID:exekias,项目名称:juju,代码行数:9,代码来源:container.go


示例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
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:35,代码来源:migration_import.go


示例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
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:35,代码来源:migration_import.go


示例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)
		}
	}
}
开发者ID:imoapps,项目名称:juju,代码行数:28,代码来源:factory_test.go


示例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)
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:provisioner.go


示例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
}
开发者ID:bac,项目名称:juju,代码行数:63,代码来源:constraints.go


示例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
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:62,代码来源:constraints.go


示例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
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:60,代码来源:constraints.go


示例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
}
开发者ID:rogpeppe,项目名称:juju,代码行数:16,代码来源:constraints.go


示例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)
		}
	}
}
开发者ID:bac,项目名称:juju,代码行数:36,代码来源:factory_test.go


示例11: ContainerType

// ContainerType returns the type of container hosting this machine.
func (m *Machine) ContainerType() instance.ContainerType {
	return instance.ContainerType(m.doc.ContainerType)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:4,代码来源:machine.go


示例12: ctypep

func ctypep(ctype string) *instance.ContainerType {
	res := instance.ContainerType(ctype)
	return &res
}
开发者ID:imoapps,项目名称:juju,代码行数:4,代码来源:constraints_test.go


示例13: container

func (c *environConfig) container() instance.ContainerType {
	return instance.ContainerType(c.attrs[ContainerKey].(string))
}
开发者ID:Pankov404,项目名称:juju,代码行数:3,代码来源:config.go



注:本文中的github.com/juju/juju/instance.ContainerType函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang instance.Id函数代码示例发布时间:2022-05-23
下一篇:
Golang testing.ParseMetadataFromDir函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap