Example #1
0
 def get(name):
     """Get a Treadmill App Group entry"""
     try:
         admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
         cli.out(formatter(admin_app_group.get(name)))
     except ldap3.LDAPNoSuchObjectResult:
         cli.bad_exit('App group does not exist: %s', name)
Example #2
0
    def configure(name, group_type, cell, pattern, endpoints, data):
        """Create or modify Treadmill App Group entry"""
        admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)

        data_struct = {}
        if group_type:
            data_struct['group-type'] = group_type
        if cell:
            data_struct['cells'] = cell
        if pattern is not None:
            data_struct['pattern'] = pattern
        if data is not None:
            data_struct['data'] = data
        if endpoints is not None:
            data_struct['endpoints'] = endpoints

        if data_struct:
            try:
                admin_app_group.create(name, data_struct)
                _LOGGER.debug('Created app group %s', name)
            except ldap3.LDAPEntryAlreadyExistsResult:
                _LOGGER.debug('Updating app group %s', name)
                admin_app_group.update(name, data_struct)

        try:
            cli.out(formatter(admin_app_group.get(name)))
        except ldap3.LDAPNoSuchObjectResult:
            cli.bad_exit('App group does not exist: %s', name)
Example #3
0
def _run_sync():
    """Sync Zookeeper with LDAP, runs with lock held."""
    def match_appgroup(name, group):
        """Match if appgroup belongs to the cell."""
        if context.GLOBAL.cell in group.get('cells', []):
            return name
        else:
            return None

    while True:
        # Sync app groups
        admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
        app_groups = admin_app_group.list({})
        _sync_collection(context.GLOBAL.zk.conn,
                         app_groups, z.path.appgroup(), match_appgroup)

        # Sync allocations.
        admin_alloc = admin.CellAllocation(context.GLOBAL.ldap.conn)

        allocations = admin_alloc.list({'cell': context.GLOBAL.cell})
        _sync_allocations(context.GLOBAL.zk.conn,
                          allocations)

        # Servers - because they can have custom topology - are loaded
        # from the plugin.
        try:
            servers_plugin = importlib.import_module(
                'treadmill.plugins.sproc.servers')
            servers_plugin.init()
        except ImportError as err:
            _LOGGER.warn('Unable to load treadmill.plugins.sproc.servers: '
                         '%s', err)

        time.sleep(60)
Example #4
0
def sync_appgroups():
    """Sync app-groups from LDAP to Zookeeper."""
    _LOGGER.info('Sync appgroups.')
    admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
    app_groups = admin_app_group.list({})
    cell_app_groups = [group for group in app_groups if _match_appgroup(group)]
    _sync_collection(context.GLOBAL.zk.conn,
                     cell_app_groups, z.path.appgroup())
    _sync_appgroup_lookups(context.GLOBAL.zk.conn, cell_app_groups)
Example #5
0
    def cells(add, remove, name):
        """Add or remove cells from the app-group."""
        admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
        existing = admin_app_group.get(name)
        group_cells = set(existing['cells'])

        if add:
            group_cells.update(add)
        if remove:
            group_cells = group_cells - set(remove)

        admin_app_group.update(name, {'cells': list(group_cells)})
        cli.out(formatter(admin_app_group.get(name)))
Example #6
0
    def configure_appgroups(ctx):
        """Configure system app groups."""
        appgroups = _appgroups(ctx)

        admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
        for name, data in six.iteritems(appgroups):
            print(name, data)
            try:
                admin_app_group.create(name, data)
            except ldap_exceptions.LDAPEntryAlreadyExistsResult:
                admin_app_group.update(name, data)

            existing = admin_app_group.get(name, dirty=True)
            group_cells = set(existing['cells'])
            group_cells.update([ctx.obj.cell])
            admin_app_group.update(name, {'cells': list(group_cells)})
            existing = admin_app_group.get(name, dirty=True)
            print(existing)
Example #7
0
    def configure_appgroups(cors_origin, krb_realm):
        """Configure system app groups."""
        ctx = CellCtx(cors=cors_origin, krb_realm=krb_realm)
        appgroups = _appgroups(ctx)

        admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
        for name, data in appgroups.items():
            print(name, data)
            try:
                admin_app_group.create(name, data)
            except admin_exceptions.AlreadyExistsResult:
                admin_app_group.update(name, data)

            existing = admin_app_group.get(name, dirty=True)
            group_cells = set(existing['cells'])
            group_cells.update([context.GLOBAL.cell])
            admin_app_group.update(name, {'cells': list(group_cells)})
            existing = admin_app_group.get(name, dirty=True)
            print(existing)
Example #8
0
def _run_sync():
    """Sync Zookeeper with LDAP, runs with lock held.
    """
    while True:
        # Sync app groups
        admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
        app_groups = admin_app_group.list({})
        _sync_collection(context.GLOBAL.zk.conn, app_groups, z.path.appgroup(),
                         _match_appgroup)

        # Sync partitions
        admin_cell = admin.Cell(context.GLOBAL.ldap.conn)
        partitions = admin_cell.partitions(context.GLOBAL.cell)
        _sync_partitions(context.GLOBAL.zk.conn, partitions)

        # Sync allocations.
        admin_alloc = admin.CellAllocation(context.GLOBAL.ldap.conn)

        allocations = admin_alloc.list({'cell': context.GLOBAL.cell})
        _sync_allocations(context.GLOBAL.zk.conn, allocations)

        # Global servers
        admin_srv = admin.Server(context.GLOBAL.ldap.conn)
        global_servers = admin_srv.list({})
        zkutils.ensure_exists(
            context.GLOBAL.zk.conn,
            z.path.globals('servers'),
            data=[server['_id'] for server in global_servers])

        # Servers - because they can have custom topology - are loaded
        # from the plugin.
        try:
            servers_plugin = importlib.import_module(
                'treadmill.plugins.sproc.servers')
            servers_plugin.init()
        except ImportError as err:
            _LOGGER.warning(
                'Unable to load treadmill.plugins.sproc.servers: %s', err)

        time.sleep(60)
Example #9
0
    def configure_appgroups(cors_origin, krb_realm, dry_run):
        """Configure system app groups."""
        ctx = cell_admin.CellCtx(cors=cors_origin, krb_realm=krb_realm)
        appgroups = cell_admin.get_appgroups(ctx)

        admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)

        for name, data in appgroups.items():
            cli.echo_green('Configuring appgroup %s: %r', name, data)

            if dry_run:
                continue

            try:
                admin_app_group.create(name, data)
            except admin_exceptions.AlreadyExistsResult:
                admin_app_group.update(name, data)

            existing = admin_app_group.get(name, dirty=True)
            group_cells = set(existing['cells'])
            group_cells.update([context.GLOBAL.cell])
            admin_app_group.update(name, {'cells': list(group_cells)})
            existing = admin_app_group.get(name, dirty=True)
            cli.out(existing)
Example #10
0
 def delete(name):
     """Delete Treadmill App Group entry"""
     admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
     admin_app_group.delete(name)
Example #11
0
 def _list():
     """List out App Group entries"""
     admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn)
     app_group_entries = admin_app_group.list({})
     cli.out(formatter(app_group_entries))
Example #12
0
 def _admin_app_group():
     """Lazily return admin object."""
     return admin.AppGroup(context.GLOBAL.ldap.conn)