|
|
bcdf71 |
From 2927279ba1677e9dda202121176a8245a7ef76ca Mon Sep 17 00:00:00 2001
|
|
|
bcdf71 |
From: tositaka77 <45960626+tositaka77@users.noreply.github.com>
|
|
|
bcdf71 |
Date: Wed, 14 Oct 2020 22:22:56 +0900
|
|
|
bcdf71 |
Subject: [PATCH] fixes and improvements
|
|
|
bcdf71 |
|
|
|
bcdf71 |
- Fixed "regional" PD functionality in attach_disk()
|
|
|
bcdf71 |
- Improve to exact match disk_name with disks.source in detach_disk()
|
|
|
bcdf71 |
---
|
|
|
bcdf71 |
heartbeat/gcp-pd-move.in | 8 +++++++-
|
|
|
bcdf71 |
1 file changed, 7 insertions(+), 1 deletion(-)
|
|
|
bcdf71 |
|
|
|
bcdf71 |
diff --git a/heartbeat/gcp-pd-move.in b/heartbeat/gcp-pd-move.in
|
|
|
bcdf71 |
index f82bd25e5..e99cc71f8 100644
|
|
|
bcdf71 |
--- a/heartbeat/gcp-pd-move.in
|
|
|
bcdf71 |
+++ b/heartbeat/gcp-pd-move.in
|
|
|
bcdf71 |
@@ -49,6 +49,7 @@ else:
|
|
|
bcdf71 |
CONN = None
|
|
|
bcdf71 |
PROJECT = None
|
|
|
bcdf71 |
ZONE = None
|
|
|
bcdf71 |
+REGION = None
|
|
|
bcdf71 |
LIST_DISK_ATTACHED_INSTANCES = None
|
|
|
bcdf71 |
INSTANCE_NAME = None
|
|
|
bcdf71 |
|
|
|
bcdf71 |
@@ -148,6 +149,7 @@ def populate_vars():
|
|
|
bcdf71 |
global INSTANCE_NAME
|
|
|
bcdf71 |
global PROJECT
|
|
|
bcdf71 |
global ZONE
|
|
|
bcdf71 |
+ global REGION
|
|
|
bcdf71 |
global LIST_DISK_ATTACHED_INSTANCES
|
|
|
bcdf71 |
|
|
|
bcdf71 |
# Populate global vars
|
|
|
bcdf71 |
@@ -175,6 +177,7 @@ def populate_vars():
|
|
|
bcdf71 |
PROJECT = get_metadata('project/project-id')
|
|
|
bcdf71 |
if PARAMETERS['disk_scope'] in ['detect', 'regional']:
|
|
|
bcdf71 |
ZONE = get_metadata('instance/zone').split('/')[-1]
|
|
|
bcdf71 |
+ REGION = ZONE[:-2]
|
|
|
bcdf71 |
else:
|
|
|
bcdf71 |
ZONE = PARAMETERS['disk_scope']
|
|
|
bcdf71 |
LIST_DISK_ATTACHED_INSTANCES = get_disk_attached_instances(
|
|
|
bcdf71 |
@@ -255,7 +258,7 @@ def detach_disk(instance, disk_name):
|
|
|
bcdf71 |
|
|
|
bcdf71 |
device_name = None
|
|
|
bcdf71 |
for disk in response['disks']:
|
|
|
bcdf71 |
- if disk_name in disk['source']:
|
|
|
bcdf71 |
+ if disk_name == re.sub('.*disks/',"",disk['source']):
|
|
|
bcdf71 |
device_name = disk['deviceName']
|
|
|
bcdf71 |
break
|
|
|
bcdf71 |
|
|
|
bcdf71 |
@@ -273,6 +276,9 @@ def detach_disk(instance, disk_name):
|
|
|
bcdf71 |
|
|
|
bcdf71 |
def attach_disk(instance, disk_name):
|
|
|
bcdf71 |
location = 'zones/%s' % ZONE
|
|
|
bcdf71 |
+ if PARAMETERS['disk_scope'] == 'regional':
|
|
|
bcdf71 |
+ location = 'regions/%s' % REGION
|
|
|
bcdf71 |
+
|
|
|
bcdf71 |
prefix = 'https://www.googleapis.com/compute/v1'
|
|
|
bcdf71 |
body = {
|
|
|
bcdf71 |
'source': '%(prefix)s/projects/%(project)s/%(location)s/disks/%(disk)s' % {
|