diff --git a/pyVmomi/VmomiSupport.py b/pyVmomi/VmomiSupport.py
index a31573b..fef0702 100644
--- a/pyVmomi/VmomiSupport.py
+++ b/pyVmomi/VmomiSupport.py
@@ -23,7 +23,7 @@ from six import itervalues
from six import text_type
from six import PY3
from datetime import datetime
-import pyVmomi.Iso8601
+from pyVmomi import Iso8601
import base64
import threading
diff --git a/tests/fixtures/iso8601_set_datetime.yaml b/tests/fixtures/iso8601_set_datetime.yaml
new file mode 100644
index 0000000..984a1c3
--- /dev/null
+++ b/tests/fixtures/iso8601_set_datetime.yaml
@@ -0,0 +1,347 @@
+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: ['Tue, 19 Aug 2014 08:29:33 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-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: ['Tue, 19 Aug 2014 08:29:33 GMT']
+ Set-Cookie: ['vmware_soap_session="52bd6093-90c7-3253-75e3-e43a480ce8cf"; 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="52bd6093-90c7-3253-75e3-e43a480ce8cf"; Path=/;
+ HttpOnly; Secure; ']
+ SOAPAction: ['"urn:vim25/5.5"']
+ method: POST
+ uri: https://vcsa:443/sdk
+ response:
+ body: {string: "\n\n\n52d559c8-dbac-f233-5751-dc3a755bfb76my_usermy_user
+ 2014-08-19T08:29:34.017448Z2014-08-19T08:29:34.017448Zenenfalse192.168.2.1000\n\n"}
+ headers:
+ Cache-Control: [no-cache]
+ Connection: [Keep-Alive]
+ Content-Length: ['790']
+ Content-Type: [text/xml; charset=utf-8]
+ Date: ['Tue, 19 Aug 2014 08:29:34 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="52bd6093-90c7-3253-75e3-e43a480ce8cf"; 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-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: ['Tue, 19 Aug 2014 08:29:34 GMT']
+ status: {code: 200, message: OK}
+- request:
+ body: '
+
+
+
+ <_this type="PropertyCollector">propertyCollectorServiceInstancefalsecontentServiceInstancefalse1
+
+ '
+ headers:
+ Accept-Encoding: ['gzip, deflate']
+ Content-Type: [text/xml; charset=UTF-8]
+ Cookie: ['vmware_soap_session="52bd6093-90c7-3253-75e3-e43a480ce8cf"; Path=/;
+ HttpOnly; Secure; ']
+ SOAPAction: ['"urn:vim25/5.5"']
+ method: POST
+ uri: https://vcsa:443/sdk
+ response:
+ body: {string: "\n\n\nServiceInstancecontentgroup-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: ['3739']
+ Content-Type: [text/xml; charset=utf-8]
+ Date: ['Tue, 19 Aug 2014 08:29:34 GMT']
+ status: {code: 200, message: OK}
+- request:
+ body: '
+
+
+
+ <_this type="SearchIndex">SearchIndex4c4c4544-0043-4d10-8056-b1c04f4c5331false
+
+ '
+ headers:
+ Accept-Encoding: ['gzip, deflate']
+ Content-Type: [text/xml; charset=UTF-8]
+ Cookie: ['vmware_soap_session="52bd6093-90c7-3253-75e3-e43a480ce8cf"; Path=/;
+ HttpOnly; Secure; ']
+ SOAPAction: ['"urn:vim25/5.5"']
+ method: POST
+ uri: https://vcsa:443/sdk
+ response:
+ body: {string: "\n\n\nhost-14\n\n"}
+ headers:
+ Cache-Control: [no-cache]
+ Connection: [Keep-Alive]
+ Content-Length: ['434']
+ Content-Type: [text/xml; charset=utf-8]
+ Date: ['Tue, 19 Aug 2014 08:29:34 GMT']
+ status: {code: 200, message: OK}
+- request:
+ body: '
+
+
+
+ <_this type="PropertyCollector">propertyCollectorHostSystemfalseconfigManagerhost-14false1
+
+ '
+ headers:
+ Accept-Encoding: ['gzip, deflate']
+ Content-Type: [text/xml; charset=UTF-8]
+ Cookie: ['vmware_soap_session="52bd6093-90c7-3253-75e3-e43a480ce8cf"; Path=/;
+ HttpOnly; Secure; ']
+ SOAPAction: ['"urn:vim25/5.5"']
+ method: POST
+ uri: https://vcsa:443/sdk
+ response:
+ body: {string: "\n\n\nhost-14configManagercpuScheduler-14datastoreSystem-14memorySystem-14storageSystem-14networkSystem-14vmotionSystem-14virtualNicManager-14serviceSystem-14firewallSystem-14EsxHostAdvSettings-14diagnosticSystem-14autoStartManager-14dateTimeSystem-14patchManager-14imageConfigManager-14bootDeviceSystem-14firmwareSystem-14healthStatusSystem-14pciPassthruSystem-14kernelModuleSystem-14authenticationManager-14powerSystem-14cacheConfigManager-14esxAgentHostManager-14iscsiManager-14\n\n"}
+ headers:
+ Cache-Control: [no-cache]
+ Connection: [Keep-Alive]
+ Content-Length: ['2597']
+ Content-Type: [text/xml; charset=utf-8]
+ Date: ['Tue, 19 Aug 2014 08:29:34 GMT']
+ status: {code: 200, message: OK}
+- request:
+ body: '
+
+
+
+ <_this type="HostDateTimeSystem">dateTimeSystem-142014-08-19T04:29:36.070918-04:00
+
+ '
+ headers:
+ Accept-Encoding: ['gzip, deflate']
+ Content-Type: [text/xml; charset=UTF-8]
+ Cookie: ['vmware_soap_session="52bd6093-90c7-3253-75e3-e43a480ce8cf"; 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: ['394']
+ Content-Type: [text/xml; charset=utf-8]
+ Date: ['Tue, 19 Aug 2014 08:29:35 GMT']
+ status: {code: 200, message: OK}
+version: 1
diff --git a/tests/test_iso8601.py b/tests/test_iso8601.py
index 075b564..b578f6c 100644
--- a/tests/test_iso8601.py
+++ b/tests/test_iso8601.py
@@ -14,12 +14,15 @@
# limitations under the License.
import atexit
from datetime import datetime
+from datetime import timedelta
from tests import fixtures_path
import unittest
import vcr
from pyVim import connect
+from pyVmomi.Iso8601 import TZManager
+
class Iso8601Tests(unittest.TestCase):
@@ -42,3 +45,58 @@ class Iso8601Tests(unittest.TestCase):
expected_time = datetime(2014, 8, 5, 17, 50, 20, 594958,
boot_time.tzinfo)
self.assertEqual(expected_time, boot_time)
+
+ def test_iso8601_set_datetime(self):
+
+ # NOTE (hartsock): This test is an example of how to register
+ # a fixture based test to compare the XML document that pyVmomi
+ # is transmitting. We needed to invent a set of tools to effectively
+ # compare logical XML documents to each other. In this case we are
+ # only interested in the 'soapenv:Body' tag and its children.
+
+ now_string = "2014-08-19T04:29:36.070918-04:00"
+ # NOTE (hartsock): the strptime formatter has a bug in python 2.x
+ # http://bugs.python.org/issue6641 so we're building the date time
+ # using the constructor arguments instead of parsing it.
+ now = datetime(2014, 8, 19, 4, 29, 36, 70918,
+ TZManager.GetTZInfo(
+ tzname='EDT',
+ utcOffset=timedelta(hours=-4, minutes=0)))
+
+ def has_tag(doc):
+ if doc is None:
+ return False
+ return '' in doc
+
+ def correct_time_string(doc):
+ return '{0}'.format(now_string) in doc
+
+ def check_date_time_value(r1, r2):
+ for r in [r1, r2]:
+ if has_tag(r.body):
+ if not correct_time_string(r.body):
+ return False
+ return True
+
+ my_vcr = vcr.VCR()
+ my_vcr.register_matcher('document', check_date_time_value)
+
+ # NOTE (hartsock): the `match_on` option is altered to use the
+ # look at the XML body sent to the server
+ with my_vcr.use_cassette('iso8601_set_datetime.yaml',
+ cassette_library_dir=fixtures_path,
+ record_mode='once',
+ match_on=['method', 'scheme', 'host', 'port',
+ 'path', 'query', 'document']):
+
+ si = connect.SmartConnect(host='vcsa',
+ user='my_user',
+ pwd='my_password')
+ atexit.register(connect.Disconnect, si)
+
+ search_index = si.content.searchIndex
+ uuid = "4c4c4544-0043-4d10-8056-b1c04f4c5331"
+ host = search_index.FindByUuid(None, uuid, False)
+ date_time_system = host.configManager.dateTimeSystem
+ # NOTE (hartsock): sending the date time 'now' to host.
+ date_time_system.UpdateDateTime(now)