Merge pull request #3 in PYTHON_PYVMOMI/pyvmomi from ~TEVESZ/pyvmomi:master to master

* commit '29d562462a8b73c0a6c4a34dab0d9c404a8b1b9c':
  Fixed indentation
  Copyright notice
  SSPI test
  Fixed indentation
This commit is contained in:
Agnes Tevesz
2015-12-11 10:38:37 -05:00
3 changed files with 292 additions and 15 deletions

View File

@@ -248,7 +248,8 @@ def Connect(host='localhost', port=443, user='root', pwd='',
si, stub = __LoginBySSPI(host, port, service, adapter, version, path,
keyFile, certFile, thumbprint, sslContext, b64token)
else:
raise Exception( 'The provided connection mechanism is not available, the supported mechanisms are userpass or sspi' )
raise Exception('''The provided connection mechanism is not available, the
supported mechanisms are userpass or sspi''')
SetSi(si)
@@ -336,8 +337,9 @@ def __Login(host, port, user, pwd, service, adapter, version, path,
raise
return si, stub
## Private method that performs the actual Connect and returns a
## Private method that performs LoginBySSPI and returns a
## connected service instance object.
## Copyright (c) 2015 Morgan Stanley. All rights reserved.
def __LoginBySSPI(host, port, service, adapter, version, path,
keyFile, certFile, thumbprint, sslContext, b64token):

258
tests/fixtures/sspi_connection.yaml vendored Normal file
View File

@@ -0,0 +1,258 @@
interactions:
- request:
body: '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body><RetrieveServiceContent xmlns="urn:vim25"><_this type="ServiceInstance">ServiceInstance</_this></RetrieveServiceContent></soapenv:Body>
</soapenv:Envelope>'
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: ['']
SOAPAction: ['"urn:vim25/4.1"']
method: POST
uri: https://vcsa/sdk
response:
body: {string: !!python/unicode "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"\
\n xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:xsd=\"\
http://www.w3.org/2001/XMLSchema\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
>\n<soapenv:Body>\n<RetrieveServiceContentResponse xmlns=\"urn:vim25\"><returnval><rootFolder\
\ type=\"Folder\">group-d1</rootFolder><propertyCollector type=\"PropertyCollector\"\
>propertyCollector</propertyCollector><viewManager type=\"ViewManager\">ViewManager</viewManager><about><name>VMware\
\ vCenter Server</name><fullName>VMware vCenter Server 6.0.0 build-3018523</fullName><vendor>VMware,\
\ Inc.</vendor><version>6.0.0</version><build>3018523</build><localeVersion>INTL</localeVersion><localeBuild>000</localeBuild><osType>linux-x64</osType><productLineId>vpx</productLineId><apiType>VirtualCenter</apiType><apiVersion>6.0</apiVersion><instanceUuid>6cbd40cc-1416-4b2d-ba7c-ae53a166d00a</instanceUuid><licenseProductName>VMware\
\ VirtualCenter Server</licenseProductName><licenseProductVersion>6.0</licenseProductVersion></about><setting\
\ type=\"OptionManager\">VpxSettings</setting><userDirectory type=\"UserDirectory\"\
>UserDirectory</userDirectory><sessionManager type=\"SessionManager\">SessionManager</sessionManager><authorizationManager\
\ type=\"AuthorizationManager\">AuthorizationManager</authorizationManager><perfManager\
\ type=\"PerformanceManager\">PerfMgr</perfManager><scheduledTaskManager type=\"\
ScheduledTaskManager\">ScheduledTaskManager</scheduledTaskManager><alarmManager\
\ type=\"AlarmManager\">AlarmManager</alarmManager><eventManager type=\"EventManager\"\
>EventManager</eventManager><taskManager type=\"TaskManager\">TaskManager</taskManager><extensionManager\
\ type=\"ExtensionManager\">ExtensionManager</extensionManager><customizationSpecManager\
\ type=\"CustomizationSpecManager\">CustomizationSpecManager</customizationSpecManager><customFieldsManager\
\ type=\"CustomFieldsManager\">CustomFieldsManager</customFieldsManager><diagnosticManager\
\ type=\"DiagnosticManager\">DiagMgr</diagnosticManager><licenseManager type=\"\
LicenseManager\">LicenseManager</licenseManager><searchIndex type=\"SearchIndex\"\
>SearchIndex</searchIndex><fileManager type=\"FileManager\">FileManager</fileManager><virtualDiskManager\
\ type=\"VirtualDiskManager\">virtualDiskManager</virtualDiskManager><snmpSystem\
\ type=\"HostSnmpSystem\">SnmpSystem</snmpSystem><vmProvisioningChecker type=\"\
VirtualMachineProvisioningChecker\">ProvChecker</vmProvisioningChecker><vmCompatibilityChecker\
\ type=\"VirtualMachineCompatibilityChecker\">CompatChecker</vmCompatibilityChecker><ovfManager\
\ type=\"OvfManager\">OvfManager</ovfManager><ipPoolManager type=\"IpPoolManager\"\
>IpPoolManager</ipPoolManager><dvSwitchManager type=\"DistributedVirtualSwitchManager\"\
>DVSManager</dvSwitchManager><hostProfileManager type=\"HostProfileManager\"\
>HostProfileManager</hostProfileManager><clusterProfileManager type=\"ClusterProfileManager\"\
>ClusterProfileManager</clusterProfileManager><complianceManager type=\"ProfileComplianceManager\"\
>MoComplianceManager</complianceManager><localizationManager type=\"LocalizationManager\"\
>LocalizationManager</localizationManager><storageResourceManager type=\"\
StorageResourceManager\">StorageResourceManager</storageResourceManager></returnval></RetrieveServiceContentResponse>\n\
</soapenv:Body>\n</soapenv:Envelope>"}
headers:
cache-control: [no-cache]
connection: [Keep-Alive]
content-length: ['3320']
content-type: [text/xml; charset=utf-8]
date: ['Mon, 12 Oct 2015 16:20:20 GMT']
status: {code: 200, message: OK}
- request:
body: '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body><LoginBySSPI xmlns="urn:vim25"><_this type="SessionManager">SessionManager</_this><base64Token>my_base64token</base64Token></LoginBySSPI></soapenv:Body>
</soapenv:Envelope>'
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: ['']
SOAPAction: ['"urn:vim25/4.1"']
method: POST
uri: https://vcsa/sdk
response:
body: {string: !!python/unicode "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"\
\n xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:xsd=\"\
http://www.w3.org/2001/XMLSchema\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
>\n<soapenv:Body>\n<LoginResponse xmlns=\"urn:vim25\"><returnval><key>52b5395a-85c2-9902-7835-13a9b77e1fec</key><userName>my_user</userName><fullName>my_user</fullName><loginTime>2015-10-12T16:20:20.388804Z</loginTime><lastActiveTime>2015-10-12T16:20:20.388804Z</lastActiveTime><locale>en</locale><messageLocale>en</messageLocale></returnval></LoginResponse>\n\
</soapenv:Body>\n</soapenv:Envelope>"}
headers:
cache-control: [no-cache]
connection: [Keep-Alive]
content-length: ['704']
content-type: [text/xml; charset=utf-8]
date: ['Mon, 12 Oct 2015 16:20:20 GMT']
set-cookie: [vmware_soap_session="57e9ef0e1210352a3cf607db32a20792334f5b81";
Path=/; HttpOnly; Secure;]
status: {code: 200, message: OK}
- request:
body: '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body><RetrieveServiceContent xmlns="urn:vim25"><_this type="ServiceInstance">ServiceInstance</_this></RetrieveServiceContent></soapenv:Body>
</soapenv:Envelope>'
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: [vmware_soap_session="57e9ef0e1210352a3cf607db32a20792334f5b81"; Path=/;
HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"']
method: POST
uri: https://vcsa/sdk
response:
body: {string: !!python/unicode "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"\
\n xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:xsd=\"\
http://www.w3.org/2001/XMLSchema\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
>\n<soapenv:Body>\n<RetrieveServiceContentResponse xmlns=\"urn:vim25\"><returnval><rootFolder\
\ type=\"Folder\">group-d1</rootFolder><propertyCollector type=\"PropertyCollector\"\
>propertyCollector</propertyCollector><viewManager type=\"ViewManager\">ViewManager</viewManager><about><name>VMware\
\ vCenter Server</name><fullName>VMware vCenter Server 6.0.0 build-3018523</fullName><vendor>VMware,\
\ Inc.</vendor><version>6.0.0</version><build>3018523</build><localeVersion>INTL</localeVersion><localeBuild>000</localeBuild><osType>linux-x64</osType><productLineId>vpx</productLineId><apiType>VirtualCenter</apiType><apiVersion>6.0</apiVersion><instanceUuid>6cbd40cc-1416-4b2d-ba7c-ae53a166d00a</instanceUuid><licenseProductName>VMware\
\ VirtualCenter Server</licenseProductName><licenseProductVersion>6.0</licenseProductVersion></about><setting\
\ type=\"OptionManager\">VpxSettings</setting><userDirectory type=\"UserDirectory\"\
>UserDirectory</userDirectory><sessionManager type=\"SessionManager\">SessionManager</sessionManager><authorizationManager\
\ type=\"AuthorizationManager\">AuthorizationManager</authorizationManager><perfManager\
\ type=\"PerformanceManager\">PerfMgr</perfManager><scheduledTaskManager type=\"\
ScheduledTaskManager\">ScheduledTaskManager</scheduledTaskManager><alarmManager\
\ type=\"AlarmManager\">AlarmManager</alarmManager><eventManager type=\"EventManager\"\
>EventManager</eventManager><taskManager type=\"TaskManager\">TaskManager</taskManager><extensionManager\
\ type=\"ExtensionManager\">ExtensionManager</extensionManager><customizationSpecManager\
\ type=\"CustomizationSpecManager\">CustomizationSpecManager</customizationSpecManager><customFieldsManager\
\ type=\"CustomFieldsManager\">CustomFieldsManager</customFieldsManager><diagnosticManager\
\ type=\"DiagnosticManager\">DiagMgr</diagnosticManager><licenseManager type=\"\
LicenseManager\">LicenseManager</licenseManager><searchIndex type=\"SearchIndex\"\
>SearchIndex</searchIndex><fileManager type=\"FileManager\">FileManager</fileManager><virtualDiskManager\
\ type=\"VirtualDiskManager\">virtualDiskManager</virtualDiskManager><snmpSystem\
\ type=\"HostSnmpSystem\">SnmpSystem</snmpSystem><vmProvisioningChecker type=\"\
VirtualMachineProvisioningChecker\">ProvChecker</vmProvisioningChecker><vmCompatibilityChecker\
\ type=\"VirtualMachineCompatibilityChecker\">CompatChecker</vmCompatibilityChecker><ovfManager\
\ type=\"OvfManager\">OvfManager</ovfManager><ipPoolManager type=\"IpPoolManager\"\
>IpPoolManager</ipPoolManager><dvSwitchManager type=\"DistributedVirtualSwitchManager\"\
>DVSManager</dvSwitchManager><hostProfileManager type=\"HostProfileManager\"\
>HostProfileManager</hostProfileManager><clusterProfileManager type=\"ClusterProfileManager\"\
>ClusterProfileManager</clusterProfileManager><complianceManager type=\"ProfileComplianceManager\"\
>MoComplianceManager</complianceManager><localizationManager type=\"LocalizationManager\"\
>LocalizationManager</localizationManager><storageResourceManager type=\"\
StorageResourceManager\">StorageResourceManager</storageResourceManager></returnval></RetrieveServiceContentResponse>\n\
</soapenv:Body>\n</soapenv:Envelope>"}
headers:
cache-control: [no-cache]
connection: [Keep-Alive]
content-length: ['3320']
content-type: [text/xml; charset=utf-8]
date: ['Mon, 12 Oct 2015 16:20:20 GMT']
status: {code: 200, message: OK}
- request:
body: '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body><RetrievePropertiesEx xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>ServiceInstance</type><all>false</all><pathSet>content</pathSet></propSet><objectSet><obj
type="ServiceInstance">ServiceInstance</obj><skip>false</skip></objectSet></specSet><options><maxObjects>1</maxObjects></options></RetrievePropertiesEx></soapenv:Body>
</soapenv:Envelope>'
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: [vmware_soap_session="57e9ef0e1210352a3cf607db32a20792334f5b81"; Path=/;
HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"']
method: POST
uri: https://vcsa/sdk
response:
body: {string: !!python/unicode "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"\
\n xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:xsd=\"\
http://www.w3.org/2001/XMLSchema\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
>\n<soapenv:Body>\n<RetrievePropertiesExResponse xmlns=\"urn:vim25\"><returnval><objects><obj\
\ type=\"ServiceInstance\">ServiceInstance</obj><propSet><name>content</name><val\
\ xsi:type=\"ServiceContent\"><rootFolder type=\"Folder\">group-d1</rootFolder><propertyCollector\
\ type=\"PropertyCollector\">propertyCollector</propertyCollector><viewManager\
\ type=\"ViewManager\">ViewManager</viewManager><about><name>VMware vCenter\
\ Server</name><fullName>VMware vCenter Server 6.0.0 build-3018523</fullName><vendor>VMware,\
\ Inc.</vendor><version>6.0.0</version><build>3018523</build><localeVersion>INTL</localeVersion><localeBuild>000</localeBuild><osType>linux-x64</osType><productLineId>vpx</productLineId><apiType>VirtualCenter</apiType><apiVersion>6.0</apiVersion><instanceUuid>6cbd40cc-1416-4b2d-ba7c-ae53a166d00a</instanceUuid><licenseProductName>VMware\
\ VirtualCenter Server</licenseProductName><licenseProductVersion>6.0</licenseProductVersion></about><setting\
\ type=\"OptionManager\">VpxSettings</setting><userDirectory type=\"UserDirectory\"\
>UserDirectory</userDirectory><sessionManager type=\"SessionManager\">SessionManager</sessionManager><authorizationManager\
\ type=\"AuthorizationManager\">AuthorizationManager</authorizationManager><perfManager\
\ type=\"PerformanceManager\">PerfMgr</perfManager><scheduledTaskManager type=\"\
ScheduledTaskManager\">ScheduledTaskManager</scheduledTaskManager><alarmManager\
\ type=\"AlarmManager\">AlarmManager</alarmManager><eventManager type=\"EventManager\"\
>EventManager</eventManager><taskManager type=\"TaskManager\">TaskManager</taskManager><extensionManager\
\ type=\"ExtensionManager\">ExtensionManager</extensionManager><customizationSpecManager\
\ type=\"CustomizationSpecManager\">CustomizationSpecManager</customizationSpecManager><customFieldsManager\
\ type=\"CustomFieldsManager\">CustomFieldsManager</customFieldsManager><diagnosticManager\
\ type=\"DiagnosticManager\">DiagMgr</diagnosticManager><licenseManager type=\"\
LicenseManager\">LicenseManager</licenseManager><searchIndex type=\"SearchIndex\"\
>SearchIndex</searchIndex><fileManager type=\"FileManager\">FileManager</fileManager><virtualDiskManager\
\ type=\"VirtualDiskManager\">virtualDiskManager</virtualDiskManager><snmpSystem\
\ type=\"HostSnmpSystem\">SnmpSystem</snmpSystem><vmProvisioningChecker type=\"\
VirtualMachineProvisioningChecker\">ProvChecker</vmProvisioningChecker><vmCompatibilityChecker\
\ type=\"VirtualMachineCompatibilityChecker\">CompatChecker</vmCompatibilityChecker><ovfManager\
\ type=\"OvfManager\">OvfManager</ovfManager><ipPoolManager type=\"IpPoolManager\"\
>IpPoolManager</ipPoolManager><dvSwitchManager type=\"DistributedVirtualSwitchManager\"\
>DVSManager</dvSwitchManager><hostProfileManager type=\"HostProfileManager\"\
>HostProfileManager</hostProfileManager><clusterProfileManager type=\"ClusterProfileManager\"\
>ClusterProfileManager</clusterProfileManager><complianceManager type=\"ProfileComplianceManager\"\
>MoComplianceManager</complianceManager><localizationManager type=\"LocalizationManager\"\
>LocalizationManager</localizationManager><storageResourceManager type=\"\
StorageResourceManager\">StorageResourceManager</storageResourceManager></val></propSet></objects></returnval></RetrievePropertiesExResponse>\n\
</soapenv:Body>\n</soapenv:Envelope>"}
headers:
cache-control: [no-cache]
connection: [Keep-Alive]
content-length: ['3460']
content-type: [text/xml; charset=utf-8]
date: ['Mon, 12 Oct 2015 16:20:20 GMT']
status: {code: 200, message: OK}
- request:
body: '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body><RetrievePropertiesEx xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>SessionManager</type><all>false</all><pathSet>currentSession</pathSet></propSet><objectSet><obj
type="SessionManager">SessionManager</obj><skip>false</skip></objectSet></specSet><options><maxObjects>1</maxObjects></options></RetrievePropertiesEx></soapenv:Body>
</soapenv:Envelope>'
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: [vmware_soap_session="57e9ef0e1210352a3cf607db32a20792334f5b81"; Path=/;
HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"']
method: POST
uri: https://vcsa/sdk
response:
body: {string: !!python/unicode "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"\
\n xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:xsd=\"\
http://www.w3.org/2001/XMLSchema\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
>\n<soapenv:Body>\n<RetrievePropertiesExResponse xmlns=\"urn:vim25\"><returnval><objects><obj\
\ type=\"SessionManager\">SessionManager</obj><propSet><name>currentSession</name><val\
\ xsi:type=\"UserSession\"><key>52b5395a-85c2-9902-7835-13a9b77e1fec</key><userName>my_user</userName><fullName>my_user</fullName><loginTime>2015-10-12T16:20:20.388804Z</loginTime><lastActiveTime>2015-10-12T16:20:20.400795Z</lastActiveTime><locale>en</locale><messageLocale>en</messageLocale></val></propSet></objects></returnval></RetrievePropertiesExResponse>\n\
</soapenv:Body>\n</soapenv:Envelope>"}
headers:
cache-control: [no-cache]
connection: [Keep-Alive]
content-length: ['880']
content-type: [text/xml; charset=utf-8]
date: ['Mon, 12 Oct 2015 16:20:20 GMT']
status: {code: 200, message: OK}
version: 1

View File

@@ -40,6 +40,23 @@ class ConnectionTests(tests.VCRTestBase):
self.assertTrue(session_id is not None)
self.assertEqual('52b5395a-85c2-9902-7835-13a9b77e1fec', session_id)
@vcr.use_cassette('sspi_connection.yaml',
cassette_library_dir=tests.fixtures_path,
record_mode='none')
def test_sspi_connection(self):
# see: http://python3porting.com/noconv.html
si = connect.Connect(host='vcsa',
mechanism='sspi',
b64token='my_base64token')
cookie = si._stub.cookie
session_id = si.content.sessionManager.currentSession.key
# NOTE (hartsock): The cookie value should never change during
# a connected session. That should be verifiable in these tests.
self.assertEqual(cookie, si._stub.cookie)
# NOTE (hartsock): assertIsNotNone does not work in Python 2.6
self.assertTrue(session_id is not None)
self.assertEqual('52b5395a-85c2-9902-7835-13a9b77e1fec', session_id)
@vcr.use_cassette('basic_connection_bad_password.yaml',
cassette_library_dir=tests.fixtures_path,
record_mode='none')