- Timestamp:
- Mar 9, 2009 11:22:42 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/string.h
r16495 r17566 428 428 bool operator < (const char *that) const { return compare (that) < 0; } 429 429 430 int compareIgnoreCase(const char *pcsz) const 431 { 432 return ::RTStrICmp(str, pcsz); 433 } 434 430 435 bool isNull() const { return str == NULL; } 431 436 operator bool() const { return !isNull(); } -
trunk/src/VBox/Main/ApplianceImpl.cpp
r17418 r17566 63 63 }; 64 64 65 struct Network66 {67 Utf8Str strNetworkName; // value from NetworkSection/Network/@name68 // unfortunately the OVF spec is unspecific about how networks should be specified further69 };70 71 65 struct VirtualHardwareItem 72 66 { … … 89 83 Utf8Str strConnection; // "All Ethernet adapters that specify the same abstract network connection name within an OVF 90 84 // package shall be deployed on the same network. The abstract network connection name shall be 91 // listed in the NetworkSection at the outermost envelope level." 85 // listed in the NetworkSection at the outermost envelope level." We ignore this and only set up 86 // a network adapter depending on the network name. 92 87 Utf8Str strAddress; // "Device-specific. For an Ethernet adapter, this specifies the MAC address." 93 88 Utf8Str strAddressOnParent; // "For a device, this specifies its location on the controller." … … 111 106 112 107 typedef map<Utf8Str, DiskImage> DiskImagesMap; 113 typedef map<Utf8Str, Network> NetworksMap;114 108 115 109 struct VirtualSystem; … … 200 194 201 195 DiskImagesMap mapDisks; // map of DiskImage structs, sorted by DiskImage.strDiskId 202 203 NetworksMap mapNetworks; // map of Network structs, sorted by Network.strNetworkName204 196 205 197 list<VirtualSystem> llVirtualSystems; // list of virtual systems, created by and valid after read() … … 405 397 return rc; 406 398 } 407 else if ( (!strcmp(pcszElemName, "NetworkSection"))399 else if ( (!strcmp(pcszElemName, "NetworkSection")) // we ignore NetworkSections for now 408 400 || ( (!strcmp(pcszElemName, "Section")) 409 401 && (!strcmp(pcszTypeAttr, "ovf:NetworkSection_Type")) … … 547 539 const xml::Node *pSectionElem) 548 540 { 549 // contains "Disk" child elements 550 xml::NodesLoop loopNetworks(*pSectionElem, "Network"); 551 const xml::Node *pelmNetwork; 552 while ((pelmNetwork = loopNetworks.forAllNodes())) 553 { 554 Network n; 555 if (!(pelmNetwork->getAttributeValue("name", n.strNetworkName))) 556 return setError(VBOX_E_FILE_ERROR, 557 tr("Error reading \"%s\": missing 'name' attribute in 'Network', line %d"), 558 pcszPath, 559 pelmNetwork->getLineNumber()); 560 561 m->mapNetworks[n.strNetworkName] = n; 562 } 541 // we ignore network sections for now 542 543 // xml::NodesLoop loopNetworks(*pSectionElem, "Network"); 544 // const xml::Node *pelmNetwork; 545 // while ((pelmNetwork = loopNetworks.forAllNodes())) 546 // { 547 // Network n; 548 // if (!(pelmNetwork->getAttributeValue("name", n.strNetworkName))) 549 // return setError(VBOX_E_FILE_ERROR, 550 // tr("Error reading \"%s\": missing 'name' attribute in 'Network', line %d"), 551 // pcszPath, 552 // pelmNetwork->getLineNumber()); 553 // 554 // m->mapNetworks[n.strNetworkName] = n; 555 // } 563 556 564 557 return S_OK; … … 802 795 at the outermost envelope level." */ 803 796 804 // make sure we have a matching NetworkSection/Network 805 NetworksMap::iterator it = m->mapNetworks.find(i.strConnection); 806 if (it == m->mapNetworks.end()) 807 return setError(VBOX_E_FILE_ERROR, 808 tr("Error reading \"%s\": Invalid connection \"%s\"; cannot find matching NetworkSection/Network element, line %d"), 809 pcszPath, 810 i.strConnection.c_str(), 811 i.ulLineNumber); 812 797 // only store the name 813 798 vsys.llNetworkNames.push_back(i.strConnection); 814 799 } … … 1427 1412 #endif /* VBOX_WITH_USB */ 1428 1413 1429 NetworksMap::const_iterator itN;1430 for (itN = m->mapNetworks.begin();1431 itN != m->mapNetworks.end();1432 ++itN)1433 {1434 const Network &nw = itN->second;1435 pNewDesc->addEntry(VirtualSystemDescriptionType_LogicalNetwork,1436 "",1437 nw.strNetworkName,1438 nw.strNetworkName);1439 }1440 1441 1414 /* Network Controller */ 1442 1415 // @todo: there is no hardware specification in the OVF file; supposedly the … … 1464 1437 { 1465 1438 Utf8Str strNetwork = *nwIt; // logical network to connect to 1439 // make sure it's one of these two 1440 if ( (strNetwork.compareIgnoreCase("Null")) 1441 && (strNetwork.compareIgnoreCase("Bridged")) 1442 && (strNetwork.compareIgnoreCase("Internal")) 1443 && (strNetwork.compareIgnoreCase("HostOnly")) 1444 ) 1445 strNetwork = "NAT"; 1446 1466 1447 pNewDesc->addEntry(VirtualSystemDescriptionType_NetworkAdapter, 1467 1448 "", // ref 1468 1449 strNetwork, // orig 1469 1450 Utf8StrFmt("%RI32", (uint32_t)nwAdapterVBox), // conf 1470 Utf8StrFmt(" network=%s", strNetwork.c_str())); // extra conf1451 Utf8StrFmt("type=%s", strNetwork.c_str())); // extra conf 1471 1452 } 1472 1453 } … … 2014 1995 ++nwIt, ++a) 2015 1996 { 2016 const Utf8Str &nwTypeVBox = (*nwIt)->strVbox; 1997 const VirtualSystemDescriptionEntry* pvsys = *nwIt; 1998 1999 const Utf8Str &nwTypeVBox = pvsys->strVbox; 2017 2000 uint32_t tt1 = RTStrToUInt32(nwTypeVBox.c_str()); 2018 ComPtr<INetworkAdapter> nwVBox;2019 rc = pNewMachine->GetNetworkAdapter((ULONG)a, nwVBox.asOutParam());2001 ComPtr<INetworkAdapter> pNetworkAdapter; 2002 rc = pNewMachine->GetNetworkAdapter((ULONG)a, pNetworkAdapter.asOutParam()); 2020 2003 if (FAILED(rc)) throw rc; 2021 2004 /* Enable the network card & set the adapter type */ 2022 /* NAT is set as default */ 2023 rc = nwVBox->COMSETTER(Enabled)(true); 2005 rc = pNetworkAdapter->COMSETTER(Enabled)(true); 2024 2006 if (FAILED(rc)) throw rc; 2025 rc = nwVBox->COMSETTER(AdapterType)(static_cast<NetworkAdapterType_T>(tt1));2007 rc = pNetworkAdapter->COMSETTER(AdapterType)(static_cast<NetworkAdapterType_T>(tt1)); 2026 2008 if (FAILED(rc)) throw rc; 2009 2010 // default is NAT; change to "bridged" if extra conf says so 2011 if (!pvsys->strExtraConfig.compareIgnoreCase("type=Bridged")) 2012 { 2013 rc = pNetworkAdapter->AttachToBridgedInterface(); 2014 if (FAILED(rc)) throw rc; 2015 } 2027 2016 } 2028 2017 } … … 2514 2503 xml::Node *pelmNetworkSectionInfo = pelmNetworkSection->createChild("Info"); 2515 2504 pelmNetworkSectionInfo->addContent("Logical networks used in the package"); 2516 // @todo for each network: 2517 // xml::Node *pelmNetwork = pelmNetworkSection->createChild("Network"); 2505 // for now, set up a map so we have a list of unique network names (to make 2506 // sure the same network name is only added once) 2507 map<Utf8Str, bool> mapNetworks; 2508 // we fill this later below when we iterate over the networks 2518 2509 2519 2510 // and here come the virtual systems: … … 2570 2561 const VirtualSystemDescriptionEntry &desc = *itD; 2571 2562 2572 OVFResourceType_T type = (OVFResourceType_T)0; // if this becomes != 0 then we do stuff 2573 Utf8Str strDescription; // must also be set then 2563 OVFResourceType_T type = (OVFResourceType_T)0; // if this becomes != 0 then we do stuff 2564 Utf8Str strDescription; // results in <rasd:Description>...</rasd:Description> block 2565 Utf8Str strCaption; // results in <rasd:Caption>...</rasd:Caption> block 2574 2566 int32_t lVirtualQuantity = -1; 2575 2567 uint64_t uTemp; 2568 bool fAutomaticAllocation = false; 2569 Utf8Str strConnection; // results in <rasd:Connection>...</rasd:Connection> block 2576 2570 2577 2571 switch (desc.type) … … 2607 2601 break; 2608 2602 2609 case VirtualSystemDescriptionType_HardDiskControllerIDE: 2603 // case VirtualSystemDescriptionType_HardDiskControllerIDE: 2604 // strDescription = "Memory Size"; 2605 // type = OVFResourceType_Memory; // 4 2606 // desc.strVbox.toInt(uTemp); 2607 // lVirtualQuantity = (int32_t)(uTemp / _1M); 2608 // break; 2609 2610 // case VirtualSystemDescriptionType_HardDiskControllerSATA: 2611 // strDescription = "Memory Size"; 2612 // type = OVFResourceType_Memory; // 4 2613 // desc.strVbox.toInt(uTemp); 2614 // lVirtualQuantity = (int32_t)(uTemp / _1M); 2615 // break; 2616 2617 // case VirtualSystemDescriptionType_HardDiskControllerSCSI: 2618 // strDescription = "Memory Size"; 2619 // type = OVFResourceType_Memory; // 4 2620 // desc.strVbox.toInt(uTemp); 2621 // lVirtualQuantity = (int32_t)(uTemp / _1M); 2622 // break; 2623 2624 // case VirtualSystemDescriptionType_HardDiskImage: 2625 // strDescription = "Memory Size"; 2626 // type = OVFResourceType_Memory; // 4 2627 // desc.strVbox.toInt(uTemp); 2628 // lVirtualQuantity = (int32_t)(uTemp / _1M); 2629 // break; 2630 2631 // case VirtualSystemDescriptionType_Floppy: 2632 // strDescription = "Memory Size"; 2633 // type = OVFResourceType_Memory; // 4 2634 // desc.strVbox.toInt(uTemp); 2635 // lVirtualQuantity = (int32_t)(uTemp / _1M); 2636 // break; 2637 2638 // case VirtualSystemDescriptionType_CDROM: 2639 // strDescription = "Memory Size"; 2640 // type = OVFResourceType_Memory; // 4 2641 // desc.strVbox.toInt(uTemp); 2642 // lVirtualQuantity = (int32_t)(uTemp / _1M); 2643 // break; 2644 2645 case VirtualSystemDescriptionType_NetworkAdapter: 2646 /* <Item> 2647 <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> 2648 <rasd:Caption>Ethernet adapter on 'VM Network'</rasd:Caption> 2649 <rasd:Connection>VM Network</rasd:Connection> 2650 <rasd:ElementName>VM network</rasd:ElementName> 2651 <rasd:InstanceID>3</rasd:InstanceID> 2652 <rasd:ResourceType>10</rasd:ResourceType> 2653 </Item> */ 2654 fAutomaticAllocation = true; 2655 strCaption = Utf8StrFmt("Ethernet adapter on '%s'", desc.strOvf.c_str()); 2656 type = OVFResourceType_EthernetAdapter; // 10 2657 strConnection = desc.strOvf; 2658 2659 mapNetworks[desc.strOvf] = true; 2610 2660 break; 2611 case VirtualSystemDescriptionType_HardDiskControllerSATA: 2612 break; 2613 case VirtualSystemDescriptionType_HardDiskControllerSCSI: 2614 break; 2615 2616 case VirtualSystemDescriptionType_HardDiskImage: 2617 break; 2618 2619 case VirtualSystemDescriptionType_Floppy: 2620 break; 2621 2622 case VirtualSystemDescriptionType_CDROM: 2623 break; 2624 2625 case VirtualSystemDescriptionType_LogicalNetwork: 2626 break; 2627 2628 case VirtualSystemDescriptionType_NetworkAdapter: 2629 break; 2630 2631 case VirtualSystemDescriptionType_USBController: 2632 break; 2633 2634 case VirtualSystemDescriptionType_SoundCard: 2635 break; 2661 2662 // case VirtualSystemDescriptionType_USBController: 2663 // strDescription = "Memory Size"; 2664 // type = OVFResourceType_Memory; // 4 2665 // desc.strVbox.toInt(uTemp); 2666 // lVirtualQuantity = (int32_t)(uTemp / _1M); 2667 // break; 2668 2669 /* case VirtualSystemDescriptionType_SoundCard: 2670 strDescription = "Memory Size"; 2671 type = OVFResourceType_Memory; // 4 2672 desc.strVbox.toInt(uTemp); 2673 lVirtualQuantity = (int32_t)(uTemp / _1M); 2674 break;*/ 2636 2675 } 2637 2676 … … 2641 2680 pItem = pelmVirtualHardwareSection->createChild("Item"); 2642 2681 2643 pItem->createChild("rasd:Description")->addContent(strDescription.c_str()); 2682 if (fAutomaticAllocation) 2683 pItem->createChild("rasd:AutomaticAllocation")->addContent("true"); 2684 2685 if (strDescription.length()) 2686 pItem->createChild("rasd:Description")->addContent(strDescription.c_str()); 2687 if (strCaption.length()) 2688 pItem->createChild("rasd:Caption")->addContent(strCaption.c_str()); 2689 2690 if (strConnection.length()) 2691 pItem->createChild("rasd:Connection")->addContent(strConnection.c_str()); 2644 2692 2645 2693 // <rasd:InstanceID>1</rasd:InstanceID> 2646 2694 pItem->createChild("rasd:InstanceID")->addContent(Utf8StrFmt("%d", ulInstanceID).c_str()); 2695 ++ulInstanceID; 2647 2696 2648 2697 // <rasd:ResourceType>3</rasd:ResourceType> … … 2655 2704 } 2656 2705 } 2706 } 2707 2708 // finally, fill in the network section we set up empty above according 2709 // to the networks we found with the hardware items 2710 map<Utf8Str, bool>::const_iterator itN; 2711 for (itN = mapNetworks.begin(); 2712 itN != mapNetworks.end(); 2713 ++itN) 2714 { 2715 const Utf8Str &strNetwork = itN->first; 2716 xml::Node *pelmNetwork = pelmNetworkSection->createChild("Network"); 2717 pelmNetwork->setAttribute("ovf:name", strNetwork.c_str()); 2718 pelmNetwork->createChild("<Description>")->addContent("Logical network used by this appliance."); 2657 2719 } 2658 2720 … … 3208 3270 3209 3271 // <const name="NetworkAdapter" value="13" /> 3272 size_t a; 3273 for (a = 0; 3274 a < SchemaDefs::NetworkAdapterCount; 3275 ++a) 3276 { 3277 ComPtr<INetworkAdapter> pNetworkAdapter; 3278 BOOL fEnabled; 3279 NetworkAdapterType_T adapterType; 3280 NetworkAttachmentType_T attachmentType; 3281 3282 rc = GetNetworkAdapter((ULONG)a, pNetworkAdapter.asOutParam()); 3283 if (FAILED(rc)) throw rc; 3284 /* Enable the network card & set the adapter type */ 3285 rc = pNetworkAdapter->COMGETTER(Enabled)(&fEnabled); 3286 if (FAILED(rc)) throw rc; 3287 3288 if (fEnabled) 3289 { 3290 Utf8Str strAttachmentType; 3291 3292 rc = pNetworkAdapter->COMGETTER(AdapterType)(&adapterType); 3293 if (FAILED(rc)) throw rc; 3294 3295 rc = pNetworkAdapter->COMGETTER(AttachmentType)(&attachmentType); 3296 if (FAILED(rc)) throw rc; 3297 3298 switch (attachmentType) 3299 { 3300 case NetworkAttachmentType_Null: 3301 strAttachmentType = "Null"; 3302 break; 3303 3304 case NetworkAttachmentType_NAT: 3305 strAttachmentType = "NAT"; 3306 break; 3307 3308 case NetworkAttachmentType_Bridged: 3309 strAttachmentType = "Bridged"; 3310 break; 3311 3312 case NetworkAttachmentType_Internal: 3313 strAttachmentType = "Internal"; 3314 break; 3315 3316 case NetworkAttachmentType_HostOnly: 3317 strAttachmentType = "HostOnly"; 3318 break; 3319 } 3320 3321 pNewDesc->addEntry(VirtualSystemDescriptionType_NetworkAdapter, 3322 "", // ref 3323 strAttachmentType, // orig 3324 Utf8StrFmt("%RI32", (uint32_t)adapterType), // conf 3325 Utf8StrFmt("type=%s", strAttachmentType.c_str())); // extra conf 3326 } 3327 } 3210 3328 3211 3329 // <const name="USBController" value="14" /> -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r17553 r17566 3071 3071 <const name="Floppy" value="10" /> 3072 3072 <const name="CDROM" value="11" /> 3073 <const name="LogicalNetwork" value="12" /> 3074 <const name="NetworkAdapter" value="13" /> 3075 <const name="USBController" value="14" /> 3076 <const name="SoundCard" value="15" /> 3073 <const name="NetworkAdapter" value="12" /> 3074 <const name="USBController" value="13" /> 3075 <const name="SoundCard" value="14" /> 3077 3076 3078 3077 </enum> … … 3166 3165 </li> 3167 3166 <li> 3168 "LogicalNetwork": a logical network to which virtual machines can connect. This is taken from3169 the Network section in the OVF that is shared between several virtual systems. OVF has no3170 formal description of how the network shall be set up (e.g. whether to use NAT or host interface3171 networking), but OVFs typically name the logical networks "nat" or "bridged" to suggest such3172 a configuration.3173 </li>3174 <li>3175 3167 "NetworkAdapter": a network adapter. The array item in aVboxValues[] will specify the hardware 3176 3168 for the network adapter, whereas the array item in aExtraConfigValues[] will have a string 3177 of the "network=<nw>" format, where <nw> must be one of the networks as specified with the 3178 LogicalNetwork type. 3169 of the "type=<X>" format, where <X> must be either "NAT" or "Bridged". 3179 3170 </li> 3180 3171 <li> … … 6516 6507 <desc>Specifies whether the IP V6 is supported/enabled for the interface.</desc> 6517 6508 </attribute> 6518 6509 6519 6510 <attribute name="IPV6Address" type="wstring" readonly="yes"> 6520 6511 <desc>Returns the IP V6 address of the interface.</desc> … … 6524 6515 <desc>Returns the IP V6 network mask of the interface.</desc> 6525 6516 </attribute> 6526 6517 6527 6518 <attribute name="hardwareAddress" type="wstring" readonly="yes"> 6528 6519 <desc>Returns the hardware address. For Ethernet it is MAC address.</desc> … … 6540 6531 <desc>specifies the host interface type.</desc> 6541 6532 </attribute> 6542 6533 6543 6534 <method name="enableStaticIpConfig"> 6544 6535 <desc>sets and enables the static IP V4 configuration for the given interface.</desc> … … 10481 10472 wsmap="managed" 10482 10473 > 10474 <desc> 10475 Represents a virtual network adapter that is attached to a virtual machine. 10476 Each virtual machine has a fixed number of network adapter slots with one 10477 instance of this attached to each of them. Call 10478 <link to="IMachine::getNetworkAdapter" /> to get the network adapter that 10479 is attached to a given slot in a given machine. 10480 10481 Each network adapter can be in one of five attachment modes, which are 10482 represented by the <link to="NetworkAttachmentType" /> enumeration; 10483 see the <link to="#attachmentType" /> attribute. 10484 </desc> 10485 10483 10486 <attribute name="adapterType" type="NetworkAdapterType"> 10484 10487 <desc>
Note:
See TracChangeset
for help on using the changeset viewer.