Search in sources :

Example 1 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareStorageProcessor method handleDatastoreAndVmdkDetachManaged.

private void handleDatastoreAndVmdkDetachManaged(String diskUuid, String iqn, String storageHost, int storagePort) throws Exception {
    if (storagePort == DEFAULT_NFS_PORT) {
        VmwareContext context = hostService.getServiceContext(null);
        VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
        // for managed NFS datastore
        hyperHost.unmountDatastore(diskUuid);
    } else {
        handleDatastoreAndVmdkDetach(VmwareResource.getDatastoreName(iqn), iqn, storageHost, storagePort);
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)

Example 2 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareStorageProcessor method handleDatastoreAndVmdkDetach.

public void handleDatastoreAndVmdkDetach(String datastoreName, String iqn, String storageHost, int storagePort) throws Exception {
    VmwareContext context = hostService.getServiceContext(null);
    VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
    removeVmfsDatastore(hyperHost, datastoreName, storageHost, storagePort, trimIqn(iqn));
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)

Example 3 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(GetStoragePoolCapabilitiesCommand cmd) {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        HostMO host = (HostMO) hyperHost;
        StorageFilerTO pool = cmd.getPool();
        ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
        if (morDatastore == null) {
            morDatastore = hyperHost.mountDatastore((pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup || pool.getType() == StoragePoolType.DatastoreCluster), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""), true);
        }
        assert (morDatastore != null);
        DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDatastore);
        GetStoragePoolCapabilitiesAnswer answer = new GetStoragePoolCapabilitiesAnswer(cmd);
        boolean hardwareAccelerationSupportForDataStore = getHardwareAccelerationSupportForDataStore(host.getMor(), dsMo.getName());
        Map<String, String> poolDetails = answer.getPoolDetails();
        poolDetails.put(Storage.Capability.HARDWARE_ACCELERATION.toString(), String.valueOf(hardwareAccelerationSupportForDataStore));
        answer.setPoolDetails(poolDetails);
        answer.setResult(true);
        return answer;
    } catch (Throwable e) {
        GetStoragePoolCapabilitiesAnswer answer = new GetStoragePoolCapabilitiesAnswer(cmd);
        answer.setResult(false);
        answer.setDetails(createLogMessageException(e, cmd));
        return answer;
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)

Example 4 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method registerVm.

/**
 * Registers the vm to the inventory given the vmx file.
 */
private void registerVm(String vmName, DatastoreMO dsMo) throws Exception {
    // 1st param
    VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
    ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
    DatacenterMO dataCenterMo = new DatacenterMO(getServiceContext(), dcMor);
    ManagedObjectReference vmFolderMor = dataCenterMo.getVmFolder();
    // 2nd param
    String vmxFilePath = dsMo.searchFileInSubFolders(vmName + ".vmx", false, VmwareManager.s_vmwareSearchExcludeFolder.value());
    // 5th param
    ManagedObjectReference morPool = hyperHost.getHyperHostOwnerResourcePool();
    ManagedObjectReference morTask = getServiceContext().getService().registerVMTask(vmFolderMor, vmxFilePath, vmName, false, morPool, hyperHost.getMor());
    boolean result = getServiceContext().getVimClient().waitForTask(morTask);
    if (!result) {
        throw new Exception("Unable to register vm due to " + TaskMO.getTaskFailureInfo(getServiceContext(), morTask));
    } else {
        getServiceContext().waitForTaskProgressDone(morTask);
    }
}
Also used : VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) 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) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Example 5 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method cleanupNetworkElementCommand.

private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
    VmwareContext context = getServiceContext();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        IpAddressTO[] ips = cmd.getIpAddresses();
        String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName);
        // the check and will try to find it within datacenter
        if (vmMo == null) {
            if (hyperHost instanceof HostMO) {
                final DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
                vmMo = dcMo.findVm(routerName);
            }
        }
        if (vmMo == null) {
            String msg = String.format("Router %s no longer exists to execute IPAssoc command ", routerName);
            s_logger.error(msg);
            throw new Exception(msg);
        }
        final String lastIp = cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
        for (IpAddressTO ip : ips) {
            if (ip.isAdd() || lastIp.equalsIgnoreCase("false")) {
                continue;
            }
            Pair<VirtualDevice, Integer> nicInfo = getVirtualDevice(vmMo, ip);
            if (nicInfo.second() == 2) {
                return new ExecutionResult(true, "Not removing eth2 in network VR because it is the public NIC of source NAT");
            }
            if (nicInfo.first() == null) {
                return new ExecutionResult(false, "Couldn't find NIC");
            }
            configureNicDevice(vmMo, nicInfo.first(), VirtualDeviceConfigSpecOperation.REMOVE, "unplugNicCommand");
        }
    } catch (Throwable e) {
        s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e);
        return new ExecutionResult(false, e.toString());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VirtualDevice(com.vmware.vim25.VirtualDevice) ExecutionResult(com.cloud.utils.ExecutionResult) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) 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) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Aggregations

VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)85 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)65 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)65 RemoteException (java.rmi.RemoteException)59 UnsupportedEncodingException (java.io.UnsupportedEncodingException)57 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)48 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)46 CloudException (com.cloud.exception.CloudException)40 InternalErrorException (com.cloud.exception.InternalErrorException)40 IOException (java.io.IOException)40 ConnectException (java.net.ConnectException)40 ConfigurationException (javax.naming.ConfigurationException)40 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)31 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)27 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)23 Pair (com.cloud.utils.Pair)15 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)12 Answer (com.cloud.agent.api.Answer)11 AttachIsoAnswer (com.cloud.agent.api.AttachIsoAnswer)10 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)10