- Timestamp:
- Feb 10, 2009 11:41:17 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r16620 r16622 1485 1485 ) 1486 1486 { 1487 // construct a unique target path 1487 /* If the href is empty use the VM name as filename */ 1488 Utf8Str strFilename = di.strHref.c_str(); 1489 if (di.strHref.c_str()[0] == 0) 1490 strFilename = Utf8StrFmt("%s.vmdk", nameVBox.c_str()); 1491 /* Construct a unique target path */ 1488 1492 Utf8StrFmt strPath("%ls%c%s", 1489 1493 bstrDefaultHardDiskLocation.raw(), 1490 1494 RTPATH_DELIMITER, 1491 di.strHref.c_str());1495 strFilename.c_str()); 1492 1496 searchUniqueDiskImageFilePath(strPath); 1493 1497 1494 / / find the description for the hard disk controller that has the1495 // same ID as hd.idController1498 /* find the description for the hard disk controller 1499 * that has the same ID as hd.idController */ 1496 1500 const VirtualSystemDescriptionEntry *pController; 1497 1501 if (!(pController = pNewDesc->findControllerFromID(hd.idController))) … … 1499 1503 tr("Internal inconsistency looking up hard disk controller.")); 1500 1504 1501 / / controller to attach to @todo bus?1505 /* controller to attach to @todo bus? */ 1502 1506 Utf8StrFmt strExtraConfig("controller=%RI16", 1503 1507 pController->ulIndex); … … 1901 1905 const VirtualDisk &vd = itVirtualDisk->second; 1902 1906 1903 /* Construct the source file path */ 1904 Utf8StrFmt strSrcFilePath("%s%c%s", strSrcDir.c_str(), RTPATH_DELIMITER, di.strHref.c_str()); 1905 /* Check if the source file exists */ 1906 if (!RTPathExists(strSrcFilePath.c_str())) 1907 /* Make sure all target directories exists */ 1908 rc = VirtualBox::ensureFilePathExists(pcszDstFilePath); 1909 CheckComRCThrowRC(rc); 1910 ComPtr<IHardDisk2> dstHdVBox; 1911 /* If strHref is empty we have to create a new file */ 1912 if (di.strHref.c_str()[0] == 0) 1907 1913 { 1908 /* @todo: we have to create a new one */ 1909 throw setError(E_FAIL, 1910 tr("Creation of new disk images not supported yet.")); 1914 /* Which format to use? */ 1915 Bstr srcFormat = L"VDI"; 1916 if ( (!RTStrICmp(di.strFormat.c_str(), "http://www.vmware.com/specifications/vmdk.html#sparse")) 1917 || (!RTStrICmp(di.strFormat.c_str(), "http://www.vmware.com/specifications/vmdk.html#compressed"))) 1918 srcFormat = L"VMDK"; 1919 /* Create an empty hard disk */ 1920 rc = app->mVirtualBox->CreateHardDisk2(srcFormat, Bstr(pcszDstFilePath), dstHdVBox.asOutParam()); 1921 CheckComRCThrowRC(rc); 1922 /* Create a dynamic growing disk image with the given capacity */ 1923 ComPtr<IProgress> progress; 1924 dstHdVBox->CreateDynamicStorage(di.iCapacity / _1M, progress.asOutParam()); 1925 CheckComRCThrowRC(rc); 1926 rc = progress->WaitForCompletion(-1); 1927 CheckComRCThrowRC(rc); 1911 1928 } 1912 1929 else 1913 1930 { 1914 /* Make sure all target directories exists */ 1915 rc = VirtualBox::ensureFilePathExists(pcszDstFilePath); 1916 CheckComRCThrowRC(rc); 1931 /* Construct the source file path */ 1932 Utf8StrFmt strSrcFilePath("%s%c%s", strSrcDir.c_str(), RTPATH_DELIMITER, di.strHref.c_str()); 1933 /* Check if the source file exists */ 1934 if (!RTPathExists(strSrcFilePath.c_str())) 1935 /* This isn't allowed */ 1936 throw setError(VBOX_E_FILE_ERROR, 1937 tr("Source virtual disk image file '%s' doesn't exists", 1938 strSrcFilePath.c_str())); 1917 1939 /* Clone the disk image (this is necessary cause the id has 1918 1940 * to be recreated for the case the same hard disk is … … 1926 1948 CheckComRCThrowRC(rc); 1927 1949 /* Create a new hard disk interface for the destination disk image */ 1928 ComPtr<IHardDisk2> dstHdVBox;1929 1950 rc = app->mVirtualBox->CreateHardDisk2(srcFormat, Bstr(pcszDstFilePath), dstHdVBox.asOutParam()); 1930 1951 CheckComRCThrowRC(rc); … … 1938 1959 rc = srcHdVBox->Close(); 1939 1960 CheckComRCThrowRC(rc); 1940 /* Now use the new uuid to attach the disk image to our new machine */1941 ComPtr<IMachine> sMachine;1942 rc = session->COMGETTER(Machine)(sMachine.asOutParam());1943 CheckComRCThrowRC(rc);1944 Guid hdId;1945 rc = dstHdVBox->COMGETTER(Id)(hdId.asOutParam());;1946 CheckComRCThrowRC(rc);1947 /* For now we assume we have one controller of every type only */1948 HardDiskController hdc = (*vsysThis.mapControllers.find(vd.idController)).second;1949 StorageBus_T sbt = StorageBus_IDE;1950 switch (hdc.system)1951 {1952 case HardDiskController::IDE: sbt = StorageBus_IDE; break;1953 case HardDiskController::SATA: sbt = StorageBus_SATA; break;1954 //case HardDiskController::SCSI: sbt = StorageBus_SCSI; break; // @todo: not available yet1955 default: break;1956 }1957 rc = sMachine->AttachHardDisk2(hdId, sbt, hdc.ulBusNumber, 0);1958 CheckComRCThrowRC(rc);1959 rc = sMachine->SaveSettings();1960 CheckComRCThrowRC(rc);1961 rc = session->Close();1962 CheckComRCThrowRC(rc);1963 1961 } 1962 /* Now use the new uuid to attach the disk image to our new machine */ 1963 ComPtr<IMachine> sMachine; 1964 rc = session->COMGETTER(Machine)(sMachine.asOutParam()); 1965 CheckComRCThrowRC(rc); 1966 Guid hdId; 1967 rc = dstHdVBox->COMGETTER(Id)(hdId.asOutParam());; 1968 CheckComRCThrowRC(rc); 1969 /* For now we assume we have one controller of every type only */ 1970 HardDiskController hdc = (*vsysThis.mapControllers.find(vd.idController)).second; 1971 StorageBus_T sbt = StorageBus_IDE; 1972 switch (hdc.system) 1973 { 1974 case HardDiskController::IDE: sbt = StorageBus_IDE; break; 1975 case HardDiskController::SATA: sbt = StorageBus_SATA; break; 1976 //case HardDiskController::SCSI: sbt = StorageBus_SCSI; break; // @todo: not available yet 1977 default: break; 1978 } 1979 rc = sMachine->AttachHardDisk2(hdId, sbt, hdc.ulBusNumber, 0); 1980 CheckComRCThrowRC(rc); 1981 rc = sMachine->SaveSettings(); 1982 CheckComRCThrowRC(rc); 1983 rc = session->Close(); 1984 CheckComRCThrowRC(rc); 1964 1985 } 1965 1986 }
Note:
See TracChangeset
for help on using the changeset viewer.