Skip to content

Instantly share code, notes, and snippets.

@RyanKor
Created November 6, 2021 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanKor/ef57f3a2837dec69410c8686180d7ff1 to your computer and use it in GitHub Desktop.
Save RyanKor/ef57f3a2837dec69410c8686180d7ff1 to your computer and use it in GitHub Desktop.
uptime
class UpTimeHypervisor(command.ShowOne):
_description = _("Display the uptime of the specified hypervisor.")
def get_parser(self, prog_name):
parser = super(UpTimeHypervisor, self).get_parser(prog_name)
parser.add_argument(
"hypervisor",
metavar="<hypervisor>",
help=_("Hypervisor to display (name or ID)")
)
return parser
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
hypervisor = utils.find_resource(compute_client.hypervisors,
parsed_args.hypervisor)._info.copy()
opts = {}
uptime = compute_client.hypervisors.uptime(hypervisor['id'])._info
# Extract data from uptime value
# format: 0 up 0, 0 users, load average: 0, 0, 0
# example: 17:37:14 up 2:33, 3 users,
# load average: 0.33, 0.36, 0.34
for key, value in uptime.items():
opts[key] = value
columns = tuple(sorted(opts))
data = utils.get_dict_properties(
opts, columns)
return (columns, data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment