Search in sources :

Example 1 with VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext 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 VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext 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 VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(CreatePrivateTemplateFromVolumeCommand cmd) {
    try {
        VmwareContext context = getServiceContext();
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        return mgr.getStorageManager().execute(this, cmd);
    } catch (Throwable e) {
        return new CreatePrivateTemplateAnswer(cmd, false, createLogMessageException(e, cmd));
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)

Example 4 with VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext 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)

Example 5 with VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext in project cloudstack by apache.

the class VmwareResource method getNewPathAndChainInfoInDatastoreCluster.

private Pair<String, String> getNewPathAndChainInfoInDatastoreCluster(VirtualMachineMO vmMo, String path, String chainInfo, boolean managed, String iscsiName, String poolUUID, String poolType) throws Exception {
    VmwareContext context = getServiceContext();
    VmwareHypervisorHost hyperHost = getHyperHost(context);
    if (poolType != null && poolType.equalsIgnoreCase(Storage.StoragePoolType.DatastoreCluster.toString())) {
        VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
        VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDiskWithVolumeDetails(diskInfoBuilder, path, chainInfo, managed, iscsiName, poolUUID, hyperHost, context);
        if (diskInfoBuilder != null && matchingExistingDisk != null) {
            String[] diskChain = matchingExistingDisk.getDiskChain();
            DatastoreFile file = new DatastoreFile(diskChain[0]);
            if (!file.getFileBaseName().equalsIgnoreCase(path)) {
                if (s_logger.isInfoEnabled())
                    s_logger.info("Detected disk-chain top file change on volume: " + path + " -> " + file.getFileBaseName());
                path = file.getFileBaseName();
                chainInfo = _gson.toJson(matchingExistingDisk);
                return new Pair<>(path, chainInfo);
            }
        }
    }
    return null;
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) VirtualMachineDiskInfoBuilder(com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) Pair(com.cloud.utils.Pair)

Aggregations

VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)106 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)66 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)65 RemoteException (java.rmi.RemoteException)53 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)49 UnsupportedEncodingException (java.io.UnsupportedEncodingException)48 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)39 IOException (java.io.IOException)38 CloudException (com.cloud.exception.CloudException)36 ConfigurationException (javax.naming.ConfigurationException)34 InternalErrorException (com.cloud.exception.InternalErrorException)31 ConnectException (java.net.ConnectException)31 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)26 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)23 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)21 Pair (com.cloud.utils.Pair)20 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)15 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)14 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)13 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)13