本文整理汇总了Golang中github.com/vmware/govmomi/vim25/types.BaseVirtualDevice类的典型用法代码示例。如果您正苦于以下问题:Golang BaseVirtualDevice类的具体用法?Golang BaseVirtualDevice怎么用?Golang BaseVirtualDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseVirtualDevice类的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:
delete(c.containers, a)
}
// long id
delete(c.containers, con.ID().String())
// short id
delete(c.containers, con.ID().Truncate().String())
// name
delete(c.containers, con.Name())
return endpoints, nil
}
var addEthernetCard = func(h *exec.Handle, s *Scope) (types.BaseVirtualDevice, error) {
var devices object.VirtualDeviceList
var d types.BaseVirtualDevice
var dc types.BaseVirtualDeviceConfigSpec
ctx := context.Background()
dcs, err := h.Spec.FindNICs(ctx, s.Network())
if err != nil {
return nil, err
}
for _, ds := range dcs {
if ds.GetVirtualDeviceConfigSpec().Operation == types.VirtualDeviceConfigSpecOperationAdd {
d = ds.GetVirtualDeviceConfigSpec().Device
dc = ds
break
}
}
示例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
//.........这里部分代码省略.........