Complete conversion to API client

This commit is contained in:
Joshua Boniface 2019-12-29 20:33:51 -05:00
parent d2f27cc8fe
commit d2af6f4508
5 changed files with 799 additions and 2062 deletions

View File

@ -25,6 +25,7 @@ import click
import json
import time
import math
import requests
import cli_lib.ansiprint as ansiprint
@ -32,6 +33,18 @@ import cli_lib.ansiprint as ansiprint
# Supplemental functions
#
def get_request_uri(config, endpoint):
"""
Return the fully-formed URI for {endpoint}
"""
uri = '{}://{}{}{}'.format(
config['api_scheme'],
config['api_host'],
config['api_prefix'],
endpoint
)
return uri
# Format byte sizes to/from human-readable units
byte_unit_matrix = {
'B': 1,
@ -99,6 +112,52 @@ def format_pct_tohuman(datapct):
#
# Status functions
#
def ceph_status(config):
"""
Get status of the Ceph cluster
API endpoint: GET /api/v1/storage/ceph/status
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/storage/ceph/status')
response = requests.get(
request_uri
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_util(config):
"""
Get utilization of the Ceph cluster
API endpoint: GET /api/v1/storage/ceph/utilization
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/storage/ceph/utilization')
response = requests.get(
request_uri
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def format_raw_output(status_data):
click.echo('{bold}Ceph cluster {stype} (primary node {end}{blue}{primary}{end}{bold}){end}\n'.format(bold=ansiprint.bold(), end=ansiprint.end(), blue=ansiprint.blue(), stype=status_data['type'], primary=status_data['primary_node']))
click.echo(status_data['ceph_data'])
@ -107,6 +166,172 @@ def format_raw_output(status_data):
#
# OSD functions
#
def ceph_osd_info(config, osd):
"""
Get information about Ceph OSD
API endpoint: GET /api/v1/storage/ceph/osd/{osd}
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/storage/ceph/osd/{osd}'.format(osd=osd))
response = requests.get(
request_uri
)
if config['debug']:
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_osd_list(config, limit):
"""
Get list information about Ceph OSDs (limited by {limit})
API endpoint: GET /api/v1/storage/ceph/osd
API arguments: limit={limit}
API schema: [{json_data_object},{json_data_object},etc.]
"""
params = dict()
if limit:
params['limit'] = limit
request_uri = get_request_uri(config, '/storage/ceph/osd')
response = requests.get(
request_uri,
params=params
)
if config['debug']:
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_osd_add(config, node, device, weight):
"""
Add new Ceph OSD
API endpoint: POST /api/v1/storage/ceph/osd
API arguments: node={node}, device={device}, weight={weight}
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/osd')
response = requests.post(
request_uri,
params={
'node': node,
'device': device,
'weight': weight
}
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_osd_remove(config, osdid):
"""
Remove Ceph OSD
API endpoint: POST /api/v1/storage/ceph/osd/{osdid}
API arguments:
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/osd/{osdid}'.format(osdid=osdid))
response = requests.post(
request_uri,
params={
'yes-i-really-mean-it': 'yes'
}
)
if config['debug']:
print('API endpoint: DELETE {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_osd_state(config, osdid, state):
"""
Set state of Ceph OSD
API endpoint: POST /api/v1/storage/ceph/osd/{osdid}/state
API arguments: state={state}
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/osd/{osdid}/state'.format(osdid=osdid))
response = requests.post(
request_uri,
params={
'state': state
}
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_osd_option(config, option, action):
"""
Set cluster option of Ceph OSDs
API endpoint: POST /api/v1/storage/ceph/option
API arguments: option={option}, action={action}
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/option')
response = requests.post(
request_uri,
params={
'option': option,
'action': action
}
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def getOutputColoursOSD(osd_information):
# Set the UP status
if osd_information['stats']['up'] == 1:
@ -127,6 +352,13 @@ def getOutputColoursOSD(osd_information):
return osd_up_flag, osd_up_colour, osd_in_flag, osd_in_colour
def format_list_osd(osd_list):
# Handle empty list
if not osd_list:
osd_list = list()
# Handle single-item list
if isinstance(osd_list, dict):
osd_list = [ osd_list ]
osd_list_output = []
osd_id_length = 3
@ -363,7 +595,123 @@ Wr: {osd_wrops: <{osd_wrops_length}} \
#
# Pool functions
#
def ceph_pool_info(config, pool):
"""
Get information about Ceph OSD
API endpoint: GET /api/v1/storage/ceph/pool/{pool}
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/storage/ceph/pool/{pool}'.format(pool=pool))
response = requests.get(
request_uri
)
if config['debug']:
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_pool_list(config, limit):
"""
Get list information about Ceph OSDs (limited by {limit})
API endpoint: GET /api/v1/storage/ceph/pool
API arguments: limit={limit}
API schema: [{json_data_object},{json_data_object},etc.]
"""
params = dict()
if limit:
params['limit'] = limit
request_uri = get_request_uri(config, '/storage/ceph/pool')
response = requests.get(
request_uri,
params=params
)
if config['debug']:
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_pool_add(config, pool, pgs, replcfg):
"""
Add new Ceph OSD
API endpoint: POST /api/v1/storage/ceph/pool
API arguments: pool={pool}, pgs={pgs}, replcfg={replcfg}
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/pool')
response = requests.post(
request_uri,
params={
'pool': pool,
'pgs': pgs,
'replcfg': replcfg
}
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_pool_remove(config, pool):
"""
Remove Ceph OSD
API endpoint: POST /api/v1/storage/ceph/pool/{pool}
API arguments:
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/pool/{pool}'.format(pool=pool))
response = requests.post(
request_uri,
params={
'yes-i-really-mean-it': 'yes'
}
)
if config['debug']:
print('API endpoint: DELETE {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def format_list_pool(pool_list):
# Handle empty list
if not pool_list:
pool_list = list()
# Handle single-entry list
if isinstance(pool_list, dict):
pool_list = [ pool_list ]
pool_list_output = []
pool_name_length = 5
@ -554,11 +902,186 @@ Wr: {pool_write_ops: <{pool_write_ops_length}} \
click.echo('\n'.join(sorted(pool_list_output)))
#
# Volume functions
#
def ceph_volume_info(config, pool, volume):
"""
Get information about Ceph volume
API endpoint: GET /api/v1/storage/ceph/volume/{pool}/{volume}
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/storage/ceph/volume/{pool}/{volume}'.format(volume=volume, pool=pool))
response = requests.get(
request_uri
)
if config['debug']:
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_volume_list(config, limit, pool):
"""
Get list information about Ceph volumes (limited by {limit} and by {pool})
API endpoint: GET /api/v1/storage/ceph/volume
API arguments: limit={limit}, pool={pool}
API schema: [{json_data_object},{json_data_object},etc.]
"""
params = dict()
if limit:
params['limit'] = limit
if pool:
params['pool'] = pool
request_uri = get_request_uri(config, '/storage/ceph/volume')
response = requests.get(
request_uri,
params=params
)
if config['debug']:
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_volume_add(config, pool, volume, size):
"""
Add new Ceph volume
API endpoint: POST /api/v1/storage/ceph/volume
API arguments: volume={volume}, pool={pool}, size={size}
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/volume')
response = requests.post(
request_uri,
params={
'volume': volume,
'pool': pool,
'size': size
}
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_volume_remove(config, pool, volume):
"""
Remove Ceph volume
API endpoint: DELETE /api/v1/storage/ceph/volume/{pool}/{volume}
API arguments:
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/volume/{pool}/{volume}'.format(volume=volume, pool=pool))
response = requests.delete(
request_uri
)
if config['debug']:
print('API endpoint: DELETE {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_volume_modify(config, pool, volume, new_name=None, new_size=None):
"""
Modify Ceph volume
API endpoint: PUT /api/v1/storage/ceph/volume/{pool}/{volume}
API arguments:
API schema: {"message":"{data}"}
"""
params = dict()
if new_name:
params['new_name'] = new_name
if new_size:
params['new_size'] = new_size
request_uri = get_request_uri(config, '/storage/ceph/volume/{pool}/{volume}'.format(volume=volume, pool=pool))
response = requests.put(
request_uri,
params=params
)
if config['debug']:
print('API endpoint: PUT {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_volume_clone(config, pool, volume, new_volume):
"""
Clone Ceph volume
API endpoint: POST /api/v1/storage/ceph/volume/{pool}/{volume}
API arguments: new_volume={new_volume
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/volume/{pool}/{volume}/clone'.format(volume=volume, pool=pool))
response = requests.post(
request_uri,
params={
'new_volume': new_volume
}
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def format_list_volume(volume_list):
# Handle empty list
if not volume_list:
volume_list = list()
# Handle single-entry list
if isinstance(volume_list, dict):
volume_list = [ volume_list ]
volume_list_output = []
volume_name_length = 5
@ -669,7 +1192,155 @@ def format_list_volume(volume_list):
#
# Snapshot functions
#
def ceph_snapshot_info(config, pool, volume, snapshot):
"""
Get information about Ceph snapshot
API endpoint: GET /api/v1/storage/ceph/snapshot/{pool}/{volume}/{snapshot}
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/storage/ceph/snapshot/{pool}/{volume}/{snapshot}'.format(snapshot=snapshot, volume=volume, pool=pool))
response = requests.get(
request_uri
)
if config['debug']:
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_snapshot_list(config, limit, volume, pool):
"""
Get list information about Ceph snapshots (limited by {limit}, by {pool}, or by {volume})
API endpoint: GET /api/v1/storage/ceph/snapshot
API arguments: limit={limit}, volume={volume}, pool={pool}
API schema: [{json_data_object},{json_data_object},etc.]
"""
params = dict()
if limit:
params['limit'] = limit
if volume:
params['volume'] = volume
if pool:
params['pool'] = pool
request_uri = get_request_uri(config, '/storage/ceph/snapshot')
response = requests.get(
request_uri,
params=params
)
if config['debug']:
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def ceph_snapshot_add(config, pool, volume, snapshot):
"""
Add new Ceph snapshot
API endpoint: POST /api/v1/storage/ceph/snapshot
API arguments: snapshot={snapshot}, volume={volume}, pool={pool}
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/snapshot')
response = requests.post(
request_uri,
params={
'snapshot': snapshot,
'volume': volume,
'pool': pool
}
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_snapshot_remove(config, pool, volume, snapshot):
"""
Remove Ceph snapshot
API endpoint: DELETE /api/v1/storage/ceph/snapshot/{pool}/{volume}/{snapshot}
API arguments:
API schema: {"message":"{data}"}
"""
request_uri = get_request_uri(config, '/storage/ceph/snapshot/{pool}/{volume}/{snapshot}'.format(snapshot=snapshot, volume=volume, pool=pool))
response = requests.delete(
request_uri
)
if config['debug']:
print('API endpoint: DELETE {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def ceph_snapshot_modify(config, pool, volume, snapshot, new_name=None):
"""
Modify Ceph snapshot
API endpoint: PUT /api/v1/storage/ceph/snapshot/{pool}/{volume}/{snapshot}
API arguments:
API schema: {"message":"{data}"}
"""
params = dict()
if new_name:
params['new_name'] = new_name
request_uri = get_request_uri(config, '/storage/ceph/snapshot/{pool}/{volume}/{snapshot}'.format(snapshot=snapshot, volume=volume, pool=pool))
response = requests.put(
request_uri,
params=params
)
if config['debug']:
print('API endpoint: PUT {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def format_list_snapshot(snapshot_list):
# Handle empty list
if not snapshot_list:
snapshot_list = list()
# Handle single-entry list
if isinstance(snapshot_list, dict):
snapshot_list = [ snapshot_list ]
snapshot_list_output = []
snapshot_name_length = 5
@ -677,8 +1348,9 @@ def format_list_snapshot(snapshot_list):
snapshot_pool_length = 5
for snapshot in snapshot_list:
volume, snapshot_name = snapshot.split('@')
snapshot_pool, snapshot_volume = volume.split('/')
snapshot_name = snapshot['snapshot']
snapshot_volume = snapshot['volume']
snapshot_pool = snapshot['pool']
# Set the Snapshot name length
_snapshot_name_length = len(snapshot_name) + 1
@ -713,8 +1385,9 @@ def format_list_snapshot(snapshot_list):
)
for snapshot in snapshot_list:
volume, snapshot_name = snapshot.split('@')
snapshot_pool, snapshot_volume = volume.split('/')
snapshot_name = snapshot['snapshot']
snapshot_volume = snapshot['volume']
snapshot_pool = snapshot['pool']
snapshot_list_output.append('{bold}\
{snapshot_name: <{snapshot_name_length}} \
{snapshot_volume: <{snapshot_volume_length}} \

View File

@ -22,9 +22,70 @@
import click
import json
import requests
import cli_lib.ansiprint as ansiprint
def get_request_uri(config, endpoint):
"""
Return the fully-formed URI for {endpoint}
"""
uri = '{}://{}{}{}'.format(
config['api_scheme'],
config['api_host'],
config['api_prefix'],
endpoint
)
return uri
def initialize(config):
"""
Initialize the PVC cluster
API endpoint: GET /api/v1/initialize
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/initialize')
response = requests.get(
request_uri
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
retstatus = True
else:
retstatus = False
return retstatus, response.json()['message']
def get_info(config):
"""
Get status of the PVC cluster
API endpoint: GET /api/v1/status
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/status')
response = requests.get(
request_uri
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
if response.status_code == 200:
return True, response.json()
else:
return False, response.json()['message']
def format_info(cluster_information, oformat):
if oformat == 'json':
print(json.dumps(cluster_information))

View File

@ -82,7 +82,7 @@ def net_info(config, net):
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
@ -110,7 +110,7 @@ def net_list(config, limit):
)
if config['debug']:
print('API endpoint: POST {}'.format(request_uri))
print('API endpoint: GET {}'.format(request_uri))
print('Response code: {}'.format(response.status_code))
print('Response headers: {}'.format(response.headers))
@ -716,6 +716,9 @@ def format_list_dhcp(dhcp_lease_list):
click.echo('\n'.join(sorted(dhcp_lease_list_output)))
def format_list_acl(acl_list):
# Handle when we get an empty entry
if not acl_list:
acl_list = list()
# Handle when we get a single entry
if isinstance(acl_list, dict):
acl_list = [ acl_list ]

View File

@ -237,7 +237,7 @@ def vm_define(config, target_node, node_limit, node_selector, node_autostart):
config_data = config.read()
config.close()
retcode, retmsg = pvc_vm.define_vm(zk_conn, config_data, target_node, node_limit, node_selector, node_autostart)
retcode, retmsg = pvc_vm.define_vm(config, config_data, target_node, node_limit, node_selector, node_autostart)
cleanup(retcode, retmsg)
###############################################################################
@ -1099,28 +1099,26 @@ def ceph_status():
Show detailed status of the storage cluster.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retdata = pvc_ceph.get_status(zk_conn)
retcode, retdata = pvc_ceph.ceph_status(config)
if retcode:
pvc_ceph.format_raw_output(retdata)
retdata = ''
cleanup(retcode, retdata, zk_conn)
cleanup(retcode, retdata)
###############################################################################
# pvc storage ceph df
# pvc storage ceph util
###############################################################################
@click.command(name='df', short_help='Show storage cluster utilization.')
def ceph_radosdf():
@click.command(name='util', short_help='Show storage cluster utilization.')
def ceph_util():
"""
Show utilization of the storage cluster.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retdata = pvc_ceph.get_radosdf(zk_conn)
retcode, retdata = pvc_ceph.ceph_util(config)
if retcode:
pvc_ceph.format_raw_output(retdata)
retdata = ''
cleanup(retcode, retdata, zk_conn)
cleanup(retcode, retdata)
###############################################################################
# pvc storage ceph osd
@ -1163,9 +1161,8 @@ def ceph_osd_add(node, device, weight, yes):
if choice != 'y' and choice != 'Y':
exit(0)
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.add_osd(zk_conn, node, device, weight)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_osd_add(config, node, device, weight)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph osd remove
@ -1190,9 +1187,8 @@ def ceph_osd_remove(osdid, yes):
if choice != 'y' and choice != 'Y':
exit(0)
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.remove_osd(zk_conn, osdid)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_osd_remove(config, osdid)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph osd in
@ -1206,9 +1202,8 @@ def ceph_osd_in(osdid):
Set a Ceph OSD with ID OSDID online in the cluster.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.in_osd(zk_conn, osdid)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_osd_state(config, osdid, 'in')
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph osd out
@ -1222,9 +1217,8 @@ def ceph_osd_out(osdid):
Set a Ceph OSD with ID OSDID offline in the cluster.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.out_osd(zk_conn, osdid)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_osd_state(config, osdid, 'out')
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph osd set
@ -1242,9 +1236,8 @@ def ceph_osd_set(osd_property):
full|pause|noup|nodown|noout|noin|nobackfill|norebalance|norecover|noscrub|nodeep-scrub|notieragent|sortbitwise|recovery_deletes|require_jewel_osds|require_kraken_osds
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.set_osd(zk_conn, osd_property)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_osd_option(config, osd_property, 'set')
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph osd unset
@ -1262,9 +1255,8 @@ def ceph_osd_unset(osd_property):
full|pause|noup|nodown|noout|noin|nobackfill|norebalance|norecover|noscrub|nodeep-scrub|notieragent|sortbitwise|recovery_deletes|require_jewel_osds|require_kraken_osds
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.unset_osd(zk_conn, osd_property)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_osd_option(config, osd_property, 'unset')
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph osd list
@ -1278,12 +1270,11 @@ def ceph_osd_list(limit):
List all Ceph OSDs in the cluster; optionally only match elements matching ID regex LIMIT.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retdata = pvc_ceph.get_list_osd(zk_conn, limit)
retcode, retdata = pvc_ceph.ceph_osd_list(config, limit)
if retcode:
pvc_ceph.format_list_osd(retdata)
retdata = ''
cleanup(retcode, retdata, zk_conn)
cleanup(retcode, retdata)
###############################################################################
# pvc storage ceph pool
@ -1319,9 +1310,8 @@ def ceph_pool_add(name, pgs, replcfg):
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.add_pool(zk_conn, name, pgs, replcfg)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_pool_add(config, name, pgs, replcfg)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph pool remove
@ -1348,9 +1338,8 @@ def ceph_pool_remove(name, yes):
if pool_name_check != name:
exit(0)
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.remove_pool(zk_conn, name)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_pool_remove(config, name)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph pool list
@ -1364,12 +1353,11 @@ def ceph_pool_list(limit):
List all Ceph RBD pools in the cluster; optionally only match elements matching name regex LIMIT.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retdata = pvc_ceph.get_list_pool(zk_conn, limit)
retcode, retdata = pvc_ceph.ceph_pool_list(config, limit)
if retcode:
pvc_ceph.format_list_pool(retdata)
retdata = ''
cleanup(retcode, retdata, zk_conn)
cleanup(retcode, retdata)
###############################################################################
# pvc storage ceph volume
@ -1399,9 +1387,8 @@ def ceph_volume_add(pool, name, size):
Add a new Ceph RBD volume with name NAME and size SIZE [in human units, e.g. 1024M, 20G, etc.] to pool POOL.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.add_volume(zk_conn, pool, name, size)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_volume_add(config, pool, name, size)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph volume remove
@ -1429,9 +1416,8 @@ def ceph_volume_remove(pool, name, yes):
if choice != 'y' and choice != 'Y':
exit(0)
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.remove_volume(zk_conn, pool, name)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_volume_remove(config, pool, name)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph volume resize
@ -1450,9 +1436,8 @@ def ceph_volume_resize(pool, name, size):
"""
Resize an existing Ceph RBD volume with name NAME in pool POOL to size SIZE [in human units, e.g. 1024M, 20G, etc.].
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.resize_volume(zk_conn, pool, name, size)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_volume_modify(config, pool, name, new_size=size)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph volume rename
@ -1471,14 +1456,13 @@ def ceph_volume_rename(pool, name, new_name):
"""
Rename an existing Ceph RBD volume with name NAME in pool POOL to name NEW_NAME.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.rename_volume(zk_conn, pool, name, new_name)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_volume_modify(config, pool, name, new_name=new_name)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph volume clone
###############################################################################
@click.command(name='rename', short_help='Clone RBD volume.')
@click.command(name='clone', short_help='Clone RBD volume.')
@click.argument(
'pool'
)
@ -1492,9 +1476,8 @@ def ceph_volume_clone(pool, name, new_name):
"""
Clone a Ceph RBD volume with name NAME in pool POOL to name NEW_NAME in pool POOL.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.clone_volume(zk_conn, pool, name, new_name)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_volume_clone(config, pool, name, new_name)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph volume list
@ -1513,12 +1496,11 @@ def ceph_volume_list(limit, pool):
List all Ceph RBD volumes in the cluster; optionally only match elements matching name regex LIMIT.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retdata = pvc_ceph.get_list_volume(zk_conn, pool, limit)
retcode, retdata = pvc_ceph.ceph_volume_list(config, limit, pool)
if retcode:
pvc_ceph.format_list_volume(retdata)
retdata = ''
cleanup(retcode, retdata, zk_conn)
cleanup(retcode, retdata)
###############################################################################
# pvc storage ceph volume snapshot
@ -1548,9 +1530,8 @@ def ceph_volume_snapshot_add(pool, volume, name):
Add a snapshot with name NAME of Ceph RBD volume VOLUME in pool POOL.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.add_snapshot(zk_conn, pool, volume, name)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_snapshot_add(config, pool, volume, name)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph volume snapshot rename
@ -1572,9 +1553,8 @@ def ceph_volume_snapshot_rename(pool, volume, name, new_name):
"""
Rename an existing Ceph RBD volume snapshot with name NAME to name NEW_NAME for volume VOLUME in pool POOL.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.rename_snapshot(zk_conn, pool, volume, name, new_name)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_snapshot_modify(config, pool, volume, name, new_name=new_name)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph volume snapshot remove
@ -1605,9 +1585,8 @@ def ceph_volume_snapshot_remove(pool, volume, name, yes):
if choice != 'y' and choice != 'Y':
exit(0)
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.remove_snapshot(zk_conn, pool, volume, name)
cleanup(retcode, retmsg, zk_conn)
retcode, retmsg = pvc_ceph.ceph_snapshot_remove(config, pool, volume, name)
cleanup(retcode, retmsg)
###############################################################################
# pvc storage ceph volume snapshot list
@ -1631,12 +1610,11 @@ def ceph_volume_snapshot_list(pool, volume, limit):
List all Ceph RBD volume snapshots; optionally only match elements matching name regex LIMIT.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retdata = pvc_ceph.get_list_snapshot(zk_conn, pool, volume, limit)
retcode, retdata = pvc_ceph.ceph_snapshot_list(config, limit, volume, pool)
if retcode:
pvc_ceph.format_list_snapshot(retdata)
retdata = ''
cleanup(retcode, retdata, zk_conn)
cleanup(retcode, retdata)
###############################################################################
@ -1652,12 +1630,11 @@ def status_cluster(oformat):
"""
Show basic information and health for the active PVC cluster.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retdata = pvc_cluster.get_info(zk_conn)
retcode, retdata = pvc_cluster.get_info(config)
if retcode:
pvc_cluster.format_info(retdata, oformat)
retdata = ''
cleanup(retcode, retdata, zk_conn)
cleanup(retcode, retdata)
###############################################################################
# pvc init
@ -1684,40 +1661,8 @@ def init_cluster(yes):
# Easter-egg
click.echo("Some music while we're Layin' Pipe? https://youtu.be/sw8S_Kv89IU")
# Open a Zookeeper connection
zk_conn = pvc_common.startZKConnection(zk_host)
# Destroy the existing data
try:
zk_conn.delete('/networks', recursive=True)
zk_conn.delete('/domains', recursive=True)
zk_conn.delete('/nodes', recursive=True)
zk_conn.delete('/primary_node', recursive=True)
zk_conn.delete('/ceph', recursive=True)
except:
pass
# Create the root keys
transaction = zk_conn.transaction()
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.create('/ceph/volumes', ''.encode('ascii'))
transaction.create('/ceph/snapshots', ''.encode('ascii'))
transaction.create('/cmd', ''.encode('ascii'))
transaction.create('/cmd/domains', ''.encode('ascii'))
transaction.create('/cmd/ceph', ''.encode('ascii'))
transaction.commit()
# Close the Zookeeper connection
pvc_common.stopZKConnection(zk_conn)
click.echo('Successfully initialized new cluster. Any running PVC daemons will need to be restarted.')
retcode, retmsg = pvc_cluster.initialize()
cleanup(retcode, retmsg)
###############################################################################
# pvc
@ -1823,6 +1768,7 @@ ceph_pool.add_command(ceph_pool_list)
ceph_volume.add_command(ceph_volume_add)
ceph_volume.add_command(ceph_volume_resize)
ceph_volume.add_command(ceph_volume_rename)
ceph_volume.add_command(ceph_volume_clone)
ceph_volume.add_command(ceph_volume_remove)
ceph_volume.add_command(ceph_volume_list)
ceph_volume.add_command(ceph_volume_snapshot)
@ -1833,7 +1779,7 @@ ceph_volume_snapshot.add_command(ceph_volume_snapshot_remove)
ceph_volume_snapshot.add_command(ceph_volume_snapshot_list)
cli_ceph.add_command(ceph_status)
cli_ceph.add_command(ceph_radosdf)
cli_ceph.add_command(ceph_util)
cli_ceph.add_command(ceph_osd)
cli_ceph.add_command(ceph_pool)
cli_ceph.add_command(ceph_volume)

File diff suppressed because it is too large Load Diff