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

项目:primecloud-controller    文件:VmwareCustomizeProcess.java   
protected List<CustomizationAdapterMapping> createCustomizationAdapterMappings(
        VmwareProcessClient vmwareProcessClient, VirtualMachine machine) {

    List<CustomizationAdapterMapping> nicSettingMap = new ArrayList<CustomizationAdapterMapping>();

    // VirtualEthernetCardを取得
    VirtualMachineConfigInfo configInfo = machine.getConfig();
    for (VirtualDevice device : configInfo.getHardware().getDevice()) {
        if (device instanceof VirtualEthernetCard) {
            VirtualEthernetCard virtualEthernetCard = VirtualEthernetCard.class.cast(device);
            CustomizationAdapterMapping mapping = new CustomizationAdapterMapping();
            CustomizationIPSettings settings = new CustomizationIPSettings();

            // すべてのNICをDHCPにする
            CustomizationDhcpIpGenerator dhcpIp = new CustomizationDhcpIpGenerator();
            settings.setIp(dhcpIp);

            mapping.setMacAddress(virtualEthernetCard.getMacAddress());
            mapping.setAdapter(settings);
            nicSettingMap.add(mapping);
        }
    }

    return nicSettingMap;
}
项目:oscm    文件:DiskManager.java   
/**
 * Reconfigures VMware system disks and data disks.
 */
public void reconfigureDisks(VirtualMachineConfigSpec vmConfigSpec,
        ManagedObjectReference vmwInstance) throws Exception {

    logger.debug("");

    long systemDiskMB = (long) paramHandler.getConfigDiskSpaceMB();
    VirtualMachineConfigInfo configSpec = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualDevice> devices = configSpec.getHardware().getDevice();
    VirtualDisk vdSystemDisk = getVMSystemDisk(devices,
            configSpec.getName());

    configureSystemDisk(vmConfigSpec, systemDiskMB, vdSystemDisk);
    configureDataDisks(vmConfigSpec, devices, vdSystemDisk);
}
项目:oscm    文件:VM.java   
public VM(VMwareClient vmw, String instanceName) throws Exception {
    this.vmw = vmw;
    this.instanceName = instanceName;

    vmInstance = vmw.getServiceUtil().getDecendentMoRef(null,
            "VirtualMachine", instanceName);
    configSpec = (VirtualMachineConfigInfo) vmw.getServiceUtil()
            .getDynamicProperty(vmInstance, "config");
    folder = (ManagedObjectReference) vmw.getServiceUtil()
            .getDynamicProperty(vmInstance, "parent");
    guestInfo = (GuestInfo) vmw.getServiceUtil()
            .getDynamicProperty(vmInstance, "guest");

    if (vmInstance == null || configSpec == null || folder == null
            || guestInfo == null) {
        LOG.warn("failed to retrieve VM");
        throw new Exception(
                "Failed to retrieve information of VM " + instanceName);
    }
}
项目:development    文件:VM.java   
public VM(VMwareClient vmw, String instanceName) throws Exception {
    this.vmw = vmw;
    this.instanceName = instanceName;

    vmInstance = vmw.getServiceUtil().getDecendentMoRef(null,
            "VirtualMachine", instanceName);
    configSpec = (VirtualMachineConfigInfo) vmw.getServiceUtil()
            .getDynamicProperty(vmInstance, "config");
    folder = (ManagedObjectReference) vmw.getServiceUtil()
            .getDynamicProperty(vmInstance, "parent");
    guestInfo = (GuestInfo) vmw.getServiceUtil()
            .getDynamicProperty(vmInstance, "guest");

    if (vmInstance == null || configSpec == null || folder == null
            || guestInfo == null) {
        LOG.warn("failed to retrieve VM");
        throw new Exception(
                "Failed to retrieve information of VM " + instanceName);
    }
}
项目:vijava    文件:RemoveVmDisk.java   
static VirtualDeviceConfigSpec createRemoveDiskConfigSpec(
    VirtualMachineConfigInfo vmConfig, String diskName) 
        throws Exception
{
  VirtualDeviceConfigSpec diskSpec = 
      new VirtualDeviceConfigSpec();      
  VirtualDisk disk = (VirtualDisk) findVirtualDevice(
      vmConfig, diskName);

  if(disk != null)
  {
    diskSpec.setOperation(
        VirtualDeviceConfigSpecOperation.remove);    
    // remove the following line can keep the disk file
    diskSpec.setFileOperation(
        VirtualDeviceConfigSpecFileOperation.destroy);           
    diskSpec.setDevice(disk);
    return diskSpec;
  }
  else 
  {
    throw new Exception("No device found: " + diskName);
  }
}
项目:cloudstack    文件:VirtualMachineMO.java   
public Pair<String, Integer> getVncPort(String hostNetworkName) throws Exception {
    HostMO hostMo = getRunningHost();
    VmwareHypervisorHostNetworkSummary summary = hostMo.getHyperHostNetworkSummary(hostNetworkName);

    VirtualMachineConfigInfo configInfo = getConfigInfo();
    List<OptionValue> values = configInfo.getExtraConfig();

    if (values != null) {
        for (OptionValue option : values) {
            if (option.getKey().equals("RemoteDisplay.vnc.port")) {
                String value = (String)option.getValue();
                if (value != null) {
                    return new Pair<String, Integer>(summary.getHostIp(), Integer.parseInt(value));
                }
            }
        }
    }
    return new Pair<String, Integer>(summary.getHostIp(), 0);
}
项目:oscm    文件:NetworkManager.java   
public static int getNumberOfNICs(VMwareClient vmw,
        ManagedObjectReference vmwInstance) throws Exception {
    logger.debug("");

    VirtualMachineConfigInfo configInfo = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualEthernetCard> vmNics = getNetworkAdapter(configInfo);
    return vmNics.size();
}
项目:oscm    文件:NetworkManager.java   
/**
 * Replaces the NICs in the given VM.
 *
 * @param vmw
 *            connected VMware client entity
 * @param paramHandler
 *            entity which holds all properties of the instance
 * @param vmwInstance
 *            the virtual machine that gets reconfigured
 */
public static void configureNetworkAdapter(VMwareClient vmw,
        VirtualMachineConfigSpec vmConfigSpec,
        VMPropertyHandler paramHandler, ManagedObjectReference vmwInstance)
        throws Exception {
    logger.debug("");

    VirtualMachineConfigInfo configInfo = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualEthernetCard> vmNics = getNetworkAdapter(configInfo);

    int numberOfNICs = Integer.parseInt(paramHandler
            .getServiceSetting(VMPropertyHandler.TS_NUMBER_OF_NICS));

    if (numberOfNICs != vmNics.size()) {
        throw new Exception(
                "the number of NICs in virtual machine does not match the service parameter. VM: "
                        + configInfo.getName() + " NICs: " + vmNics.size()
                        + " " + VMPropertyHandler.TS_NUMBER_OF_NICS + ": "
                        + numberOfNICs);
    }

    for (int i = 1; i <= numberOfNICs; i++) {
        String newNetworkName = paramHandler.getNetworkAdapter(i);
        VirtualEthernetCard vmNic = vmNics.get(i - 1);
        String vmNetworkName = getNetworkName(vmw, vmwInstance, i);
        if (newNetworkName != null && newNetworkName.length() > 0
                && !newNetworkName.equals(vmNetworkName)) {
            ManagedObjectReference newNetworkRef = getNetworkFromHost(vmw,
                    vmwInstance, newNetworkName);

            replaceNetworkAdapter(vmConfigSpec, vmNic, newNetworkRef,
                    newNetworkName);
        } else {
            connectNIC(vmConfigSpec, vmNic, vmNetworkName);
        }
    }
}
项目:oscm    文件:NetworkManager.java   
public static List<VirtualEthernetCard> getNetworkAdapter(
        VirtualMachineConfigInfo configInfo) {
    List<VirtualEthernetCard> nics = new ArrayList<VirtualEthernetCard>();
    List<VirtualDevice> devices = configInfo.getHardware().getDevice();
    for (VirtualDevice vd : devices) {
        if (vd instanceof VirtualEthernetCard) {
            nics.add((VirtualEthernetCard) vd);
        }
    }

    return nics;
}
项目:development    文件:NetworkManager.java   
public static int getNumberOfNICs(VMwareClient vmw,
        ManagedObjectReference vmwInstance) throws Exception {
    logger.debug("");

    VirtualMachineConfigInfo configInfo = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualEthernetCard> vmNics = getNetworkAdapter(configInfo);
    return vmNics.size();
}
项目:development    文件:NetworkManager.java   
/**
 * Replaces the NICs in the given VM.
 *
 * @param vmw
 *            connected VMware client entity
 * @param paramHandler
 *            entity which holds all properties of the instance
 * @param vmwInstance
 *            the virtual machine that gets reconfigured
 */
public static void configureNetworkAdapter(VMwareClient vmw,
        VirtualMachineConfigSpec vmConfigSpec,
        VMPropertyHandler paramHandler, ManagedObjectReference vmwInstance)
        throws Exception {
    logger.debug("");

    VirtualMachineConfigInfo configInfo = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualEthernetCard> vmNics = getNetworkAdapter(configInfo);

    int numberOfNICs = Integer.parseInt(paramHandler
            .getServiceSetting(VMPropertyHandler.TS_NUMBER_OF_NICS));

    if (numberOfNICs != vmNics.size()) {
        throw new Exception(
                "the number of NICs in virtual machine does not match the service parameter. VM: "
                        + configInfo.getName() + " NICs: " + vmNics.size()
                        + " " + VMPropertyHandler.TS_NUMBER_OF_NICS + ": "
                        + numberOfNICs);
    }

    for (int i = 1; i <= numberOfNICs; i++) {
        String newNetworkName = paramHandler.getNetworkAdapter(i);
        VirtualEthernetCard vmNic = vmNics.get(i - 1);
        String vmNetworkName = getNetworkName(vmw, vmwInstance, i);
        if (newNetworkName != null && newNetworkName.length() > 0
                && !newNetworkName.equals(vmNetworkName)) {
            ManagedObjectReference newNetworkRef = getNetworkFromHost(vmw,
                    vmwInstance, newNetworkName);

            replaceNetworkAdapter(vmConfigSpec, vmNic, newNetworkRef,
                    newNetworkName);
        } else {
            connectNIC(vmConfigSpec, vmNic, vmNetworkName);
        }
    }
}
项目:development    文件:NetworkManager.java   
public static List<VirtualEthernetCard> getNetworkAdapter(
        VirtualMachineConfigInfo configInfo) {
    List<VirtualEthernetCard> nics = new ArrayList<VirtualEthernetCard>();
    List<VirtualDevice> devices = configInfo.getHardware().getDevice();
    for (VirtualDevice vd : devices) {
        if (vd instanceof VirtualEthernetCard) {
            nics.add((VirtualEthernetCard) vd);
        }
    }

    return nics;
}
项目:development    文件:DiskManager.java   
/**
 * Reconfigures VMware system disks and data disks.
 */
public void reconfigureDisks(VirtualMachineConfigSpec vmConfigSpec,
        ManagedObjectReference vmwInstance) throws Exception {

    logger.debug("");

    long systemDiskMB = (long) paramHandler.getConfigDiskSpaceMB();
    VirtualMachineConfigInfo configSpec = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualDevice> devices = configSpec.getHardware().getDevice();
    VirtualDisk vdSystemDisk = getVMSystemDisk(devices,
            configSpec.getName());

    configureSystemDisk(vmConfigSpec, systemDiskMB, vdSystemDisk);
    configureDataDisks(vmConfigSpec, devices, vdSystemDisk);
}
项目:contrail-vcenter-plugin    文件:VCenterDB.java   
protected static String getVirtualMachineMacAddress(
        VirtualMachineConfigInfo vmConfigInfo,
        DistributedVirtualPortgroup portGroup) {
    VirtualDevice devices[] = vmConfigInfo.getHardware().getDevice();
    for (VirtualDevice device : devices) {
        // Assuming only one interface
        if (device instanceof VirtualEthernetCard) {
            VirtualDeviceBackingInfo backingInfo =
                    device.getBacking();

            if (backingInfo == null)
                continue;

            // Is it backed by the distributed virtual port group?
            if (backingInfo instanceof
                VirtualEthernetCardDistributedVirtualPortBackingInfo) {
                VirtualEthernetCardDistributedVirtualPortBackingInfo
                dvpBackingInfo =
                (VirtualEthernetCardDistributedVirtualPortBackingInfo)
                backingInfo;
                if ((dvpBackingInfo.getPort() == null) ||
                    (dvpBackingInfo.getPort().getPortgroupKey() == null))
                    continue;

                if (dvpBackingInfo.getPort().getPortgroupKey().
                        equals(portGroup.getKey())) {
                    String vmMac = ((VirtualEthernetCard) device).
                            getMacAddress();
                    return vmMac;
                }
            }
        }
    }
    s_logger.error("dvPg: " + portGroup.getName() + " vmConfig: " +
            vmConfigInfo + " MAC Address NOT found");
    return null;
}
项目:vijava    文件:VmDiskOp.java   
private static VirtualDevice findVirtualDevice(
    VirtualMachineConfigInfo vmConfig, String name)
{
  VirtualDevice [] devices = vmConfig.getHardware().getDevice();
  for(int i=0;i<devices.length;i++)
  {
    if(devices[i].getDeviceInfo().getLabel().equals(name))
    {                             
      return devices[i];
    }
  }
  return null;
}
项目:vijava    文件:VmCdOp.java   
private static VirtualDevice findVirtualDevice(
    VirtualMachineConfigInfo vmConfig, String name)
{
  VirtualDevice [] devices = vmConfig.getHardware().getDevice();
  for(int i=0;i<devices.length;i++)
  {
    if(devices[i].getDeviceInfo().getLabel().equals(name))
    {                             
      return devices[i];
    }
  }
  return null;
}
项目:vijava    文件:RemoveVmDisk.java   
private static VirtualDevice findVirtualDevice(
    VirtualMachineConfigInfo cfg, String name)
{
  VirtualDevice [] devices = cfg.getHardware().getDevice();
  for(int i=0;devices!=null && i<devices.length; i++)
  {
    if(devices[i].getDeviceInfo().getLabel().equals(name))
    {                             
      return devices[i];
    }
  }
  return null;
}
项目: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;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public boolean isTemplate() throws Exception {
    VirtualMachineConfigInfo configInfo = getConfigInfo();
    return configInfo.isTemplate();
}
项目:cloudstack    文件:VirtualMachineMO.java   
public VirtualMachineConfigInfo getConfigInfo() throws Exception {
    return (VirtualMachineConfigInfo)_context.getVimClient().getDynamicProperty(_mor, "config");
}
项目:cloudstack    文件:SiocManagerImpl.java   
private ResultWrapper updateSiocInfoForWorkerVM(VMwareUtil.VMwareConnection connection, ManagedObjectReference morVm, String datastoreName,
                                                int limitIopsPerGB) throws Exception {
    int limitIopsTotal = 0;
    List<ManagedObjectReference> tasks = new ArrayList<>();

    VirtualMachineConfigInfo vmci = (VirtualMachineConfigInfo)VMwareUtil.getEntityProps(connection, morVm,
            new String[] { "config" }).get("config");
    List<VirtualDevice> devices = vmci.getHardware().getDevice();

    for (VirtualDevice device : devices) {
        if (device instanceof VirtualDisk) {
            VirtualDisk disk = (VirtualDisk)device;

            if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) {
                VirtualDeviceFileBackingInfo backingInfo = (VirtualDeviceFileBackingInfo)disk.getBacking();

                if (backingInfo.getFileName().contains(datastoreName)) {
                    boolean diskUpdated = false;

                    StorageIOAllocationInfo sioai = disk.getStorageIOAllocation();

                    long currentLimitIops = sioai.getLimit() !=  null ? sioai.getLimit() : Long.MIN_VALUE;
                    long newLimitIops = getNewLimitIopsBasedOnVolumeSize(disk.getCapacityInBytes(), limitIopsPerGB);

                    limitIopsTotal += newLimitIops;

                    if (currentLimitIops != newLimitIops) {
                        sioai.setLimit(newLimitIops);

                        diskUpdated = true;
                    }

                    if (diskUpdated) {
                        VirtualDeviceConfigSpec vdcs = new VirtualDeviceConfigSpec();

                        vdcs.setDevice(disk);
                        vdcs.setOperation(VirtualDeviceConfigSpecOperation.EDIT);

                        VirtualMachineConfigSpec vmcs = new VirtualMachineConfigSpec();

                        vmcs.getDeviceChange().add(vdcs);

                        try {
                            ManagedObjectReference task = VMwareUtil.reconfigureVm(connection, morVm, vmcs);

                            tasks.add(task);

                            LOGGER.info(getInfoMsgForWorkerVm(newLimitIops));
                        } catch (Exception ex) {
                            throw new Exception("Error: " + ex.getMessage());
                        }
                    }
                }
            }
        }
    }

    return new ResultWrapper(limitIopsTotal, tasks);
}
项目:vijava    文件:VmDiskOp.java   
static VirtualDeviceConfigSpec createAddDiskConfigSpec(
    VirtualMachine vm, int diskSize, String diskMode, String diskName) throws Exception
{
  VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();      
  VirtualMachineConfigInfo vmConfig = (VirtualMachineConfigInfo)vm.getConfig();
  VirtualDevice[] vds = vmConfig.getHardware().getDevice();

  VirtualDisk disk =  new VirtualDisk();
  VirtualDiskFlatVer2BackingInfo diskfileBacking = new VirtualDiskFlatVer2BackingInfo();

  int key = 0;
  int unitNumber = 0;
  for(int k=0;k<vds.length;k++)
  {
    if(vds[k].getDeviceInfo().getLabel().equalsIgnoreCase("SCSI Controller 0"))
    {
      key = vds[k].getKey();
    }
  }

  unitNumber = vds.length + 1; //***********************seems NOT correct!!!
  String dsName = getFreeDatastoreName(vm, diskSize);
  if(dsName==null)
  {
    return null;
  }
  String fileName = "["+ dsName +"] "+ vm.getName() + "/" + diskName + ".vmdk";

  diskfileBacking.setFileName(fileName);
  diskfileBacking.setDiskMode(diskMode);

  disk.setControllerKey(key);
  disk.setUnitNumber(unitNumber);
  disk.setBacking(diskfileBacking);
  disk.setCapacityInKB(1024 * diskSize);
  disk.setKey(-1);

  diskSpec.setOperation(VirtualDeviceConfigSpecOperation.add);           
  diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);           
  diskSpec.setDevice(disk);                 
  return diskSpec;
}