예제 #1
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a backend ID")

        backend = get_backend(args[0])

        # Ensure fields correspondence with options and Backend model
        credentials_changed = False
        fields = ("clustername", "port", "username", "password")
        for field in fields:
            value = options.get(field)
            if value is not None:
                backend.__setattr__(field, value)
                credentials_changed = True

        if credentials_changed:
            # check credentials, if any of them changed!
            check_backend_credentials(backend.clustername, backend.port, backend.username, backend.password)
        if options["drained"]:
            backend.drained = parse_bool(options["drained"], strict=True)
        if options["offline"]:
            backend.offline = parse_bool(options["offline"], strict=True)
        hypervisor = options["hypervisor"]
        if hypervisor:
            backend.hypervisor = hypervisor

        backend.save()
예제 #2
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a backend ID")

        backend = common.get_resource("backend", args[0], for_update=True)

        # Ensure fields correspondence with options and Backend model
        credentials_changed = False
        fields = ('clustername', 'port', 'username', 'password')
        for field in fields:
            value = options.get(field)
            if value is not None:
                backend.__setattr__(field, value)
                credentials_changed = True

        if credentials_changed:
                # check credentials, if any of them changed!
                common.check_backend_credentials(backend.clustername,
                                                 backend.port,
                                                 backend.username,
                                                 backend.password)
        if options['drained']:
            backend.drained = parse_bool(options['drained'], strict=True)
        if options['offline']:
            backend.offline = parse_bool(options['offline'], strict=True)
        if options['public']:
            backend.public = parse_bool(options['public'], strict=True)
        hypervisor = options["hypervisor"]
        if hypervisor:
            backend.hypervisor = hypervisor

        backend.save()
예제 #3
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a backend ID")

        backend = get_backend(args[0])

        # Ensure fields correspondence with options and Backend model
        credentials_changed = False
        fields = ('clustername', 'port', 'username', 'password')
        for field in fields:
            value = options.get(field)
            if value is not None:
                backend.__setattr__(field, value)
                credentials_changed = True

        if credentials_changed:
                # check credentials, if any of them changed!
                check_backend_credentials(backend.clustername, backend.port,
                                          backend.username, backend.password)
        if options['drained']:
            backend.drained = parse_bool(options['drained'], strict=True)
        if options['offline']:
            backend.offline = parse_bool(options['offline'], strict=True)
        hypervisor = options["hypervisor"]
        if hypervisor:
            backend.hypervisor = hypervisor

        backend.save()
예제 #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)
예제 #5
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)
예제 #6
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']

        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)

        create_backend(clustername, port, username, password,
                       hypervisor=options["hypervisor"],
                       initialize=options["init"])
예제 #7
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']

        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)

        self.create_backend(clustername,
                            port,
                            username,
                            password,
                            hypervisor=options["hypervisor"],
                            initialize=options["init"])