ansible-test: vcenter through a HTTP proxy

Give the ansible-test user the ability to target a lab behind a HTTP proxy.
pull/59018/head
Gonéri Le Bouder 5 years ago
parent 617972499f
commit 31baab85f9

@ -63,6 +63,7 @@ class VcenterProvider(CloudProvider):
self.endpoint = ''
self.hostname = ''
self.port = 443
self.proxy = None
def filter(self, targets, exclude):
"""Filter out the cloud tests when the necessary config and resources are not available.
@ -222,6 +223,10 @@ class VcenterProvider(CloudProvider):
if parser.get('DEFAULT', 'vmware_validate_certs').lower() in ('no', 'false'):
self.insecure = True
proxy_host = parser.get('DEFAULT', 'vmware_proxy_host')
proxy_port = int(parser.get('DEFAULT', 'vmware_proxy_port'))
if proxy_host and proxy_port:
self.proxy = 'http://%s:%d' % (proxy_host, proxy_port)
self._wait_for_service()
@ -230,7 +235,7 @@ class VcenterProvider(CloudProvider):
if self.args.explain:
return
client = HttpClient(self.args, always=True, insecure=self.insecure)
client = HttpClient(self.args, always=True, insecure=self.insecure, proxy=self.proxy)
endpoint = 'https://%s:%s' % (self.endpoint, self.port)
for i in range(1, 30):

@ -35,7 +35,7 @@ from lib.util_common import (
class HttpClient(object):
"""Make HTTP requests via curl."""
def __init__(self, args, always=False, insecure=False):
def __init__(self, args, always=False, insecure=False, proxy=None):
"""
:type args: CommonConfig
:type always: bool
@ -44,6 +44,7 @@ class HttpClient(object):
self.args = args
self.always = always
self.insecure = insecure
self.proxy = proxy
self.username = None
self.password = None
@ -102,6 +103,9 @@ class HttpClient(object):
if data is not None:
cmd += ['-d', data]
if self.proxy:
cmd += ['-x', self.proxy]
cmd += [url]
attempts = 0

Loading…
Cancel
Save