Blame SOURCES/bz1913932-1-gcp-vpc-move-add-project-parameter.patch

030326
From 560683500b3f9d5d8e183a569daea27422ae5268 Mon Sep 17 00:00:00 2001
030326
From: Reid Wahl <nrwahl@protonmail.com>
030326
Date: Thu, 7 Jan 2021 12:25:04 -0800
030326
Subject: [PATCH] gcp-vpc-move-route, gcp-vpc-move-vip: Parameterize project ID
030326
030326
Resolves: RHBZ#1913932
030326
Resolves: RHBZ#1913936
030326
030326
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
030326
---
030326
 heartbeat/gcp-vpc-move-route.in | 13 ++++++++++++-
030326
 heartbeat/gcp-vpc-move-vip.in   | 16 ++++++++++++++--
030326
 2 files changed, 26 insertions(+), 3 deletions(-)
030326
030326
diff --git a/heartbeat/gcp-vpc-move-route.in b/heartbeat/gcp-vpc-move-route.in
030326
index d8e8ea8dd..179eba15a 100644
030326
--- a/heartbeat/gcp-vpc-move-route.in
030326
+++ b/heartbeat/gcp-vpc-move-route.in
030326
@@ -106,6 +106,16 @@ Name of the VPC network
030326
 <content type="string" default="default" />
030326
 </parameter>
030326
 
030326
+<parameter name="project">
030326
+<longdesc lang="en">
030326
+Project ID of the instance. It can be useful to set this attribute if
030326
+the instance is in a shared service project. Otherwise, the agent should
030326
+be able to determine the project ID automatically.
030326
+</longdesc>
030326
+<shortdesc lang="en">Project ID</shortdesc>
030326
+<content type="string" default="default" />
030326
+</parameter>
030326
+
030326
 <parameter name="interface">
030326
 <longdesc lang="en">
030326
 Name of the network interface
030326
@@ -215,7 +225,8 @@ def validate(ctx):
030326
   try:
030326
     ctx.instance = get_metadata('instance/name')
030326
     ctx.zone = get_metadata('instance/zone').split('/')[-1]
030326
-    ctx.project = get_metadata('project/project-id')
030326
+    ctx.project = os.environ.get(
030326
+        'OCF_RESKEY_project', get_metadata('project/project-id'))
030326
   except Exception as e:
030326
     logger.error(
030326
         'Instance information not found. Is this a GCE instance ?: %s', str(e))
030326
diff --git a/heartbeat/gcp-vpc-move-vip.in b/heartbeat/gcp-vpc-move-vip.in
030326
index 01d91a59d..e792f71d5 100755
030326
--- a/heartbeat/gcp-vpc-move-vip.in
030326
+++ b/heartbeat/gcp-vpc-move-vip.in
030326
@@ -75,6 +75,16 @@ METADATA = \
030326
       <shortdesc lang="en">Host list</shortdesc>
030326
       <content type="string" default="" />
030326
     </parameter>
030326
+    <parameter name="project" unique="0" required="0">
030326
+      <longdesc lang="en">
030326
+        Project ID of the instance. It can be useful to set this
030326
+        attribute if the instance is in a shared service project.
030326
+        Otherwise, the agent should be able to determine the project ID
030326
+        automatically.
030326
+      </longdesc>
030326
+      <shortdesc lang="en">Project ID</shortdesc>
030326
+      <content type="string" default="default" />
030326
+    </parameter>
030326
     <parameter name="stackdriver_logging" unique="0" required="0">
030326
       <longdesc lang="en">If enabled (set to true), IP failover logs will be posted to stackdriver logging</longdesc>
030326
       <shortdesc lang="en">Stackdriver-logging support</shortdesc>
030326
@@ -267,7 +277,8 @@ def get_instances_list(project, exclude):
030326
 def gcp_alias_start(alias):
030326
   my_aliases = get_localhost_aliases()
030326
   my_zone = get_metadata('instance/zone').split('/')[-1]
030326
-  project = get_metadata('project/project-id')
030326
+  project = os.environ.get(
030326
+        'OCF_RESKEY_project', get_metadata('project/project-id'))
030326
 
030326
   if alias in my_aliases:
030326
     # TODO: Do we need to check alias_range_name?
030326
@@ -315,7 +326,8 @@ def gcp_alias_start(alias):
030326
 def gcp_alias_stop(alias):
030326
   my_aliases = get_localhost_aliases()
030326
   my_zone = get_metadata('instance/zone').split('/')[-1]
030326
-  project = get_metadata('project/project-id')
030326
+  project = os.environ.get(
030326
+        'OCF_RESKEY_project', get_metadata('project/project-id'))
030326
 
030326
   if alias in my_aliases:
030326
     logger.info('Removing %s from %s' % (alias, THIS_VM))