Search in sources :

Example 21 with FileInfo

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

the class VirtualMachineMO method setSnapshotDirectory.

// snapshot directory in format of: /vmfs/volumes/<datastore name>/<path>
@Deprecated
public void setSnapshotDirectory(String snapshotDir) throws Exception {
    VirtualMachineFileInfo fileInfo = getFileInfo();
    Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
    String vmxUrl = _context.composeDatastoreBrowseUrl(dcInfo.second(), fileInfo.getVmPathName());
    byte[] vmxContent = _context.getResourceContent(vmxUrl);
    BufferedReader in = null;
    BufferedWriter out = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    boolean replaced = false;
    try {
        in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(vmxContent), "UTF-8"));
        out = new BufferedWriter(new OutputStreamWriter(bos, "UTF-8"));
        String line;
        while ((line = in.readLine()) != null) {
            if (line.startsWith("workingDir")) {
                replaced = true;
                out.write(String.format("workingDir=\"%s\"", snapshotDir));
                out.newLine();
            } else {
                out.write(line);
                out.newLine();
            }
        }
        if (!replaced) {
            out.newLine();
            out.write(String.format("workingDir=\"%s\"", snapshotDir));
            out.newLine();
        }
    } finally {
        if (in != null) {
            in.close();
        }
        if (out != null) {
            out.close();
        }
    }
    _context.uploadResourceContent(vmxUrl, bos.toByteArray());
// It seems that I don't need to do re-registration. VMware has bug in writing the correct snapshot's VMDK path to
// its disk backing info anyway.
// redoRegistration();
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo) BufferedWriter(java.io.BufferedWriter)

Example 22 with FileInfo

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

the class VirtualMachineMO method getSnapshotDescriptorDatastorePath.

public String getSnapshotDescriptorDatastorePath() throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().add("name");
    pSpec.getPathSet().add("config.files");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.FALSE);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    assert (ocs != null);
    String vmName = null;
    VirtualMachineFileInfo fileInfo = null;
    assert (ocs.size() == 1);
    for (ObjectContent oc : ocs) {
        List<DynamicProperty> props = oc.getPropSet();
        if (props != null) {
            assert (props.size() == 2);
            for (DynamicProperty prop : props) {
                if (prop.getName().equals("name")) {
                    vmName = prop.getVal().toString();
                } else {
                    fileInfo = (VirtualMachineFileInfo) prop.getVal();
                }
            }
        }
    }
    assert (vmName != null);
    assert (fileInfo != null);
    // .vmsd file exists at the same directory of .vmx file
    DatastoreFile vmxFile = new DatastoreFile(fileInfo.getVmPathName());
    return vmxFile.getCompanionPath(vmName + ".vmsd");
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) ArrayList(java.util.ArrayList) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo)

Aggregations

VirtualMachineFileInfo (com.vmware.vim25.VirtualMachineFileInfo)11 FileInfo (com.vmware.vim25.FileInfo)6 HostDatastoreBrowserSearchResults (com.vmware.vim25.HostDatastoreBrowserSearchResults)6 FileInfo (com.intellij.openapi.util.io.win32.FileInfo)4 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)3 CloudException (com.cloud.exception.CloudException)2 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)2 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)2 DynamicProperty (com.vmware.vim25.DynamicProperty)2 ObjectContent (com.vmware.vim25.ObjectContent)2 ObjectSpec (com.vmware.vim25.ObjectSpec)2 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)2 PropertySpec (com.vmware.vim25.PropertySpec)2 VirtualLsiLogicController (com.vmware.vim25.VirtualLsiLogicController)2 VirtualMachineVideoCard (com.vmware.vim25.VirtualMachineVideoCard)2 THashMap (gnu.trove.THashMap)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2