当前位置: 首页>>代码示例>>Golang>>正文


Golang BaseVirtualDevice.GetVirtualDevice方法代码示例

本文整理汇总了Golang中github.com/vmware/govmomi/vim25/types.BaseVirtualDevice.GetVirtualDevice方法的典型用法代码示例。如果您正苦于以下问题:Golang BaseVirtualDevice.GetVirtualDevice方法的具体用法?Golang BaseVirtualDevice.GetVirtualDevice怎么用?Golang BaseVirtualDevice.GetVirtualDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/vmware/govmomi/vim25/types.BaseVirtualDevice的用法示例。


在下文中一共展示了BaseVirtualDevice.GetVirtualDevice方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getVirtualDiskUUID

func getVirtualDiskUUID(newDevice types.BaseVirtualDevice) (string, error) {
	vd := newDevice.GetVirtualDevice()

	if b, ok := vd.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
		uuidWithNoHypens := strings.Replace(b.Uuid, "-", "", -1)
		return strings.ToLower(uuidWithNoHypens), nil
	}
	return "", ErrNoDiskUUIDFound
}
开发者ID:XbinZh,项目名称:kubernetes,代码行数:9,代码来源:vsphere.go

示例2: getVirtualDiskUUID

// Returns formatted UUID for a virtual disk device.
func getVirtualDiskUUID(newDevice types.BaseVirtualDevice) (string, error) {
	vd := newDevice.GetVirtualDevice()

	if b, ok := vd.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
		uuid := formatVirtualDiskUUID(b.Uuid)
		return uuid, nil
	}
	return "", ErrNoDiskUUIDFound
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:10,代码来源:vsphere.go

示例3: AssignController

// AssignController assigns a device to a controller.
func (l VirtualDeviceList) AssignController(device types.BaseVirtualDevice, c types.BaseVirtualController) {
	d := device.GetVirtualDevice()
	d.ControllerKey = c.GetVirtualController().Key
	d.UnitNumber = new(int32)
	*d.UnitNumber = l.newUnitNumber(c)
	if d.Key == 0 {
		d.Key = -1
	}
}
开发者ID:odacremolbap,项目名称:kubernetes,代码行数:10,代码来源:virtual_device_list.go

示例4: connectivity

func (l VirtualDeviceList) connectivity(device types.BaseVirtualDevice, v bool) error {
	c := device.GetVirtualDevice().Connectable
	if c == nil {
		return fmt.Errorf("%s is not connectable", l.Name(device))
	}

	c.Connected = v
	c.StartConnected = v

	return nil
}
开发者ID:odacremolbap,项目名称:kubernetes,代码行数:11,代码来源:virtual_device_list.go

示例5: AssignController

// AssignController assigns a device to a controller.
func (l VirtualDeviceList) AssignController(device types.BaseVirtualDevice, c types.BaseVirtualController) {
	d := device.GetVirtualDevice()
	d.ControllerKey = c.GetVirtualController().Key
	d.UnitNumber = l.newUnitNumber(c)
	if d.UnitNumber == 0 {
		d.UnitNumber = -1 // TODO: this field is annotated as omitempty
	}
	if d.Key == 0 {
		d.Key = -1
	}
}
开发者ID:bruceadowns,项目名称:govmomi,代码行数:12,代码来源:virtual_device_list.go

示例6: VirtualDeviceSlotNumber

// VirtualDeviceSlotNumber returns the PCI slot number of a device
func VirtualDeviceSlotNumber(d types.BaseVirtualDevice) int32 {
	s := d.GetVirtualDevice().SlotInfo
	if s == nil {
		return NilSlot
	}

	if i, ok := s.(*types.VirtualDevicePciBusSlotInfo); ok {
		return i.PciSlotNumber
	}

	return NilSlot
}
开发者ID:kjplatz,项目名称:vic,代码行数:13,代码来源:spec.go

示例7: AssignSlotNumber

// AssignSlotNumber assigns a specific PCI slot number to the specified device. This ensures that
// the slot is valid and not in use by anything else in the spec
func (s *VirtualMachineConfigSpec) AssignSlotNumber(dev types.BaseVirtualDevice, known map[int32]bool) int32 {
	slot := VirtualDeviceSlotNumber(dev)
	if slot != NilSlot {
		return slot
	}

	// build the slots in use from the spec
	slots := s.CollectSlotNumbers(known)
	slot = findSlotNumber(slots)
	if slot != NilSlot {
		dev.GetVirtualDevice().SlotInfo = &types.VirtualDevicePciBusSlotInfo{PciSlotNumber: slot}
	}

	return slot
}
开发者ID:kjplatz,项目名称:vic,代码行数:17,代码来源:spec.go

示例8: Name

// Name returns a stable, human-readable name for the given device
func (l VirtualDeviceList) Name(device types.BaseVirtualDevice) string {
	var key string
	d := device.GetVirtualDevice()
	dtype := l.Type(device)

	switch dtype {
	case DeviceTypeEthernet:
		key = fmt.Sprintf("%d", d.UnitNumber-7)
	case DeviceTypeDisk:
		key = fmt.Sprintf("%d-%d", d.ControllerKey, d.UnitNumber)
	default:
		key = fmt.Sprintf("%d", d.Key)
	}

	return fmt.Sprintf("%s-%s", dtype, key)
}
开发者ID:bruceadowns,项目名称:govmomi,代码行数:17,代码来源:virtual_device_list.go

示例9:

			dc = ds
			break
		}
	}

	if d == nil {
		backing, err := s.Network().EthernetCardBackingInfo(ctx)
		if err != nil {
			return nil, err
		}

		if d, err = devices.CreateEthernetCard("vmxnet3", backing); err != nil {
			return nil, err
		}

		d.GetVirtualDevice().DeviceInfo = &types.Description{
			Label: s.name,
		}
	}

	if spec.VirtualDeviceSlotNumber(d) == spec.NilSlot {
		slots := make(map[int32]bool)
		for _, e := range h.ExecConfig.Networks {
			if e.Common.ID != "" {
				slot, err := strconv.Atoi(e.Common.ID)
				if err == nil {
					slots[int32(slot)] = true
				}
			}
		}
开发者ID:vmware,项目名称:vic,代码行数:30,代码来源:context.go

示例10: addVirtualNIC

func (s *VirtualMachineConfigSpec) addVirtualNIC(device types.BaseVirtualDevice) *VirtualMachineConfigSpec {
	device.GetVirtualDevice().Key = s.generateNextKey()

	return s.AddVirtualDevice(device)
}
开发者ID:vmware,项目名称:vic,代码行数:5,代码来源:network.go

示例11: TestContextAddContainer

func TestContextAddContainer(t *testing.T) {
	ctx, err := NewContext(net.IPNet{IP: net.IPv4(172, 16, 0, 0), Mask: net.CIDRMask(12, 32)}, net.CIDRMask(16, 32))
	if err != nil {
		t.Fatalf("NewContext() => (nil, %s), want (ctx, nil)", err)
		return
	}

	h := exec.NewContainer("foo")

	var devices object.VirtualDeviceList
	backing, _ := ctx.DefaultScope().Network().EthernetCardBackingInfo(context.TODO())

	specWithEthCard := &spec.VirtualMachineConfigSpec{
		VirtualMachineConfigSpec: &types.VirtualMachineConfigSpec{},
	}

	var d types.BaseVirtualDevice
	if d, err = devices.CreateEthernetCard("vmxnet3", backing); err == nil {
		d.GetVirtualDevice().SlotInfo = &types.VirtualDevicePciBusSlotInfo{
			PciSlotNumber: 1111,
		}
		devices = append(devices, d)
		var cs []types.BaseVirtualDeviceConfigSpec
		if cs, err = devices.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd); err == nil {
			specWithEthCard.DeviceChange = cs
		}
	}

	if err != nil {
		t.Fatalf(err.Error())
	}

	aecErr := func(_ *exec.Handle, _ *Scope) (types.BaseVirtualDevice, error) {
		return nil, fmt.Errorf("error")
	}

	otherScope, err := ctx.NewScope(BridgeScopeType, "other", nil, net.IPv4(0, 0, 0, 0), nil, nil)
	if err != nil {
		t.Fatalf("failed to add scope")
	}

	hBar := exec.NewContainer(uid.New())

	var tests = []struct {
		aec   func(h *exec.Handle, s *Scope) (types.BaseVirtualDevice, error)
		h     *exec.Handle
		s     *spec.VirtualMachineConfigSpec
		scope string
		ip    *net.IP
		err   error
	}{
		// nil handle
		{nil, nil, nil, "", nil, fmt.Errorf("")},
		// scope not found
		{nil, h, nil, "foo", nil, ResourceNotFoundError{}},
		// addEthernetCard returns error
		{aecErr, h, nil, "default", nil, fmt.Errorf("")},
		// add a container
		{nil, h, nil, "default", nil, nil},
		// container already added
		{nil, h, nil, "default", nil, nil},
		{nil, hBar, specWithEthCard, "default", nil, nil},
		{nil, hBar, nil, otherScope.Name(), nil, nil},
	}

	origAEC := addEthernetCard
	defer func() { addEthernetCard = origAEC }()

	for i, te := range tests {
		// setup
		addEthernetCard = origAEC
		scopy := &spec.VirtualMachineConfigSpec{}
		if te.h != nil {
			te.h.SetSpec(te.s)
			if te.h.Spec != nil {
				*scopy = *te.h.Spec
			}
		}

		if te.aec != nil {
			addEthernetCard = te.aec
		}

		options := &AddContainerOptions{
			Scope: te.scope,
			IP:    te.ip,
		}
		err := ctx.AddContainer(te.h, options)
		if te.err != nil {
			// expect an error
			if err == nil {
				t.Fatalf("case %d: ctx.AddContainer(%v, %s, %s) => nil want err", i, te.h, te.scope, te.ip)
			}

			if reflect.TypeOf(err) != reflect.TypeOf(te.err) {
				t.Fatalf("case %d: ctx.AddContainer(%v, %s, %s) => (%v, %v) want (%v, %v)", i, te.h, te.scope, te.ip, err, te.err, err, te.err)
			}

			if _, ok := te.err.(DuplicateResourceError); ok {
				continue
//.........这里部分代码省略.........
开发者ID:kjplatz,项目名称:vic,代码行数:101,代码来源:context_test.go


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