Search in sources :

Example 66 with ManagedObjectReference

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

the class HostDatastoreSystemMO method createVmfsDatastore.

public ManagedObjectReference createVmfsDatastore(String datastoreName, HostScsiDisk hostScsiDisk) throws Exception {
    // just grab the first instance of VmfsDatastoreOption
    VmfsDatastoreOption vmfsDatastoreOption = _context.getService().queryVmfsDatastoreCreateOptions(_mor, hostScsiDisk.getDevicePath(), 5).get(0);
    VmfsDatastoreCreateSpec vmfsDatastoreCreateSpec = (VmfsDatastoreCreateSpec) vmfsDatastoreOption.getSpec();
    // set the name of the datastore to be created
    vmfsDatastoreCreateSpec.getVmfs().setVolumeName(datastoreName);
    return _context.getService().createVmfsDatastore(_mor, vmfsDatastoreCreateSpec);
}
Also used : VmfsDatastoreOption(com.vmware.vim25.VmfsDatastoreOption) VmfsDatastoreCreateSpec(com.vmware.vim25.VmfsDatastoreCreateSpec)

Example 67 with ManagedObjectReference

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

the class HostDatastoreSystemMO method findDatastoreByUrl.

// storeUrl in nfs://host/exportpath format
public ManagedObjectReference findDatastoreByUrl(String storeUrl) throws Exception {
    assert (storeUrl != null);
    List<ManagedObjectReference> datastores = getDatastores();
    if (datastores != null && datastores.size() > 0) {
        for (ManagedObjectReference morDatastore : datastores) {
            NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
            if (info != null) {
                URI uri = new URI(storeUrl);
                String vmwareStyleUrl = "netfs://" + uri.getHost() + "/" + uri.getPath() + "/";
                if (info.getUrl().equals(vmwareStyleUrl))
                    return morDatastore;
            }
        }
    }
    return null;
}
Also used : NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 68 with ManagedObjectReference

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

the class DatastoreMO method deleteFolder.

public boolean deleteFolder(String folder, ManagedObjectReference morDc) throws Exception {
    ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
    ManagedObjectReference morTask = _context.getService().deleteDatastoreFileTask(morFileManager, folder, morDc);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware deleteDatastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 69 with ManagedObjectReference

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

the class DatastoreMO method deleteFile.

public boolean deleteFile(String path, ManagedObjectReference morDc, boolean testExistence) throws Exception {
    String datastoreName = getName();
    ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
    String fullPath = path;
    if (!DatastoreFile.isFullDatastorePath(fullPath))
        fullPath = String.format("[%s] %s", datastoreName, path);
    DatastoreFile file = new DatastoreFile(fullPath);
    // Test if file specified is null or empty. We don't need to attempt to delete and return success.
    if (file.getFileName() == null || file.getFileName().isEmpty()) {
        return true;
    }
    try {
        if (testExistence && !fileExists(fullPath)) {
            String searchResult = searchFileInSubFolders(file.getFileName(), true);
            if (searchResult == null) {
                return true;
            } else {
                fullPath = searchResult;
            }
        }
    } catch (Exception e) {
        s_logger.info("Unable to test file existence due to exception " + e.getClass().getName() + ", skip deleting of it");
        return true;
    }
    ManagedObjectReference morTask = _context.getService().deleteDatastoreFileTask(morFileManager, fullPath, morDc);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware deleteDatastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : CloudException(com.cloud.exception.CloudException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 70 with ManagedObjectReference

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

the class DistributedVirtualSwitchMO method retrieveVlanPvlan.

public Map<Integer, HypervisorHostHelper.PvlanType> retrieveVlanPvlan(int vlanid, int secondaryvlanid, ManagedObjectReference dvSwitchMor) throws Exception {
    assert (dvSwitchMor != null);
    Map<Integer, HypervisorHostHelper.PvlanType> result = new HashMap<Integer, HypervisorHostHelper.PvlanType>();
    VMwareDVSConfigInfo configinfo = (VMwareDVSConfigInfo) _context.getVimClient().getDynamicProperty(dvSwitchMor, "config");
    List<VMwareDVSPvlanMapEntry> pvlanconfig = null;
    pvlanconfig = configinfo.getPvlanConfig();
    if (null == pvlanconfig || 0 == pvlanconfig.size()) {
        return result;
    }
    for (VMwareDVSPvlanMapEntry mapEntry : pvlanconfig) {
        int entryVlanid = mapEntry.getPrimaryVlanId();
        int entryPvlanid = mapEntry.getSecondaryVlanId();
        if (entryVlanid == entryPvlanid) {
            // promiscuous
            if (vlanid == entryVlanid) {
                // pvlan type will always be promiscuous in this case.
                result.put(vlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
            } else if ((vlanid != secondaryvlanid) && secondaryvlanid == entryVlanid) {
                result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
            }
        } else {
            if (vlanid == entryVlanid) {
                // vlan id in entry is promiscuous
                result.put(vlanid, HypervisorHostHelper.PvlanType.promiscuous);
            } else if (vlanid == entryPvlanid) {
                result.put(vlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
            }
            if ((vlanid != secondaryvlanid) && secondaryvlanid == entryVlanid) {
                //promiscuous
                result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.promiscuous);
            } else if (secondaryvlanid == entryPvlanid) {
                result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
            }
        }
        // go over the entire list. Return.
        if (result.containsKey(vlanid) && result.get(vlanid) != HypervisorHostHelper.PvlanType.promiscuous)
            return result;
        // If we've already found both vlanid and pvlanid, we have enough info to make a decision. Return.
        if (result.containsKey(vlanid) && result.containsKey(secondaryvlanid))
            return result;
    }
    return result;
}
Also used : VMwareDVSConfigInfo(com.vmware.vim25.VMwareDVSConfigInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VMwareDVSPvlanMapEntry(com.vmware.vim25.VMwareDVSPvlanMapEntry)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)236 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)62 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)57 Pair (com.cloud.utils.Pair)49 RemoteException (java.rmi.RemoteException)48 ArrayList (java.util.ArrayList)45 UnsupportedEncodingException (java.io.UnsupportedEncodingException)39 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)35 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)32 IOException (java.io.IOException)31 CloudException (com.cloud.exception.CloudException)30 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)30 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)29 ObjectContent (com.vmware.vim25.ObjectContent)28 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)27 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)25 ConfigurationException (javax.naming.ConfigurationException)24 InternalErrorException (com.cloud.exception.InternalErrorException)23 VirtualDisk (com.vmware.vim25.VirtualDisk)23 ConnectException (java.net.ConnectException)23