From 103ae95fb9866fef116fee22b9dfe9be374ceb3e Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 27 Oct 2018 18:11:58 -0400 Subject: [PATCH] Add Ceph commands and status handling --- client-cli/pvc.py | 68 +++++++++++++++++++++++++++++++++++++++-- client-common/ceph.py | 55 +++++++++++++++++++++++++++++++++ client-common/common.py | 9 +++--- 3 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 client-common/ceph.py diff --git a/client-cli/pvc.py b/client-cli/pvc.py index d605b9cf..39e59680 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -33,6 +33,7 @@ import client_lib.common as pvc_common import client_lib.node as pvc_node import client_lib.vm as pvc_vm import client_lib.network as pvc_network +import client_lib.ceph as pvc_ceph myhostname = socket.gethostname() zk_host = '' @@ -904,6 +905,48 @@ def net_acl_list(net, limit, direction): retcode, retmsg = pvc_network.get_list_acl(zk_conn, net, limit, direction) cleanup(retcode, retmsg, zk_conn) +############################################################################### +# pvc ceph +############################################################################### +@click.group(name='ceph', short_help='Manage the PVC Ceph storage cluster.', context_settings=CONTEXT_SETTINGS) +def cli_ceph(): + """ + Manage the Ceph storage of the PVC cluster. + """ + pass + +############################################################################### +# pvc ceph status +############################################################################### +@click.command(name='status', short_help='Show storage cluster status.') +def ceph_status(): + """ + Show detailed status of the storage cluster. + """ + + zk_conn = pvc_common.startZKConnection(zk_host) + retcode, retmsg = pvc_ceph.get_status(zk_conn) + cleanup(retcode, retmsg, zk_conn) + +############################################################################### +# pvc ceph osd +############################################################################### +@click.group(name='osd', short_help='Manage OSDs in the PVC storage cluster.', context_settings=CONTEXT_SETTINGS) +def ceph_osd(): + """ + Manage the Ceph OSDs of the PVC cluster. + """ + pass + +############################################################################### +# pvc ceph pool +############################################################################### +@click.group(name='pool', short_help='Manage RBD pools in the PVC storage cluster.', context_settings=CONTEXT_SETTINGS) +def ceph_pool(): + """ + Manage the Ceph RBD pools of the PVC cluster. + """ + pass ############################################################################### @@ -937,11 +980,13 @@ def init_cluster(): # Create the root keys transaction = zk_conn.transaction() - transaction.create('/networks', ''.encode('ascii')) - transaction.create('/domains', ''.encode('ascii')) transaction.create('/nodes', ''.encode('ascii')) transaction.create('/primary_node', 'none'.encode('ascii')) + transaction.create('/domains', ''.encode('ascii')) + transaction.create('/networks', ''.encode('ascii')) transaction.create('/ceph', ''.encode('ascii')) + transaction.create('/ceph/osds', ''.encode('ascii')) + transaction.create('/ceph/pools', ''.encode('ascii')) transaction.commit() # Close the Zookeeper connection @@ -1032,9 +1077,28 @@ net_acl.add_command(net_acl_add) net_acl.add_command(net_acl_remove) net_acl.add_command(net_acl_list) +#ceph_osd.add_command(ceph_osd_add) +#ceph_osd.add_command(ceph_osd_remove) +#ceph_osd.add_command(ceph_osd_in) +#ceph_osd.add_command(ceph_osd_out) +#ceph_osd.add_command(ceph_osd_set) +#ceph_osd.add_command(ceph_osd_unset) +#ceph_osd.add_command(ceph_osd_info) +#ceph_osd.add_command(ceph_osd_list) + +#ceph_pool.add_command(ceph_pool_add) +#ceph_pool.add_command(ceph_pool_remove) +#ceph_pool.add_command(ceph_pool_info) +#ceph_pool.add_command(ceph_pool_list) + +cli_ceph.add_command(ceph_status) +cli_ceph.add_command(ceph_osd) +cli_ceph.add_command(ceph_pool) + cli.add_command(cli_node) cli.add_command(cli_vm) cli.add_command(cli_network) +cli.add_command(cli_ceph) cli.add_command(init_cluster) # diff --git a/client-common/ceph.py b/client-common/ceph.py new file mode 100644 index 00000000..9240c14f --- /dev/null +++ b/client-common/ceph.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +# ceph.py - PVC client function library, Ceph cluster fuctions +# Part of the Parallel Virtual Cluster (PVC) system +# +# Copyright (C) 2018 Joshua M. Boniface +# +# 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, either version 3 of the License, or +# (at your option) any later version. +# +# 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 . +# +############################################################################### + +import os +import socket +import time +import uuid +import re +import tempfile +import subprocess +import difflib +import colorama +import click +import lxml.objectify +import configparser +import kazoo.client + +import client_lib.ansiprint as ansiprint +import client_lib.zkhandler as zkhandler +import client_lib.common as common + +# +# Supplemental functions +# + + +# +# Direct functions +# +def get_status(zk_conn): + status_data = zkhandler.readdata(zk_conn, '/ceph').rstrip() + primary_node = zkhandler.readdata(zk_conn, '/primary_node') + click.echo('{bold}Ceph cluster status (primary node {end}{blue}{primary}{end}{bold}){end}\n'.format(bold=ansiprint.bold(), end=ansiprint.end(), blue=ansiprint.blue(), primary=primary_node)) + click.echo(status_data) + click.echo('') + return True, '' diff --git a/client-common/common.py b/client-common/common.py index dbf704d9..5e1e4f63 100644 --- a/client-common/common.py +++ b/client-common/common.py @@ -24,10 +24,6 @@ import uuid import lxml import math import kazoo.client -import paramiko -import hashlib -import dns.resolver -import dns.flags import client_lib.zkhandler as zkhandler @@ -305,6 +301,11 @@ def findTargetNodeVMs(zk_conn, dom_uuid): # Connect to the primary host and run a command def runRemoteCommand(node, command, become=False): + import paramiko + import hashlib + import dns.resolver + import dns.flags + # Support doing SSHFP checks class DnssecPolicy(paramiko.client.MissingHostKeyPolicy): def missing_host_key(self, client, hostname, key):