1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lvmdbusd: manager.py, remove duplicate code

Move similar code to common functions, less is more!
This commit is contained in:
Tony Asleson 2017-02-01 18:57:01 -06:00
parent 945842fa68
commit 3eccbb4b47

View File

@ -30,6 +30,16 @@ class Manager(AutomatedProperties):
def Version(self):
return dbus.String('1.0.0')
@staticmethod
def handle_execute(rc, out, err):
if rc == 0:
cfg.load()
else:
# Need to work on error handling, need consistent
raise dbus.exceptions.DBusException(
MANAGER_INTERFACE,
'Exit code %s, stderr = %s' % (str(rc), err))
@staticmethod
def _pv_create(device, create_options):
@ -41,15 +51,8 @@ class Manager(AutomatedProperties):
MANAGER_INTERFACE, "PV Already exists!")
rc, out, err = cmdhandler.pv_create(create_options, [device])
if rc == 0:
cfg.load()
created_pv = cfg.om.get_object_path_by_lvm_id(device)
else:
raise dbus.exceptions.DBusException(
MANAGER_INTERFACE,
'Exit code %s, stderr = %s' % (str(rc), err))
return created_pv
Manager.handle_execute(rc, out, err)
return cfg.om.get_object_path_by_lvm_id(device)
@dbus.service.method(
dbus_interface=MANAGER_INTERFACE,
@ -76,14 +79,8 @@ class Manager(AutomatedProperties):
MANAGER_INTERFACE, 'object path = %s not found' % p)
rc, out, err = cmdhandler.vg_create(create_options, pv_devices, name)
if rc == 0:
cfg.load()
return cfg.om.get_object_path_by_lvm_id(name)
else:
raise dbus.exceptions.DBusException(
MANAGER_INTERFACE,
'Exit code %s, stderr = %s' % (str(rc), err))
Manager.handle_execute(rc, out, err)
return cfg.om.get_object_path_by_lvm_id(name)
@dbus.service.method(
dbus_interface=MANAGER_INTERFACE,
@ -200,15 +197,8 @@ class Manager(AutomatedProperties):
activate, cache, device_path,
major_minor, scan_options)
if rc == 0:
# This could potentially change the state quite a bit, so lets
# update everything to be safe
cfg.load()
return '/'
else:
raise dbus.exceptions.DBusException(
MANAGER_INTERFACE,
'Exit code %s, stderr = %s' % (str(rc), err))
Manager.handle_execute(rc, out, err)
return '/'
@dbus.service.method(
dbus_interface=MANAGER_INTERFACE,