<s> from cStringIO import StringIO <EOL> import errno <EOL> import logging <EOL> import os <EOL> from ceph_deploy import conf <EOL> from ceph_deploy import exc <EOL> from ceph_deploy import hosts <EOL> from ceph_deploy . util import system <EOL> from ceph_deploy . lib import remoto <EOL> from ceph_deploy . cliutil import priority <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def get_bootstrap_mds_key ( cluster ) : <EOL> """<STR_LIT>""" <EOL> path = '<STR_LIT>' . format ( cluster = cluster ) <EOL> try : <EOL> with file ( path , '<STR_LIT:rb>' ) as f : <EOL> return f . read ( ) <EOL> except IOError : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> def create_mds ( distro , name , cluster , init ) : <EOL> conn = distro . conn <EOL> path = '<STR_LIT>' . format ( <EOL> cluster = cluster , <EOL> name = name <EOL> ) <EOL> conn . remote_module . safe_mkdir ( path ) <EOL> bootstrap_keyring = '<STR_LIT>' . format ( <EOL> cluster = cluster <EOL> ) <EOL> keypath = os . path . join ( path , '<STR_LIT>' ) <EOL> stdout , stderr , returncode = remoto . process . check ( <EOL> conn , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , cluster , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , bootstrap_keyring , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' . format ( name = name ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> os . path . join ( keypath ) , <EOL> ] <EOL> ) <EOL> if returncode > <NUM_LIT:0> and returncode != errno . EACCES : <EOL> for line in stderr : <EOL> conn . logger . error ( line ) <EOL> for line in stdout : <EOL> conn . logger . error ( line ) <EOL> conn . logger . error ( '<STR_LIT>' % returncode ) <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> remoto . process . check ( <EOL> conn , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , cluster , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , bootstrap_keyring , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' . format ( name = name ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> os . path . join ( keypath ) , <EOL> ] <EOL> ) <EOL> conn . remote_module . touch_file ( os . path . join ( path , '<STR_LIT>' ) ) <EOL> conn . remote_module . touch_file ( os . path . join ( path , init ) ) <EOL> if init == '<STR_LIT>' : <EOL> remoto . process . run ( <EOL> conn , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( cluster = cluster ) , <EOL> '<STR_LIT>' . format ( name = name ) , <EOL> ] , <EOL> timeout = <NUM_LIT:7> <EOL> ) <EOL> elif init == '<STR_LIT>' : <EOL> remoto . process . run ( <EOL> conn , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:start>' , <EOL> '<STR_LIT>' . format ( name = name ) , <EOL> ] , <EOL> timeout = <NUM_LIT:7> <EOL> ) <EOL> if distro . is_el : <EOL> system . enable_service ( distro . conn ) <EOL> elif init == '<STR_LIT>' : <EOL> remoto . process . run ( <EOL> conn , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( name = name ) , <EOL> ] , <EOL> timeout = <NUM_LIT:7> <EOL> ) <EOL> remoto . process . run ( <EOL> conn , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:start>' , <EOL> '<STR_LIT>' . format ( name = name ) , <EOL> ] , <EOL> timeout = <NUM_LIT:7> <EOL> ) <EOL> remoto . process . run ( <EOL> conn , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> timeout = <NUM_LIT:7> <EOL> ) <EOL> def mds_create ( args ) : <EOL> cfg = conf . ceph . load ( args ) <EOL> LOG . debug ( <EOL> '<STR_LIT>' , <EOL> args . cluster , <EOL> '<STR_LIT:U+0020>' . join ( '<STR_LIT::>' . join ( x or '<STR_LIT>' for x in t ) for t in args . mds ) , <EOL> ) <EOL> key = get_bootstrap_mds_key ( cluster = args . cluster ) <EOL> bootstrapped = set ( ) <EOL> errors = <NUM_LIT:0> <EOL> failed_on_rhel = False <EOL> for hostname , name in args . mds : <EOL> try : <EOL> distro = hosts . get ( hostname , username = args . username ) <EOL> rlogger = distro . conn . logger <EOL> LOG . info ( <EOL> '<STR_LIT>' , <EOL> distro . name , <EOL> distro . release , <EOL> distro . codename <EOL> ) <EOL> LOG . debug ( '<STR_LIT>' , distro . init ) <EOL> if hostname not in bootstrapped : <EOL> bootstrapped . add ( hostname ) <EOL> LOG . debug ( '<STR_LIT>' , hostname ) <EOL> conf_data = StringIO ( ) <EOL> cfg . write ( conf_data ) <EOL> distro . conn . remote_module . write_conf ( <EOL> args . cluster , <EOL> conf_data . getvalue ( ) , <EOL> args . overwrite_conf , <EOL> ) <EOL> path = '<STR_LIT>' . format ( <EOL> cluster = args . cluster , <EOL> ) <EOL> if not distro . conn . remote_module . path_exists ( path ) : <EOL> rlogger . warning ( '<STR_LIT>' ) <EOL> distro . conn . remote_module . write_keyring ( path , key ) <EOL> create_mds ( distro , name , args . cluster , distro . init ) <EOL> distro . conn . exit ( ) <EOL> except RuntimeError as e : <EOL> if distro . normalized_name == '<STR_LIT>' : <EOL> LOG . error ( '<STR_LIT>' % ( distro . name , distro . release ) ) <EOL> failed_on_rhel = True <EOL> LOG . error ( e ) <EOL> errors += <NUM_LIT:1> <EOL> if errors : <EOL> if failed_on_rhel : <EOL> LOG . error ( <EOL> '<STR_LIT>' <EOL> ) <EOL> raise exc . GenericError ( '<STR_LIT>' % errors ) <EOL> def mds ( args ) : <EOL> if args . subcommand == '<STR_LIT>' : <EOL> mds_create ( args ) <EOL> else : <EOL> LOG . error ( '<STR_LIT>' , args . subcommand ) <EOL> def colon_separated ( s ) : <EOL> host = s <EOL> name = s <EOL> if s . count ( '<STR_LIT::>' ) == <NUM_LIT:1> : <EOL> ( host , name ) = s . split ( '<STR_LIT::>' ) <EOL> return ( host , name ) <EOL> @ priority ( <NUM_LIT:30> ) <EOL> def make ( parser ) : <EOL> """<STR_LIT>""" <EOL> mds_parser = parser . add_subparsers ( dest = '<STR_LIT>' ) <EOL> mds_create = mds_parser . add_parser ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> mds_create . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> nargs = '<STR_LIT:+>' , <EOL> type = colon_separated , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . set_defaults ( <EOL> func = mds , <EOL> ) </s>
