diff --git a/tests/fixtures/vm_to_mac.yaml b/tests/fixtures/vm_to_mac.yaml new file mode 100644 index 0000000..63905b4 --- /dev/null +++ b/tests/fixtures/vm_to_mac.yaml @@ -0,0 +1,410 @@ +interactions: +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [python-requests/2.4.0 CPython/2.6.8 Darwin/13.4.0] + method: GET + uri: https://vcsa:443//sdk/vimServiceVersions.xml + response: + body: {string: !!python/unicode "\n\n\n \n urn:vim25\n 5.5\n + \ \n 5.1\n 5.0\n + \ 4.1\n 4.0\n 2.5u2\n + \ 2.5\n \n \n \n + \ urn:vim2\n 2.0\n \n\n"} + headers: + connection: [Keep-Alive] + content-length: ['530'] + content-type: [text/xml] + date: ['Fri, 10 Apr 2015 23:20:44 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="ServiceInstance">ServiceInstance + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [''] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1623101VMware, + Inc.5.5.01623101INTL000linux-x64vpxVirtualCenter5.57FE5EAEC-D956-4BF1-BC24-28D6242EA017VMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['3599'] + content-type: [text/xml; charset=utf-8] + date: ['Fri, 10 Apr 2015 23:20:44 GMT'] + set-cookie: [vmware_soap_session="5271f341-16fd-3d6e-6d12-2bccb326c12d"; Path=/; + HttpOnly; Secure;] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="SessionManager">SessionManagermy_usermy_password + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="5271f341-16fd-3d6e-6d12-2bccb326c12d"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\n521b0b0d-cff3-0275-7afe-f8555219a9f5my_usermy_user + 2015-04-10T23:20:45.007085Z2015-04-10T23:20:45.007085Zenenfalse192.168.2.1000\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['790'] + content-type: [text/xml; charset=utf-8] + date: ['Fri, 10 Apr 2015 23:20:45 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="ServiceInstance">ServiceInstance + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="5271f341-16fd-3d6e-6d12-2bccb326c12d"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1623101VMware, + Inc.5.5.01623101INTL000linux-x64vpxVirtualCenter5.57FE5EAEC-D956-4BF1-BC24-28D6242EA017VMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['3599'] + content-type: [text/xml; charset=utf-8] + date: ['Fri, 10 Apr 2015 23:20:45 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="SearchIndex">SearchIndexDatacenter0/vm/box + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="5271f341-16fd-3d6e-6d12-2bccb326c12d"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\nvm-722\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['455'] + content-type: [text/xml; charset=utf-8] + date: ['Fri, 10 Apr 2015 23:20:45 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="ServiceInstance">ServiceInstance + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="5271f341-16fd-3d6e-6d12-2bccb326c12d"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1623101VMware, + Inc.5.5.01623101INTL000linux-x64vpxVirtualCenter5.57FE5EAEC-D956-4BF1-BC24-28D6242EA017VMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['3599'] + content-type: [text/xml; charset=utf-8] + date: ['Fri, 10 Apr 2015 23:20:45 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="PropertyCollector">propertyCollectorVirtualMachinefalsenamevm-722false1 + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="5271f341-16fd-3d6e-6d12-2bccb326c12d"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\nvm-722namebox\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['559'] + content-type: [text/xml; charset=utf-8] + date: ['Fri, 10 Apr 2015 23:20:45 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="PropertyCollector">propertyCollectorVirtualMachinefalseconfigvm-722false1 + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="5271f341-16fd-3d6e-6d12-2bccb326c12d"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\nvm-722config2015-04-10T21:56:46.79505Z1970-01-01T00:00:00ZboxUbuntu + Linux (64-bit)vmx-08420264ab-848b-1586-b589-b9bd3a71b3aa500221fe-3473-60ff-fab2-1811600208a0true564d7427-3c77-fede-9448-44dbaa170c80ubuntu64Guest[storage0] + box/box.vmx[storage0] box/[storage0] + box/[storage0] box/9216truetruetruetruemanualfalse0falsetruefalsefalsereleaseanyfalseautomatichvAutopowerOfffalsesofthardsoftsofthardsoftcheckpoint422048falsefalse200IDE + 00201IDE 113002300PS2 controller 00600700100PCI controller 005001200010004000400SIO controller 008000600Keyboard3000700Pointing device; Devicefalseautodetect3001500Video card100040961falsefalseautomatic12000Device on the virtual machine PCI bus that provides + support for the virtual machine communication interface3310017980530090false1000LSI Logic16100302000truenoSharing7200016,777,216 + KB[storage0] + box/box-000001.vmdkdatastore-21persistentfalsefalsetrue6000C295-0720-c428-8fe9-fcb547507d1350c631d86f4d7efcffa707ab954b86d8[storage0] + box/box.vmdkdatastore-21persistenttrue6000C295-0720-c428-8fe9-fcb547507d13977342514f17e373aa3ac64b22a4c16eredoLogFormatfalse10000167772161000normal-11000normal3002ATAPI + /vmfs/devices/cdrom/mpx.vmhba0:C0:T0:L0/vmfs/devices/cdrom/mpx.vmhba0:C0:T0:L0falsefalsetruefalseuntried20104000VM NetworkVM + Networkfalsenetwork-22truetruetrueok321007assigned00:50:56:82:28:7dtrue8000Remotefalsefalsetruefalseuntried40000false-11000normal0false-110240normalnormalfalsefalsefalse20480hpet0.presenttruenvrambox.nvramvirtualHW.productCompatibilityhostedpciBridge0.presenttruepciBridge4.presenttruescsi0.pciSlotNumber16ethernet0.pciSlotNumber32vmci0.pciSlotNumber33replay.supportedfalsesched.swap.derivedName/vmfs/volumes/501fa6d9-8907f56a-fa19-782bcb74158e/box/box-fbe87ab9.vswpreplay.filenamescsi0:0.redopciBridge0.pciSlotNumber17pciBridge4.pciSlotNumber21pciBridge5.pciSlotNumber22pciBridge6.pciSlotNumber23pciBridge7.pciSlotNumber24pciBridge4.virtualDevpcieRootPorttools.remindInstalltruehostCPUID.00000000b756e65476c65746e49656e69hostCPUID.1000206c220200800029ee3ffbfebfbffhostCPUID.800000010000000000000000000000012c100800guestCPUID.00000000b756e65476c65746e49656e69guestCPUID.1000206c200020800829822031fabfbffguestCPUID.8000000100000000000000000000000128100800userCPUID.00000000b756e65476c65746e49656e69userCPUID.1000206c220200800029822031fabfbffuserCPUID.8000000100000000000000000000000128100800evcCompatibilityModefalsevmotion.checkpointFBSize4194304softPowerOffFALSEcpuid.coresPerSocket2pciBridge4.functions8unity.wasCapablefalsepciBridge5.presenttruepciBridge5.virtualDevpcieRootPortpciBridge5.functions8pciBridge6.presenttruepciBridge6.virtualDevpcieRootPortpciBridge6.functions8pciBridge7.presenttruepciBridge7.virtualDevpcieRootPortpciBridge7.functions8vmware.tools.internalversion9216vmware.tools.requiredversion9216vmware.tools.installstatenonevmware.tools.lastInstallStatusunknownmigrate.hostLogStatenonemigrate.migrationId0storage0/vmfs/volumes/501fa6d9-8907f56a-fa19-782bcb74158einherit0falsefalse10000falsefalsebios40falsefalse207392768324444160falsefalsenevernone\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['15380'] + content-type: [text/xml; charset=utf-8] + date: ['Fri, 10 Apr 2015 23:20:45 GMT'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/test_virtual_machine_object.py b/tests/test_virtual_machine_object.py index d51e60a..22d0ae7 100644 --- a/tests/test_virtual_machine_object.py +++ b/tests/test_virtual_machine_object.py @@ -14,9 +14,9 @@ # limitations under the License. from __future__ import print_function -import tests import vcr +import tests from pyVim import connect from pyVmomi import vim @@ -70,3 +70,18 @@ class VirtualMachineTests(tests.VCRTestBase): if virtual_machine.guest: for net in virtual_machine.guest.net: self.assertTrue(net.macAddress in macs) + + @vcr.use_cassette('vm_to_mac.yaml', + cassette_library_dir=tests.fixtures_path, + record_mode='once') + def test_vm_to_mac(self): + si = connect.SmartConnect(host='vcsa', + user='my_user', + pwd='my_password') + content = si.RetrieveContent() + # where the name of the VM is 'box' + vm = content.searchIndex.FindByInventoryPath("Datacenter0/vm/box") + self.assertEqual(vm.name, 'box') + nics = [dev for dev in vm.config.hardware.device + if isinstance(dev, vim.vm.device.VirtualEthernetCard)] + self.assertEqual(nics[0].macAddress, '00:50:56:82:28:7d')