<s> """<STR_LIT>""" <EOL> from ovs . log . logHandler import LogHandler <EOL> logger = LogHandler . get ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> class OVSMigrator ( object ) : <EOL> """<STR_LIT>""" <EOL> identifier = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ staticmethod <EOL> def migrate ( previous_version , master_ips = None , extra_ips = None ) : <EOL> """<STR_LIT>""" <EOL> working_version = previous_version <EOL> if working_version < <NUM_LIT:1> : <EOL> try : <EOL> from ovs . extensions . generic . configuration import Configuration <EOL> if Configuration . exists ( '<STR_LIT>' ) : <EOL> Configuration . delete ( '<STR_LIT>' , remove_root = True ) <EOL> Configuration . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except : <EOL> logger . exception ( '<STR_LIT>' ) <EOL> working_version = <NUM_LIT:1> <EOL> if working_version < <NUM_LIT:2> : <EOL> try : <EOL> import time <EOL> from ovs . extensions . generic . configuration import Configuration <EOL> if not Configuration . exists ( '<STR_LIT>' ) : <EOL> Configuration . set ( '<STR_LIT>' , False ) <EOL> Configuration . set ( '<STR_LIT>' , time . time ( ) ) <EOL> except : <EOL> logger . exception ( '<STR_LIT>' ) <EOL> working_version = <NUM_LIT:2> <EOL> if working_version < <NUM_LIT:3> : <EOL> try : <EOL> from ovs . extensions . db . arakoon import ArakoonInstaller <EOL> reload ( ArakoonInstaller ) <EOL> from ovs . extensions . db . arakoon . ArakoonInstaller import ArakoonInstaller <EOL> from ovs . extensions . generic . sshclient import SSHClient <EOL> from ovs . extensions . generic . configuration import Configuration <EOL> if master_ips is not None : <EOL> for ip in master_ips : <EOL> client = SSHClient ( ip ) <EOL> if client . dir_exists ( ArakoonInstaller . ARAKOON_CONFIG_DIR ) : <EOL> for cluster_name in client . dir_list ( ArakoonInstaller . ARAKOON_CONFIG_DIR ) : <EOL> try : <EOL> ArakoonInstaller . deploy_cluster ( cluster_name , ip ) <EOL> except : <EOL> pass <EOL> if Configuration . exists ( '<STR_LIT>' ) : <EOL> Configuration . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except : <EOL> logger . exception ( '<STR_LIT>' ) <EOL> working_version = <NUM_LIT:3> <EOL> if working_version < <NUM_LIT:4> : <EOL> try : <EOL> import os <EOL> import json <EOL> from ConfigParser import RawConfigParser <EOL> from ovs . extensions . db . etcd import installer <EOL> reload ( installer ) <EOL> from ovs . extensions . db . etcd . installer import EtcdInstaller <EOL> from ovs . extensions . db . etcd . configuration import EtcdConfiguration <EOL> from ovs . extensions . generic . system import System <EOL> host_id = System . get_my_machine_id ( ) <EOL> etcd_migrate = False <EOL> if EtcdInstaller . has_cluster ( '<STR_LIT:127.0.0.1>' , '<STR_LIT>' ) : <EOL> etcd_migrate = True <EOL> else : <EOL> if master_ips is not None and extra_ips is not None : <EOL> cluster_ip = None <EOL> for ip in master_ips + extra_ips : <EOL> if EtcdInstaller . has_cluster ( ip , '<STR_LIT>' ) : <EOL> cluster_ip = ip <EOL> break <EOL> node_ip = None <EOL> path = '<STR_LIT>' <EOL> if os . path . exists ( path ) : <EOL> with open ( path ) as config_file : <EOL> config = json . load ( config_file ) <EOL> node_ip = config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if node_ip is not None : <EOL> if cluster_ip is None : <EOL> EtcdInstaller . create_cluster ( '<STR_LIT>' , node_ip ) <EOL> EtcdConfiguration . initialize ( ) <EOL> EtcdConfiguration . initialize_host ( host_id ) <EOL> else : <EOL> EtcdInstaller . extend_cluster ( cluster_ip , node_ip , '<STR_LIT>' ) <EOL> EtcdConfiguration . initialize_host ( host_id ) <EOL> etcd_migrate = True <EOL> if etcd_migrate is True : <EOL> path = '<STR_LIT>' <EOL> if os . path . exists ( path ) : <EOL> with open ( path ) as config_file : <EOL> config = json . load ( config_file ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if not EtcdConfiguration . exists ( '<STR_LIT>' ) : <EOL> EtcdConfiguration . set ( '<STR_LIT>' , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> else : <EOL> EtcdConfiguration . set ( '<STR_LIT>' , min ( EtcdConfiguration . get ( '<STR_LIT>' ) , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , config [ '<STR_LIT>' ] ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , { '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] } ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , { '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] } ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , { '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] } ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , { '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] } ) <EOL> EtcdConfiguration . set ( '<STR_LIT>' , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT:user>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT:port>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:port>' ] , <EOL> '<STR_LIT:password>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:password>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] } ) <EOL> host_key = '<STR_LIT>' . format ( host_id ) <EOL> EtcdConfiguration . set ( host_key . format ( '<STR_LIT>' ) , { '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] [ '<STR_LIT>' ] } ) <EOL> EtcdConfiguration . set ( host_key . format ( '<STR_LIT>' ) , config [ '<STR_LIT>' ] ) <EOL> EtcdConfiguration . set ( host_key . format ( '<STR_LIT>' ) , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> EtcdConfiguration . set ( host_key . format ( '<STR_LIT>' ) , config [ '<STR_LIT>' ] . get ( '<STR_LIT>' , { } ) ) <EOL> EtcdConfiguration . set ( host_key . format ( '<STR_LIT>' ) , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> EtcdConfiguration . set ( host_key . format ( '<STR_LIT>' ) , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> path = '<STR_LIT>' . format ( EtcdConfiguration . get ( '<STR_LIT>' ) ) <EOL> if os . path . exists ( path ) : <EOL> config = RawConfigParser ( ) <EOL> config . read ( path ) <EOL> nodes = [ config . get ( node . strip ( ) , '<STR_LIT:location>' ) . strip ( ) <EOL> for node in config . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) ] <EOL> EtcdConfiguration . set ( '<STR_LIT>' , nodes ) <EOL> os . remove ( path ) <EOL> path = '<STR_LIT>' . format ( EtcdConfiguration . get ( '<STR_LIT>' ) ) <EOL> if os . path . exists ( path ) : <EOL> config = RawConfigParser ( ) <EOL> config . read ( path ) <EOL> nodes = [ config . get ( node . strip ( ) , '<STR_LIT:location>' ) . strip ( ) <EOL> for node in config . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) ] <EOL> EtcdConfiguration . set ( '<STR_LIT>' , nodes ) <EOL> os . remove ( path ) <EOL> from ovs . extensions . db . arakoon import ArakoonInstaller <EOL> reload ( ArakoonInstaller ) <EOL> from ovs . extensions . db . arakoon . ArakoonInstaller import ArakoonInstaller , ArakoonClusterConfig <EOL> from ovs . extensions . generic . sshclient import SSHClient <EOL> if master_ips is not None : <EOL> config_dir = '<STR_LIT>' <EOL> for ip in master_ips : <EOL> client = SSHClient ( ip ) <EOL> if client . dir_exists ( config_dir ) : <EOL> for cluster_name in client . dir_list ( config_dir ) : <EOL> try : <EOL> with open ( '<STR_LIT>' . format ( config_dir , cluster_name ) ) as config_file : <EOL> EtcdConfiguration . set ( ArakoonClusterConfig . ETCD_CONFIG_KEY . format ( cluster_name ) , <EOL> config_file . read ( ) , <EOL> raw = True ) <EOL> ArakoonInstaller . deploy_cluster ( cluster_name , ip ) <EOL> except : <EOL> logger . exception ( '<STR_LIT>' . format ( cluster_name , ip ) ) <EOL> client . dir_delete ( config_dir ) <EOL> except : <EOL> logger . exception ( '<STR_LIT>' ) <EOL> working_version = <NUM_LIT:4> <EOL> return working_version </s>
