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

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