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

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