Here are the examples of the python api system.osi.uptime taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
3
Example 1
Project: rockstor-core Source File: data_collector.py
def send_uptime(self):
# Seems redundant
while self.start:
self.emit('sysinfo:uptime', {
'data': uptime(), 'key': 'sysinfo:uptime'
})
gevent.sleep(60)
0
Example 2
Project: rockstor-core Source File: command.py
@transaction.atomic
def post(self, request, command):
if (command == 'bootstrap'):
self._refresh_pool_state()
for p in Pool.objects.all():
import_shares(p, request)
for share in Share.objects.all():
try:
if (share.pqgroup == settings.MODEL_DEFS['pqgroup']):
share.pqgroup = qgroup_create(share.pool)
share.save()
if (not is_share_mounted(share.name)):
mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
mount_share(share, mnt_pt)
except Exception, e:
e_msg = ('Exception while mounting a share(%s) during '
'bootstrap: %s' % (share.name, e.__str__()))
logger.error(e_msg)
logger.exception(e)
try:
import_snapshots(share)
except Exception, e:
e_msg = ('Exception while importing Snapshots of '
'Share(%s): %s' % (share.name, e.__str__()))
logger.error(e_msg)
logger.exception(e)
for snap in Snapshot.objects.all():
if (snap.uvisible):
try:
mount_snap(snap.share, snap.real_name)
except Exception, e:
e_msg = ('Failed to make the Snapshot(%s) visible. '
'Exception: %s' % (snap.real_name, e.__str__()))
logger.error(e_msg)
mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT)
for sftpo in SFTP.objects.all():
try:
sftp_mount(sftpo.share, settings.MNT_PT,
settings.SFTP_MNT_ROOT, mnt_map, sftpo.editable)
sftp_snap_toggle(sftpo.share)
except Exception, e:
e_msg = ('Exception while exportin a sftp share during '
'bootstrap: %s' % e.__str__())
logger.error(e_msg)
try:
adv_entries = [a.export_str for a in AdvancedNFSExport.objects.all()]
exports_d = self.create_adv_nfs_export_input(adv_entries, request)
exports = self.create_nfs_export_input(NFSExport.objects.all())
exports.update(exports_d)
self.refresh_wrapper(exports, request, logger)
except Exception, e:
e_msg = ('Exception while bootstrapping NFS: %s' % e.__str__())
logger.error(e_msg)
# bootstrap services
try:
systemctl('firewalld', 'stop')
systemctl('firewalld', 'disable')
systemctl('nginx', 'stop')
systemctl('nginx', 'disable')
systemctl('atd', 'enable')
systemctl('atd', 'start')
except Exception, e:
e_msg = ('Exception while setting service statuses during '
'bootstrap: %s' % e.__str__())
logger.error(e_msg)
handle_exception(Exception(e_msg), request)
logger.debug('Bootstrap operations completed')
return Response()
if (command == 'utcnow'):
return Response(datetime.utcnow().replace(tzinfo=utc))
if (command == 'uptime'):
return Response(uptime())
if (command == 'kernel'):
try:
return Response(kernel_info(settings.SUPPORTED_KERNEL_VERSION))
except Exception, e:
handle_exception(e, request)
if (command == 'update-check'):
try:
subo = None
try:
subo = UpdateSubscription.objects.get(name='Stable', status='active')
except UpdateSubscription.DoesNotExist:
try:
subo = UpdateSubscription.objects.get(name='Testing', status='active')
except UpdateSubscription.DoesNotExist:
pass
return Response(update_check(subscription=subo))
except Exception, e:
e_msg = ('Unable to check update due to a system error: %s' % e.__str__())
handle_exception(Exception(e_msg), request)
if (command == 'update'):
try:
update_run()
return Response('Done')
except Exception, e:
e_msg = ('Update failed due to this exception: %s' % e.__str__())
handle_exception(Exception(e_msg), request)
if (command == 'current-version'):
try:
return Response(current_version())
except Exception, e:
e_msg = ('Unable to check current version due to this '
'exception: ' % e.__str__())
handle_exception(Exception(e_msg), request)
if (command == 'shutdown'):
msg = ('The system will now be shutdown')
try:
request.session.flush()
system_shutdown()
except Exception, e:
msg = ('Failed to shutdown the system due to a low level '
'error: %s' % e.__str__())
handle_exception(Exception(msg), request)
finally:
return Response(msg)
if (command == 'reboot'):
msg = ('The system will now reboot')
try:
request.session.flush()
system_reboot()
except Exception, e:
msg = ('Failed to reboot the system due to a low level error: '
'%s' % e.__str__())
handle_exception(Exception(msg), request)
finally:
return Response(msg)
if (command == 'current-user'):
return Response(request.user.username)
if (command == 'auto-update-status'):
status = True
try:
status = auto_update_status()
except:
status = False
finally:
return Response({'enabled': status, })
if (command == 'enable-auto-update'):
try:
auto_update(enable=True)
return Response({'enabled': True, })
except Exception, e:
msg = ('Failed to enable auto update due to this exception: '
'%s' % e.__str__())
handle_exception(Exception(msg), request)
if (command == 'disable-auto-update'):
try:
auto_update(enable=False)
return Response({'enabled': False, })
except Exception, e:
msg = ('Failed to disable auto update due to this exception: '
'%s' % e.__str__())
handle_exception(Exception(msg), request)
if (command == 'refresh-pool-state'):
self._refresh_pool_state()
return Response()
if (command == 'refresh-share-state'):
for p in Pool.objects.all():
import_shares(p, request)
return Response()
if (command == 'refresh-snapshot-state'):
for share in Share.objects.all():
import_snapshots(share)
return Response()