|
|
02ddf4 |
From 9dedf4d4ad3a94e4ce75e0f29ffdd018e3709ae3 Mon Sep 17 00:00:00 2001
|
|
|
02ddf4 |
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
|
|
|
02ddf4 |
Date: Thu, 28 May 2020 11:39:20 +0200
|
|
|
02ddf4 |
Subject: [PATCH] gcp-pd-move: fixes and improvements
|
|
|
02ddf4 |
|
|
|
02ddf4 |
- Fixed Python 3 encoding issue
|
|
|
02ddf4 |
- Improved metadata
|
|
|
02ddf4 |
- Change monitor loglevel to debug
|
|
|
02ddf4 |
- Removed "regional" functionality that doesnt work with attachDisk()
|
|
|
02ddf4 |
- Updated rw/ro to READ_WRITE/READ_ONLY in metadata/default value
|
|
|
02ddf4 |
---
|
|
|
02ddf4 |
heartbeat/gcp-pd-move.in | 63 ++++++++++++++++++++--------------------
|
|
|
02ddf4 |
1 file changed, 32 insertions(+), 31 deletions(-)
|
|
|
02ddf4 |
mode change 100755 => 100644 heartbeat/gcp-pd-move.in
|
|
|
02ddf4 |
|
|
|
02ddf4 |
diff --git a/heartbeat/gcp-pd-move.in b/heartbeat/gcp-pd-move.in
|
|
|
02ddf4 |
old mode 100755
|
|
|
02ddf4 |
new mode 100644
|
|
|
02ddf4 |
index 7fabc80dc..f82bd25e5
|
|
|
02ddf4 |
--- a/heartbeat/gcp-pd-move.in
|
|
|
02ddf4 |
+++ b/heartbeat/gcp-pd-move.in
|
|
|
02ddf4 |
@@ -29,6 +29,7 @@ OCF_FUNCTIONS_DIR = os.environ.get("OCF_FUNCTIONS_DIR", "%s/lib/heartbeat" % os.
|
|
|
02ddf4 |
sys.path.append(OCF_FUNCTIONS_DIR)
|
|
|
02ddf4 |
|
|
|
02ddf4 |
import ocf
|
|
|
02ddf4 |
+from ocf import logger
|
|
|
02ddf4 |
|
|
|
02ddf4 |
try:
|
|
|
02ddf4 |
import googleapiclient.discovery
|
|
|
02ddf4 |
@@ -48,16 +49,16 @@ else:
|
|
|
02ddf4 |
CONN = None
|
|
|
02ddf4 |
PROJECT = None
|
|
|
02ddf4 |
ZONE = None
|
|
|
02ddf4 |
-REGION = None
|
|
|
02ddf4 |
LIST_DISK_ATTACHED_INSTANCES = None
|
|
|
02ddf4 |
INSTANCE_NAME = None
|
|
|
02ddf4 |
|
|
|
02ddf4 |
PARAMETERS = {
|
|
|
02ddf4 |
- 'disk_name': None,
|
|
|
02ddf4 |
- 'disk_scope': None,
|
|
|
02ddf4 |
- 'disk_csek_file': None,
|
|
|
02ddf4 |
- 'mode': None,
|
|
|
02ddf4 |
- 'device_name': None,
|
|
|
02ddf4 |
+ 'disk_name': '',
|
|
|
02ddf4 |
+ 'disk_scope': 'detect',
|
|
|
02ddf4 |
+ 'disk_csek_file': '',
|
|
|
02ddf4 |
+ 'mode': "READ_WRITE",
|
|
|
02ddf4 |
+ 'device_name': '',
|
|
|
02ddf4 |
+ 'stackdriver_logging': 'no',
|
|
|
02ddf4 |
}
|
|
|
02ddf4 |
|
|
|
02ddf4 |
MANDATORY_PARAMETERS = ['disk_name', 'disk_scope']
|
|
|
02ddf4 |
@@ -80,32 +81,32 @@ correctly.
|
|
|
02ddf4 |
<parameter name="disk_name" unique="1" required="1">
|
|
|
02ddf4 |
<longdesc lang="en">The name of the GCP disk.</longdesc>
|
|
|
02ddf4 |
<shortdesc lang="en">Disk name</shortdesc>
|
|
|
02ddf4 |
-<content type="string" default="" />
|
|
|
02ddf4 |
+<content type="string" default="{}" />
|
|
|
02ddf4 |
</parameter>
|
|
|
02ddf4 |
-<parameter name="disk_scope" unique="1" required="1">
|
|
|
02ddf4 |
-<longdesc lang="en">Disk scope </longdesc>
|
|
|
02ddf4 |
+<parameter name="disk_scope">
|
|
|
02ddf4 |
+<longdesc lang="en">Disk scope</longdesc>
|
|
|
02ddf4 |
<shortdesc lang="en">Network name</shortdesc>
|
|
|
02ddf4 |
-<content type="string" default="regional" />
|
|
|
02ddf4 |
+<content type="string" default="{}" />
|
|
|
02ddf4 |
</parameter>
|
|
|
02ddf4 |
-<parameter name="disk_csek_file" unique="1" required="0">
|
|
|
02ddf4 |
+<parameter name="disk_csek_file">
|
|
|
02ddf4 |
<longdesc lang="en">Path to a Customer-Supplied Encryption Key (CSEK) key file</longdesc>
|
|
|
02ddf4 |
<shortdesc lang="en">Customer-Supplied Encryption Key file</shortdesc>
|
|
|
02ddf4 |
-<content type="string" default="" />
|
|
|
02ddf4 |
+<content type="string" default="{}" />
|
|
|
02ddf4 |
</parameter>
|
|
|
02ddf4 |
-<parameter name="mode" unique="1" required="0">
|
|
|
02ddf4 |
-<longdesc lang="en">Attachment mode (rw, ro)</longdesc>
|
|
|
02ddf4 |
+<parameter name="mode">
|
|
|
02ddf4 |
+<longdesc lang="en">Attachment mode (READ_WRITE, READ_ONLY)</longdesc>
|
|
|
02ddf4 |
<shortdesc lang="en">Attachment mode</shortdesc>
|
|
|
02ddf4 |
-<content type="string" default="rw" />
|
|
|
02ddf4 |
+<content type="string" default="{}" />
|
|
|
02ddf4 |
</parameter>
|
|
|
02ddf4 |
-<parameter name="device_name" unique="0" required="0">
|
|
|
02ddf4 |
+<parameter name="device_name">
|
|
|
02ddf4 |
<longdesc lang="en">An optional name that indicates the disk name the guest operating system will see.</longdesc>
|
|
|
02ddf4 |
<shortdesc lang="en">Optional device name</shortdesc>
|
|
|
02ddf4 |
-<content type="boolean" default="" />
|
|
|
02ddf4 |
+<content type="boolean" default="{}" />
|
|
|
02ddf4 |
</parameter>
|
|
|
02ddf4 |
-<parameter name="stackdriver_logging" unique="1" required="0">
|
|
|
02ddf4 |
+<parameter name="stackdriver_logging">
|
|
|
02ddf4 |
<longdesc lang="en">Use stackdriver_logging output to global resource (yes, true, enabled)</longdesc>
|
|
|
02ddf4 |
<shortdesc lang="en">Use stackdriver_logging</shortdesc>
|
|
|
02ddf4 |
-<content type="string" default="no" />
|
|
|
02ddf4 |
+<content type="string" default="{}" />
|
|
|
02ddf4 |
</parameter>
|
|
|
02ddf4 |
</parameters>
|
|
|
02ddf4 |
<actions>
|
|
|
02ddf4 |
@@ -114,7 +115,9 @@ correctly.
|
|
|
02ddf4 |
<action name="monitor" timeout="15s" interval="10s" depth="0" />
|
|
|
02ddf4 |
<action name="meta-data" timeout="5s" />
|
|
|
02ddf4 |
</actions>
|
|
|
02ddf4 |
-</resource-agent>'''
|
|
|
02ddf4 |
+</resource-agent>'''.format(PARAMETERS['disk_name'], PARAMETERS['disk_scope'],
|
|
|
02ddf4 |
+ PARAMETERS['disk_csek_file'], PARAMETERS['mode'], PARAMETERS['device_name'],
|
|
|
02ddf4 |
+ PARAMETERS['stackdriver_logging'])
|
|
|
02ddf4 |
|
|
|
02ddf4 |
|
|
|
02ddf4 |
def get_metadata(metadata_key, params=None, timeout=None):
|
|
|
02ddf4 |
@@ -137,7 +140,7 @@ def get_metadata(metadata_key, params=None, timeout=None):
|
|
|
02ddf4 |
url = '%s?%s' % (metadata_url, params)
|
|
|
02ddf4 |
request = urlrequest.Request(url, headers=METADATA_HEADERS)
|
|
|
02ddf4 |
request_opener = urlrequest.build_opener(urlrequest.ProxyHandler({}))
|
|
|
02ddf4 |
- return request_opener.open(request, timeout=timeout * 1.1).read()
|
|
|
02ddf4 |
+ return request_opener.open(request, timeout=timeout * 1.1).read().decode("utf-8")
|
|
|
02ddf4 |
|
|
|
02ddf4 |
|
|
|
02ddf4 |
def populate_vars():
|
|
|
02ddf4 |
@@ -145,11 +148,8 @@ def populate_vars():
|
|
|
02ddf4 |
global INSTANCE_NAME
|
|
|
02ddf4 |
global PROJECT
|
|
|
02ddf4 |
global ZONE
|
|
|
02ddf4 |
- global REGION
|
|
|
02ddf4 |
global LIST_DISK_ATTACHED_INSTANCES
|
|
|
02ddf4 |
|
|
|
02ddf4 |
- global PARAMETERS
|
|
|
02ddf4 |
-
|
|
|
02ddf4 |
# Populate global vars
|
|
|
02ddf4 |
try:
|
|
|
02ddf4 |
CONN = googleapiclient.discovery.build('compute', 'v1')
|
|
|
02ddf4 |
@@ -158,11 +158,12 @@ def populate_vars():
|
|
|
02ddf4 |
sys.exit(ocf.OCF_ERR_CONFIGURED)
|
|
|
02ddf4 |
|
|
|
02ddf4 |
for param in PARAMETERS:
|
|
|
02ddf4 |
- value = os.environ.get('OCF_RESKEY_%s' % param, None)
|
|
|
02ddf4 |
+ value = os.environ.get('OCF_RESKEY_%s' % param, PARAMETERS[param])
|
|
|
02ddf4 |
if not value and param in MANDATORY_PARAMETERS:
|
|
|
02ddf4 |
logger.error('Missing %s mandatory parameter' % param)
|
|
|
02ddf4 |
sys.exit(ocf.OCF_ERR_CONFIGURED)
|
|
|
02ddf4 |
- PARAMETERS[param] = value
|
|
|
02ddf4 |
+ elif value:
|
|
|
02ddf4 |
+ PARAMETERS[param] = value
|
|
|
02ddf4 |
|
|
|
02ddf4 |
try:
|
|
|
02ddf4 |
INSTANCE_NAME = get_metadata('instance/name')
|
|
|
02ddf4 |
@@ -172,8 +173,10 @@ def populate_vars():
|
|
|
02ddf4 |
sys.exit(ocf.OCF_ERR_CONFIGURED)
|
|
|
02ddf4 |
|
|
|
02ddf4 |
PROJECT = get_metadata('project/project-id')
|
|
|
02ddf4 |
- ZONE = get_metadata('instance/zone').split('/')[-1]
|
|
|
02ddf4 |
- REGION = ZONE[:-2]
|
|
|
02ddf4 |
+ if PARAMETERS['disk_scope'] in ['detect', 'regional']:
|
|
|
02ddf4 |
+ ZONE = get_metadata('instance/zone').split('/')[-1]
|
|
|
02ddf4 |
+ else:
|
|
|
02ddf4 |
+ ZONE = PARAMETERS['disk_scope']
|
|
|
02ddf4 |
LIST_DISK_ATTACHED_INSTANCES = get_disk_attached_instances(
|
|
|
02ddf4 |
PARAMETERS['disk_name'])
|
|
|
02ddf4 |
|
|
|
02ddf4 |
@@ -270,8 +273,6 @@ def detach_disk(instance, disk_name):
|
|
|
02ddf4 |
|
|
|
02ddf4 |
def attach_disk(instance, disk_name):
|
|
|
02ddf4 |
location = 'zones/%s' % ZONE
|
|
|
02ddf4 |
- if PARAMETERS['disk_scope'] == 'regional':
|
|
|
02ddf4 |
- location = 'regions/%s' % REGION
|
|
|
02ddf4 |
prefix = 'https://www.googleapis.com/compute/v1'
|
|
|
02ddf4 |
body = {
|
|
|
02ddf4 |
'source': '%(prefix)s/projects/%(project)s/%(location)s/disks/%(disk)s' % {
|
|
|
02ddf4 |
@@ -342,7 +343,7 @@ def gcp_pd_move_stop():
|
|
|
02ddf4 |
def gcp_pd_move_status():
|
|
|
02ddf4 |
fetch_data()
|
|
|
02ddf4 |
if is_disk_attached(INSTANCE_NAME):
|
|
|
02ddf4 |
- logger.info("Disk %(disk_name)s is correctly attached to %(instance)s" % {
|
|
|
02ddf4 |
+ logger.debug("Disk %(disk_name)s is correctly attached to %(instance)s" % {
|
|
|
02ddf4 |
'disk_name': PARAMETERS['disk_name'],
|
|
|
02ddf4 |
'instance': INSTANCE_NAME,
|
|
|
02ddf4 |
})
|