Example #1
0
    def create(self, args, config, connection):
        forest = Forest(args['name'],
                        args['forest_host'],
                        connection=connection)
        if forest.exists():
            self.logger.error("Forest already exists: {0}".format(
                args['name']))
            sys.exit(1)

        if args['json'] is not None:
            forest = self._read(args['name'], args['json'])
            if forest.host() is None:
                forest.set_host(args['forest_host'])

        self._properties(forest, args)
        dbname = forest.database()

        if dbname is not None:
            database = Database(dbname)
            database.read(connection)
        else:
            database = None

        self.logger.info("Create forest {0}...".format(args['name']))
        forest.create(connection=connection)

        if database is not None:
            database.add_forest_name(forest.forest_name())
            database.update(connection)
Example #2
0
    def forest(self, forest_name, host=None, connection=None):
        """
        Get the named forest.
        """
        if host is None:
            if connection is None:
                db = Forest(forest_name,
                            connection=self.connection,
                            save_connection=self.save_connection)
            else:
                db = Forest(forest_name,
                            connection=connection,
                            save_connection=False)
        else:
            if connection is None:
                db = Forest(forest_name,
                            host.host_name(),
                            connection=self.connection,
                            save_connection=self.save_connection)
            else:
                db = Forest(forest_name,
                            host.host_name(),
                            connection=connection,
                            save_connection=False)

        if connection is None:
            return db.read(self.connection)
        else:
            return db.read(connection)
Example #3
0
    def get(self, args, config, connection):
        forest = Forest(args['name'], connection=connection)
        if not forest.exists():
            print("Error: Forest does not exist: {0}".format(args['name']))
            sys.exit(1)

        forest.read()
        self.jprint(forest)
Example #4
0
    def get(self, args, config, connection):
        forest = Forest(args['name'], connection=connection)
        if not forest.exists():
            print("Error: Forest does not exist: {0}".format(args['name']))
            sys.exit(1)

        forest.read()
        self.jprint(forest)
Example #5
0
    def delete(self, args, config, connection):
        forest = Forest(args['name'], args['forest_host'], connection=connection)
        if not forest.exists():
            return

        level = args['level']
        replicas = args['replicas']

        print("Delete forest {0}...".format(args['name']))
        forest.delete(level,replicas,connection)
Example #6
0
    def create(self, args, config, connection):
        forest = Forest(args['name'], args['forest_host'], connection=connection)
        if forest.exists():
            self.logger.error("Forest already exists: {0}".format(args['name']))
            sys.exit(1)

        if args['json'] is not None:
            forest = self._read(args['name'], args['json'])
            if forest.host() is None:
                forest.set_host(args['forest_host'])

        self._properties(forest, args)
        dbname = forest.database()

        if dbname is not None:
            database = Database(dbname)
            database.read(connection)
        else:
            database = None

        self.logger.info("Create forest {0}...".format(args['name']))
        forest.create(connection=connection)

        if database is not None:
            database.add_forest_name(forest.forest_name())
            database.update(connection)
Example #7
0
    def delete(self, args, config, connection):
        forest = Forest(args['name'],
                        args['forest_host'],
                        connection=connection)
        if not forest.exists():
            return

        level = args['level']
        replicas = args['replicas']

        print("Delete forest {0}...".format(args['name']))
        forest.delete(level, replicas, connection)
Example #8
0
    def forests(self, connection=None):
        """
        Get a list of the forests in the local cluster.
        """
        if connection is None:
            connection = self.connection

        return Forest.list(connection)
Example #9
0
    def forests(self, connection=None):
        """
        Get a list of the forests in the local cluster.
        """
        if connection is None:
            connection = self.connection

        return Forest.list(connection)
Example #10
0
    def modify(self, args, config, connection):
        name = args['name']
        forest = Forest(name, connection=connection)
        if not forest.exists():
            print("Error: Forest does not exist: {0}".format(name))
            sys.exit(1)

        if args['json'] is not None:
            forest = self._read(None, args['json'], connection=connection)
            if forest.host() is None and 'forest_host' in args:
                forest.set_host(args['forest_host'])
            forest.name = name

        self._properties(forest, args)
        print("Modify forest {0}...".format(name))
        forest.update(connection=connection)
Example #11
0
    def forest(self, forest_name, host=None, connection=None):
        """
        Get the named forest.
        """
        if host is None:
            if connection is None:
                db = Forest(forest_name, connection=self.connection,
                            save_connection=self.save_connection)
            else:
                db = Forest(forest_name, connection=connection,
                            save_connection=False)
        else:
            if connection is None:
                db = Forest(forest_name, host.host_name(),
                              connection=self.connection,
                              save_connection=self.save_connection)
            else:
                db = Forest(forest_name, host.host_name(),
                              connection=connection,
                              save_connection=False)

        if connection is None:
            return db.read(self.connection)
        else:
            return db.read(connection)
Example #12
0
    def modify(self, args, config, connection):
        name = args['name']
        forest = Forest(name, connection=connection)
        if not forest.exists():
            print("Error: Forest does not exist: {0}".format(name))
            sys.exit(1)

        if args['json'] is not None:
            forest = self._read(None, args['json'], connection=connection)
            if forest.host() is None and 'forest_host' in args:
                forest.set_host(args['forest_host'])
            forest.name = name

        self._properties(forest, args)
        print("Modify forest {0}...".format(name))
        forest.update(connection=connection)
Example #13
0
    def _read(self, name, jsonfile, connection=None, save_connection=True):
        jf = open(jsonfile).read()
        data = json.loads(jf)

        if name is not None:
            data['forest-name'] = name

        if 'database' in data:
            del (data['database'])

        forest = Forest.unmarshal(data,
                                  connection=connection,
                                  save_connection=save_connection)

        return forest
Example #14
0
    def _read(self, name, jsonfile,
              connection=None, save_connection=True):
        jf = open(jsonfile).read()
        data = json.loads(jf)

        if name is not None:
            data['forest-name'] = name

        if 'database' in data:
            del(data['database'])

        forest = Forest.unmarshal(data,
                                  connection=connection,
                                  save_connection=save_connection)

        return forest
Example #15
0
    def create(self, args, config, connection):
        name = args['name']
        host = args['forest_host']

        if args['json'] is not None:
            forest = self._read(name, args['json'], connection=connection)
            name = forest.forest_name()
            host = forest.host()
        else:
            forest = Forest(name, host, connection=connection)

        if forest.exists():
            self.logger.error("Forest already exists: {0}".format(name))
            sys.exit(1)

        self._properties(forest, args)
        dbname = forest.database()

        # Strip out properties that we know the server will reject
        cluster = LocalCluster(connection)
        cluster.read()
        if cluster.security_version() is None:
            for key in ['database-replication', 'failover-enable']:
                if key in forest._config:
                    del (forest._config[key])
                    self.logger.debug(
                        "Ignoring {0}, not supported by server".format(key))

        if dbname is not None:
            database = Database(dbname)
            database.read(connection)
        else:
            database = None

        self.logger.info("Create forest {0}...".format(name))
        forest.create(connection=connection)

        if database is not None:
            database.add_forest_name(forest.forest_name())
            database.update(connection)
Example #16
0
    def create(self, args, config, connection):
        name = args['name']
        host = args['forest_host']

        if args['json'] is not None:
            forest = self._read(name, args['json'], connection=connection)
            name = forest.forest_name()
            host = forest.host()
        else:
            forest = Forest(name, host, connection=connection)

        if forest.exists():
            self.logger.error("Forest already exists: {0}".format(name))
            sys.exit(1)

        self._properties(forest, args)
        dbname = forest.database()

        # Strip out properties that we know the server will reject
        cluster = LocalCluster(connection)
        cluster.read()
        if cluster.security_version() is None:
            for key in ['database-replication', 'failover-enable']:
                if key in forest._config:
                    del(forest._config[key])
                    self.logger.debug("Ignoring {0}, not supported by server"
                                      .format(key))

        if dbname is not None:
            database = Database(dbname)
            database.read(connection)
        else:
            database = None

        self.logger.info("Create forest {0}...".format(name))
        forest.create(connection=connection)

        if database is not None:
            database.add_forest_name(forest.forest_name())
            database.update(connection)
    def forests(self, connection=None):
        if connection is None:
            connection = self.connection

        return Forest.list(connection)
Example #18
0
 def list(self, args, config, connection):
     forests = Forest.list(connection)
     print(json.dumps(forests, sort_keys=True, indent=2))
Example #19
0
 def list(self, args, config, connection):
     print(Forest.list(connection))
Example #20
0
 def _read(self, name, jsonfile):
     jf = open(jsonfile).read()
     data = json.loads(jf)
     data['forest-name'] = name
     forest = Forest.unmarshal(data)
     return forest
Example #21
0
    def forests(self, connection=None):
        if connection is None:
            connection = self.connection

        return Forest.list(connection)
Example #22
0
    def create_forests(self):
        conn = Connection(self.host,
                          HTTPDigestAuth(self.adminuser, self.adminpass))
        self.marklogic = MarkLogic(conn)

        if self.failhost is None and self.failover != "none":
            print("Invalid configuration, specify failover-host for failover:",
                  self.failover)
            sys.exit(1)

        if self.hosts is None:
            host_names = self.marklogic.hosts()
        else:
            host_names = self.hosts

        exists = []
        host_index = 0
        for host_name in host_names:
            host_index += 1
            for count in range(1,self.forests + 1):
                name = self.prefix + "-" + str(host_index) + "-" + str(count)
                forest = Forest(name, host_name, conn)
                if forest.exists():
                    exists.append(host_name + ":" + name)

        if len(exists) != 0:
            print("Abort: forest(s) already exist:")
            for f in exists:
                print("   ", f)
            sys.exit(1)

        host_index = 0
        for host_name in host_names:
            host_index += 1
            for count in range(self.start,self.start + self.forests):
                name = self.prefix + "-" + str(host_index) + "-" + str(count)
                forest = Forest(name, host_name, conn)
                if self.data_dir is not None:
                    forest.set_data_directory(self.data_dir)
                if self.large_data_dir is not None:
                    forest.set_large_data_directory(self.large_data_dir)
                if self.fast_data_dir is not None:
                    forest.set_fast_data_directory(self.fast_data_dir)

                if self.failhost is not None:
                    forest.set_failover(self.failover)
                    forest.set_failover_host_names(self.failhost)

                if self.database is not None:
                    forest.set_database(self.database)

                print("Create forest " + name + " on " + host_name)
                if self.dry_run:
                    print(json.dumps(forest.marshal(), sort_keys=True, indent=2))
                else:
                    forest.create()

        print("Finished")
Example #23
0
 def list(self, args, config, connection):
     print(Forest.list(connection))
Example #24
0
 def _read(self, name, jsonfile):
     jf = open(jsonfile).read()
     data = json.loads(jf)
     data['forest-name'] = name
     forest = Forest.unmarshal(data)
     return forest
        verb = "Creating"
        user = User.unmarshal(config)
        # Must assign some sort of password
        user.set_password(base64.urlsafe_b64encode(os.urandom(32)).decode('utf-8'))
        print("{0} user: {1}".format(verb, name))
        user.create(conn)
    else:
        verb = "Updating"
        user = User.unmarshal(config)
        print("{0} user: {1}".format(verb, name))
        user.update(conn)

# Create forests
for config in data['forests']:
    name = config['forest-name']
    f = Forest.lookup(conn, name)
    if f is None:
        print("Need to create forest: {0}".format(name))
        f = Forest(name)
        f.create(conn)

# Update forests
for config in data['forests']:
    name = config['forest-name']
    f = Forest.unmarshal(config)
    print("Updating forest: {0}".format(name))
    f.update(conn)

# Create databases
for config in data['databases']:
    name = config['database-name']
    def close(self, conn, group='Default'):
        closed = False
        while not closed:
            closed = True

            newitems = []
            for key in self.servers:
                item = self.servers[key]
                if item is None:
                    closed = False
                    newitems.append(Server.lookup(conn, key, group))

            for server in newitems:
                self._close_over_server(server)

            newitems = []
            for key in self.databases:
                item = self.databases[key]
                if item is None:
                    closed = False
                    newitems.append(Database.lookup(conn, key))

            for database in newitems:
                self._close_over_database(database)

            newitems = []
            for key in self.forests:
                item = self.forests[key]
                if item is None:
                    closed = False
                    newitems.append(Forest.lookup(conn, key))

            for forest in newitems:
                self._close_over_forest(forest)

            newitems = []
            for key in self.users:
                item = self.users[key]
                if item is None:
                    closed = False
                    newitems.append(User.lookup(conn, key))

            for user in newitems:
                self._close_over_user(user)

            newitems = []
            for key in self.roles:
                item = self.roles[key]
                if item is None:
                    closed = False
                    newitems.append(Role.lookup(conn, key))

            for role in newitems:
                self._close_over_role(role)

            delitems = []
            newitems = []
            for key in self.privileges:
                item = self.privileges[key]
                parts = key.split("|")
                kind = parts[0]
                name = parts[1]
                if isinstance(item, str):
                    closed = False
                    if "//" in key:
                        # Assume it's an action
                        priv = Privilege.lookup(conn, action=name, kind=kind)
                        delitems.append(key)
                    else:
                        priv = Privilege.lookup(conn, name, kind)
                    newitems.append(priv)

            for item in delitems:
                del self.privileges[item]

            for priv in newitems:
                self._close_over_privilege(priv)
Example #27
0
 def list(self, args, config, connection):
     forests = Forest.list(connection)
     print(json.dumps(forests, sort_keys=True, indent=2))