本文整理汇总了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
}
示例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
}
示例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
}
}
示例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
}
示例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
}
}
示例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
}
示例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
}
示例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)
}
示例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
}
}
}
示例10: addVirtualNIC
func (s *VirtualMachineConfigSpec) addVirtualNIC(device types.BaseVirtualDevice) *VirtualMachineConfigSpec {
device.GetVirtualDevice().Key = s.generateNextKey()
return s.AddVirtualDevice(device)
}
示例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
//.........这里部分代码省略.........