Java 类com.vmware.vim25.VirtualPCNet32 实例源码

项目:vijava    文件:CreateVM.java   
static VirtualDeviceConfigSpec createNicSpec(String netName, 
    String nicName) throws Exception
{
  VirtualDeviceConfigSpec nicSpec = 
      new VirtualDeviceConfigSpec();
  nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add);

  VirtualEthernetCard nic =  new VirtualPCNet32();
  VirtualEthernetCardNetworkBackingInfo nicBacking = 
      new VirtualEthernetCardNetworkBackingInfo();
  nicBacking.setDeviceName(netName);

  Description info = new Description();
  info.setLabel(nicName);
  info.setSummary(netName);
  nic.setDeviceInfo(info);

  // type: "generated", "manual", "assigned" by VC
  nic.setAddressType("generated");
  nic.setBacking(nicBacking);
  nic.setKey(0);

  nicSpec.setDevice(nic);
  return nicSpec;
}
项目:cs-actions    文件:VmUtils.java   
private VirtualEthernetCard getEth(String fileName, String addressType, Integer key) {
    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(fileName);

    VirtualEthernetCard nic = new VirtualPCNet32();
    nic.setBacking(nicBacking);
    nic.setAddressType(addressType);
    nic.setKey(key);

    return nic;
}
项目:vijava    文件:VmNicOp.java   
static VirtualDeviceConfigSpec getNICDeviceConfigSpec(
    VirtualMachine vm, String op, String name) 
      throws Exception
{
  VirtualDeviceConfigSpec nicSpec = 
    new VirtualDeviceConfigSpec();
  VirtualMachineConfigInfo vmConfigInfo = vm.getConfig();

  if("add".equalsIgnoreCase(op) 
      && doesNetworkNameExist(vm, name)) 
  {
    nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
    VirtualEthernetCard nic =  new VirtualPCNet32();
    VirtualEthernetCardNetworkBackingInfo nicBacking = 
      new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(name);
    nic.setAddressType("generated");
    nic.setBacking(nicBacking);
    nic.setKey(4);
    nicSpec.setDevice(nic);
    return nicSpec;
  }
  else if("remove".equalsIgnoreCase(op))
  {
    VirtualDevice [] vds = 
      vmConfigInfo.getHardware().getDevice();
    nicSpec.setOperation(
        VirtualDeviceConfigSpecOperation.remove);
    for(int i=0;i<vds.length;i++)
    {
      if((vds[i] instanceof VirtualEthernetCard) &&
        (vds[i].getDeviceInfo().getLabel().equalsIgnoreCase(
            name)))
      {                             
        nicSpec.setDevice(vds[i]);
        return nicSpec;
      }
    }
  }
  return null;
}