diff mbox series

[1/1] UBUNTU: SAUCE: move proxy setup to a Canonical specific catch-all

Message ID 20200303111916.77250-2-paolo.pisati@canonical.com
State New
Headers show
Series [1/1] UBUNTU: SAUCE: move proxy setup to a Canonical specific catch-all | expand

Commit Message

Paolo Pisati March 3, 2020, 11:19 a.m. UTC
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
---
 client/canonical.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 client/canonical.py

Comments

Po-Hsu Lin March 5, 2020, 3:07 a.m. UTC | #1
Done some quick test and it looks good.
Acked-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
diff mbox series

Patch

diff --git a/client/canonical.py b/client/canonical.py
new file mode 100644
index 00000000..41810be6
--- /dev/null
+++ b/client/canonical.py
@@ -0,0 +1,23 @@ 
+"""
+Canonical specific code catch-all
+"""
+
+import os, utils
+
+def setup_proxy():
+    # Hacky way to use proxy settings, ideally this should be done on deployment stage
+    #
+    print "Setup the http/https proxy"
+    proxysets = [{'addr': 'squid.internal', 'desc': 'Running in the Canonical CI environment'},
+              {'addr': '91.189.89.216', 'desc': 'Running in the Canonical enablement environment'},
+              {'addr': '10.245.64.1', 'desc': 'Running in the Canonical enablement environment'}]
+    for proxy in proxysets:
+        cmd = 'nc -w 2 ' + proxy['addr'] + ' 3128'
+        try:
+            utils.system_output(cmd, retain_output=False)
+            print proxy['desc']
+            os.environ['http_proxy'] = 'http://' + proxy['addr'] + ':3128'
+            os.environ['https_proxy'] = 'http://' + proxy['addr'] + ':3128'
+            break
+        except:
+            pass