ceph / ceph-upgrade

Upgrade Ceph components like ceph-disk OSDs to ceph-volume
1 stars 1 forks source link

get running ceph-osd units #1

Open alfredodeza opened 5 years ago

alfredodeza commented 5 years ago

Must parse output from:

# systemctl list-units --state=running --type=service
UNIT                      LOAD   ACTIVE SUB     DESCRIPTION
accounts-daemon.service   loaded active running Accounts Service
acpid.service             loaded active running ACPI event daemon
atd.service               loaded active running Deferred execution scheduler
ceph-osd@17.service       loaded active running Ceph object storage daemon osd.17
cron.service              loaded active running Regular background program processing daemon
dbus.service              loaded active running D-Bus System Message Bus
getty@tty1.service        loaded active running Getty on tty1
iscsid.service            loaded active running iSCSI initiator daemon (iscsid)
lvm2-lvmetad.service      loaded active running LVM2 metadata daemon
lxcfs.service             loaded active running FUSE filesystem for LXC
mdadm.service             loaded active running LSB: MD monitoring daemon
polkitd.service           loaded active running Authenticate and Authorize Users to Run Privileged Tasks
rsyslog.service           loaded active running System Logging Service
ssh.service               loaded active running OpenBSD Secure Shell server
systemd-journald.service  loaded active running Journal Service
systemd-logind.service    loaded active running Login Service
systemd-timesyncd.service loaded active running Network Time Synchronization
systemd-udevd.service     loaded active running udev Kernel Device Manager
user@1000.service         loaded active running User Manager for UID 1000

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

19 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
ktdreyer commented 5 years ago

Dunno whether you want to go down this route, but we can get the information from dbus

import dbus
sysbus = dbus.SystemBus()
systemd1 = sysbus.get_object('org.freedesktop.systemd1',
                             '/org/freedesktop/systemd1')

manager = dbus.Interface(systemd1, 'org.freedesktop.systemd1.Manager')

jobs = manager.ListUnits()

running = [job for job in jobs if str(job[4]) == 'running']

running_services = [job for job in running if str(job[0]).endswith('.service')]

for job in running_services:
    print(job)  # dbus.Struct
alfredodeza commented 5 years ago

@ktdreyer is this dbus a package?

The thing here is we just want to see what IDs are running, so we aren't really like "parsing" but more like checking if ceph-osd is in a line and then getting the ID

ktdreyer commented 5 years ago

Right, it's the "python3-dbus" package on Fedora, https://dbus.freedesktop.org/doc/dbus-python/tutorial.html