1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +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): def Version(self):
return dbus.String('1.0.0') 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 @staticmethod
def _pv_create(device, create_options): def _pv_create(device, create_options):
@ -41,15 +51,8 @@ class Manager(AutomatedProperties):
MANAGER_INTERFACE, "PV Already exists!") MANAGER_INTERFACE, "PV Already exists!")
rc, out, err = cmdhandler.pv_create(create_options, [device]) rc, out, err = cmdhandler.pv_create(create_options, [device])
if rc == 0: Manager.handle_execute(rc, out, err)
cfg.load() return cfg.om.get_object_path_by_lvm_id(device)
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
@dbus.service.method( @dbus.service.method(
dbus_interface=MANAGER_INTERFACE, dbus_interface=MANAGER_INTERFACE,
@ -76,14 +79,8 @@ class Manager(AutomatedProperties):
MANAGER_INTERFACE, 'object path = %s not found' % p) MANAGER_INTERFACE, 'object path = %s not found' % p)
rc, out, err = cmdhandler.vg_create(create_options, pv_devices, name) rc, out, err = cmdhandler.vg_create(create_options, pv_devices, name)
Manager.handle_execute(rc, out, err)
if rc == 0:
cfg.load()
return cfg.om.get_object_path_by_lvm_id(name) 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))
@dbus.service.method( @dbus.service.method(
dbus_interface=MANAGER_INTERFACE, dbus_interface=MANAGER_INTERFACE,
@ -200,15 +197,8 @@ class Manager(AutomatedProperties):
activate, cache, device_path, activate, cache, device_path,
major_minor, scan_options) major_minor, scan_options)
if rc == 0: Manager.handle_execute(rc, out, err)
# This could potentially change the state quite a bit, so lets
# update everything to be safe
cfg.load()
return '/' return '/'
else:
raise dbus.exceptions.DBusException(
MANAGER_INTERFACE,
'Exit code %s, stderr = %s' % (str(rc), err))
@dbus.service.method( @dbus.service.method(
dbus_interface=MANAGER_INTERFACE, dbus_interface=MANAGER_INTERFACE,