Changeset 81086 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Sep 30, 2019 6:33:56 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageAppliance.cpp
r81085 r81086 44 44 #include <VBox/param.h> 45 45 46 47 #ifndef VBOX_WITH_PROTOBUF48 #define VBOX_WITH_PROTOBUF49 #endif50 51 #ifdef VBOX_WITH_PROTOBUF52 #include <google/protobuf/util/json_util.h>53 #include <google/protobuf/text_format.h>54 #include <VBox/vsd.pb.h>55 #include <fstream>56 using namespace std;57 using namespace google::protobuf;58 #endif59 60 46 #include "VBoxManage.h" 61 47 using namespace com; 48 62 49 63 50 // funcs … … 313 300 break; 314 301 315 /*--cloud and --vsys are mutually exclusive, only one must be presented*/302 /*--cloud and --vsys are orthogonal, only one must be presented*/ 316 303 case 'j': // --cloud 317 304 if (fCloud == false && actionType == NOT_SET) … … 1508 1495 */ 1509 1496 1510 #ifdef VBOX_WITH_PROTOBUF1511 std::map< ComPtr<IVirtualSystemDescription>, vsd::InstanceDescription > VSDToInstanceDescriptionMap;1512 #else1513 1497 /* VSDList is needed for the second stage where we launch the cloud instances if it was requested by user */ 1514 1498 std::list< ComPtr<IVirtualSystemDescription> > VSDList; 1515 #endif1516 1517 1499 std::list< ComPtr<IMachine> >::iterator itM; 1518 1500 uint32_t i=0; … … 1525 1507 CHECK_ERROR_BREAK(pMachine, ExportTo(pAppliance, Bstr(pszAbsFilePath).raw(), pVSD.asOutParam())); 1526 1508 1527 #ifdef VBOX_WITH_PROTOBUF1528 vsd::InstanceDescription protobufInstDesc;1529 RTEXITCODE rcExit = RTEXITCODE_SUCCESS;1530 Bstr bstrDesc;1531 CHECK_ERROR_BREAK(pVSD, GetVSDDescription(bstrDesc.asOutParam()));1532 Utf8Str strHumanReadableFormVSD(bstrDesc);1533 {1534 bool st = google::protobuf::TextFormat::ParseFromString(strHumanReadableFormVSD.c_str(), &protobufInstDesc);1535 if (st)1536 {1537 RTPrintf("message protobufInstDesc was parsed.\n");1538 string strJson;1539 google::protobuf::util::Status status = google::protobuf::util::MessageToJsonString(protobufInstDesc, &strJson);1540 RTPrintf("\nvsd::InstanceDescription:\n%s\n##################\n", strJson.c_str());1541 }1542 }1543 1544 vsd::InstanceDescription protobufUserInstDesc;1545 #endif1546 1547 1509 // Add additional info to the virtual system description if the user wants so 1548 1510 ArgsMap *pmapArgs = NULL; … … 1552 1514 if (pmapArgs) 1553 1515 { 1554 1555 #ifdef VBOX_WITH_PROTOBUF1556 vsd::InstanceDescription_CloudSettings* pInstCloudSettings = NULL;1557 if (actionType == CLOUD)1558 {1559 pInstCloudSettings = protobufUserInstDesc.mutable_cloud();1560 pInstCloudSettings->set_providershortname(strOutputFile.substr(0, strOutputFile.find("://")).c_str());1561 }1562 #endif1563 1564 1516 ArgsMap::iterator itD; 1565 1517 for (itD = pmapArgs->begin(); … … 1571 1523 //remove default value if user has specified new name (default value is set in the ExportTo()) 1572 1524 // pVSD->RemoveDescriptionByType(VirtualSystemDescriptionType_Name); 1573 #ifndef VBOX_WITH_PROTOBUF1574 1525 pVSD->AddDescription(VirtualSystemDescriptionType_Name, 1575 1526 Bstr(itD->second).raw(), 1576 1527 Bstr(itD->second).raw()); 1577 #else1578 protobufUserInstDesc.set_name(itD->second.c_str());1579 #endif1580 1528 } 1581 1529 else if (itD->first == "product") 1582 {1583 #ifndef VBOX_WITH_PROTOBUF1584 1530 pVSD->AddDescription(VirtualSystemDescriptionType_Product, 1585 1531 Bstr(itD->second).raw(), 1586 1532 Bstr(itD->second).raw()); 1587 #else1588 protobufUserInstDesc.set_product(itD->second.c_str());1589 #endif1590 }1591 1533 else if (itD->first == "producturl") 1592 {1593 #ifndef VBOX_WITH_PROTOBUF1594 1534 pVSD->AddDescription(VirtualSystemDescriptionType_ProductUrl, 1595 1535 Bstr(itD->second).raw(), 1596 1536 Bstr(itD->second).raw()); 1597 #else1598 protobufUserInstDesc.set_producturl(itD->second.c_str());1599 #endif1600 }1601 1537 else if (itD->first == "vendor") 1602 {1603 #ifndef VBOX_WITH_PROTOBUF1604 1538 pVSD->AddDescription(VirtualSystemDescriptionType_Vendor, 1605 1539 Bstr(itD->second).raw(), 1606 1540 Bstr(itD->second).raw()); 1607 #else1608 protobufUserInstDesc.set_vendor(itD->second.c_str());1609 #endif1610 }1611 1541 else if (itD->first == "vendorurl") 1612 {1613 #ifndef VBOX_WITH_PROTOBUF1614 1542 pVSD->AddDescription(VirtualSystemDescriptionType_VendorUrl, 1615 1543 Bstr(itD->second).raw(), 1616 1544 Bstr(itD->second).raw()); 1617 #else1618 protobufUserInstDesc.set_vendorurl(itD->second.c_str());1619 #endif1620 }1621 1545 else if (itD->first == "version") 1622 {1623 #ifndef VBOX_WITH_PROTOBUF1624 1546 pVSD->AddDescription(VirtualSystemDescriptionType_Version, 1625 1547 Bstr(itD->second).raw(), 1626 1548 Bstr(itD->second).raw()); 1627 #else1628 protobufUserInstDesc.set_version(itD->second.c_str());1629 #endif1630 }1631 1549 else if (itD->first == "description") 1632 {1633 #ifndef VBOX_WITH_PROTOBUF1634 1550 pVSD->AddDescription(VirtualSystemDescriptionType_Description, 1635 1551 Bstr(itD->second).raw(), 1636 1552 Bstr(itD->second).raw()); 1637 #else1638 protobufUserInstDesc.set_description(itD->second.c_str());1639 #endif1640 }1641 1553 else if (itD->first == "eula") 1642 {1643 1554 pVSD->AddDescription(VirtualSystemDescriptionType_License, 1644 1555 Bstr(itD->second).raw(), 1645 1556 Bstr(itD->second).raw()); 1646 }1647 1557 else if (itD->first == "eulafile") 1648 1558 { … … 1668 1578 /* add cloud export settings */ 1669 1579 else if (itD->first == "cloudshape") 1670 {1671 #ifndef VBOX_WITH_PROTOBUF1672 1580 pVSD->AddDescription(VirtualSystemDescriptionType_CloudInstanceShape, 1673 1581 Bstr(itD->second).raw(), 1674 1582 Bstr(itD->second).raw()); 1675 #else1676 pInstCloudSettings->set_instanceshape(itD->second.c_str());1677 #endif1678 }1679 1583 else if (itD->first == "clouddomain") 1680 {1681 #ifndef VBOX_WITH_PROTOBUF1682 1584 pVSD->AddDescription(VirtualSystemDescriptionType_CloudDomain, 1683 1585 Bstr(itD->second).raw(), 1684 1586 Bstr(itD->second).raw()); 1685 #else1686 pInstCloudSettings->set_domain(itD->second.c_str());1687 #endif1688 }1689 1587 else if (itD->first == "clouddisksize") 1690 {1691 #ifndef VBOX_WITH_PROTOBUF1692 1588 pVSD->AddDescription(VirtualSystemDescriptionType_CloudBootDiskSize, 1693 1589 Bstr(itD->second).raw(), 1694 1590 Bstr(itD->second).raw()); 1695 #else1696 pInstCloudSettings->set_bootdisksize(itD->second.toUInt64());1697 #endif1698 }1699 1591 else if (itD->first == "cloudbucket") 1700 {1701 #ifndef VBOX_WITH_PROTOBUF1702 1592 pVSD->AddDescription(VirtualSystemDescriptionType_CloudBucket, 1703 1593 Bstr(itD->second).raw(), 1704 1594 Bstr(itD->second).raw()); 1705 #else1706 pInstCloudSettings->set_bucket(itD->second.c_str());1707 #endif1708 }1709 1595 else if (itD->first == "cloudocivcn") 1710 {1711 #ifndef VBOX_WITH_PROTOBUF1712 1596 pVSD->AddDescription(VirtualSystemDescriptionType_CloudOCIVCN, 1713 1597 Bstr(itD->second).raw(), 1714 1598 Bstr(itD->second).raw()); 1715 #else1716 pInstCloudSettings->set_vcn(itD->second.c_str());1717 #endif1718 }1719 1599 else if (itD->first == "cloudpublicip") 1720 {1721 #ifndef VBOX_WITH_PROTOBUF1722 1600 pVSD->AddDescription(VirtualSystemDescriptionType_CloudPublicIP, 1723 1601 Bstr(itD->second).raw(), 1724 1602 Bstr(itD->second).raw()); 1725 #else1726 pInstCloudSettings->set_fpublicip(itD->second.equals("true") ? true:false);1727 #endif1728 }1729 1603 else if (itD->first == "cloudprivateip") 1730 {1731 #ifndef VBOX_WITH_PROTOBUF1732 1604 pVSD->AddDescription(VirtualSystemDescriptionType_CloudPrivateIP, 1733 1605 Bstr(itD->second).raw(), NULL); 1734 #else1735 // pInstCloudSettings.set_fpublicip(itD->second.equals("true") ? true:false);1736 #endif1737 }1738 1606 else if (itD->first == "cloudprofile") 1739 {1740 #ifndef VBOX_WITH_PROTOBUF1741 1607 pVSD->AddDescription(VirtualSystemDescriptionType_CloudProfileName, 1742 1608 Bstr(itD->second).raw(), 1743 1609 Bstr(itD->second).raw()); 1744 #else1745 pInstCloudSettings->set_profilename(itD->second.c_str());1746 #endif1747 }1748 1610 else if (itD->first == "cloudocisubnet") 1749 {1750 #ifndef VBOX_WITH_PROTOBUF1751 1611 pVSD->AddDescription(VirtualSystemDescriptionType_CloudOCISubnet, 1752 1612 Bstr(itD->second).raw(), 1753 1613 Bstr(itD->second).raw()); 1754 #else1755 pInstCloudSettings->set_subnet(itD->second.c_str());1756 #endif1757 }1758 1614 else if (itD->first == "cloudkeepobject") 1759 {1760 #ifndef VBOX_WITH_PROTOBUF1761 1615 pVSD->AddDescription(VirtualSystemDescriptionType_CloudKeepObject, 1762 1616 Bstr(itD->second).raw(), 1763 1617 Bstr(itD->second).raw()); 1764 #else1765 pInstCloudSettings->set_fkeepobject(itD->second.equals("true") ? true:false);1766 #endif1767 }1768 1618 else if (itD->first == "cloudlaunchmode") 1769 {1770 #ifndef VBOX_WITH_PROTOBUF1771 1619 pVSD->AddDescription(VirtualSystemDescriptionType_CloudOCILaunchMode, 1772 1620 Bstr(itD->second).raw(), NULL); 1773 #else1774 // pInstCloudSettings.set_launch_mode(itD->second.c_str());1775 #endif1776 }1777 1621 else if (itD->first == "cloudlaunchinstance") 1778 {1779 #ifndef VBOX_WITH_PROTOBUF1780 1622 pVSD->AddDescription(VirtualSystemDescriptionType_CloudLaunchInstance, 1781 1623 Bstr(itD->second).raw(), 1782 1624 Bstr(itD->second).raw()); 1783 #else1784 pInstCloudSettings->set_flaunchinstance(itD->second.equals("true") ? true:false);1785 #endif1786 }1787 1625 } 1788 1626 } 1789 1627 1790 #ifndef VBOX_WITH_PROTOBUF1791 1628 VSDList.push_back(pVSD);//store vsd for the possible second stage 1792 #else1793 protobufInstDesc.MergeFrom(protobufUserInstDesc);1794 VSDToInstanceDescriptionMap.insert(make_pair(pVSD,protobufInstDesc));1795 1796 {1797 int messageSize = protobufUserInstDesc.ByteSizeLong();1798 RTPrintf("messageSize of protobufUserInstDesc is %d\n", messageSize);1799 string output;1800 bool st = google::protobuf::TextFormat::PrintToString(protobufUserInstDesc, &output);1801 if (st)1802 {1803 RTPrintf("message protobufUserInstDesc is %s\n", output.c_str());1804 Bstr updatedVersion(output.c_str());1805 CHECK_ERROR_BREAK(pVSD, UpdateVSDDescription(updatedVersion.raw()));1806 }1807 }1808 1809 {1810 int messageSize = protobufInstDesc.ByteSizeLong();1811 string output;1812 RTPrintf("messageSize of protobufInstDesc is %d\n", messageSize);1813 bool st = google::protobuf::TextFormat::PrintToString(protobufInstDesc, &output);1814 if (st)1815 RTPrintf("message protobufInstDesc is %s\n", output.c_str());1816 }1817 #endif1818 1819 1629 } 1820 1630 … … 1877 1687 { 1878 1688 /* Launch the exported VM if the appropriate flag had been set on the first stage */ 1879 1880 #ifndef VBOX_WITH_PROTOBUF1881 1689 for (std::list< ComPtr<IVirtualSystemDescription> >::iterator itVSD = VSDList.begin(); 1882 1690 itVSD != VSDList.end(); … … 1884 1692 { 1885 1693 ComPtr<IVirtualSystemDescription> pVSD = *itVSD; 1694 1886 1695 com::SafeArray<VirtualSystemDescriptionType_T> retTypes; 1887 1696 com::SafeArray<BSTR> aRefs; … … 1901 1710 1902 1711 if (flagCloudLaunchInstance.equals("true")) 1903 #else1904 for (std::map< ComPtr<IVirtualSystemDescription>, vsd::InstanceDescription >::iterator itIDL = VSDToInstanceDescriptionMap.begin();1905 itIDL != VSDToInstanceDescriptionMap.end();1906 ++itIDL)1907 {1908 ComPtr<IVirtualSystemDescription> pVSD = itIDL->first;1909 vsd::InstanceDescription protobufInstDesc = itIDL->second;1910 vsd::InstanceDescription_CloudSettings* pInstCloudSettings = protobufInstDesc.mutable_cloud();1911 bool boolflagCloudLaunchInstance = pInstCloudSettings->flaunchinstance();1912 1913 if (boolflagCloudLaunchInstance)1914 #endif1915 1712 { 1916 1713 /* Getting the short provider name */ … … 1925 1722 GetProviderByShortName(bstrCloudProviderShortName.raw(), pCloudProvider.asOutParam())); 1926 1723 1927 #ifndef VBOX_WITH_PROTOBUF1928 1724 CHECK_ERROR_BREAK(pVSD, GetDescriptionByType(VirtualSystemDescriptionType_CloudProfileName, 1929 1725 ComSafeArrayAsOutParam(retTypes), … … 1932 1728 ComSafeArrayAsOutParam(aVBoxValues), 1933 1729 ComSafeArrayAsOutParam(aExtraConfigValues))); 1730 1934 1731 ComPtr<ICloudProfile> pCloudProfile; 1935 1732 CHECK_ERROR_BREAK(pCloudProvider, GetProfileByName(Bstr(aVBoxValues[0]).raw(), pCloudProfile.asOutParam())); 1936 1733 retTypes.setNull(); aRefs.setNull(); aOvfValues.setNull(); aVBoxValues.setNull(); aExtraConfigValues.setNull(); 1937 #else1938 Utf8Str profilename(pInstCloudSettings->profilename().c_str());1939 ComPtr<ICloudProfile> pCloudProfile;1940 CHECK_ERROR_BREAK(pCloudProvider, GetProfileByName(Bstr(profilename).raw(), pCloudProfile.asOutParam()));1941 #endif1942 1734 1943 1735 ComObjPtr<ICloudClient> oCloudClient; … … 1952 1744 if (SUCCEEDED(rc)) 1953 1745 { 1954 #ifndef VBOX_WITH_PROTOBUF1955 1746 CHECK_ERROR_BREAK(pVSD, GetDescriptionByType(VirtualSystemDescriptionType_CloudInstanceId, 1956 1747 ComSafeArrayAsOutParam(retTypes), … … 1964 1755 Utf8Str(bstrCloudProviderShortName.raw()).c_str()); 1965 1756 retTypes.setNull(); aRefs.setNull(); aOvfValues.setNull(); aVBoxValues.setNull(); aExtraConfigValues.setNull(); 1966 #else1967 Bstr bstrDesc;1968 CHECK_ERROR_BREAK(pVSD, GetVSDDescription(bstrDesc.asOutParam()));1969 Utf8Str strHumanReadableFormVSD(bstrDesc);1970 vsd::InstanceDescription protobufInstDescWithInstanceId;1971 bool st = google::protobuf::TextFormat::ParseFromString(strHumanReadableFormVSD.c_str(), &protobufInstDescWithInstanceId);1972 if (st)1973 {1974 RTPrintf("message protobufInstDescWithInstanceId was parsed.\n");1975 string strJson;1976 google::protobuf::util::Status status = google::protobuf::util::MessageToJsonString(protobufInstDescWithInstanceId, &strJson);1977 RTPrintf("\nvsd::InstanceDescription:\n%s\n##################\n", strJson.c_str());1978 }1979 1980 vsd::InstanceDescription_CloudSettings* pInstCloudSettingsWithInstanceId = protobufInstDescWithInstanceId.mutable_cloud();1981 Utf8Str instanceId(pInstCloudSettingsWithInstanceId->instanceid().c_str());1982 RTPrintf("A cloud instance with id '%' (provider '%s') was started\n",1983 instanceId.c_str(),1984 /* Utf8Str(Bstr(aVBoxValues[0]).raw()).c_str(),*/1985 Utf8Str(bstrCloudProviderShortName.raw()).c_str());1986 #endif1987 1757 } 1988 1758 } 1989 1759 } 1990 1760 } 1991 1992 #ifdef VBOX_WITH_PROTOBUF1993 std::list< ComPtr<IMachine> >::iterator itM1;1994 i=0;1995 for (itM1 = llMachines.begin();1996 itM1 != llMachines.end();1997 ++itM1, ++i)1998 {1999 ComPtr<IMachine> pMachine = *itM1;2000 ComPtr<IVirtualSystemDescription> pVSD;2001 vsd::InstanceDescription protobufInstDesc;2002 2003 Bstr bstrMachineName;2004 CHECK_ERROR_BREAK(pMachine, COMGETTER(Name)(bstrMachineName.asOutParam()));2005 Bstr bstrSettingsFilePath;2006 CHECK_ERROR_BREAK(pMachine, COMGETTER(SettingsFilePath)(bstrSettingsFilePath.asOutParam()));2007 com::Utf8Str strBinaryVSDFile(bstrSettingsFilePath);2008 strBinaryVSDFile.stripFilename();2009 strBinaryVSDFile.append("/").append(Utf8Str(bstrMachineName)).append("-proto.export");2010 2011 fstream input(strBinaryVSDFile.c_str(), ios::in | ios::binary);2012 if (!input.good() || !protobufInstDesc.ParseFromIstream(&input))2013 {2014 RTMsgError("Cannot read the file \"%s\"\n", strBinaryVSDFile.c_str());2015 return RTEXITCODE_FAILURE;2016 }2017 input.close();2018 2019 RTPrintf("Successfully read the test file \"%s\"\n", strBinaryVSDFile.c_str());2020 const google::protobuf::Map< ::std::string, ::vsd::ImageDescription >& imList = protobufInstDesc.images();2021 google::protobuf::Map< ::std::string, ::vsd::ImageDescription >::const_iterator imListIt = imList.begin();2022 RTPrintf("\n########Instance decription########\n");2023 RTPrintf("Name: %s\n", protobufInstDesc.name().c_str());2024 RTPrintf("Id: %s\n", protobufInstDesc.id().c_str());2025 RTPrintf("Path: %s\n", protobufInstDesc.path().c_str());2026 RTPrintf("Description: %s\n", protobufInstDesc.description().c_str());2027 RTPrintf("Os: %s\n", protobufInstDesc.os().c_str());2028 RTPrintf("Product: %s\n", protobufInstDesc.product().c_str());2029 RTPrintf("Vendor: %s\n", protobufInstDesc.vendor().c_str());2030 RTPrintf("Version: %s\n", protobufInstDesc.version().c_str());2031 RTPrintf("Product url: %s\n", protobufInstDesc.producturl().c_str());2032 RTPrintf("Vendor url: %s\n", protobufInstDesc.vendorurl().c_str());2033 RTPrintf("Cpu: %u\n", protobufInstDesc.cpu());2034 RTPrintf("Memory: %u\n", protobufInstDesc.memory());2035 while (imListIt != imList.end())2036 {2037 com::Utf8Str key(imListIt->first.c_str());2038 vsd::ImageDescription imDesc(imListIt->second);2039 RTPrintf("\n###Image decription###\n");2040 RTPrintf("Name: %s\n", imDesc.name().c_str());2041 RTPrintf("Id: %s\n", imDesc.id().c_str());2042 RTPrintf("Path: %s\n", imDesc.path().c_str());2043 RTPrintf("Description: %s\n", imDesc.description().c_str());2044 RTPrintf("Size (MB): %u\n", imDesc.size());2045 const vsd::ImageDescription_StorageBus& stBus = imDesc.storagebus();2046 RTPrintf("Bus type: %u\n", stBus.bustype());2047 RTPrintf("Controller: %u\n", stBus.controller());2048 RTPrintf("Channel: %u\n", stBus.channel());2049 RTPrintf("###End Image decription###\n");2050 ++imListIt;2051 }2052 RTPrintf("########End Instance decription########\n");2053 }2054 #endif2055 2056 1761 } while (0); 2057 1762 … … 2060 1765 2061 1766 #endif /* !VBOX_ONLY_DOCS */ 1767
Note:
See TracChangeset
for help on using the changeset viewer.