def status(cls, name=None): fields = ['name', 'power', 'image', 'user', 'description'] if name: nodes = [db.get(cls._resource_name(), name)] else: nodes = db.list(cls._resource_name()) nodes.sort(key=lambda node: node['name']) for node in nodes: try: node['power'] = drivers.get(node).status() except exceptions.DriverFailed: node['power'] = '(unkown)' utils.print_table(fields, nodes)
def destroy(cls, name): cls._check_permission(name) node = db.get(cls._resource_name(), name) drivers.get(node).destroy()
def shutdown(cls, name): cls._check_permission(name) node = db.get(cls._resource_name(), name) drivers.get(node).shutdown()
def acquire(cls, name): user = utils.get_username() node = db.get(cls._resource_name(), name) if node['user']: raise Exception("Node %s is occupied." % name) db.update(cls._resource_name(), name, user=user)
def _check_permission(cls, name): user = utils.get_username() node = db.get(cls._resource_name(), name) if user not in (node['user'], 'root'): raise Exception("You don't have permission.") return node