diff --git a/tests/fixtures/basic_container_view.yaml b/tests/fixtures/basic_container_view.yaml new file mode 100644 index 0000000..8a4b09d --- /dev/null +++ b/tests/fixtures/basic_container_view.yaml @@ -0,0 +1,357 @@ +interactions: +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + User-Agent: [python-requests/2.3.0 CPython/3.4.1 Darwin/13.3.0] + method: GET + uri: https://vcsa:443//sdk/vimServiceVersions.xml + response: + body: {string: "\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: ['Thu, 31 Jul 2014 17:32:04 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: "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware, + Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + Cache-Control: [no-cache] + Connection: [Keep-Alive] + Content-Length: ['3611'] + Content-Type: [text/xml; charset=utf-8] + Date: ['Thu, 31 Jul 2014 17:32:04 GMT'] + Set-Cookie: ['vmware_soap_session="52b88a08-629d-c211-6863-551af1238da8"; 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="52b88a08-629d-c211-6863-551af1238da8"; Path=/; + HttpOnly; Secure; '] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: "\n\n\n52dc4501-0677-e49d-f836-92045c1e5335my_usermy_user + 2014-07-31T17:32:04.959361Z2014-07-31T17:32:04.959361Zenenfalse172.16.16.10\n\n"} + headers: + Cache-Control: [no-cache] + Connection: [Keep-Alive] + Content-Length: ['788'] + Content-Type: [text/xml; charset=utf-8] + Date: ['Thu, 31 Jul 2014 17:32:04 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="52b88a08-629d-c211-6863-551af1238da8"; Path=/; + HttpOnly; Secure; '] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware, + Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + Cache-Control: [no-cache] + Connection: [Keep-Alive] + Content-Length: ['3611'] + Content-Type: [text/xml; charset=utf-8] + Date: ['Thu, 31 Jul 2014 17:32:04 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="ViewManager">ViewManagergroup-d1Datacentertrue + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: ['vmware_soap_session="52b88a08-629d-c211-6863-551af1238da8"; Path=/; + HttpOnly; Secure; '] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: "\n\n\nsession[1c697f87-8ba4-8cf9-7be1-fd21ab003a42]528c1847-b0c0-7a9b-63c1-2c6cd72956b4\n\n"} + headers: + Cache-Control: [no-cache] + Connection: [Keep-Alive] + Content-Length: ['529'] + Content-Type: [text/xml; charset=utf-8] + Date: ['Thu, 31 Jul 2014 17:32:05 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="52b88a08-629d-c211-6863-551af1238da8"; Path=/; + HttpOnly; Secure; '] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware, + Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + Cache-Control: [no-cache] + Connection: [Keep-Alive] + Content-Length: ['3611'] + Content-Type: [text/xml; charset=utf-8] + Date: ['Thu, 31 Jul 2014 17:32:05 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="PropertyCollector">propertyCollectorContainerViewfalseviewsession[1c697f87-8ba4-8cf9-7be1-fd21ab003a42]528c1847-b0c0-7a9b-63c1-2c6cd72956b4false1 + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: ['vmware_soap_session="52b88a08-629d-c211-6863-551af1238da8"; Path=/; + HttpOnly; Secure; '] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: "\n\n\nsession[1c697f87-8ba4-8cf9-7be1-fd21ab003a42]528c1847-b0c0-7a9b-63c1-2c6cd72956b4viewdatacenter-2\n\n"} + headers: + Cache-Control: [no-cache] + Connection: [Keep-Alive] + Content-Length: ['762'] + Content-Type: [text/xml; charset=utf-8] + Date: ['Thu, 31 Jul 2014 17:32:05 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="PropertyCollector">propertyCollectorDatacenterfalsedatastoredatacenter-2false1 + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: ['vmware_soap_session="52b88a08-629d-c211-6863-551af1238da8"; Path=/; + HttpOnly; Secure; '] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: "\n\n\ndatacenter-2datastoredatastore-11\n\n"} + headers: + Cache-Control: [no-cache] + Connection: [Keep-Alive] + Content-Length: ['694'] + Content-Type: [text/xml; charset=utf-8] + Date: ['Thu, 31 Jul 2014 17:32:05 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="ContainerView">session[1c697f87-8ba4-8cf9-7be1-fd21ab003a42]528c1847-b0c0-7a9b-63c1-2c6cd72956b4 + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: ['vmware_soap_session="52b88a08-629d-c211-6863-551af1238da8"; Path=/; + HttpOnly; Secure; '] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: "\n\n\n\n\n"} + headers: + Cache-Control: [no-cache] + Connection: [Keep-Alive] + Content-Length: ['388'] + Content-Type: [text/xml; charset=utf-8] + Date: ['Thu, 31 Jul 2014 17:32:05 GMT'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/test_container_view.py b/tests/test_container_view.py new file mode 100644 index 0000000..62350a5 --- /dev/null +++ b/tests/test_container_view.py @@ -0,0 +1,54 @@ +# VMware vSphere Python SDK +# Copyright (c) 2008-2014 VMware, Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import atexit +from tests import fixtures_path +import logging +from pprint import pprint +import unittest +import vcr + +from pyVim import connect +from pyVmomi import vim + + +class ContainerViewTests(unittest.TestCase): + + def setUp(self): + logging.basicConfig() + vcr_log = logging.getLogger('vcr') + vcr_log.setLevel(logging.DEBUG) + + @vcr.use_cassette('basic_container_view.yaml', + cassette_library_dir=fixtures_path, record_mode='once') + def test_basic_container_view(self): + # see: http://python3porting.com/noconv.html + si = connect.SmartConnect(host='vcsa', + user='my_user', + pwd='my_password') + atexit.register(connect.Disconnect, si) + + content = si.RetrieveContent() + + datacenter_object_view = content.viewManager.CreateContainerView( + content.rootFolder, [vim.Datacenter], True) + + for datacenter in datacenter_object_view.view: + datastores = datacenter.datastore + # NOTE (hartsocks): the object handle here is a managed object + # reference, until we ask for more details, no other detail is + # transmitted. Our sample fixture is quite small. + self.assertEqual(1, len(datastores)) + + datacenter_object_view.Destroy()