Merge pull request #1033 from jfckm/remove-packaging-package
Remove dependency on packaging Python package
This commit is contained in:
commit
ab96a7d736
@ -1,2 +1 @@
|
|||||||
packaging>=20.3
|
|
||||||
PyYAML>=6.0
|
PyYAML>=6.0
|
||||||
|
93
utils/casctl
93
utils/casctl
@ -4,16 +4,19 @@
|
|||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
from packaging import version
|
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
min_ver = version.parse("3.6")
|
min_ver = "3.6"
|
||||||
ver = version.parse(platform.python_version())
|
ver = platform.python_version()
|
||||||
if ver < min_ver:
|
if ver < min_ver:
|
||||||
print((f"Minimum required python version is {min_ver}\n"
|
print(
|
||||||
f"Detected python version is {ver}"),
|
"Minimum required python version is {}. Detected python version is {}".format(
|
||||||
file = sys.stderr)
|
min_ver,
|
||||||
|
ver,
|
||||||
|
),
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
@ -21,85 +24,114 @@ import re
|
|||||||
|
|
||||||
import opencas
|
import opencas
|
||||||
|
|
||||||
|
|
||||||
def eprint(*args, **kwargs):
|
def eprint(*args, **kwargs):
|
||||||
print(*args, file=sys.stderr, **kwargs)
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
# Start - load all the caches and add cores
|
# Start - load all the caches and add cores
|
||||||
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
try:
|
try:
|
||||||
config = opencas.cas_config.from_file('/etc/opencas/opencas.conf',
|
config = opencas.cas_config.from_file(
|
||||||
allow_incomplete=True)
|
"/etc/opencas/opencas.conf", allow_incomplete=True
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
eprint(e)
|
eprint(e)
|
||||||
eprint('Unable to parse config file.')
|
eprint("Unable to parse config file.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
for cache in config.caches.values():
|
for cache in config.caches.values():
|
||||||
try:
|
try:
|
||||||
opencas.start_cache(cache, True)
|
opencas.start_cache(cache, True)
|
||||||
except opencas.casadm.CasadmError as e:
|
except opencas.casadm.CasadmError as e:
|
||||||
eprint('Unable to load cache {0} ({1}). Reason:\n{2}'
|
eprint(
|
||||||
.format(cache.cache_id, cache.device, e.result.stderr))
|
"Unable to load cache {0} ({1}). Reason:\n{2}".format(
|
||||||
|
cache.cache_id, cache.device, e.result.stderr
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Initial cache start
|
# Initial cache start
|
||||||
|
|
||||||
|
|
||||||
def add_core_recursive(core, config):
|
def add_core_recursive(core, config):
|
||||||
with_error = False
|
with_error = False
|
||||||
if core.added:
|
if core.added:
|
||||||
return with_error
|
return with_error
|
||||||
if core.marked:
|
if core.marked:
|
||||||
eprint('Unable to add core {0} to cache {1}. Reason:\nRecursive core configuration!'
|
eprint(
|
||||||
.format(core.device, core.cache_id))
|
"Unable to add core {0} to cache {1}. Reason:\nRecursive core configuration!".format(
|
||||||
|
core.device, core.cache_id
|
||||||
|
)
|
||||||
|
)
|
||||||
exit(3)
|
exit(3)
|
||||||
core.marked = True
|
core.marked = True
|
||||||
match = re.match(r'/dev/cas(\d{1,5})-(\d{1,4})', core.device)
|
match = re.match(r"/dev/cas(\d{1,5})-(\d{1,4})", core.device)
|
||||||
if match:
|
if match:
|
||||||
cache_id,core_id = match.groups()
|
cache_id, core_id = match.groups()
|
||||||
with_error = add_core_recursive(config.caches[int(cache_id)].cores[int(core_id)], config)
|
with_error = add_core_recursive(
|
||||||
|
config.caches[int(cache_id)].cores[int(core_id)], config
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
opencas.add_core(core, False)
|
opencas.add_core(core, False)
|
||||||
core.added = True
|
core.added = True
|
||||||
except opencas.casadm.CasadmError as e:
|
except opencas.casadm.CasadmError as e:
|
||||||
eprint('Unable to add core {0} to cache {1}. Reason:\n{2}'
|
eprint(
|
||||||
.format(core.device, core.cache_id, e.result.stderr))
|
"Unable to add core {0} to cache {1}. Reason:\n{2}".format(
|
||||||
|
core.device, core.cache_id, e.result.stderr
|
||||||
|
)
|
||||||
|
)
|
||||||
with_error = True
|
with_error = True
|
||||||
return with_error
|
return with_error
|
||||||
|
|
||||||
|
|
||||||
def init(force):
|
def init(force):
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
try:
|
try:
|
||||||
config = opencas.cas_config.from_file('/etc/opencas/opencas.conf')
|
config = opencas.cas_config.from_file("/etc/opencas/opencas.conf")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
eprint(e)
|
eprint(e)
|
||||||
eprint('Unable to parse config file.')
|
eprint("Unable to parse config file.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if not force:
|
if not force:
|
||||||
for cache in config.caches.values():
|
for cache in config.caches.values():
|
||||||
try:
|
try:
|
||||||
status = opencas.check_cache_device(cache.device)
|
status = opencas.check_cache_device(cache.device)
|
||||||
if status['Is cache'] == 'yes' and status['Cache dirty'] == 'yes':
|
if status["Is cache"] == "yes" and status["Cache dirty"] == "yes":
|
||||||
eprint('Unable to perform initial configuration.\n' \
|
eprint(
|
||||||
'One of cache devices contains dirty data.')
|
"Unable to perform initial configuration.\n"
|
||||||
|
"One of cache devices contains dirty data."
|
||||||
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
except opencas.casadm.CasadmError as e:
|
except opencas.casadm.CasadmError as e:
|
||||||
eprint('Unable to check status of device {0}. Reason:\n{1}'
|
eprint(
|
||||||
.format(cache.device, e.result.stderr))
|
"Unable to check status of device {0}. Reason:\n{1}".format(
|
||||||
|
cache.device, e.result.stderr
|
||||||
|
)
|
||||||
|
)
|
||||||
exit(e.result.exit_code)
|
exit(e.result.exit_code)
|
||||||
|
|
||||||
for cache in config.caches.values():
|
for cache in config.caches.values():
|
||||||
try:
|
try:
|
||||||
opencas.start_cache(cache, False, force)
|
opencas.start_cache(cache, False, force)
|
||||||
except opencas.casadm.CasadmError as e:
|
except opencas.casadm.CasadmError as e:
|
||||||
eprint('Unable to start cache {0} ({1}). Reason:\n{2}'
|
eprint(
|
||||||
.format(cache.cache_id, cache.device, e.result.stderr))
|
"Unable to start cache {0} ({1}). Reason:\n{2}".format(
|
||||||
|
cache.cache_id, cache.device, e.result.stderr
|
||||||
|
)
|
||||||
|
)
|
||||||
exit_code = 2
|
exit_code = 2
|
||||||
try:
|
try:
|
||||||
opencas.configure_cache(cache)
|
opencas.configure_cache(cache)
|
||||||
except opencas.casadm.CasadmError as e:
|
except opencas.casadm.CasadmError as e:
|
||||||
eprint('Unable to configure cache {0} ({1}). Reason:\n{2}'
|
eprint(
|
||||||
.format(cache.cache_id, cache.device, e.result.stderr))
|
"Unable to configure cache {0} ({1}). Reason:\n{2}".format(
|
||||||
|
cache.cache_id, cache.device, e.result.stderr
|
||||||
|
)
|
||||||
|
)
|
||||||
exit_code = 2
|
exit_code = 2
|
||||||
|
|
||||||
for core in config.cores:
|
for core in config.cores:
|
||||||
@ -204,6 +236,7 @@ class cas:
|
|||||||
def command_stop(self, args):
|
def command_stop(self, args):
|
||||||
stop(args.flush)
|
stop(args.flush)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
opencas.wait_for_cas_ctrl()
|
opencas.wait_for_cas_ctrl()
|
||||||
cas()
|
cas()
|
||||||
|
Loading…
Reference in New Issue
Block a user