Blame SOURCES/bz1969953-fence_gce-1-add-proxy-support.patch

16bf74
diff --color -uNr a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
16bf74
--- a/agents/gce/fence_gce.py	2021-06-11 14:57:01.138390529 +0200
16bf74
+++ b/agents/gce/fence_gce.py	2021-06-11 15:12:45.829855806 +0200
16bf74
@@ -1,6 +1,7 @@
16bf74
 #!@PYTHON@ -tt
16bf74
 
16bf74
 import atexit
16bf74
+import httplib2
16bf74
 import logging
16bf74
 import os
16bf74
 import sys
16bf74
@@ -18,6 +19,7 @@
16bf74
 from fencing import fail_usage, run_delay, all_opt, atexit_handler, check_input, process_input, show_docs, fence_action
16bf74
 try:
16bf74
   import googleapiclient.discovery
16bf74
+  import socks
16bf74
   try:
16bf74
     from google.oauth2.credentials import Credentials as GoogleCredentials
16bf74
   except:
16bf74
@@ -189,13 +191,30 @@
16bf74
 		"required" : "0",
16bf74
 		"order" : 9
16bf74
 	}
16bf74
+	all_opt["proxyhost"] = {
16bf74
+		"getopt" : ":",
16bf74
+		"longopt" : "proxyhost",
16bf74
+		"help" : "--proxyhost=[proxy_host]       The proxy host to use, if one is needed to access the internet (Example: 10.122.0.33)",
16bf74
+		"shortdesc" : "If a proxy is used for internet access, the proxy host should be specified.",
16bf74
+		"required" : "0",
16bf74
+		"order" : 10
16bf74
+	}
16bf74
+	all_opt["proxyport"] = {
16bf74
+		"getopt" : ":",
16bf74
+		"type" : "integer",
16bf74
+		"longopt" : "proxyport",
16bf74
+		"help" : "--proxyport=[proxy_port]       The proxy port to use, if one is needed to access the internet (Example: 3127)",
16bf74
+		"shortdesc" : "If a proxy is used for internet access, the proxy port should be specified.",
16bf74
+		"required" : "0",
16bf74
+		"order" : 11
16bf74
+	}
16bf74
 
16bf74
 
16bf74
 def main():
16bf74
 	conn = None
16bf74
 
16bf74
 	device_opt = ["port", "no_password", "zone", "project", "stackdriver-logging",
16bf74
-		"method", "serviceaccount"]
16bf74
+		"method", "serviceaccount", "proxyhost", "proxyport"]
16bf74
 
16bf74
 	atexit.register(atexit_handler)
16bf74
 
16bf74
@@ -259,7 +278,17 @@
16bf74
 				credentials = GoogleCredentials.get_application_default()
16bf74
 			logging.debug("using application default credentials")
16bf74
 
16bf74
-		conn = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
16bf74
+		if options.get("--proxyhost") and options.get("--proxyport"):
16bf74
+			proxy_info = httplib2.ProxyInfo(
16bf74
+				proxy_type=socks.PROXY_TYPE_HTTP,
16bf74
+				proxy_host=options.get("--proxyhost"),
16bf74
+				proxy_port=int(options.get("--proxyport")))
16bf74
+			http = credentials.authorize(httplib2.Http(proxy_info=proxy_info))
16bf74
+			conn = googleapiclient.discovery.build(
16bf74
+				'compute', 'v1', http=http, cache_discovery=False)
16bf74
+		else:
16bf74
+			conn = googleapiclient.discovery.build(
16bf74
+				'compute', 'v1', credentials=credentials, cache_discovery=False)
16bf74
 	except Exception as err:
16bf74
 		fail_usage("Failed: Create GCE compute v1 connection: {}".format(str(err)))
16bf74