def cli(ctx, wipe, scale, pickle_it, task_ids, dry_run): """Delete specified task ids. """ uri = 'tasks/delete' ctx.obj['logger'].debug({ 'uri': uri, 'wipe': wipe, 'scale': scale, 'pickle_it': pickle_it, 'task_ids': task_ids, 'dry_run': dry_run }) delete_task_ids = [] for tid in task_ids: delete_task_ids.append(tid) ctx.obj['logger'].debug({'delete_task_ids': delete_task_ids}) if dry_run: click.echo(format_json({'[DryRun] POST': uri})) return tasks = post(uri, json={"ids": delete_task_ids}) if pickle_it: pickle_object(tasks, 'delete-tasks') click.echo(format_json(tasks.json()))
def cli(ctx, app_id, pickle_it, dry_run): """Destroy app. :param app_id: **required**. Ensure create or update app with this name :type app_id: str Example: :: marathon delete-app --pickle my-app """ uri = 'apps/%s' % app_id ctx.obj['logger'].debug({'app_id': app_id, 'uri': uri}) if dry_run: click.echo(format_json({'[DryRun] DELETE': uri})) return response = delete(uri) ctx.obj['logger'].debug({'response': response}) if pickle_it: pickle_object(response, 'delete-app-{}'.format(app_id)) click.echo(format_json(response.json()))
def cli(ctx, app_id, pickle_it, dry_run, force): """Restart app. :param app_id: **required**. Ensure create or update app with this name :type app_id: str Example: :: marathon restart-app --pickle my-app """ uri = 'apps/%s/restart' % app_id ctx.obj['logger'].debug({'app_id': app_id, 'uri': uri}) if force: uri += '?force=true' if dry_run: click.echo(format_json({'[DryRun] POST': uri})) return response = post(uri) ctx.obj['logger'].debug({'response': response}) if pickle_it: pickle_object(response, 'restart-app-{}'.format(app_id)) click.echo(format_json(response.json()))
def cli(ctx, app_id, template_file, template_vars, pickle_it, dry_run, force): """Update or create an app with id. :param app_id: **required**. Ensure create or update app with this name :type app_id: str :param template_file: **required**. jinja template file :type template_file: file :param template_vars: key value pairs used by the jinja template. - Environment variables: ``env=VAR_NAME`` - Contents of a file: ``file=FILE_NAME`` :type template_vars: mapping Example: :: marathon put-app --dry-run --pickle my-app app.json.j2 prj_key=foo env=AWS_ACCOUNT_ID app_env=dev file=VERSION """ uri = 'apps/' + app_id if force: uri += '/?force=true' ctx.obj['logger'].debug({'app_id': app_id, 'uri': uri, 'template_file': template_file, 'template_vars': template_vars}) jinja_vars = {'app_id': app_id} if template_vars: for var in template_vars: (key, value) = var.split('=') if key == 'env': key = value value = os.getenv(value) elif key == 'file': key = value value = open(key).read().strip() jinja_vars[key] = value app_request = Template(template_file.read()).render(**jinja_vars) app_request = json.loads(app_request) if dry_run: click.echo(format_json(app_request)) return response = put(uri, json=app_request) ctx.obj['logger'].debug({'response': response}) if pickle_it: pickle_object(response, 'put-app-{}'.format(app_id)) click.echo(format_json(response.json()))
def cli(ctx): """Get the ids of all apps deployed to a marathon instance. """ ctx.obj['logger'].debug('Get the ids of all apps deployed to a marathon instance.') apps = get('apps').json() apps = sorted(jmespath.search('apps[*].id', apps)) click.echo(format_json({'app-ids': apps, 'count': len(apps)}))
def cli(ctx, client, *args, **kwargs): if kwargs.get('version', False): return click.echo('aws-lookup version: {}'.format(settings.VERSION)) # kwargs['logger'] = settings.get_logger() if client in ctx.help_option_names: return click.echo(ctx.get_help()) # if client is None: return click.echo(format_json(get_services()))
def cli(ctx, app_ids, pickle_it): """Get apps deployed to a marathon instance. Retrieve all apps when no app ids are given. If an app id is provided, send a GET request for only that app id. If multiple app ids are provided, find those apps and return them. """ ctx.obj['logger'].info('Get all apps deployed to a marathon instance.') uri = 'apps/' if len(app_ids) == 1: uri += app_ids[0] ctx.obj['logger'].debug({'app_ids': app_ids, 'uri': uri}) apps = get(uri) if pickle_it: pickle_object(apps, 'apps') apps = apps.json() if len(app_ids) == 1: click.echo(format_json(apps)) return response = {'apps': [], 'count': 0} apps = apps.get('apps') if len(app_ids) > 1: for app_id in app_ids: if not app_id.startswith('/'): app_id = '/' + app_id for app in apps: if app.get('id') == app_id: response['apps'].append(app) else: response['apps'] = apps response['count'] = len(response['apps']) click.echo(format_json(response))
def cli(ctx, app_id, app_tasks, pickle_it, dry_run): """Kill app tasks. Kill all tasks when no task is given. If a task id is provided, kill only that task. If multiple tasks are provided, kill those tasks. """ uri = 'apps/%s/tasks/' % app_id ctx.obj['logger'].debug({'app_id': app_id, 'tasks': app_tasks, 'uri': uri}) responses = [] if len(app_tasks) == 1: uri += app_tasks[0] if len(app_tasks) > 1: for task_id in app_tasks: if not task_id.startswith('/'): task_id = '/' + task_id if dry_run: click.echo(format_json({'[DryRun] DELETE': uri + task_id})) else: ctx.obj['logger'].info({'DELETE': uri + task_id}) thing = delete(uri + task_id) if pickle_it: __pickle_it(thing, uri + task_id) responses.append(thing.json()) else: if dry_run: click.echo(format_json({'[DryRun] DELETE': uri})) else: ctx.obj['logger'].info({'DELETE': uri}) thing = delete(uri) if pickle_it: __pickle_it(thing, uri) responses.append(thing.json()) click.echo(format_json({'Killed': responses}))
def cli(ctx, app_id, app_versions, pickle_it): """Get app versions. Retrieve all versions when no version is given. If a version id is provided, send a GET request for only that app version. If multiple versions are provided, find those app versions and return them. """ uri = 'apps/%s/versions/' % app_id if len(app_versions) == 1: uri += app_versions[0] ctx.obj['logger'].debug({'app_id': app_id, 'versions': app_versions, 'uri': uri}) versions = get(uri) if pickle_it: pickle_object(versions, 'app-versions-{}'.format(app_id)) versions = versions.json() if len(app_versions) == 1: click.echo(format_json(versions)) return response = {'app_versions': [], 'count': 0} versions = versions.get('versions') if len(app_versions) > 1: for version_id in app_versions: if not version_id.startswith('/'): version_id = '/' + version_id for version in versions: if version == version_id: response['app_versions'].append(get(uri + version_id)) else: response['app_versions'] = versions response['count'] = len(response['app_versions']) click.echo(format_json(response))
def cli(ctx, app_id, pickle_it): """Get app tasks. """ uri = 'apps/%s/tasks/' % app_id ctx.obj['logger'].debug({'app_id': app_id, 'uri': uri}) tasks = get(uri) if pickle_it: pickle_object(tasks, 'app-tasks-{}'.format(app_id)) tasks = tasks.json() tasks = tasks.get('tasks') click.echo(format_json({'app_tasks': tasks, 'count': len(tasks)}))
def get_request(ctx, uri, pickle_it, with_version=True): """Send GET request to Marathon instance. .. versionadded:: 1.1.8 """ response = get(uri, with_version=with_version) ctx.obj['logger'].debug({ 'connection.config': response.connection.config, 'elapsed': str(response.elapsed), 'encoding': response.encoding, 'headers': dict(response.headers), 'status_code': response.status_code, 'url': response.url, }) if pickle_it: pickle_object(response, uri.replace('/', '-')) try: return format_json(response.json()) except: return response.text
import excel_helper import pretty_json json = excel_helper.open_excel_json("file\新建 Microsoft Excel 工作表.xlsx", remove_enter=True) print(pretty_json.format_json(json))
def pformat(json): return format_json(json, 'solarized')
def pformat(output): return format_json(output, 'solarized')