Exemple #1
0
def refresh_backends_stats(backends):
    """ Refresh the statistics of the backends.

    Set db backend state to the actual state of the backend, if
    BACKEND_REFRESH_MIN time has passed.

    """

    now = datetime.datetime.now()
    delta = datetime.timedelta(minutes=BACKEND_REFRESH_MIN)
    for b in backends:
        if now > b.updated + delta:
            log.debug("Updating resources of backend %r. Last Updated %r", b,
                      b.updated)
            update_resources(b)
Exemple #2
0
def refresh_backends_stats(backends):
    """ Refresh the statistics of the backends.

    Set db backend state to the actual state of the backend, if
    BACKEND_REFRESH_MIN time has passed.

    """

    now = datetime.datetime.now()
    delta = datetime.timedelta(minutes=BACKEND_REFRESH_MIN)
    for b in backends:
        if now > b.updated + delta:
            log.debug("Updating resources of backend %r. Last Updated %r",
                      b, b.updated)
            update_resources(b)
    def handle(self, *args, **options):
        if len(args) > 0:
            raise CommandError("Command takes no arguments")

        clustername = options['clustername']
        port = options['port']
        username = options['username']
        password = options['password']
        hypervisor = options["hypervisor"]

        if not (clustername and username and password):
            raise CommandError("Clustername, user and pass must be supplied")

        # Ensure correctness of credentials
        if options['check']:
            check_backend_credentials(clustername, port, username, password)

        kw = {
            "clustername": clustername,
            "port": port,
            "username": username,
            "password": password,
            "drained": True
        }

        if hypervisor:
            kw["hypervisor"] = hypervisor
        # Create the new backend in database
        try:
            backend = Backend.objects.create(**kw)
        except IntegrityError as e:
            raise CommandError("Cannot create backend: %s\n" % e)

        self.stdout.write('\nSuccessfully created backend with id %d\n' %
                          backend.id)

        if not options['check']:
            return

        self.stdout.write('\rRetrieving backend resources:\n')
        resources = get_physical_resources(backend)
        attr = ['mfree', 'mtotal', 'dfree', 'dtotal', 'pinst_cnt', 'ctotal']

        table = [[str(resources[x]) for x in attr]]
        pprint_table(self.stdout, table, attr)

        update_resources(backend, resources)
Exemple #4
0
    def handle(self, *args, **options):
        if len(args) > 0:
            raise CommandError("Command takes no arguments")

        clustername = options['clustername']
        port = options['port']
        username = options['username']
        password = options['password']
        hypervisor = options["hypervisor"]

        if not (clustername and username and password):
            raise CommandError("Clustername, user and pass must be supplied")

        # Ensure correctness of credentials
        if options['check']:
            check_backend_credentials(clustername, port, username, password)

        kw = {"clustername": clustername,
              "port": port,
              "username": username,
              "password": password,
              "drained": True}

        if hypervisor:
            kw["hypervisor"] = hypervisor
        # Create the new backend in database
        try:
            backend = Backend.objects.create(**kw)
        except IntegrityError as e:
            raise CommandError("Cannot create backend: %s\n" % e)

        self.stdout.write('\nSuccessfully created backend with id %d\n' %
                          backend.id)

        if not options['check']:
            return

        self.stdout.write('\rRetrieving backend resources:\n')
        resources = get_physical_resources(backend)
        attr = ['mfree', 'mtotal', 'dfree', 'dtotal', 'pinst_cnt', 'ctotal']

        table = [[str(resources[x]) for x in attr]]
        pprint_table(self.stdout, table, attr)

        update_resources(backend, resources)
Exemple #5
0
    def handle(self, **options):

        if options['backend_id']:
            backends = [get_backend(options['backend_id'])]
        else:
            backends = Backend.objects.filter(offline=False)
            if not options['drained']:
                backends = backends.filter(drained=False)

        now = datetime.datetime.now()
        if options['older_than'] is not None:
            minutes = int(options['older_than'])
        else:
            minutes = settings.BACKEND_REFRESH_MIN

        delta = datetime.timedelta(minutes=minutes)

        for b in backends:
            if now > b.updated + delta:
                update_resources(b)
                print 'Successfully updated backend with id: %d' % b.id
            else:
                print 'Backend %d does not need update' % b.id
    def handle(self, **options):

        if options["backend_id"]:
            backends = [get_backend(options["backend_id"])]
        else:
            backends = Backend.objects.filter(offline=False)
            if not options["drained"]:
                backends = backends.filter(drained=False)

        now = datetime.datetime.now()
        if options["older_than"] is not None:
            minutes = int(options["older_than"])
        else:
            minutes = settings.BACKEND_REFRESH_MIN

        delta = datetime.timedelta(minutes=minutes)

        for b in backends:
            if now > b.updated + delta:
                update_resources(b)
                print "Successfully updated backend with id: %d" % b.id
            else:
                print "Backend %d does not need update" % b.id