2021-08-21 02:46:11 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# CephInstance.py - Class implementing a PVC node Ceph instance
|
|
|
|
# Part of the Parallel Virtual Cluster (PVC) system
|
|
|
|
#
|
2022-10-06 11:55:27 -04:00
|
|
|
# Copyright (C) 2018-2022 Joshua M. Boniface <joshua@boniface.me>
|
2021-08-21 02:46:11 -04:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, version 3.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
import daemon_lib.common as common
|
2021-09-23 13:59:49 -04:00
|
|
|
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
class CephOSDInstance(object):
|
2022-05-02 12:11:32 -04:00
|
|
|
def __init__(self, zkhandler, logger, this_node, osd_id):
|
2021-08-21 02:46:11 -04:00
|
|
|
self.zkhandler = zkhandler
|
2022-05-02 12:11:32 -04:00
|
|
|
self.logger = logger
|
2021-08-21 02:46:11 -04:00
|
|
|
self.this_node = this_node
|
|
|
|
self.osd_id = osd_id
|
|
|
|
self.node = None
|
2022-05-02 12:11:32 -04:00
|
|
|
self.device = None
|
|
|
|
self.vg = None
|
|
|
|
self.lv = None
|
2021-08-21 02:46:11 -04:00
|
|
|
self.stats = dict()
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path("osd.node", self.osd_id)
|
|
|
|
)
|
|
|
|
def watch_osd_node(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
2021-08-21 02:46:11 -04:00
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = data.decode("ascii")
|
2021-08-21 02:46:11 -04:00
|
|
|
except AttributeError:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = ""
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
if data and data != self.node:
|
|
|
|
self.node = data
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path("osd.stats", self.osd_id)
|
|
|
|
)
|
|
|
|
def watch_osd_stats(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
2021-08-21 02:46:11 -04:00
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = data.decode("ascii")
|
2021-08-21 02:46:11 -04:00
|
|
|
except AttributeError:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = ""
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
if data and data != self.stats:
|
|
|
|
self.stats = json.loads(data)
|
|
|
|
|
2022-05-02 12:11:32 -04:00
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path("osd.device", self.osd_id)
|
|
|
|
)
|
|
|
|
def watch_osd_device(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
data = data.decode("ascii")
|
|
|
|
except AttributeError:
|
|
|
|
data = ""
|
|
|
|
|
|
|
|
if data and data != self.device:
|
|
|
|
self.device = data
|
|
|
|
|
|
|
|
# Exception conditional for migration from schema v7 to schema v8
|
|
|
|
try:
|
|
|
|
|
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path("osd.vg", self.osd_id)
|
|
|
|
)
|
|
|
|
def watch_osd_vg(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
data = data.decode("ascii")
|
|
|
|
except AttributeError:
|
|
|
|
data = ""
|
|
|
|
|
|
|
|
if data and data != self.vg:
|
|
|
|
self.vg = data
|
|
|
|
|
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path("osd.lv", self.osd_id)
|
|
|
|
)
|
|
|
|
def watch_osd_lv(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
data = data.decode("ascii")
|
|
|
|
except AttributeError:
|
|
|
|
data = ""
|
|
|
|
|
|
|
|
if data and data != self.lv:
|
|
|
|
self.lv = data
|
|
|
|
|
|
|
|
if self.node == self.this_node.name:
|
|
|
|
self.update_information()
|
|
|
|
except TypeError:
|
|
|
|
return
|
|
|
|
|
|
|
|
def update_information(self):
|
|
|
|
if self.vg is not None and self.lv is not None:
|
|
|
|
find_device = f"/dev/{self.vg}/{self.lv}"
|
|
|
|
else:
|
|
|
|
find_device = self.device
|
|
|
|
|
|
|
|
self.logger.out(
|
|
|
|
f"Updating stored disk information for OSD {self.osd_id}",
|
|
|
|
state="i",
|
|
|
|
)
|
|
|
|
|
|
|
|
retcode, stdout, stderr = common.run_os_command(
|
|
|
|
f"ceph-volume lvm list {find_device}"
|
|
|
|
)
|
2022-05-06 15:31:58 -04:00
|
|
|
osd_blockdev = None
|
|
|
|
osd_fsid = None
|
|
|
|
osd_clusterfsid = None
|
|
|
|
osd_device = None
|
2022-05-02 12:11:32 -04:00
|
|
|
for line in stdout.split("\n"):
|
|
|
|
if "block device" in line:
|
|
|
|
osd_blockdev = line.split()[-1]
|
|
|
|
if "osd fsid" in line:
|
|
|
|
osd_fsid = line.split()[-1]
|
|
|
|
if "cluster fsid" in line:
|
|
|
|
osd_clusterfsid = line.split()[-1]
|
|
|
|
if "devices" in line:
|
|
|
|
osd_device = line.split()[-1]
|
|
|
|
|
2022-05-06 15:31:58 -04:00
|
|
|
if not osd_blockdev or not osd_fsid or not osd_clusterfsid or not osd_device:
|
2022-05-02 12:11:32 -04:00
|
|
|
self.logger.out(
|
|
|
|
f"Failed to find updated OSD information via ceph-volume for {find_device}",
|
|
|
|
state="e",
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
# Split OSD blockdev into VG and LV components
|
|
|
|
# osd_blockdev = /dev/ceph-<uuid>/osd-block-<uuid>
|
|
|
|
_, _, osd_vg, osd_lv = osd_blockdev.split("/")
|
|
|
|
|
|
|
|
# Except for potentially the "osd.device", this should never change, but this ensures
|
|
|
|
# that the data is added at lease once on initialization for existing OSDs.
|
|
|
|
self.zkhandler.write(
|
|
|
|
[
|
|
|
|
(("osd.device", self.osd_id), osd_device),
|
|
|
|
(("osd.fsid", self.osd_id), ""),
|
|
|
|
(("osd.ofsid", self.osd_id), osd_fsid),
|
|
|
|
(("osd.cfsid", self.osd_id), osd_clusterfsid),
|
|
|
|
(("osd.lvm", self.osd_id), ""),
|
|
|
|
(("osd.vg", self.osd_id), osd_vg),
|
|
|
|
(("osd.lv", self.osd_id), osd_lv),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
self.device = osd_device
|
|
|
|
self.vg = osd_vg
|
|
|
|
self.lv = osd_lv
|
|
|
|
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
class CephPoolInstance(object):
|
2022-05-02 12:11:32 -04:00
|
|
|
def __init__(self, zkhandler, logger, this_node, name):
|
2021-08-21 02:46:11 -04:00
|
|
|
self.zkhandler = zkhandler
|
2022-05-02 12:11:32 -04:00
|
|
|
self.logger = logger
|
2021-08-21 02:46:11 -04:00
|
|
|
self.this_node = this_node
|
|
|
|
self.name = name
|
2021-11-06 03:02:43 -04:00
|
|
|
self.pgs = ""
|
2021-08-21 02:46:11 -04:00
|
|
|
self.stats = dict()
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path("pool.pgs", self.name)
|
|
|
|
)
|
|
|
|
def watch_pool_node(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
2021-08-21 02:46:11 -04:00
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = data.decode("ascii")
|
2021-08-21 02:46:11 -04:00
|
|
|
except AttributeError:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = ""
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
if data and data != self.pgs:
|
|
|
|
self.pgs = data
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path("pool.stats", self.name)
|
|
|
|
)
|
|
|
|
def watch_pool_stats(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
2021-08-21 02:46:11 -04:00
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = data.decode("ascii")
|
2021-08-21 02:46:11 -04:00
|
|
|
except AttributeError:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = ""
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
if data and data != self.stats:
|
|
|
|
self.stats = json.loads(data)
|
|
|
|
|
|
|
|
|
|
|
|
class CephVolumeInstance(object):
|
2022-05-02 12:11:32 -04:00
|
|
|
def __init__(self, zkhandler, logger, this_node, pool, name):
|
2021-08-21 02:46:11 -04:00
|
|
|
self.zkhandler = zkhandler
|
2022-05-02 12:11:32 -04:00
|
|
|
self.logger = logger
|
2021-08-21 02:46:11 -04:00
|
|
|
self.this_node = this_node
|
|
|
|
self.pool = pool
|
|
|
|
self.name = name
|
|
|
|
self.stats = dict()
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path("volume.stats", f"{self.pool}/{self.name}")
|
|
|
|
)
|
|
|
|
def watch_volume_stats(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
2021-08-21 02:46:11 -04:00
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = data.decode("ascii")
|
2021-08-21 02:46:11 -04:00
|
|
|
except AttributeError:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = ""
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
if data and data != self.stats:
|
|
|
|
self.stats = json.loads(data)
|
|
|
|
|
|
|
|
|
|
|
|
class CephSnapshotInstance(object):
|
|
|
|
def __init__(self, zkhandler, this_node, pool, volume, name):
|
|
|
|
self.zkhandler = zkhandler
|
|
|
|
self.this_node = this_node
|
|
|
|
self.pool = pool
|
|
|
|
self.volume = volume
|
|
|
|
self.name = name
|
|
|
|
self.stats = dict()
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@self.zkhandler.zk_conn.DataWatch(
|
|
|
|
self.zkhandler.schema.path(
|
|
|
|
"snapshot.stats", f"{self.pool}/{self.volume}/{self.name}"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
def watch_snapshot_stats(data, stat, event=""):
|
|
|
|
if event and event.type == "DELETED":
|
2021-08-21 02:46:11 -04:00
|
|
|
# The key has been deleted after existing before; terminate this watcher
|
|
|
|
# because this class instance is about to be reaped in Daemon.py
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = data.decode("ascii")
|
2021-08-21 02:46:11 -04:00
|
|
|
except AttributeError:
|
2021-11-06 03:02:43 -04:00
|
|
|
data = ""
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
if data and data != self.stats:
|
|
|
|
self.stats = json.loads(data)
|