Esempio n. 1
0
    def input_by_ip(self):
        '''
            按照ip地址方式输入,必须验证ip合法性
        '''
        show_header_info('deploy_by_ip')
        while True:
            try:
                realip = raw_input("\n【退到主菜单输入 exit】请输入 \033[1;32;40m  Machine ip \033[0m;  >>")
            # my_lib.writelog("【退到主菜单输入 exit】请输入\033[1;32;40m Machine ip \033[0m;【**Not Vlan IP**】    >>",'i')

                if realip.strip() == "exit":
                    my_lib.writelog("exit",'i')
                    main()
                if len(realip.strip()) == 0:
                    my_lib.writelog("\033[1;31;40m**Error**\033[0m 输入的ip地址非法!\n",'e')
                    continue
                if realip.strip() == "quit":
                    if confirm_quit():
                        sys.exit(1)

            except KeyboardInterrupt:
                sys.exit(1)

            if self.tool.ipFormatChk(realip.strip()):
                real_ip = realip.strip()
            else:
                my_lib.writelog("\033[1;31;40m**Error**\033[0m 输入的ip地址非法!\n",'e')
                continue

            if my_ping.verbose_ping(real_ip):
                break
            else:
                my_lib.writelog("\033[1;31;40m**Error**\033[0m 网络不可达!\n",'e')
            continue

        while True:
            try:
                vlanip = raw_input("\n【退到主菜单输入 exit】请输入\033[1;32;40m VLAN IP \033[0m;  >>")

                if len(vlanip.strip()) == 0:
                    continue
                if vlanip.strip() == "exit":
                    my_lib.writelog("exit",'i')
                    main()
                if vlanip.strip() == "quit":
                    if confirm_quit():
                        sys.exit(1)

            except KeyboardInterrupt:
                sys.exit(1)


            if self.tool.ipFormatChk(vlanip.strip()):
                vlan_ip = vlanip.strip()
            else:
                my_lib.writelog("\033[1;31;40m**Error**\033[0m 输入的ip地址非法!\n",'e')
                continue


            url = "http://10.13.195.150/system/server/getserverinfo?busi_key=ip_switch&mip=%(real_ip)s&vip=%(vlan_ip)s" % {'real_ip':real_ip,'vlan_ip':vlan_ip}

            host_info = self.tool.get_hostinfo_by_ip(url,real_ip,vlan_ip)

            host_info['date_time'] = time.strftime("%Y-%m-%d %H:%M",time.localtime())
            host_info['user'] = getpass.getuser()

            if (host_info):
                result = self.set_info_by_name(host_info,'ip')
                if result == 1:
                    my_lib.writelog("\033[1;32;40m**Success**\033[0m  按照ip方式部署vlan ip 成功!\n",'i')
                    content = my_lib.html_result(host_info,'vc')
                    if self.tool.send_email(content):
                        my_lib.writelog("\033[1;32;40m**Success**\033[0m 发送邮件 成功!\n",'i')
                        return True
                    else:
                        my_lib.writelog("\033[1;31;40m**Error**\033[0m 发送邮件 失败! 请检查收件人是否配置正确.\n",'e')
                        break
                elif result == 2:
                    break
                else:
                    my_lib.writelog("\033[1;31;40m**Error**\033[0m  按照ip方式部署vlan ip 失败!\n",'i')
                    break
            else:
                my_lib.writelog("\033[1;31;40m**Error**\033[0m 无法获取主机信息.\n",'e')
                break

        main()
Esempio n. 2
0
    def input_by_name(self,tag):
        '''
            按照模块名方式输入,输入模块前请提前在bizmonitor平台配置好相关信息
        '''

        host_info = {}
        if tag == "deploy_by_name":
            show_header_info('deploy_by_name')

        elif tag == "switch_has_vlan":
            show_header_info('switch_has_vlan')

        elif tag == "show_vlan_info":
            show_header_info('show_vlan_info')

        while True:
            try:
                mode_name = raw_input("\n【相关Module Name可以在bizop平台(http://bizop.sogou-inc.com)进行查询】\n **请输入模块名称**  >>")
                #mode_name = "centre-dubhe"
                # my_lib.writelog("\n【相关Mode Name可以在bizop平台(http://bizop.sogou-inc.com)进行查询】\n **请输入模块名称** >>",'i',False)
                if mode_name.strip() == "":
                    continue
                elif mode_name.strip() == "exit":
                    my_lib.writelog("exit",'i')
                    main()
                elif mode_name.strip() == "quit":
                    if confirm_quit():
                        sys.exit(1)
            except KeyboardInterrupt:
                sys.exit(1)


            if self.tool.ipFormatChk(mode_name.strip()):
                my_lib.writelog("\033[1;31;40m**Error**\033[0m 输入的模块名非法!\n",'e')
                continue
            else:
                pass

            host_info = self.get_info_by_name(mode_name)

            if host_info:
                host_info['date_time'] = time.strftime("%Y-%m-%d %H:%M",time.localtime())
                host_info['user'] = getpass.getuser()
            else:
                continue

            if tag == 'deploy_by_name':
                result = self.set_info_by_name(host_info,'name')
                if result == 1:
                    my_lib.writelog("\033[1;32;40m**Success**\033[0m 配置vlan ip 成功.\n",'i')
                    content = my_lib.html_result(host_info,'vc')
                    if self.tool.send_email(content):
                        my_lib.writelog("\033[1;32;40m**Success**\033[0m 发送邮件 成功.\n",'i')
                        return
                    else:
                        my_lib.writelog("\033[1;31;40m**Error**\033[0m 发送邮件 失败! 请检查收件人是否配置正确.\n",'e')

                elif result == 2:
                    continue

                else:
                    my_lib.writelog("\033[1;31;40m**Error**\033[0m 配置vlan ip 失败!\n",'e')

            elif tag == 'switch_has_vlan' :
                result = self.switch_remote_vlanip(host_info)
                if  result == 1:
                    my_lib.writelog("\033[1;32;40m**Success**\033[0m 切换vlan ip 成功!\n",'i')
                    content = my_lib.html_result(host_info,'vs')
                    if self.tool.send_email(content):
                        my_lib.writelog("\033[1;32;40m**Success**\033[0m 发送邮件 成功!\n",'i')
                        return True
                    else:
                        my_lib.writelog("\033[1;31;40m**Error**\033[0m 发送邮件 失败! 请检查收件人是否配置正确.\n",'e')
                elif result == 2:
                    continue
                else:
                    my_lib.writelog("\033[1;31;40m**Error**\033[0m 切换vlan ip 失败!\n",'e')

            elif tag == 'switch_no_vlan':
                if self.switch_remote_ip(host_info):
                    my_lib.writelog("\033[1;32;40m**Success**\033[0m 切换server ip 成功!\n",'i')
                    content = my_lib.html_result(host_info,'ms')
                    if self.tool.send_email(content):
                        my_lib.writelog("\033[1;32;40m**Success**\033[0m 发送邮件 成功!\n",'i')
                        return True
                    else:
                        my_lib.writelog("\033[1;31;40m**Error**\033[0m 发送邮件 失败! 请检查收件人是否配置正确.\n",'e')
                else:
                    my_lib.writelog("\033[1;31;40m**Error**\033[0m 切换server ip 失败!\n",'e')

            elif tag == 'show_vlan_info':
                e1 = multiprocessing.Event()
                w1 = multiprocessing.Process(name='block',
                                 target=self.tool.timer_progress,
                                 args=(e1,))
                w1.start()
                self.show_vlanip_info(host_info,'switch')
                e1.set()
                w1.join()
                return True

            elif tag == 'check_vlan_net':
                e1 = multiprocessing.Event()
                w1 = multiprocessing.Process(name='block',
                                 target=self.tool.timer_progress,
                                 args=(e1,))
                w1.start()
                self.check_vlanip_network(host_info)
                e1.set()
                w1.join()
                return True

            else:
                my_lib.writelog("\033[1;31;40m**Error**\033[0m 非法参数.\n",'e')