def run_ckan_commands(instance_id_or_name, command, dry_run=False, use_paster=False):
    instance_id, instance_type, instance = _get_instance_id_and_type(instance_id_or_name)
    if not dry_run:
        pod_name = _get_running_pod_name(instance_id)
        logs.info(f'Running Search Index {command}')
        if use_paster:
            answer = logs.subprocess_check_output(
                f'kubectl -n {instance_id} exec -i {pod_name} -- ckan-paster --plugin=ckan -c /etc/ckan/production.ini {command}',
                shell=True
            )
            for line in str(answer).replace('\\r', '\\n').split('\\n'):
                if line:
                    logs.info(str(line))
        else:
            answer = logs.subprocess_check_output(
                f'kubectl -n {instance_id} exec -i {pod_name} -- ckan --config /etc/ckan/production.ini {command}',
                shell=True
            )
            for line in str(answer).replace('\\r', '\\n').split('\\n'):
                if line:
                    logs.info(str(line))
Beispiel #2
0
def get(what, *args, required=True, namespace='ckan-cloud', get_cmd='get', **kwargs):
    extra_args = ' '.join(args)
    extra_kwargs = ' '.join([f'{k} {v}' for k, v in kwargs.items()])
    try:
        return yaml.load(
            logs.subprocess_check_output(
                f'kubectl -n {namespace} {get_cmd} {what} {extra_args} -o yaml {extra_kwargs}', shell=True,
            )
        )
    except subprocess.CalledProcessError:
        if required:
            raise
        else:
            return None
Beispiel #3
0
def check_output(cmd, namespace='ckan-cloud'):
    return logs.subprocess_check_output(f'kubectl -n {namespace} {cmd}', shell=True)