def do_package_show(mc, args): """Display details for a package.""" try: package = mc.packages.get(args.id) except common_exceptions.HTTPNotFound: raise exceptions.CommandError("Package %s not found" % args.id) else: to_display = dict( id=package.id, type=package.type, owner_id=package.owner_id, name=package.name, fully_qualified_name=package.fully_qualified_name, is_public=package.is_public, enabled=package.enabled, class_definitions=", ".join(package.class_definitions), categories=", ".join(package.categories), tags=", ".join(package.tags), description=package.description ) formatters = { 'class_definitions': utils.text_wrap_formatter, 'categories': utils.text_wrap_formatter, 'tags': utils.text_wrap_formatter, 'description': utils.text_wrap_formatter, } utils.print_dict(to_display, formatters)
def do_environment_session_create(mc, args): """Creates a new configuration session for environment ID.""" environment_id = args.id session_id = mc.sessions.configure(environment_id).id print("Created new session:") formatters = {"id": utils.text_wrap_formatter} utils.print_dict({"id": session_id}, formatters=formatters)
def do_app_show(mc, args): """List applications, added to specified environment.""" if args.path == '/': apps = mc.services.list(args.id) formatters = { 'id': lambda x: getattr(x, '?')['id'], 'type': lambda x: getattr(x, '?')['type'] } field_labels = ['Id', 'Name', 'Type'] fields = ['id', 'name', 'type'] utils.print_list(apps, fields, field_labels, formatters=formatters) else: if not args.path.startswith('/'): args.path = '/' + args.path app = mc.services.get(args.id, args.path) # If app with specified path is not found, it is empty. if hasattr(app, '?'): formatters = {} for key in app.to_dict().keys(): formatters[key] = utils.json_formatter utils.print_dict(app.to_dict(), formatters) else: raise exceptions.CommandError("Could not find application at path" " %s" % args.path)
def do_package_show(mc, args): """Display details for a package.""" try: package = mc.packages.get(args.id) except common_exceptions.HTTPNotFound: raise exceptions.CommandError("Package %s not found" % args.id) else: to_display = dict(id=package.id, type=package.type, owner_id=package.owner_id, name=package.name, fully_qualified_name=package.fully_qualified_name, is_public=package.is_public, enabled=package.enabled, class_definitions=", ".join( package.class_definitions), categories=", ".join(package.categories), tags=", ".join(package.tags), description=package.description) formatters = { 'class_definitions': utils.text_wrap_formatter, 'categories': utils.text_wrap_formatter, 'tags': utils.text_wrap_formatter, 'description': utils.text_wrap_formatter, } utils.print_dict(to_display, formatters)
def do_category_show(mc, args): """Display category details.""" category = mc.categories.get(args.id) to_display = dict(id=category.id, name=category.name, packages=', '.join(p['name'] for p in category.packages)) formatters = {'packages': utils.text_wrap_formatter} utils.print_dict(to_display, formatters)
def do_env_template_create_env(mc, args): """Create a new environment from template.""" try: template = mc.env_templates.create_env(args.id, args.name) except common_exceptions.HTTPNotFound: raise exceptions.CommandError("Environment template %s not found" % args.id) else: formatters = { "environment_id": utils.text_wrap_formatter, "session_id": utils.text_wrap_formatter } utils.print_dict(template.to_dict(), formatters=formatters)
def do_env_template_show(mc, args): """Display environment template details.""" try: env_template = mc.env_templates.get(args.id) except common_exceptions.HTTPNotFound: raise exceptions.CommandError("Environment template %s not found" % args.id) else: formatters = { "id": utils.text_wrap_formatter, "created": utils.text_wrap_formatter, "name": utils.text_wrap_formatter, "tenant_id": utils.text_wrap_formatter, "services": utils.json_formatter, } utils.print_dict(env_template.to_dict(), formatters=formatters)
def do_environment_show(mc, args): """Display environment details.""" try: environment = utils.find_resource(mc.environments, args.id) except exceptions.NotFound: raise exceptions.CommandError("Environment %s not found" % args.id) else: formatters = { "id": utils.text_wrap_formatter, "created": utils.text_wrap_formatter, "name": utils.text_wrap_formatter, "tenant_id": utils.text_wrap_formatter, "services": utils.json_formatter, } utils.print_dict(environment.to_dict(), formatters=formatters)
def do_env_template_clone(mc, args): """Create a new template, cloned from template.""" try: env_template = mc.env_templates.clone(args.id, args.name) except common_exceptions.HTTPNotFound: raise exceptions.CommandError("Environment template %s not found" % args.id) else: formatters = { "id": utils.text_wrap_formatter, "created": utils.text_wrap_formatter, "updated": utils.text_wrap_formatter, "version": utils.text_wrap_formatter, "name": utils.text_wrap_formatter, "tenant_id": utils.text_wrap_formatter, "is_public": utils.text_wrap_formatter, "services": utils.json_formatter, } utils.print_dict(env_template.to_dict(), formatters=formatters)
def do_environment_show(mc, args): """Display environment details.""" try: environment = utils.find_resource(mc.environments, args.id, session_id=args.session_id) except exceptions.NotFound: raise exceptions.CommandError("Environment %s not found" % args.id) else: if getattr(args, 'only_apps', False): print(utils.json_formatter(environment.services)) else: formatters = { "id": utils.text_wrap_formatter, "created": utils.text_wrap_formatter, "name": utils.text_wrap_formatter, "tenant_id": utils.text_wrap_formatter, "services": utils.json_formatter, } utils.print_dict(environment.to_dict(), formatters=formatters)
def do_app_show(mc, args): """List applications, added to specified environment.""" if args.path == '/': apps = mc.services.list(args.id) formatters = {'id': lambda x: getattr(x, '?')['id'], 'type': lambda x: getattr(x, '?')['type']} field_labels = ['Id', 'Name', 'Type'] fields = ['id', 'name', 'type'] utils.print_list(apps, fields, field_labels, formatters=formatters) else: if not args.path.startswith('/'): args.path = '/' + args.path app = mc.services.get(args.id, args.path) # If app with specified path is not found, it is empty. if hasattr(app, '?'): formatters = {} for key in app.to_dict().keys(): formatters[key] = utils.json_formatter utils.print_dict(app.to_dict(), formatters) else: raise exceptions.CommandError("Could not find application at path" " %s" % args.path)