def do_run(cs, args): """Run a command in a new container.""" opts = {} opts['name'] = args.name opts['image'] = args.image opts['memory'] = args.memory opts['cpu'] = args.cpu opts['environment'] = zun_utils.format_args(args.environment) opts['workdir'] = args.workdir opts['auto_remove'] = args.auto_remove opts['labels'] = zun_utils.format_args(args.label) opts['image_pull_policy'] = args.image_pull_policy opts['image_driver'] = args.image_driver opts['hints'] = zun_utils.format_args(args.hint) opts['nets'] = zun_utils.parse_nets(args.net) opts['mounts'] = zun_utils.parse_mounts(args.mount) opts['runtime'] = args.runtime opts['hostname'] = args.hostname opts['disk'] = args.disk opts['availability_zone'] = args.availability_zone opts['command'] = args.command opts['registry'] = args.registry if args.healthcheck: opts['healthcheck'] = zun_utils.parse_health(args.healthcheck) if args.auto_heal: opts['auto_heal'] = args.auto_heal if args.security_group: opts['security_groups'] = args.security_group if args.expose_port: opts['exposed_ports'] = zun_utils.parse_exposed_ports(args.expose_port) if args.restart: opts['restart_policy'] = zun_utils.check_restart_policy(args.restart) if args.interactive: opts['interactive'] = True if args.privileged: opts['privileged'] = True opts = zun_utils.remove_null_parms(**opts) container = cs.containers.run(**opts) _show_container(container) container_uuid = getattr(container, 'uuid', None) if args.interactive: ready_for_attach = False while True: container = cs.containers.get(container_uuid) if zun_utils.check_container_status(container, 'Running'): ready_for_attach = True break if zun_utils.check_container_status(container, 'Error'): raise exceptions.ContainerStateError(container_uuid) print("Waiting for container start") time.sleep(1) if ready_for_attach is True: response = cs.containers.attach(container_uuid) websocketclient.do_attach(cs, response, container_uuid, "~", 0.5) else: raise exceptions.InvalidWebSocketLink(container_uuid)
def do_create(cs, args): """Create a container.""" opts = {} opts['name'] = args.name opts['image'] = args.image opts['memory'] = args.memory opts['cpu'] = args.cpu opts['environment'] = zun_utils.format_args(args.environment) opts['auto_remove'] = args.auto_remove opts['workdir'] = args.workdir opts['labels'] = zun_utils.format_args(args.label) opts['image_pull_policy'] = args.image_pull_policy opts['image_driver'] = args.image_driver opts['hints'] = zun_utils.format_args(args.hint) opts['nets'] = zun_utils.parse_nets(args.net) opts['mounts'] = zun_utils.parse_mounts(args.mount) opts['runtime'] = args.runtime opts['hostname'] = args.hostname opts['disk'] = args.disk opts['availability_zone'] = args.availability_zone opts['command'] = args.command opts['registry'] = args.registry if args.healthcheck: opts['healthcheck'] = zun_utils.parse_health(args.healthcheck) if args.auto_heal: opts['auto_heal'] = args.auto_heal if args.security_group: opts['security_groups'] = args.security_group if args.expose_port: opts['exposed_ports'] = zun_utils.parse_exposed_ports(args.expose_port) if args.restart: opts['restart_policy'] = zun_utils.check_restart_policy(args.restart) if args.interactive: opts['interactive'] = True if args.privileged: opts['privileged'] = True opts = zun_utils.remove_null_parms(**opts) _show_container(cs.containers.create(**opts))