axxyhtrx / pysphere

Automatically exported from code.google.com/p/pysphere
0 stars 0 forks source link

VIVirtualMachine.send_file() gratuitiosly overwrites urllib2's installed default opener #26

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. have a default proxy configured that does not allow access to the ESXi hosts.
2. configure urllib2 to not use a proxy:

proxy_handler = urllib2.ProxyHandler({})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)

3. try uploading a file to a guest with vm.send_file()

What is the expected output? What do you see instead?

This causes send_file() to abort with an exception because the connection
to the ESX host can't be established.

What version of the product are you using? On what operating system?

pysphere 0.1.7, python 2.6.8, Windows 7

urllib2.urlopen() has accepted a request object since at least python 2.5.

Apply the following patch:

--- vi_virtual_machine.py,0     2012-10-09 18:04:01.576577700 +0200             
+++ vi_virtual_machine.py       2012-10-09 19:12:04.782569200 +0200             
@@ -1276,10 +1276,9 @@                                                          

             url = url.replace("*", urlparse(self._server._proxy.binding.url    
                                                                      ).hostname
)                                                                               
-            opener = urllib2.build_opener(urllib2.HTTPHandler)                 
             request = urllib2.Request(url, data=content)                       
             request.get_method = lambda: 'PUT'                                 
-            resp = opener.open(request)                                        
+            resp = urllib2.urlopen(request)                                    
             if not resp.code == 200:                                           
                 raise VIException("File could not be send",                    
                                   FaultTypes.TASK_ERROR)

Original issue reported on code.google.com by badur...@googlemail.com on 9 Oct 2012 at 7:46

GoogleCodeExporter commented 9 years ago
Thanks!

This has been fixed in r85

Original comment by argo...@gmail.com on 10 Oct 2012 at 12:52