Example #1
0
    def _replace_neutron_l2_proxy_json(self, host_info):
        """
        TODO: to get host ip of proxies, and scp config file of json to these proxies.
        :return:
        """

        log.info('Start to replace neutron l2 proxy json in proxy nodes. self.proxies = %s' % self.proxies)
        log.info('Start to replace neutron l2 proxy json in proxy nodes. host_info = %s' % host_info)

        for proxy in self.proxies:
            log.info('Start to replace neutron l2 proxy json in proxy nodes. proxy = %s' % proxy)
            neutron_network_role = self._get_neutron_role_name(proxy)
            for host in host_info['hosts']:

                roles_list = host['roles']
                local_path_of_neutron_l2_proxy = os.path.join(
                    utils.get_patches_tool_path(), CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                if neutron_network_role in roles_list:
                    proxy_host_ip = host['manageip']
                    log.info('Start remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                    try:
                        # utils.remote_open_root_permit_for_host(proxy_host_ip)
                        ssh = SSHConnection(proxy_host_ip, SysUserInfo.ROOT, SysUserInfo.ROOT_PWD)
                        ssh.put(local_path_of_neutron_l2_proxy, CfgFilePath.NEUTRON_L2_PROXY_PATH)
                        ssh.close()
                        log.info('Finish remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                    except Exception, e:
                        log.error('Exception when remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                        log.error('Exception: %s' % traceback.format_exc())
                    finally:
                        break
Example #2
0
    def config_big_l2_layer_in_proxy_node(self):
        host_list = None
        for i in range(3):
            try:
                host_list = RefCPSService.host_list()
                log.info("get host list success.")
                break
            except Exception as e:
                log.error("get host list error, try again. error: %s" % e.message)
                time.sleep(1)
                continue

        if host_list is None:
            log.error("config big l2 layer for proxies failed, get host list failed.")
            return False

        for proxy in self.proxies:
            # enable l2 remote port
            self.__enable_l2_remote_port_for_proxy__(proxy)

            # copy file
            host_id = self.proxy_match_host[proxy]
            host_ip = None
            for host in host_list["hosts"]:
                if host_id == host["id"]:
                    host_ip = host["manageip"]
                    break

            if host_ip is None:
                log.error("proxy not exist, proxy: %s, proxy id: %s" % (proxy, host_id))
                continue

            log.info('start to replace neutron l2 proxy json in proxy nodes. proxy: %s' % proxy)
            replace_result = False
            for i in range(3):
                try:
                    # utils.remote_open_root_permit_for_host(proxy_host_ip)
                    local_path_of_neutron_l2_proxy = os.path.join(
                        utils.get_patches_tool_path(),
                        CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                    ssh = SSHConnection(host_ip, SysUserInfo.ROOT, SysUserInfo.ROOT_PWD)
                    ssh.put(local_path_of_neutron_l2_proxy, CfgFilePath.NEUTRON_L2_PROXY_PATH)
                    ssh.close()
                    replace_result = True
                    log.info('replace neutron l2 proxy json success, proxy: %s' % proxy)
                    break
                except Exception, e:
                    log.error('replace neutron l2 proxy json error, try again, proxy: %s, error: %s' % (proxy, e.message))
                    time.sleep(1)
                    continue
                finally:
                    ssh.close()
Example #3
0
    def install(self):
        result = 'FAILED'
        patch_files = self.get_patch_files(self.patch_path, self.filters)
        if not patch_files:
            logger.error('No files in %s' % self.patch_path)
        for absolute_path, relative_path in patch_files:
            # installed_path is full install path,
            # for example: /usr/lib/python2.7/dist-packages/nova/conductor/manager.py
            openstack_installed_file = os.path.join(self.openstack_install_path, relative_path)
            # self.bak_patched_file(openstack_installed_file, relative_path)

            copy_dir = os.path.dirname(openstack_installed_file)

            ssh = SSHConnection(self.host_ip, 'root', 'Huawei@CLOUD8!')
            # cp_result = CommonCMD.cp_to(absolute_path, openstack_installed_file)
            try:
                if not stat.S_ISDIR(ssh.get_sftp().stat(copy_dir).st_mode):
                    log.info('create dir: %s' % copy_dir)
                    ssh.get_sftp().mkdir(copy_dir)
                ssh.put(absolute_path, openstack_installed_file)
            except IOError, e:
                if e.args[1] == 'No such file':
                    log.info('There is no such dir in host: %s, create dir: %s' % (self.host_ip, copy_dir))
                    ssh.get_sftp().mkdir(copy_dir)
                else:
                     error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                     log.error(error_message)
                     print(error_message)
            except Exception, e:
                error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                log.error(error_message)
                print(error_message)
Example #4
0
    def _replace_neutron_l2_proxy_json(self, host_info):
        """
        TODO: to get host ip of proxies, and scp config file of json to these proxies.
        :return:
        """
        log.info('Start to replace neutron l2 proxy json in proxy nodes..')
        print('Start to replace neutron l2 proxy json..')
        for proxy in self.proxies:
            neutron_network_role = self._get_neutron_role_name(proxy)
            for host in host_info['hosts']:
                roles_list = host['roles']
                local_path_of_neutron_l2_proxy = os.path.join(
                    utils.get_patches_tool_path(),
                    CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                if neutron_network_role in roles_list:
                    proxy_host_ip = host['manageip']
                    log.info(
                        'Start remote copy neutron l2 proxy json to host: %s' %
                        proxy_host_ip)
                    try:
                        utils.remote_open_root_permit_for_host(proxy_host_ip)
                        ssh = SSHConnection(proxy_host_ip, SysUserInfo.ROOT,
                                            SysUserInfo.ROOT_PWD)
                        ssh.put(local_path_of_neutron_l2_proxy,
                                CfgFilePath.NEUTRON_L2_PROXY_PATH)
                        ssh.close()
                    except Exception, e:
                        log.error(
                            'Exception when remote copy neutron l2 proxy json to host: %s'
                            % proxy_host_ip)
                        log.error('Exception: %s' % traceback.format_exc())

                    log.info(
                        'Finish remote copy neutron l2 proxy json to host: %s'
                        % proxy_host_ip)
Example #5
0
    def install(self):
        result = 'FAILED'
        patch_files = self.get_patch_files(self.patch_path, self.filters)
        if not patch_files:
            logger.error('No files in %s' % self.patch_path)
        for absolute_path, relative_path in patch_files:
            # installed_path is full install path,
            openstack_installed_file = os.path.join(self.openstack_install_path, relative_path)

            copy_dir = os.path.dirname(openstack_installed_file)

            ssh = SSHConnection(self.host_ip, 'root', 'Huawei@CLOUD8!')
            try:
                if not stat.S_ISDIR(ssh.get_sftp().stat(copy_dir).st_mode):
                    log.info('create dir: %s' % copy_dir)
                    ssh.get_sftp().mkdir(copy_dir)
                ssh.put(absolute_path, openstack_installed_file)
            except IOError, e:
                if e.args[1] == 'No such file':
                    log.info('There is no such dir in host: %s, create dir: %s' % (self.host_ip, copy_dir))
                    cmd = "mkdir -p %s" % copy_dir
                    utils.remote_execute_cmd(host_ip=self.host_ip, user="******", passwd="Huawei@CLOUD8!", cmd=cmd)
                else:
                     error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                     log.error(error_message)
                     print(error_message)
            except Exception, e:
                error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                log.error(error_message)
                print(error_message)
Example #6
0
    def install(self):
        result = 'FAILED'
        patch_files = self.get_patch_files(self.patch_path, self.filters)
        if not patch_files:
            logger.error('No files in %s' % self.patch_path)
        for absolute_path, relative_path in patch_files:
            # installed_path is full install path,
            # for example: /usr/lib/python2.7/dist-packages/nova/conductor/manager.py
            openstack_installed_file = os.path.join(
                self.openstack_install_path, relative_path)
            # self.bak_patched_file(openstack_installed_file, relative_path)

            copy_dir = os.path.dirname(openstack_installed_file)

            ssh = SSHConnection(self.host_ip, 'root', 'Huawei@CLOUD8!')
            # cp_result = CommonCMD.cp_to(absolute_path, openstack_installed_file)
            try:
                if not stat.S_ISDIR(ssh.get_sftp().stat(copy_dir).st_mode):
                    log.info('create dir: %s' % copy_dir)
                    ssh.get_sftp().mkdir(copy_dir)
                ssh.put(absolute_path, openstack_installed_file)
            except IOError, e:
                if e.args[1] == 'No such file':
                    log.info(
                        'There is no such dir in host: %s, create dir: %s' %
                        (self.host_ip, copy_dir))
                    ssh.get_sftp().mkdir(copy_dir)
                else:
                    error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                               % (openstack_installed_file, e.args)
                    log.error(error_message)
                    print(error_message)
            except Exception, e:
                error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                log.error(error_message)
                print(error_message)
Example #7
0
    def upload(self):
        remote_host = Deploy.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                        'hostname')
        remote_port = Deploy.config.getint(Const.CONFIG_SECTIONS_REMOTE,
                                           'port')
        remote_user = Deploy.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                        'username')
        remote_passwd = Deploy.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                          'password')
        print('romote_host: ', remote_host, ", remote_user: ", remote_user)

        # 建立远程连接
        ssh = SSHConnection.SSHConnection(remote_host, remote_port,
                                          remote_user, remote_passwd)
        ssh.ssh_client()
        # 上传
        srcdir = Deploy.config.get(Const.CONFIG_SECTIONS_LOCAL, 'localdir')
        destdir = Deploy.config.get(Const.CONFIG_SECTIONS_REMOTE, 'remotedir')
        ssh.upload_dir(srcdir, destdir)
Example #8
0
    def install(self):
        result = 'FAILED'
        patch_files = self.get_patch_files(self.patch_path, self.filters)
        if not patch_files:
            logger.error('No files in %s' % self.patch_path)
        for absolute_path, relative_path in patch_files:
            # installed_path is full install path,
            openstack_installed_file = os.path.join(
                self.openstack_install_path, relative_path)

            copy_dir = os.path.dirname(openstack_installed_file)

            ssh = SSHConnection(self.host_ip, 'root', 'Huawei@CLOUD8!')
            try:
                if not stat.S_ISDIR(ssh.get_sftp().stat(copy_dir).st_mode):
                    log.info('create dir: %s' % copy_dir)
                    ssh.get_sftp().mkdir(copy_dir)
                ssh.put(absolute_path, openstack_installed_file)
            except IOError, e:
                if e.args[1] == 'No such file':
                    log.info(
                        'There is no such dir in host: %s, create dir: %s' %
                        (self.host_ip, copy_dir))
                    cmd = "mkdir -p %s" % copy_dir
                    utils.remote_execute_cmd(host_ip=self.host_ip,
                                             user="******",
                                             passwd="Huawei@CLOUD8!",
                                             cmd=cmd)
                else:
                    error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                               % (openstack_installed_file, e.args)
                    log.error(error_message)
                    print(error_message)
            except Exception, e:
                error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                log.error(error_message)
                print(error_message)
Example #9
0
    def deploy(self):
        start = int(round(time.time() * 1000))

        CONFIG_SECTIONS_GLOBAL = 'global'
        CONFIG_SECTIONS_LOCAL = 'local'
        CONFIG_SECTIONS_REMOTE = 'remote'

        NOW = time.strftime('%Y%m%d_%H%M%S')

        print('loading config file:', self.__config_file)
        config = configparser.ConfigParser()
        config.read(self.__config_file)
        print('loading config file success!')

        # global
        PROJECT_NAME = config.get(CONFIG_SECTIONS_GLOBAL, 'project_name')
        ENV = config.get(CONFIG_SECTIONS_GLOBAL, 'env')

        # local
        LOCAL_PROJECT_DIR = config.get(CONFIG_SECTIONS_LOCAL, 'project_dir')
        SRC = LOCAL_PROJECT_DIR + '/target/ROOT.war'

        # remote
        REMOTE_HOSTNAME = config.get(CONFIG_SECTIONS_REMOTE, 'hostname')
        REMOTE_PORT = config.getint(CONFIG_SECTIONS_REMOTE, 'port')
        REMOTE_USERNAME = config.get(CONFIG_SECTIONS_REMOTE, 'username')
        REMOTE_PASSWORD = config.get(CONFIG_SECTIONS_REMOTE, 'password')

        REMOTE_DB_USERNAME = config.get(CONFIG_SECTIONS_REMOTE, 'db_username')
        REMOTE_DB_PASSWORD = config.get(CONFIG_SECTIONS_REMOTE, 'db_password')
        REMOTE_DB_PORT = config.get(CONFIG_SECTIONS_REMOTE, 'db_port')
        REMOTE_DB_NAME = config.get(CONFIG_SECTIONS_REMOTE, 'db_name')

        TMP_DIR = config.get(CONFIG_SECTIONS_REMOTE, 'tmp_dir')
        BAK_DIR = config.get(CONFIG_SECTIONS_REMOTE, 'bak_dir')
        BAK_DB_DIR = BAK_DIR + '/db'
        BAK_APP_DIR = BAK_DIR + '/app'

        TOMCAT_HOME = config.get(CONFIG_SECTIONS_REMOTE, 'tomcat_home')
        APP_TEST_URL = config.get(CONFIG_SECTIONS_REMOTE, 'app_test_url')

        KEY_MAVEN_HOME = 'MAVEN_HOME'
        MAVEN_HOME = os.getenv(KEY_MAVEN_HOME)

        if (MAVEN_HOME == None):
            print('没有配置环境变量[' + KEY_MAVEN_HOME + ']')
            os._exit(0)

        # 本地打包
        cmd = MAVEN_HOME + '/bin/mvn -f' + LOCAL_PROJECT_DIR + '/pom.xml package -Denv=' + ENV + ' -Dmaven.test.skip=true -q'
        print('Running local command:', cmd)
        os.system(cmd)
        print('Running local command success, file path:', SRC)

        # 建立远程连接
        ssh = SSHConnection.SSHConnection(REMOTE_HOSTNAME, REMOTE_PORT,
                                          REMOTE_USERNAME, REMOTE_PASSWORD)
        ssh.SSHClient()

        # war包上传
        ssh.upload(SRC, TMP_DIR + '/ROOT.war')

        # 远程数据库备份
        print('backup database....')
        ssh.exec_command('mysqldump -u' + REMOTE_DB_USERNAME + ' -p' +
                         REMOTE_DB_PASSWORD + ' ' + ' -P' + REMOTE_DB_PORT +
                         ' ' + REMOTE_DB_NAME + ' > ' + BAK_DB_DIR + '/' +
                         NOW + '.sql')
        print('backup database success')

        # 远程关闭tomcat
        print('stop tomcat....')
        ssh.exec_command(TOMCAT_HOME + '/bin/shutdown.sh')
        print('stop tomcat success')

        print('kill process....')
        ssh.exec_command(
            'ps -ef | grep ' + TOMCAT_HOME +
            ' | grep -v grep | awk \'{print $2}\' | xargs kill -15')
        print('kill process success')

        # 远程备份应用
        print('backup webapp....')
        ssh.exec_command('cp -r ' + TOMCAT_HOME + '/webapps/ROOT ' +
                         BAK_APP_DIR + '/' + NOW)
        print('backup webapp success')

        # 远程删除工程
        print('remove project....')
        ssh.exec_command('rm -rf ' + TOMCAT_HOME + '/webapps/ROOT*')
        print('remove project success')

        # 远程清空缓存
        print('remove work....')
        ssh.exec_command('rm -rf ' + TOMCAT_HOME + '/work')
        print('remove work success')

        # 远程移动war到tomcat下
        print('mv war....')
        SRC = TMP_DIR + '/ROOT.war'
        DST = TOMCAT_HOME + '/webapps/'
        ssh.exec_command('mv %s %s' % (SRC, DST))
        print('mv war success: %s --> %s' % (SRC, DST))

        # 远程启动tomcat
        print('start tomcat....')
        ssh.exec_command(TOMCAT_HOME + '/bin/startup.sh')
        print('start tomcat success')

        # 关闭连接
        ssh.close()

        # 检测是否成功
        print('connectionning', APP_TEST_URL, '....')
        response = urllib.request.urlopen(APP_TEST_URL)
        print('connection', APP_TEST_URL, ' http code:', response.getcode())
        if (response.getcode() == 200):
            print('Success!')
        else:
            print('Fail !!!')

        end = int(round(time.time() * 1000))

        print('deploy %s use time %dms.' % (PROJECT_NAME, (end - start)))
Example #10
0
    def deploy(self):
        start = int(round(time.time() * 1000))
        now = time.strftime('%Y%m%d_%H%M%S')

        # global
        project_name = self.config.get(Const.CONFIG_SECTIONS_GLOBAL,
                                       'project_name')
        env = self.config.get(Const.CONFIG_SECTIONS_GLOBAL, 'env')

        # local
        project_dir = self.config.get(Const.CONFIG_SECTIONS_LOCAL,
                                      'project_dir')
        war_location = self.config.get(Const.CONFIG_SECTIONS_LOCAL,
                                       'war_location')

        # remote
        remote_hostname = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                          'hostname')
        remote_port = self.config.getint(Const.CONFIG_SECTIONS_REMOTE, 'port')
        remote_username = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                          'username')
        remote_password = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                          'password')

        remote_db_username = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                             'db_username')
        remote_db_password = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                             'db_password')
        remote_db_port = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                         'db_port')
        remote_db_name = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                         'db_name')

        tmp_dir = self.config.get(Const.CONFIG_SECTIONS_REMOTE, 'tmp_dir')
        bak_dir = self.config.get(Const.CONFIG_SECTIONS_REMOTE, 'bak_dir')
        bak_db_dir = bak_dir + '/db'
        bak_app_dir = bak_dir + '/app'

        tomcat_home = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                      'tomcat_home')
        app_test_url = self.config.get(Const.CONFIG_SECTIONS_REMOTE,
                                       'app_test_url')

        key_maven_home = 'MAVEN_HOME'
        maven_home = os.getenv(key_maven_home)

        if maven_home is None:
            print('没有配置环境变量[' + key_maven_home + ']')
            return

        # 本地打包
        cmd = 'mvn -f ' + project_dir + '/pom.xml clean install -Dmaven.test.skip=true -P ' + env + ' -q'
        print('Running local command:', cmd)
        os.system(cmd)
        print('Running local command success')

        # 建立远程连接
        ssh = SSHConnection.SSHConnection(remote_hostname, remote_port,
                                          remote_username, remote_password)
        ssh.ssh_client()

        # war包上传
        ssh.upload(war_location, tmp_dir + '/everobo.war')

        # 远程数据库备份
        print('backup database....')
        ssh.exec_command('mysqldump -u' + remote_db_username + ' -p' +
                         remote_db_password + ' ' + ' -P' + remote_db_port +
                         ' ' + remote_db_name + ' > ' + bak_db_dir + '/' +
                         now + '.sql')
        print('backup database success')

        # 远程关闭tomcat
        print('shutdown tomcat....')
        ssh.exec_command(tomcat_home + '/bin/shutdown.sh')
        print('stop tomcat success')

        print('kill tomcat process....')
        ssh.exec_command(
            'ps -ef | grep ' + tomcat_home +
            ' | grep -v grep | awk \'{print $2}\' | xargs kill -15')
        print('kill tomcat process success')

        # 远程备份应用
        print('backup webapp....')
        ssh.exec_command('cp -r ' + tomcat_home + '/webapps/everobo* ' +
                         bak_app_dir + '/' + now)
        print('backup webapp success')

        # 远程删除工程
        print('remove project....')
        ssh.exec_command('rm -rf ' + tomcat_home + '/webapps/everobo*')
        print('remove project success')

        # 远程清空缓存
        print('remove work....')
        ssh.exec_command('rm -rf ' + tomcat_home + '/work')
        print('remove work success')

        # 远程移动war到tomcat下
        print('mv war....')
        src = tmp_dir + '/everobo.war'
        dst = tomcat_home + '/webapps/'
        ssh.exec_command('mv %s %s' % (src, dst))
        print('mv war success: %s --> %s' % (src, dst))

        # 远程启动tomcat
        print('start tomcat....')
        ssh.exec_command(tomcat_home + '/bin/startup.sh')
        print('start tomcat success')

        # 关闭连接
        ssh.close()

        print('wait tomcat to starting....')
        for i in range(1, 5):
            time.sleep(1)
            print('already wait %d second ' % i)

        # 检测是否成功
        print('connectionning ', app_test_url, '....')
        response = urllib.request.urlopen(app_test_url)
        print('connection', app_test_url, ' http code:', response.getcode())
        if response.getcode() is 200:
            print('Success!')
        else:
            print('Fail !!!')

        end = int(round(time.time() * 1000))
        print('deploy %s use time %dms.' % (project_name, (end - start)))
Example #11
0
    def deploy(self):
        start = int(round(time.time() * 1000))



        NOW = time.strftime('%Y%m%d_%H%M%S')

        print ('loading config file:', self.config_file)
        config = configparser.ConfigParser()
        config.read(self.config_file)
        print ('loading config file success!')

        # global
        project_name = config.get('global', 'project_name')
        war_name = project_name+'-0.1.war'
        config__file_name = 'app-config.properties'

        # ENV = config.get('global', 'env')

        # local
        local_package_dir = config.get('local', 'local_package_dir')
        local_config_dir = config.get('local', 'local_config_dir')
        src = local_package_dir + '/'+war_name
        config_file =local_config_dir + '/'+config__file_name


        # remote
        hostname = config.get('remote', 'hostname')
        port = config.getint('remote', 'port')
        username = config.get('remote', 'username')
        password = config.get('remote', 'password')



        remote_package_dir = config.get('remote', 'remote_package_dir')
        remote_config_dir = config.get('remote', 'remote_config_dir')


        tomcat_home = config.get('remote', 'tomcat_home')
        app_test_url = config.get('remote', 'app_test_url')

        # 建立远程连接
        ssh = SSHConnection.SSHConnection(hostname, port, username, password)
        ssh.SSHClient()

        # war包上传
        # ssh.upload(src, tmp_dir + '/bosspe-01.war')
        ssh.upload(src, remote_package_dir+'/'+war_name)
        ssh.upload(config_file,remote_config_dir+ '/'+config__file_name)



        # 远程关闭tomcat
        print ('stop tomcat....')
        ssh.exec_command(tomcat_home + '/bin/shutdown.sh')
        print ('stop tomcat success')

        print ('kill process....')
        ssh.exec_command('ps -ef | grep ' + tomcat_home + ' | grep -v grep | awk \'{print $2}\' | xargs kill -15')
        print ('kill process success')



        # # 远程解压war到tomcat下
        # print ('unzip war....')
        # # src = tmp_dir + '/bosspe-01.war'
        # src=remote_package_dir +'/'+war_name
        # # dst = tomcat_home + '/webapps/bosspe'
        # dst = tomcat_home + '/webapps/'+project_name
        # ssh.exec_command('unzip -o  %s -d  %s' % (src, dst))
        # print ('unzip war success: %s --> %s' % (src, dst))

        # 远程拷贝config文件到tomcat下
        print ('cp config....')
        src = remote_config_dir + '/'+config__file_name
        dst = tomcat_home + '/webapps/'+project_name+'/WEB-INF/classes'
        ssh.exec_command('cp %s %s' % (src, dst))
        print ('cp config success: %s --> %s' % (src, dst))



        # # 远程启动tomcat
        # print ('start tomcat....')
        # ssh.exec_command(tomcat_home + '/bin/startup.sh')
        # print ('start tomcat success')

        # 关闭连接
        ssh.close()
Example #12
0
    def config_big_l2_layer_in_proxy_node(self):
        host_list = None
        for i in range(3):
            try:
                host_list = RefCPSService.host_list()
                log.info("get host list success.")
                break
            except Exception as e:
                log.error("get host list error, try again. error: %s" %
                          e.message)
                time.sleep(1)
                continue

        if host_list is None:
            log.error(
                "config big l2 layer for proxies failed, get host list failed."
            )
            return False

        for proxy in self.proxies:
            # enable l2 remote port
            self.__enable_l2_remote_port_for_proxy__(proxy)

            # copy file
            host_id = self.proxy_match_host[proxy]
            host_ip = None
            for host in host_list["hosts"]:
                if host_id == host["id"]:
                    host_ip = host["manageip"]
                    break

            if host_ip is None:
                log.error("proxy not exist, proxy: %s, proxy id: %s" %
                          (proxy, host_id))
                continue

            log.info(
                'start to replace neutron l2 proxy json in proxy nodes. proxy: %s'
                % proxy)
            replace_result = False
            for i in range(3):
                try:
                    # utils.remote_open_root_permit_for_host(proxy_host_ip)
                    local_path_of_neutron_l2_proxy = os.path.join(
                        utils.get_patches_tool_path(),
                        CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                    ssh = SSHConnection(host_ip, SysUserInfo.ROOT,
                                        SysUserInfo.ROOT_PWD)
                    ssh.put(local_path_of_neutron_l2_proxy,
                            CfgFilePath.NEUTRON_L2_PROXY_PATH)
                    ssh.close()
                    replace_result = True
                    log.info(
                        'replace neutron l2 proxy json success, proxy: %s' %
                        proxy)
                    break
                except Exception, e:
                    log.error(
                        'replace neutron l2 proxy json error, try again, proxy: %s, error: %s'
                        % (proxy, e.message))
                    time.sleep(1)
                    continue
                finally:
                    ssh.close()
Example #13
0
    def deploy(self):
        start = int(round(time.time() * 1000))
        NOW = time.strftime('%Y%m%d_%H%M%S')
        row_count = self.mydata.get_lines()

        for i in row_count:
            is_run = self.mydata.get_isrun(i)
            if is_run:
                project_name = self.mydata.get_proname(i)
                war_name = self.mydata.get_warname(i)
                config_name = self.mydata.get_configname(i)
                local_dir = self.mydata.get_localdir(i)
                remote_dir = self.mydata.get_remotedir(i)
                tomcat_dir = self.mydata.get_tomcatdir(i)
                test_url = self.mydata.get_testurl(i)
                src_war = local_dir + '/' + war_name
                src_config = local_dir + '/' + config_name
                hostname = self.mydata.get_remoteIP(i)

                # 建立远程连接
                ssh = SSHConnection.SSHConnection(hostname, 22, 'root',
                                                  '123456')
                ssh.SSHClient()

                # war包上传
                # ssh.upload(src, tmp_dir + '/bosspe-01.war')
                ssh.upload(src_war, remote_dir + '/' + war_name)
                ssh.upload(src_config, remote_dir + '/' + config_name)

                # 远程关闭tomcat
                print('stop tomcat....')
                ssh.exec_command(tomcat_dir + '/bin/shutdown.sh')
                print('stop tomcat success')

                print('kill process....')
                ssh.exec_command(
                    'ps -ef | grep ' + tomcat_dir +
                    ' | grep -v grep | awk \'{print $2}\' | xargs kill -15')
                print('kill process success')

                # # 远程解压war到tomcat下
                # print ('unzip war....')
                # # src = tmp_dir + '/bosspe-01.war'
                # src=remote_dir +'/'+war_name
                # # dst = tomcat_home + '/webapps/bosspe'
                # dst = tomcat_dir + '/webapps/'+project_name
                # ssh.exec_command('unzip -o  %s -d  %s' % (src, dst))
                # print ('unzip war success: %s --> %s' % (src, dst))
                #
                # # 远程拷贝config文件到tomcat下
                # print ('cp config....')
                # src = remote_dir + '/'+config_name
                # dst = tomcat_dir + '/webapps/'+project_name+'/WEB-INF/classes'
                # ssh.exec_command('cp %s %s' % (src, dst))
                # print ('cp config success: %s --> %s' % (src, dst))

                # # 远程启动tomcat
                # print ('start tomcat....')
                # ssh.exec_command(tomcat_home + '/bin/startup.sh')
                # print ('start tomcat success')

                # 关闭连接
                ssh.close()
Example #14
0
    def deploy(self):

        start = int(round(time.time() * 1000))
        NOW = time.strftime('%Y%m%d_%H%M%S')
        row_count = self.mydata.get_lines()
        print type(row_count)
        for i in range(1, row_count):
            is_run = self.mydata.get_isrun(i)
            if is_run:
                project_name = self.mydata.get_proname(i)
                print 'project name: ' + project_name
                war_name = self.mydata.get_warname(i)
                print 'war name: ' + war_name
                config_name = self.mydata.get_configname(i)
                print 'config_name:' + config_name
                local_dir = self.mydata.get_localdir(i)
                print 'local dir: ' + local_dir
                ftp_dir = self.mydata.get_ftpdir(i)
                print 'ftp dir ' + ftp_dir
                ftp_war = ftp_dir + '/' + war_name
                # ftp_war=ftp_war.encode('utf-8')
                remote_config = self.mydata.get_remote_config(i)
                print 'remote_config: ' + remote_config
                remote_package = self.mydata.get_remote_package(i)
                print 'remote_package: ' + remote_package
                tomcat_dir = self.mydata.get_tomcatdir(i)
                print 'tomcat_dir: ' + tomcat_dir
                test_url = self.mydata.get_testurl(i)
                print 'test_url: ' + test_url
                src_war = local_dir + '\\' + war_name
                print 'src_war: ' + src_war
                src_config = local_dir + '\\' + config_name
                print 'src_config: ' + src_config
                hostname = self.mydata.get_remoteIP(i)
                print 'hostname: ' + hostname

                # 建立远程连接
                ssh = SSHConnection.SSHConnection(hostname, 22, 'root',
                                                  '123456')
                ssh.SSHClient()

                #从ftp下载包到本地
                print 'download war from ftp...' + ftp_dir + '/' + war_name
                myftp = FTPConnection.FTPConnection('192.168.15.204', 'write',
                                                    '123456')
                myftp.downloadfile(ftp_war.encode('utf-8'), src_war)
                print "download war from ftp success"

                # war包上传
                # ssh.upload(src, tmp_dir + '/bosspe-01.war')
                print 'start upload war...' + remote_package + '/' + war_name
                ssh.upload(src_war, remote_package + '/' + war_name)
                print 'start upload cinfig...' + remote_config + '/' + config_name
                ssh.upload(src_config, remote_config + '/' + config_name)

                # 远程关闭tomcat
                print 'stop tomcat....'
                ssh.exec_command(tomcat_dir + '/bin/shutdown.sh')
                print 'stop tomcat success'

                print 'kill process....'
                ssh.exec_command(
                    'ps -ef | grep ' + tomcat_dir +
                    ' | grep -v grep | awk \'{print $2}\' | xargs kill -15')
                print 'kill process success'

                #
                # # 远程备份配置文件
                # print ('backup webapp....')
                # ssh.exec_command('cp -r ' + tomcat_dir + '/webapps/'+project_name+'/WEB-INF/classes/app-config.properties'  self.backup_dir + '/'+project_name+'/'+self.now)
                # print ('backup webapp success')

                #删除项目目录下的所有文件
                print 'delete all files...'
                ssh.exec_command('rm -rf ' + tomcat_dir + '/webapps/' +
                                 project_name + '/*')
                print 'delete all files success!'

                # 远程解压war到tomcat下
                print 'unzip war....'
                src_war = remote_package + '/' + war_name

                #clinicpad 项目解压路径
                if project_name == 'clinicpad' and hostname == '192.168.14.64':
                    dst_war = tomcat_dir + '/webapps/ROOT'
                else:
                    dst_war = tomcat_dir + '/webapps/' + project_name

                ssh.exec_command('unzip -o  %s -d  %s' % (src_war, dst_war))
                print('unzip war success: %s --> %s' % (src_war, dst_war))

                # 远程拷贝config文件到tomcat下
                print('cp config....')
                src_config = remote_config + '/' + config_name
                dst_config = dst_war + '/WEB-INF/classes'
                ssh.exec_command('cp %s %s' % (src_config, dst_config))
                print('cp config success: %s --> %s' %
                      (src_config, dst_config))