Exemple #1
0
    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)
Exemple #2
0
 def destroy(cls, name):
     cls._check_permission(name)
     node = db.get(cls._resource_name(), name)
     drivers.get(node).destroy()
Exemple #3
0
 def shutdown(cls, name):
     cls._check_permission(name)
     node = db.get(cls._resource_name(), name)
     drivers.get(node).shutdown()
Exemple #4
0
 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)
Exemple #5
0
 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