Deactivate but do not delete user accounts
    :param server_context: A LabKey server context. See utils.create_server_context.
    :param target_ids:
    :param container_path:
    :return:
542407
def deactivate_users(server_context, target_ids, container_path=None):
    
    # This action responds with HTML so we just check if it responds OK
    response = __make_user_api_request(server_context, target_ids=target_ids, api='deactivateUsers.view',
                                       container_path=container_path)
    if response is not None and response['status_code'] == 200:
        return dict(success=True)
    else:
        raise ValueError("Unable to deactivate users {0}".format(target_ids))
575815
def delete(self, request, id):
        
        if not id:
            # can't delete the whole container
            raise errors.MethodNotAllowed()
        try:
            models.User.objects.get(pk=id).delete()
        except models.User.DoesNotExist:
            # we never had it, so it's definitely deleted
            pass
1259121
def deleteAllActivationKeys(server):
    '''
    
    '''

    try:
        client, key = _get_session(server)
    except Exception as exc:
        err_msg = 'Exception raised when connecting to spacewalk server ({0}): {1}'.format(server, exc)
        log.error(err_msg)
        return {'Error': err_msg}

    activation_keys = client.activationkey.listActivationKeys(key)

    deleted_keys = []
    failed_keys = []

    for aKey in activation_keys:
        if client.activationkey.delete(key, aKey['key']) == 1:
            deleted_keys.append(aKey['key'])
        else:
            failed_keys.append(aKey['key'])

    ret = {'deleted': deleted_keys}
    if failed_keys:
        ret['failed'] = failed_keys
    return ret
135781
def delete_contexts(self, context_id_list):
        
        for c_id in context_id_list:
            if c_id in self._contexts:
                del self._contexts[c_id]
877025
protected void deactivate(ComponentContext context) {
        deactivated = true;
        if (mbean != null)
            mbean.unregister();
        if (taskStore != null)
            DatabaseTaskStore.unget(persistentStore);
        appTrackerRef.deactivate(context);
        contextSvcRef.deactivate(context);
        controllerRef.deactivate(context);
        localTranCurrentRef.deactivate(context);
        serializationSvcRef.deactivate(context);
        tranMgrRef.deactivate(context);

    }
356187
protected void deactivate(ComponentContext context) {
        final boolean trace = TraceComponent.isAnyTracingEnabled();
        if (trace && tc.isEntryEnabled())
            Tr.entry(this, tc, "deactivate", name);

        lock.writeLock().lock();
        try {
            if (pmMBean != null) {
                pmMBean.unregister();
                pmMBean = null;
            }
            pm = null;
            properties = null;
        } finally {
            lock.writeLock().unlock();
        }

        if (trace && tc.isEntryEnabled())
            Tr.exit(this, tc, "deactivate");
    }
185312
protected void deactivate(ComponentContext context) {
        final boolean trace = TraceComponent.isAnyTracingEnabled();
        if (trace && tc.isEntryEnabled())
            Tr.entry(this, tc, "deactivate");

        destroyConnectionFactories(true);

        if (trace && tc.isEntryEnabled())
            Tr.exit(this, tc, "deactivate", id + ' ' + context.getProperties().get(JNDI_NAME));
    }
215973
async def deactivate(cls, access_key: str) -> dict:
        '''
        
        '''
        q = 'mutation($access_key: String!, $input: ModifyKeyPairInput!) {' + \
            '  modify_keypair(access_key: $access_key, props: $input) {' \
            '    ok msg' \
            '  }' \
            '}'
        variables = {
            'access_key': access_key,
            'input': {
                'is_active': False,
                'is_admin': None,
                'resource_policy': None,
                'rate_limit': None,
            },
        }
        rqst = Request(cls.session, 'POST', '/admin/graphql')
        rqst.set_json({
            'query': q,
            'variables': variables,
        })
        async with rqst.fetch() as resp:
            data = await resp.json()
            return data['modify_keypair']
1182486
def purge_portlets(portal):
    
    logger.info("Purging portlets ...")

    def remove_portlets(context_portlet):
        mapping = portal.restrictedTraverse(context_portlet)
        for key in mapping.keys():
            if key not in PORTLETS_TO_PURGE:
                logger.info("Skipping portlet: '{}'".format(key))
                continue
            logger.info("Removing portlet: '{}'".format(key))
            del mapping[key]

    remove_portlets("++contextportlets++plone.leftcolumn")
    remove_portlets("++contextportlets++plone.rightcolumn")

    # Reimport the portlets profile
    setup = portal.portal_setup
    setup.runImportStepFromProfile(profile, 'portlets')
    logger.info("Purging portlets [DONE]")
77138
protected void deactivate(ComponentContext context) {
        transactionInflowManagerRef.deactivate(context);

        // TODO remove the following temporary code once the transaction manager provides a proper mechanism to prevent a transaction on multiple threads at once
        SuspendCount suspendCount = suspendCountRef.get();
        if (suspendCount != null)
            ((UOWCurrent) transactionManager).unsetUOWEventListener(suspendCount);
    }
192708
protected synchronized void deactivate(ComponentContext context) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Unregistering JNDIEntry " + serviceRegistration);
        }
        if (this.serviceRegistration != null) {
            this.serviceRegistration.unregister();
        }
    }
1270812
def delete_servers(self, server_id):
        
        endpoint = "https://api.newrelic.com"
        uri = "{endpoint}/api/v1/accounts/{account_id}/servers/{server_id}.xml".format(
            endpoint=endpoint,
            account_id=self.account_id,
            server_id=server_id)
        response = self._make_delete_request(uri)
        failed_deletions = []
        for server in response.findall('.//server'):
            if not 'deleted' in server.findall('.//result')[0].text:
                failed_deletions.append({'server_id': server.get('id')})

        return failed_deletions
806826
protected void deactivate(ComponentContext context) {
        final boolean trace = TraceComponent.isAnyTracingEnabled();
        if (trace && tc.isEntryEnabled())
            Tr.entry(this, tc, "deactivate");

        lock.writeLock().lock();
        try {
            if (isInitialized) {
                if (classloader != null) {
                    if (isDerbyEmbedded.get())
                        shutdownDerbyEmbedded();
                    classloader = null;
                }
                for (Iterator<Class<? extends CommonDataSource>> it = introspectedClasses.iterator(); it.hasNext(); it.remove())
                    Introspector.flushFromCaches(it.next());
                isInitialized = false;
            }
        } finally {
            lock.writeLock().unlock();
        }

        if (trace && tc.isEntryEnabled())
            Tr.exit(this, tc, "deactivate");
    }
1329944
def create_user(server_context, email, container_path=None, send_email=False):
    
    url = server_context.build_url(security_controller, 'createNewUser.api', container_path)
    payload = {
        'email': email,
        'sendEmail': send_email
    }

    return server_context.make_request(url, payload)
92983
def unregister(name, server_url):
    '''
    
    '''

    try:
        client, key = _get_session(server_url)
    except Exception as exc:
        err_msg = 'Exception raised when connecting to spacewalk server ({0}): {1}'.format(server_url, exc)
        log.error(err_msg)
        return {name: err_msg}

    systems_list = client.system.getId(key, name)

    if systems_list:
        for system in systems_list:
            out = client.system.deleteSystem(key, system['id'])
            if out == 1:
                return {name: 'Successfully unregistered from {0}'.format(server_url)}
            else:
                return {name: 'Failed to unregister from {0}'.format(server_url)}
    else:
        return {name: 'System does not exist in spacewalk server ({0})'.format(server_url)}
781524
def get_user_by_email(server_context, email):
    
    url = server_context.build_url(user_controller, 'getUsers.api')
    payload = dict(includeDeactivatedAccounts=True)
    result = server_context.make_request(url, payload)

    if result is None or result['users'] is None:
        raise ValueError("No Users in container" + email)

    for user in result['users']:
        if user['email'] == email:
            return user
    else:
        raise ValueError("User not found: " + email)
57080
def stop_instance(self, instance_id):
        
        self._init_az_api()

        cluster_name, node_name = instance_id
        self._init_inventory(cluster_name)

        for name, api_version in [
                # we must delete resources in a specific order: e.g.,
                # a public IP address cannot be deleted if it's still
                # in use by a NIC...
                (node_name,                '2018-06-01'),
                (node_name + '-nic',       '2018-10-01'),
                (node_name + '-public-ip', '2018-10-01'),
                (node_name + '-disk',      '2018-09-30'),
            (self._make_storage_account_name(
                    cluster_name, node_name),
                                           '2018-07-01'),
        ]:
            rsc_id = self._inventory[name]
            log.debug("Deleting resource %s (`%s`) ...", name, rsc_id)
            oper = self._resource_client.resources.delete_by_id(rsc_id, api_version)
            oper.wait()
            del self._inventory[name]

        self._vm_details.pop(node_name, None)

        # if this was the last VM to be deleted, clean up leftover resource group
        with self.__lock:
            if len(self._inventory) == 2:
                log.debug("Cleaning up leftover resource group ...")
                oper = self._resource_client.resource_groups.delete(cluster_name)
                oper.wait()
                self._inventory = {}