예제 #1
0
파일: views.py 프로젝트: ehelms/Opus
 def newf(request, *args, **kwargs):
     try:
         return f(request, *args, **kwargs)
     except (ValidationError, DeploymentException), e:
         log.warning("Caught an error while running view %s, rendering error.html. %s", f.__name__, e)
         return render("error.html",
                 {'message': e},
                 request)
예제 #2
0
 def logout_idle_users(self):
     """Logs off idle users for all nodes in this cluster."""
     for node in self.active:
         try:
             osutil_node = osutils.get_os_object(node.ip, settings.MEDIA_ROOT + str(self.app.ssh_key))
             osutil_node.user_cleanup(10)
         except HostNotConnectableError:
             # Ignore this host that doesn't seem to be ssh'able, but log it as an error
             log.warning('Node %s is NOT sshable and should be looked into')
예제 #3
0
    def get_stats(self):
        """
        Count number of sessions on all nodes. Get available headroom for cluster.
        Return two as a tuple (number_of_users, available_headroom)
        """
        number_of_users = 0
        for node in self.active:
            try:
                osutil_node = osutils.get_os_object(node.ip, settings.MEDIA_ROOT + str(self.app.ssh_key))
                number_of_users += len(osutil_node.sessions)
            except HostNotConnectableError:
                # Ignore this host that doesn't seem to be ssh'able, but log it as an error
                log.warning('Node %s is NOT sshable and should be looked into')

        return (number_of_users, self.avail_headroom)
예제 #4
0
 def _map_app_cluster_inuse(self, app_pk):
     """
     Returns a list of tuples, sorted by 'priority' from lowest to highest: [ (ip,numInUse), (ip,numInUse), .... ]
     Index 0 of the returned list has the priority closest to 0.  Here a low number indicates high priority.
     numInUse are the number of clients currently using a given host
     This function only considers instances in state '2'
     """
     app_map = []
     nodes = self.active.order_by('priority')
     for host in nodes:
         try:
             osutil_node = osutils.get_os_object(host.ip, settings.MEDIA_ROOT + str(self.app.ssh_key))
             cur_users = len(osutil_node.sessions)
             app_map.append((host, cur_users))
         except HostNotConnectableError:
             # Ignore this host that doesn't seem to be ssh'able, but log it as an error
             log.warning('Node %s is NOT sshable and should be looked into')
     return app_map
예제 #5
0
def terminate_instances(instances):
    """Turns off the list of instances given.

    instances should be an iterable of vdi.models.Instance objects, for
    example, a django queryset.  The number of instances that were successfully
    terminated is returned.

    """
    num = 0
    for instance in instances:
        prov_instance = driver.instance(instance.instanceId)
        if prov_instance.stop():
            dbitem = Instance.objects.filter(instanceId=instance.instanceId)[0]
            log.debug('The node has been deleted.  I will now move %s into a deleted state' % dbitem.instanceId)
            dbitem.state = 5
            dbitem.save()
            num += 1
        else:
            log.warning('Could not shut down instance "%s"' % instance.instanceId)
    return num
예제 #6
0
파일: ssh_tools.py 프로젝트: bmbouter/Opus
    def ssh_run_command(self, cmd):
        """Runs a command on the remote machine with the given options.

        Returns a string of the command's output.  This is a blocking call.
        cmd is a list of strings, the first is the command to run, and the rest
        are arguments.

        """
        if not self.ssh_avail():
            raise HostNotConnectableError
        command = ["ssh",
                "-l", self.username,
                "-p", str(self.SSH_PORT),
                "-i", self.key,
                "-o", "StrictHostKeyChecking=no",
                "-o","UserKnownHostsFile=/dev/null",
                self.ip,
                ]
        command.extend(cmd)
        log.warning(' '.join(command))
        return subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
예제 #7
0
def terminate_instances(instances):
    """Turns off the list of instances given.

    instances should be an iterable of vdi.models.Instance objects, for
    example, a django queryset.  The number of instances that were successfully
    terminated is returned.

    """
    num = 0
    for instance in instances:
        prov_instance = driver.instance(instance.instanceId)
        if prov_instance.stop():
            dbitem = Instance.objects.filter(instanceId=instance.instanceId)[0]
            log.debug(
                'The node has been deleted.  I will now move %s into a deleted state'
                % dbitem.instanceId)
            dbitem.state = 5
            dbitem.save()
            num += 1
        else:
            log.warning('Could not shut down instance "%s"' %
                        instance.instanceId)
    return num