<s> import json <EOL> import logging <EOL> import os <EOL> import six <EOL> from fuel_dev_tools import command <EOL> from fuel_dev_tools import exc <EOL> from fuel_dev_tools import ssh <EOL> DOCKER_CONTAINER_PATH = '<STR_LIT>' <EOL> DOCKER_DEVICEMAPPER_PATH = '<STR_LIT>' <EOL> class DockerMixin ( ssh . SSHMixin ) : <EOL> container = None <EOL> default_command = None <EOL> def get_log_directory ( self ) : <EOL> return '<STR_LIT>' <EOL> def container_command ( self , * commands ) : <EOL> return [ <EOL> '<STR_LIT>' , '<STR_LIT>' , self . get_docker_id ( ) <EOL> ] + list ( commands ) <EOL> def container_command_interactive ( self , * commands ) : <EOL> return [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . get_docker_id ( ) <EOL> ] + list ( commands ) <EOL> def get_container_config ( self ) : <EOL> d = self . get_container_config_directory ( ) <EOL> config = self . ssh_command ( '<STR_LIT>' % d ) . decode ( '<STR_LIT:utf-8>' ) <EOL> return json . loads ( config ) <EOL> def get_container_config_directory ( self ) : <EOL> iid = self . get_docker_id ( ) <EOL> paths = self . ssh_command ( <EOL> '<STR_LIT>' % ( DOCKER_CONTAINER_PATH , iid ) <EOL> ) . decode ( '<STR_LIT:utf-8>' ) <EOL> return os . path . join ( DOCKER_CONTAINER_PATH , paths . split ( ) [ <NUM_LIT:0> ] ) <EOL> def get_container_directory ( self ) : <EOL> iid = self . get_docker_id ( ) <EOL> if not iid : <EOL> raise exc . DockerError ( '<STR_LIT>' ) <EOL> paths = self . ssh_command ( <EOL> '<STR_LIT>' % ( DOCKER_DEVICEMAPPER_PATH , iid ) <EOL> ) . decode ( '<STR_LIT:utf-8>' ) <EOL> return os . path . join ( DOCKER_DEVICEMAPPER_PATH , paths . split ( ) [ <NUM_LIT:0> ] ) <EOL> def get_docker_id ( self , get_exited = False ) : <EOL> """<STR_LIT>""" <EOL> up = self . ssh_command ( <EOL> '<STR_LIT>' % <EOL> self . container <EOL> ) . decode ( '<STR_LIT:utf-8>' ) <EOL> self . print_debug ( '<STR_LIT>' % up ) <EOL> if not up and get_exited : <EOL> self . print_debug ( '<STR_LIT>' ) <EOL> up = self . ssh_command ( <EOL> '<STR_LIT>' % <EOL> self . container <EOL> ) . decode ( '<STR_LIT:utf-8>' ) <EOL> self . print_debug ( '<STR_LIT>' % up ) <EOL> if not up : <EOL> raise exc . DockerError ( <EOL> "<STR_LIT>" % <EOL> self . container <EOL> ) <EOL> return up <EOL> def get_full_docker_id ( self , get_exited = False ) : <EOL> """<STR_LIT>""" <EOL> iid = self . get_docker_id ( get_exited = get_exited ) <EOL> iid = self . ssh_command ( <EOL> "<STR_LIT>" % iid <EOL> ) . decode ( '<STR_LIT:utf-8>' ) . strip ( ) <EOL> return iid <EOL> def get_log_files ( self , args ) : <EOL> log_dir = self . get_log_directory ( ) <EOL> files = '<STR_LIT>' <EOL> if args . files : <EOL> if len ( args . files ) == <NUM_LIT:1> : <EOL> files = '<STR_LIT>' % args . files [ <NUM_LIT:0> ] <EOL> else : <EOL> files = '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( args . files ) <EOL> return os . path . join ( log_dir , files ) <EOL> def restart_container ( self ) : <EOL> result = self . ssh_command ( <EOL> '<STR_LIT>' % self . get_docker_id ( ) <EOL> ) <EOL> self . print_debug ( result ) <EOL> def start_container ( self ) : <EOL> result = self . ssh_command ( <EOL> '<STR_LIT>' % self . get_docker_id ( get_exited = True ) <EOL> ) <EOL> self . print_debug ( result ) <EOL> def stop_container ( self ) : <EOL> result = self . ssh_command ( <EOL> '<STR_LIT>' % self . get_docker_id ( ) <EOL> ) <EOL> self . print_debug ( result ) <EOL> class IdCommand ( command . BaseCommand ) : <EOL> def take_action ( self , parsed_args ) : <EOL> six . print_ ( self . get_docker_id ( get_exited = True ) ) <EOL> class ConfigCommand ( command . BaseCommand ) : <EOL> def take_action ( self , parsed_args ) : <EOL> six . print_ ( json . dumps ( self . get_container_config ( ) , indent = <NUM_LIT:2> ) ) <EOL> class DirCommand ( command . BaseCommand ) : <EOL> def take_action ( self , parsed_args ) : <EOL> six . print_ ( self . get_container_directory ( ) ) <EOL> class LogCommand ( command . BaseCommand ) : <EOL> def get_log_directory ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( LogCommand , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> type = str , <EOL> nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> six . print_ ( <EOL> self . ssh_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . get_log_files ( parsed_args ) <EOL> ) <EOL> ) <EOL> class RestartCommand ( command . BaseCommand ) : <EOL> def take_action ( self , parsed_args ) : <EOL> self . restart_container ( ) <EOL> class RsyncCommand ( command . RsyncCommand ) : <EOL> @ property <EOL> def base_target_dir ( self ) : <EOL> return os . path . join ( <EOL> self . get_container_directory ( ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> class ShellCommand ( command . BaseCommand ) : <EOL> default_command = None <EOL> log = logging . getLogger ( __name__ ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ShellCommand , self ) . get_parser ( prog_name ) <EOL> help_msg = '<STR_LIT>' <EOL> if self . default_command : <EOL> help_msg = '<STR_LIT>' % ( help_msg , self . default_command ) <EOL> parser . add_argument ( <EOL> '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> default = None , <EOL> help = help_msg <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> command = parsed_args . command <EOL> if not command : <EOL> command = self . default_command <EOL> if not command : <EOL> command = '<STR_LIT>' <EOL> return self . ssh_command_interactive ( <EOL> * self . container_command_interactive ( command ) <EOL> ) <EOL> class StartCommand ( command . BaseCommand ) : <EOL> def take_action ( self , parsed_args ) : <EOL> self . start_container ( ) <EOL> class StopCommand ( command . BaseCommand ) : <EOL> def take_action ( self , parsed_args ) : <EOL> self . stop_container ( ) <EOL> class TailCommand ( command . BaseCommand ) : <EOL> def get_log_directory ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( TailCommand , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> type = str , <EOL> nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . ssh_command_interactive ( <EOL> '<STR_LIT>' , '<STR_LIT>' , self . get_log_files ( parsed_args ) <EOL> ) <EOL> class VolumesCommand ( command . BaseCommand ) : <EOL> def take_action ( self , parsed_args ) : <EOL> six . print_ ( <EOL> json . dumps ( <EOL> self . get_container_config ( ) . get ( '<STR_LIT>' , { } ) , indent = <NUM_LIT:2> <EOL> ) <EOL> ) </s>
