Beispiel #1
0
    def configure(server, features, parent, partition, memory, cpu, disk):
        """Create, get or modify server configuration"""
        if parent:
            path = parent.split('/')
            bucket = None
            for bucket, bucket_parent in zip(path, [None] + path[:-1]):
                masterapi.create_bucket(context.GLOBAL.zk.conn, bucket,
                                        bucket_parent)
            assert bucket is not None, 'server topology missing.'

            masterapi.create_server(context.GLOBAL.zk.conn,
                                    server,
                                    bucket,
                                    partition=partition)

        features = cli.combine(features)
        if features:
            # This is special case - reset features to empty.
            if features == ['-']:
                features = []

            masterapi.update_server_features(context.GLOBAL.zk.conn, server,
                                             features)

        if memory or cpu or disk:
            masterapi.update_server_capacity(context.GLOBAL.zk.conn,
                                             server,
                                             memory=memory,
                                             cpu=cpu,
                                             disk=disk)

        server_obj = masterapi.get_server(context.GLOBAL.zk.conn, server)
        server_obj['name'] = server

        cli.out(formatter(server_obj))
Beispiel #2
0
    def list():  # pylint: disable=W0622
        """List servers"""
        servers = []
        for name in masterapi.list_servers(context.GLOBAL.zk.conn):
            server = masterapi.get_server(context.GLOBAL.zk.conn,
                                          name,
                                          placement=True)
            server['name'] = name
            servers.append(server)

        cli.out(formatter(servers))