def get_magma_services_status(): """ Get health for all the running services """ # DBus Unit objects: https://www.freedesktop.org/wiki/Software/systemd/dbus/ chan = ServiceRegistry.get_rpc_channel('magmad', ServiceRegistry.LOCAL) client = MagmadStub(chan) configs = client.GetConfigs(common_pb2.Void()) services_health_summary = [] for service_name in configs.configs_by_key: unit = Unit('magma@{}.service'.format(service_name), _autoload=True) active_state = ActiveState.dbus2state[unit.Unit.ActiveState] sub_state = str(unit.Unit.SubState, 'utf-8') if active_state == ActiveState.ACTIVE: pid = unit.Service.MainPID process = subprocess.Popen( 'ps -o etime= -p {}'.format(pid).split(), stdout=subprocess.PIPE) time_running, error = process.communicate() else: time_running = b'00' services_health_summary.append( ServiceHealth(service_name=service_name, active_state=active_state, sub_state=sub_state, time_running=str(time_running, 'utf-8').strip())) return services_health_summary
def check_stateless(client, args): response = client.CheckStateless(common_pb2.Void()) print( "AGW Mode:", magmad_pb2.CheckStatelessResponse.AGWMode.Name(response.agw_mode), )
def get_gateway_id(client, args): response = client.GetGatewayId(common_pb2.Void()) print(response)
def reboot(client, args): client.Reboot(common_pb2.Void())
def stop_services(client, args): client.StopServices(common_pb2.Void())
def start_services(client, args): client.StartServices(common_pb2.Void())
def wrapper(*args, **kwargs): func(*args, **kwargs) return common_pb2.Void()
def end_call_trace(client, args): res = client.EndCallTrace(common_pb2.Void()) print("Result of call trace: ", res)