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_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 take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['name'] = parsed_args.name opts['image'] = parsed_args.image opts['memory'] = parsed_args.memory opts['cpu'] = parsed_args.cpu opts['environment'] = zun_utils.format_args(parsed_args.environment) opts['workdir'] = parsed_args.workdir opts['labels'] = zun_utils.format_args(parsed_args.label) opts['image_pull_policy'] = parsed_args.image_pull_policy opts['image_driver'] = parsed_args.image_driver opts['auto_remove'] = parsed_args.auto_remove if parsed_args.security_group: opts['security_groups'] = parsed_args.security_group if parsed_args.command: opts['command'] = zun_utils.parse_command(parsed_args.command) if parsed_args.restart: opts['restart_policy'] = \ zun_utils.check_restart_policy(parsed_args.restart) if parsed_args.interactive: opts['interactive'] = True opts['hints'] = zun_utils.format_args(parsed_args.hint) opts['nets'] = zun_utils.parse_nets(parsed_args.net) opts['mounts'] = zun_utils.parse_mounts(parsed_args.mount) opts['runtime'] = parsed_args.runtime opts['hostname'] = parsed_args.hostname opts['disk'] = parsed_args.disk opts['availability_zone'] = parsed_args.availability_zone opts['auto_heal'] = parsed_args.auto_heal opts = zun_utils.remove_null_parms(**opts) container = client.containers.run(**opts) columns = _container_columns(container) container_uuid = getattr(container, 'uuid', None) if parsed_args.interactive: ready_for_attach = False while True: container = client.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'): break print("Waiting for container start") time.sleep(1) if ready_for_attach is True: response = client.containers.attach(container_uuid) websocketclient.do_attach(client, response, container_uuid, "~", 0.5) else: raise exceptions.InvalidWebSocketLink(container_uuid) return columns, utils.get_item_properties(container, columns)
def do_attach(cs, args): """Attach to a running container.""" response = cs.containers.attach(args.container) websocketclient.do_attach(cs, response, args.container, "~", 0.5)
def take_action(self, parsed_args): client = _get_client(self, parsed_args) response = client.containers.attach(parsed_args.container) websocketclient.do_attach(client, response, parsed_args.container, "~", 0.5)
def do_attach(cs, args): """Attach to a running container.""" response = cs.containers.attach(args.container) websocketclient.do_attach(cs, response, args.container, "~", 0.5)