def do_network_list(cs, args): """List networks on a container""" opts = {} opts['container'] = args.container opts = zun_utils.remove_null_parms(**opts) networks = cs.containers.network_list(**opts) zun_utils.list_container_networks(networks)
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.rm 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) if args.security_group: opts['security_groups'] = args.security_group if args.command: opts['command'] = zun_utils.parse_command(args.command) if args.restart: opts['restart_policy'] = zun_utils.check_restart_policy(args.restart) if args.interactive: opts['interactive'] = True opts = zun_utils.remove_null_parms(**opts) _show_container(cs.containers.create(**opts))
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['all_projects'] = parsed_args.all_projects opts['marker'] = parsed_args.marker opts['limit'] = parsed_args.limit opts['sort_key'] = parsed_args.sort_key opts['sort_dir'] = parsed_args.sort_dir opts['image'] = parsed_args.image opts['name'] = parsed_args.name opts['project_id'] = parsed_args.project_id opts['user_id'] = parsed_args.user_id opts['host'] = parsed_args.host opts['task_state'] = parsed_args.task_state opts['memory'] = parsed_args.memory opts['auto_remove'] = parsed_args.auto_remove opts['status'] = parsed_args.status opts = zun_utils.remove_null_parms(**opts) containers = client.containers.list(**opts) for c in containers: zun_utils.format_container_addresses(c) columns = ('uuid', 'name', 'image', 'status', 'task_state', 'addresses', 'ports') return (columns, (utils.get_item_properties(container, columns) for container in containers))
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 = zun_utils.remove_null_parms(**opts) container = client.containers.create(**opts) columns = _container_columns(container) return columns, utils.get_item_properties(container, columns)
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['id'] = parsed_args.registry opts = zun_utils.remove_null_parms(**opts) registry = client.registries.get(**opts) return zip(*sorted(registry._info['registry'].items()))
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['id'] = parsed_args.registry opts = zun_utils.remove_null_parms(**opts) registry = client.registries.get(**opts) return zip(*sorted(six.iteritems(registry._info['registry'])))
def do_registry_create(cs, args): """Create a registry.""" opts = {} opts['name'] = args.name opts['domain'] = args.domain opts['username'] = args.username opts['password'] = args.password opts = zun_utils.remove_null_parms(**opts) _show_registry(cs.registries.create(**opts))
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['id'] = parsed_args.capsule opts = zun_utils.remove_null_parms(**opts) capsule = client.capsules.get(**opts) zun_utils.format_container_addresses(capsule) columns = _capsule_columns(capsule) return columns, utils.get_item_properties(capsule, columns)
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['container'] = parsed_args.container opts = zun_utils.remove_null_parms(**opts) networks = client.containers.network_list(**opts) columns = ('net_id', 'subnet_id', 'port_id', 'version', 'ip_address') return (columns, (utils.get_item_properties(network, columns) for network in networks))
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['name'] = parsed_args.name opts['domain'] = parsed_args.domain opts['username'] = parsed_args.username opts['password'] = parsed_args.password opts = zun_utils.remove_null_parms(**opts) registry = client.registries.create(**opts) return zip(*sorted(registry._info['registry'].items()))
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['id'] = parsed_args.container opts['all_tenants'] = parsed_args.all_tenants opts = zun_utils.remove_null_parms(**opts) container = client.containers.get(**opts) columns = _container_columns(container) return columns, utils.get_item_properties(container, columns)
def do_network_list(cs, args): """List networks on a container""" opts = {} opts['container'] = args.container opts = zun_utils.remove_null_parms(**opts) networks = cs.containers.network_list(**opts) columns = ('net_id', 'subnet_id', 'port_id', 'version', 'ip_address') utils.print_list(networks, columns, {'versions': zun_utils.print_list_field('versions')}, sortby_index=None)
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['name'] = parsed_args.name opts['domain'] = parsed_args.domain opts['username'] = parsed_args.username opts['password'] = parsed_args.password opts = zun_utils.remove_null_parms(**opts) registry = client.registries.create(**opts) return zip(*sorted(six.iteritems(registry._info['registry'])))
def do_update(cs, args): """Update one or more attributes of the container.""" opts = {} opts['memory'] = args.memory opts['cpu'] = args.cpu opts = zun_utils.remove_null_parms(**opts) if not opts: raise exc.CommandError("You must update at least one property") container = cs.containers.update(args.container, **opts) _show_container(container)
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['image_driver'] = parsed_args.image_driver opts['image'] = parsed_args.image_name opts['exact_match'] = parsed_args.exact_match opts = zun_utils.remove_null_parms(**opts) images = client.images.search_image(**opts) columns = ('ID', 'Name', 'Tags', 'Status', 'Size', 'Metadata') return (columns, (utils.get_item_properties(image, columns) for image in images))
def do_commit(cs, args): """Create a new image from a container's changes.""" opts = zun_utils.check_commit_container_args(args) opts = zun_utils.remove_null_parms(**opts) try: image = cs.containers.commit(args.container, **opts) print("Request to commit container %s has been accepted. " "The image is %s." % (args.container, image['uuid'])) except Exception as e: print("Commit for container %(container)s failed: %(e)s" % {'container': args.container, 'e': e})
def do_list(cs, args): """Print a list of available containers.""" opts = {} opts['all_tenants'] = args.all_tenants opts['marker'] = args.marker opts['limit'] = args.limit opts['sort_key'] = args.sort_key opts['sort_dir'] = args.sort_dir opts = zun_utils.remove_null_parms(**opts) containers = cs.containers.list(**opts) zun_utils.list_containers(containers)
def do_capsule_list(cs, args): """Print a list of available capsules.""" opts = {} opts['all_projects'] = args.all_projects opts['marker'] = args.marker opts['limit'] = args.limit opts['sort_key'] = args.sort_key opts['sort_dir'] = args.sort_dir opts = zun_utils.remove_null_parms(**opts) capsules = cs.capsules.list(**opts) zun_utils.list_capsules(capsules)
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_logs(cs, args): """Get logs of a container.""" opts = {} opts['id'] = args.container opts['stdout'] = args.stdout opts['stderr'] = args.stderr opts['since'] = args.since opts['timestamps'] = args.timestamps opts['tail'] = args.tail opts = zun_utils.remove_null_parms(**opts) logs = cs.containers.logs(**opts) print(logs)
def do_registry_update(cs, args): """Update one or more attributes of the registry.""" opts = {} opts['username'] = args.username opts['password'] = args.password opts['domain'] = args.domain opts['name'] = args.name opts = zun_utils.remove_null_parms(**opts) if not opts: raise exc.CommandError("You must update at least one property") registry = cs.registries.update(args.registry, **opts) _show_registry(registry)
def take_action(self, parsed_args): client = _get_client(self, parsed_args) container = parsed_args.container opts = {} opts['memory'] = parsed_args.memory opts['cpu'] = parsed_args.cpu opts = zun_utils.remove_null_parms(**opts) if not opts: raise exc.CommandError("You must update at least one property") container = client.containers.update(container, **opts) columns = _container_columns(container) return columns, utils.get_item_properties(container, columns)
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['marker'] = parsed_args.marker opts['limit'] = parsed_args.limit opts['sort_key'] = parsed_args.sort_key opts['sort_dir'] = parsed_args.sort_dir opts = zun_utils.remove_null_parms(**opts) images = client.images.list(**opts) columns = ('uuid', 'image_id', 'repo', 'tag', 'size') return (columns, (utils.get_item_properties(image, columns) for image in images))
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['id'] = parsed_args.container opts['stdout'] = parsed_args.stdout opts['stderr'] = parsed_args.stderr opts['since'] = parsed_args.since opts['timestamps'] = parsed_args.timestamps opts['tail'] = parsed_args.tail opts = zun_utils.remove_null_parms(**opts) logs = client.containers.logs(**opts) print(logs)
def do_registry_show(cs, args): """Show details of a registry.""" opts = {} opts['id'] = args.registry opts = zun_utils.remove_null_parms(**opts) registry = cs.registries.get(**opts) if args.format == 'json': print(jsonutils.dumps(registry._info, indent=4, sort_keys=True)) elif args.format == 'yaml': print(yaml.safe_dump(registry._info, default_flow_style=False)) elif args.format == 'table': _show_registry(registry)
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['marker'] = parsed_args.marker opts['limit'] = parsed_args.limit opts['sort_key'] = parsed_args.sort_key opts['sort_dir'] = parsed_args.sort_dir opts = zun_utils.remove_null_parms(**opts) hosts = client.hosts.list(**opts) columns = ('uuid', 'hostname', 'mem_total', 'cpus', 'os', 'labels') return (columns, (utils.get_item_properties(host, columns) for host in hosts))
def do_registry_delete(cs, args): """Delete specified registries.""" for registry in args.registries: opts = {} opts['id'] = registry opts = zun_utils.remove_null_parms(**opts) try: cs.registries.delete(**opts) print("Request to delete registry %s has been accepted." % registry) except Exception as e: print("Delete for registry %(registry)s failed: %(e)s" % {'registry': registry, 'e': e})
def do_show(cs, args): """Show details of a container.""" opts = {} opts['id'] = args.container opts['all_projects'] = args.all_projects opts = zun_utils.remove_null_parms(**opts) container = cs.containers.get(**opts) if args.format == 'json': print(jsonutils.dumps(container._info, indent=4, sort_keys=True)) elif args.format == 'yaml': print(yaml.safe_dump(container._info, default_flow_style=False)) elif args.format == 'table': _show_container(container)
def do_remove_security_group(cs, args): """Remove security group for specified container.""" opts = {} opts['id'] = args.container opts['security_group'] = args.security_group opts = zun_utils.remove_null_parms(**opts) try: cs.containers.remove_security_group(**opts) print("Request to remove security group for container %s " "has been accepted." % args.container) except Exception as e: print("Remove security group for container %(container)s " "failed: %(e)s" % {'container': args.container, 'e': e})
def do_add_security_group(cs, args): """Add security group for specified container.""" opts = {} opts['id'] = args.container opts['security_group'] = args.security_group opts = zun_utils.remove_null_parms(**opts) try: cs.containers.add_security_group(**opts) print("Request to add security group for container %s " "has been accepted." % args.container) except Exception as e: print("Add security group for container %(container)s " "failed: %(e)s" % {'container': args.container, 'e': e})
def do_network_attach(cs, args): """Attach a network to the container.""" opts = {} opts['container'] = args.container opts['network'] = args.network opts = zun_utils.remove_null_parms(**opts) try: cs.containers.network_attach(**opts) print("Request to attach network to container %s " "has been accepted." % args.container) except Exception as e: print("Attach network to container %(container)s " "failed: %(e)s" % {'container': args.container, 'e': e})
def take_action(self, parsed_args): client = _get_client(self, parsed_args) registry = parsed_args.registry opts = {} opts['username'] = parsed_args.username opts['password'] = parsed_args.password opts['domain'] = parsed_args.domain opts['name'] = parsed_args.name opts = zun_utils.remove_null_parms(**opts) if not opts: raise exc.CommandError("You must update at least one property") registry = client.registries.update(registry, **opts) return zip(*sorted(six.iteritems(registry._info['registry'])))
def do_host_list(cs, args): """Print a list of available host.""" opts = {} opts['marker'] = args.marker opts['limit'] = args.limit opts['sort_key'] = args.sort_key opts['sort_dir'] = args.sort_dir opts = zun_utils.remove_null_parms(**opts) hosts = cs.hosts.list(**opts) columns = ('uuid', 'hostname', 'mem_total', 'cpus', 'disk_total') utils.print_list(hosts, columns, {'versions': zun_utils.print_list_field('versions')}, sortby_index=None)
def do_network_detach(cs, args): """Detach a network from the container.""" opts = {} opts['container'] = args.container opts['network'] = args.network opts['port'] = args.port opts = zun_utils.remove_null_parms(**opts) try: cs.containers.network_detach(**opts) print("Request to detach network from container %s " "has been accepted." % args.container) except Exception as e: print("Detach network from container %(container)s " "failed: %(e)s" % {'container': args.container, 'e': e})
def take_action(self, parsed_args): client = _get_client(self, parsed_args) registries = parsed_args.registry for registry in registries: opts = {} opts['id'] = registry opts = zun_utils.remove_null_parms(**opts) try: client.registries.delete(**opts) print(_('Request to delete registry %s has been accepted.') % registry) except Exception as e: print("Delete for registry %(registry)s failed: %(e)s" % {'registry': registry, 'e': e})
def do_update(cs, args): """Update one or more attributes of the container.""" opts = {} opts['memory'] = args.memory opts['cpu'] = args.cpu opts['name'] = args.name if 'auto_heal' in args and args.auto_heal: opts['auto_heal'] = True if 'no_auto_heal' in args and args.no_auto_heal: opts['auto_heal'] = False opts = zun_utils.remove_null_parms(**opts) if not opts: raise exc.CommandError("You must update at least one property") container = cs.containers.update(args.container, **opts) _show_container(container)
def do_delete(cs, args): """Delete specified containers.""" for container in args.containers: opts = {} opts['id'] = container opts['force'] = args.force opts['stop'] = args.stop opts['all_projects'] = args.all_projects opts = zun_utils.remove_null_parms(**opts) try: cs.containers.delete(**opts) print("Request to delete container %s has been accepted." % container) except Exception as e: print("Delete for container %(container)s failed: %(e)s" % {'container': container, 'e': e})
def do_kill(cs, args): """Kill one or more running container(s).""" for container in args.containers: opts = {} opts['id'] = container opts['signal'] = args.signal opts = zun_utils.remove_null_parms(**opts) try: cs.containers.kill(**opts) print( "Request to kill signal to container %s has been accepted." % container) except Exception as e: print( "kill signal for container %(container)s failed: %(e)s" % {'container': container, 'e': e})
def take_action(self, parsed_args): client = _get_client(self, parsed_args) opts = {} opts['all_projects'] = parsed_args.all_projects opts['marker'] = parsed_args.marker opts['limit'] = parsed_args.limit opts['sort_key'] = parsed_args.sort_key opts['sort_dir'] = parsed_args.sort_dir opts['domain'] = parsed_args.domain opts['name'] = parsed_args.name opts['project_id'] = parsed_args.project_id opts['user_id'] = parsed_args.user_id opts['username'] = parsed_args.username opts = zun_utils.remove_null_parms(**opts) registries = client.registries.list(**opts) columns = ('uuid', 'name', 'domain', 'username', 'password') return (columns, (utils.get_item_properties(registry, columns) for registry in registries))
def do_registry_list(cs, args): """Print a list of available registries.""" opts = {} opts['all_projects'] = args.all_projects opts['marker'] = args.marker opts['limit'] = args.limit opts['sort_key'] = args.sort_key opts['sort_dir'] = args.sort_dir opts['domain'] = args.domain opts['name'] = args.name opts['project_id'] = args.project_id opts['user_id'] = args.user_id opts['username'] = args.username opts = zun_utils.remove_null_parms(**opts) registries = cs.registries.list(**opts) columns = ('uuid', 'name', 'domain', 'username', 'password') utils.print_list(registries, columns, sortby_index=None)
def do_list(cs, args): """Print a list of available containers.""" opts = {} opts['all_projects'] = args.all_projects opts['marker'] = args.marker opts['limit'] = args.limit opts['sort_key'] = args.sort_key opts['sort_dir'] = args.sort_dir opts['image'] = args.image opts['name'] = args.name opts['project_id'] = args.project_id opts['user_id'] = args.user_id opts['host'] = args.host opts['task_state'] = args.task_state opts['memory'] = args.memory opts['auto_remove'] = args.auto_remove opts['status'] = args.status opts = zun_utils.remove_null_parms(**opts) containers = cs.containers.list(**opts) zun_utils.list_containers(containers)
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))