Search in sources :

Example 6 with VirtualMachineConfigSpec

use of com.vmware.vim25.VirtualMachineConfigSpec in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method ensureScsiDeviceController.

public void ensureScsiDeviceController() throws Exception {
    int scsiControllerKey = getScsiDeviceControllerKeyNoException();
    if (scsiControllerKey < 0) {
        VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
        // Scsi controller
        VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
        scsiController.setSharedBus(VirtualSCSISharing.noSharing);
        scsiController.setBusNumber(0);
        scsiController.setKey(1);
        VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
        scsiControllerSpec.setDevice(scsiController);
        scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
        vmConfig.setDeviceChange(new VirtualDeviceConfigSpec[] { scsiControllerSpec });
        if (configureVm(vmConfig)) {
            throw new Exception("Unable to add Scsi controller");
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController)

Example 7 with VirtualMachineConfigSpec

use of com.vmware.vim25.VirtualMachineConfigSpec in project cloudstack by apache.

the class VmwareHelper method setVmScaleUpConfig.

public static void setVmScaleUpConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz, int memoryMB, int memoryReserveMB, boolean limitCpuUse) {
    // VM config for scaling up
    vmConfig.setMemoryMB((long) memoryMB);
    vmConfig.setNumCPUs(cpuCount);
    ResourceAllocationInfo cpuInfo = new ResourceAllocationInfo();
    if (limitCpuUse) {
        cpuInfo.setLimit((long) (cpuSpeedMHz * cpuCount));
    } else {
        cpuInfo.setLimit(-1L);
    }
    cpuInfo.setReservation((long) cpuReservedMhz);
    vmConfig.setCpuAllocation(cpuInfo);
    ResourceAllocationInfo memInfo = new ResourceAllocationInfo();
    memInfo.setLimit((long) memoryMB);
    memInfo.setReservation((long) memoryReserveMB);
    vmConfig.setMemoryAllocation(memInfo);
}
Also used : ResourceAllocationInfo(com.vmware.vim25.ResourceAllocationInfo)

Example 8 with VirtualMachineConfigSpec

use of com.vmware.vim25.VirtualMachineConfigSpec in project cloudstack by apache.

the class VmwareHelper method setBasicVmConfig.

public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz, int memoryMB, int memoryReserveMB, String guestOsIdentifier, boolean limitCpuUse) {
    // VM config basics
    vmConfig.setMemoryMB((long) memoryMB);
    vmConfig.setNumCPUs(cpuCount);
    ResourceAllocationInfo cpuInfo = new ResourceAllocationInfo();
    if (limitCpuUse) {
        cpuInfo.setLimit(((long) cpuSpeedMHz * cpuCount));
    } else {
        cpuInfo.setLimit(-1L);
    }
    cpuInfo.setReservation((long) cpuReservedMhz);
    vmConfig.setCpuAllocation(cpuInfo);
    if (cpuSpeedMHz != cpuReservedMhz) {
        vmConfig.setCpuHotAddEnabled(true);
    }
    if (memoryMB != memoryReserveMB) {
        vmConfig.setMemoryHotAddEnabled(true);
    }
    ResourceAllocationInfo memInfo = new ResourceAllocationInfo();
    memInfo.setLimit((long) memoryMB);
    memInfo.setReservation((long) memoryReserveMB);
    vmConfig.setMemoryAllocation(memInfo);
    vmConfig.setGuestId(guestOsIdentifier);
}
Also used : ResourceAllocationInfo(com.vmware.vim25.ResourceAllocationInfo)

Example 9 with VirtualMachineConfigSpec

use of com.vmware.vim25.VirtualMachineConfigSpec in project cloudstack by apache.

the class ClusterMO method createVm.

@Override
public boolean createVm(VirtualMachineConfigSpec vmSpec) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createVM_Task(). target MOR: " + _mor.getValue() + ", VirtualMachineConfigSpec: " + new Gson().toJson(vmSpec));
    assert (vmSpec != null);
    DatacenterMO dcMo = new DatacenterMO(_context, getHyperHostDatacenter());
    ManagedObjectReference morPool = getHyperHostOwnerResourcePool();
    ManagedObjectReference morTask = _context.getService().createVMTask(dcMo.getVmFolder(), vmSpec, morPool, null);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - createVM_Task() done(successfully)");
        return true;
    } else {
        s_logger.error("VMware createVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createVM_Task() done(failed)");
    return false;
}
Also used : Gson(com.google.gson.Gson) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 10 with VirtualMachineConfigSpec

use of com.vmware.vim25.VirtualMachineConfigSpec in project cloudstack by apache.

the class VmwareResource method plugPublicNic.

private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception {
    // TODO : probably need to set traffic shaping
    Pair<ManagedObjectReference, String> networkInfo = null;
    VirtualSwitchType vSwitchType = VirtualSwitchType.StandardVirtualSwitch;
    if (_publicTrafficInfo != null) {
        vSwitchType = _publicTrafficInfo.getVirtualSwitchType();
    }
    /** FIXME We have no clue which network this nic is on and that means that we can't figure out the BroadcastDomainType
         *  so we assume that it's VLAN for now
         */
    if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
        networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, _opsTimeout, true, BroadcastDomainType.Vlan, null);
    } else {
        networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null, _opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials);
    }
    int nicIndex = allocPublicNicIndex(vmMo);
    try {
        VirtualDevice[] nicDevices = vmMo.getNicDevices();
        VirtualEthernetCard device = (VirtualEthernetCard) nicDevices[nicIndex];
        if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
            VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
            nicBacking.setDeviceName(networkInfo.second());
            nicBacking.setNetwork(networkInfo.first());
            device.setBacking(nicBacking);
        } else {
            HostMO hostMo = vmMo.getRunningHost();
            DatacenterMO dataCenterMo = new DatacenterMO(hostMo.getContext(), hostMo.getHyperHostDatacenter());
            device.setBacking(dataCenterMo.getDvPortBackingInfo(networkInfo));
        }
        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        //VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
        VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
        deviceConfigSpec.setDevice(device);
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
        vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
        if (!vmMo.configureVm(vmConfigSpec)) {
            throw new Exception("Failed to configure devices when plugPublicNic");
        }
    } catch (Exception e) {
        // restore allocation mask in case of exceptions
        String nicMasksStr = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK);
        int nicMasks = Integer.parseInt(nicMasksStr);
        nicMasks &= ~(1 << nicIndex);
        vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, String.valueOf(nicMasks));
        throw e;
    }
}
Also used : VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualSwitchType(com.cloud.hypervisor.vmware.mo.VirtualSwitchType) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Aggregations

VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)44 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)42 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)32 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)22 VirtualDevice (com.vmware.vim25.VirtualDevice)20 VirtualDisk (com.vmware.vim25.VirtualDisk)10 CloudException (com.cloud.exception.CloudException)7 InternalErrorException (com.cloud.exception.InternalErrorException)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 Gson (com.google.gson.Gson)7 IOException (java.io.IOException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ConnectException (java.net.ConnectException)7 RemoteException (java.rmi.RemoteException)7 ConfigurationException (javax.naming.ConfigurationException)7 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)5 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)5 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)5 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)5 Pair (com.cloud.utils.Pair)4