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()
Exemple #2
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()
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a network ID")

        network = get_network(args[0])

        # Validate subnet
        if options.get('subnet'):
            validate_network_info(options)

        # Validate state
        state = options.get('state')
        if state:
            allowed = [x[0] for x in Network.OPER_STATES]
            if state not in allowed:
                msg = "Invalid state, must be one of %s" % ', '.join(allowed)
                raise CommandError(msg)

        dhcp = options.get("dhcp")
        if dhcp:
            options["dhcp"] = parse_bool(dhcp)
        drained = options.get("drained")
        if drained:
            options["drained"] = parse_bool(drained)
        fields = ('name', 'userid', 'subnet', 'gateway', 'subnet6', 'gateway6',
                  'dhcp', 'state', 'link', 'mac_prefix', 'drained')
        for field in fields:
            value = options.get(field, None)
            if value is not None:
                network.__setattr__(field, value)

        add_reserved_ips = options.get('add_reserved_ips')
        remove_reserved_ips = options.get('remove_reserved_ips')
        if add_reserved_ips or remove_reserved_ips:
            if add_reserved_ips:
                add_reserved_ips = add_reserved_ips.split(",")
            if remove_reserved_ips:
                remove_reserved_ips = remove_reserved_ips.split(",")

        for bnetwork in network.backend_networks.all():
            with pooled_rapi_client(bnetwork.backend) as c:
                c.ModifyNetwork(network=network.backend_id,
                                add_reserved_ips=add_reserved_ips,
                                remove_reserved_ips=remove_reserved_ips)

        network.save()
Exemple #4
0
    def set_allow_in_projects(self, resource_name, allow):
        if resource_name is None:
            raise CommandError("Please provide a resource name.")

        try:
            allow = utils.parse_bool(allow)
        except ValueError:
            raise CommandError("Expecting a boolean value.")
        resource = self.get_resource(resource_name)
        resource.allow_in_projects = allow
        resource.save()
Exemple #5
0
    def set_allow_in_projects(self, resource_name, allow):
        if resource_name is None:
            raise CommandError("Please provide a resource name.")

        try:
            allow = utils.parse_bool(allow)
        except ValueError:
            raise CommandError("Expecting a boolean value.")
        resource = self.get_resource(resource_name)
        resource.allow_in_projects = allow
        resource.save()
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a flavor ID")

        flavor = get_flavor(args[0])

        deleted = options['deleted']
        if deleted:
            deleted = parse_bool(deleted)
            log.info("Marking flavor %s as deleted=%s", flavor, deleted)
            flavor.deleted = deleted
            flavor.save()
        else:
            log.info("Nothing changed!")
Exemple #7
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a flavor ID")

        flavor = get_flavor(args[0])

        deleted = options['deleted']
        if deleted:
            deleted = parse_bool(deleted)
            log.info("Marking flavor %s as deleted=%s", flavor, deleted)
            flavor.deleted = deleted
            flavor.save()
        else:
            log.info("Nothing changed!")