from ..model.weather_model import weather_location
    from ..model.weather_model import weather_data

except:
    import sys
    sys.path.append('../')
    sys.path.append('../../')
    from base_model import Base
    from config_helper import ConfigHelper
    from model.weather_model import weather_location
    from model.weather_model import weather_data
    from model.weather_model import weather_notify
    from login.login_funtion import User
    from model.push_model import push_queue

WEATHER_KEY = ConfigHelper().get('WEATHER_KEY')
WEATHER_EXPIRE_HOUR = 3
WEATHER_PUSH_TITLE = '天气异常!'
WEATHER_PUSH_TYPE_RAIN = 'rain'
WEATHER_PUSH_TYPE_AIR = 'air'
WEATHER_PUSH_TYPE_TEMPERATURE = 'temperature'


class WeatherData(Base):
    def __init__(self, location_id, location):
        '''
            location_id
            location
        '''
        self.location_id = location_id
        self.location = location
            self.zk.ensure_path("/%s/%s" % (servicename, type))
            self.zk.create("/%s/%s/ID" % (servicename, type),
                           json.dumps(address).encode('utf-8'),
                           ephemeral=ephemeral,
                           sequence=sequence)

    def get_register(self, servicename, type):
        if self.return_service_type(type):
            result = self.zk.get_children("/%s/%s" % (servicename, type))
            register = []
            if result:
                for i in result:
                    data, stat = self.zk.get("/%s/%s/%s" %
                                             (servicename, type, i))
                    register.append(data.decode("utf-8"))
        return register


if __name__ == "__main__":
    host = ConfigHelper().getConfig("zookeeper", "host")
    port = ConfigHelper().getConfig("zookeeper", "port")
    rs = RegisterCenter("{}:{}".format(host, port))
    rs.connect()
    rs.service_register("hello_provider", "provider", {
        "host": "127.0.0.1",
        "port": 8002
    })
    LoggerHelper().info("============get_register:")
    LoggerHelper().info(rs.get_register("hello_provider", "provider"))
    rs.close()
示例#3
0
    def __stop_command(self):
        try:
            self.orig_master_host = getattr(self, "orig_master_host")
            self.orig_master_config = ConfigHelper(self.orig_master_host)
        except Exception as e:
            print("Failed to read configuration for original master: %s" %
                  str(e))
            return False

        # Original master
        try:
            orig_master_ip = getattr(self, "orig_master_ip",
                                     self.orig_master_host)
            orig_master_mysql_port = getattr(self, "orig_master_port", None)
            orig_master_ssh_ip = getattr(self, "orig_master_ssh_ip",
                                         orig_master_ip)
            orig_master_ssh_port = getattr(self, "orig_master_ssh_port", None)
            orig_master_ssh_user = getattr(self, "orig_master_ssh_user", None)
            orig_master_ssh_options = getattr(self, "ssh_options", None)
            orig_master_mysql_user = self.__unescape_from_shell(
                getattr(self, "orig_master_user"))
            orig_master_mysql_pass = self.__unescape_from_shell(
                getattr(self, "orig_master_password"))
        except AttributeError as e:
            print(
                "Failed to read one or more required original master parameter(s): %s"
                % str(e))
            return False

        # Setup MySQL connections
        mysql_orig_master = MySQLHelper(orig_master_ip, orig_master_mysql_port,
                                        orig_master_mysql_user,
                                        orig_master_mysql_pass)

        try:
            print("Connecting to mysql on the original master '%s'" %
                  self.orig_master_host)
            if not mysql_orig_master.connect():
                return False

            if self.orig_master_config.get_manage_vip():
                vip_type = self.orig_master_config.get_vip_type()
                print(
                    "Removing the vip using the '%s' provider from the original master '%s'"
                    % (vip_type, self.orig_master_host))

                if not self.__remove_vip_from_host(
                        vip_type, self.orig_master_host, orig_master_ssh_ip,
                        orig_master_ssh_user, orig_master_ssh_port,
                        orig_master_ssh_options, self.FAILOVER_TYPE_ONLINE):
                    return False

            if self.orig_master_config.get_super_read_only(
            ) and mysql_orig_master.super_read_only_supported():
                print(
                    "Setting super_read_only to '1' on the original master '%s'"
                    % self.orig_master_host)
                if not mysql_orig_master.set_super_read_only(
                ) or not mysql_orig_master.is_super_read_only():
                    return False
            else:
                print("Setting read_only to '1' on the original master '%s'" %
                      self.orig_master_host)
                if not mysql_orig_master.set_read_only(
                ) or not mysql_orig_master.is_read_only():
                    return False

            if not self.__mysql_kill_threads(
                    self.orig_master_host, mysql_orig_master,
                    self.orig_master_config.get_kill_after_timeout()):
                return False
        except Exception as e:
            print("Unexpected error: %s" % str(e))
            return False
        finally:
            print("Disconnecting from mysql on the original master '%s'" %
                  self.orig_master_host)
            mysql_orig_master.disconnect()

        return True
示例#4
0
    def __rollback_stop_command(self):
        try:
            self.orig_master_host = getattr(self, "orig_master_host")
            self.orig_master_config = ConfigHelper(self.orig_master_host)
        except Exception as e:
            print("Failed to read configuration for original master: %s" %
                  str(e))
            return False

        # Original master
        try:
            orig_master_ip = getattr(self, "orig_master_ip",
                                     self.orig_master_host)
            orig_master_mysql_port = getattr(self, "orig_master_port", None)
            orig_master_mysql_user = self.__unescape_from_shell(
                getattr(self, "orig_master_user"))
            orig_master_mysql_pass = self.__unescape_from_shell(
                getattr(self, "orig_master_password"))
            orig_master_ssh_ip = getattr(self, "orig_master_ssh_ip",
                                         orig_master_ip)
            orig_master_ssh_port = getattr(self, "orig_master_ssh_port", None)
            orig_master_ssh_user = getattr(self, "orig_master_ssh_user", None)
            orig_master_ssh_options = getattr(self, "ssh_options", None)
        except AttributeError as e:
            print(
                "Failed to read one or more required original master parameter(s): %s"
                % str(e))
            return False

        # Setup MySQL connections
        mysql_orig_master = MySQLHelper(orig_master_ip, orig_master_mysql_port,
                                        orig_master_mysql_user,
                                        orig_master_mysql_pass)

        print("Rolling back the failover changes on the original master '%s'" %
              self.orig_master_host)
        try:
            if not mysql_orig_master.connect():
                print(
                    "Failed to connect to mysql on the original master '%s'" %
                    self.orig_master_host)
                return False

            if not mysql_orig_master.unset_read_only(
            ) or mysql_orig_master.is_read_only():
                print(
                    "Failed to reset read_only to '0' on the original master '%s'"
                    % self.orig_master_host)
                return False

            print("Set read_only back to '0' on the original master '%s'" %
                  self.orig_master_host)

            if self.orig_master_config.get_manage_vip():
                vip_type = self.orig_master_config.get_vip_type()
                if not self.__add_vip_to_host(
                        vip_type, self.orig_master_host, orig_master_ssh_ip,
                        orig_master_ssh_user, orig_master_ssh_port,
                        orig_master_ssh_options):
                    print(
                        "Failed to add back the vip using the '%s' provider to the original master '%s'"
                        % (vip_type, self.orig_master_host))
                    return False

                print("Added back the vip to the original master '%s'" %
                      self.orig_master_host)
        except Exception as e:
            print("Unexpected error: %s" % str(e))
            return False
        finally:
            mysql_orig_master.disconnect()

        return True
示例#5
0
    def __start_command(self):
        try:
            self.orig_master_host = getattr(self, "orig_master_host")
            self.orig_master_config = ConfigHelper(self.orig_master_host)
        except Exception as e:
            print("Failed to read configuration for original master: %s" %
                  str(e))
            return False

        try:
            self.new_master_host = getattr(self, "new_master_host")
            self.new_master_config = ConfigHelper(self.new_master_host)
        except Exception as e:
            print("Failed to read configuration for new master: %s" % str(e))
            return False

        # New master
        try:
            new_master_ip = getattr(self, "new_master_ip",
                                    self.new_master_host)
            new_master_mysql_port = getattr(self, "new_master_port", None)
            new_master_mysql_user = self.__unescape_from_shell(
                getattr(self, "new_master_user"))
            new_master_mysql_pass = self.__unescape_from_shell(
                getattr(self, "new_master_password"))
            new_master_ssh_ip = getattr(self, "new_master_ssh_ip",
                                        new_master_ip)
            new_master_ssh_port = getattr(self, "new_master_ssh_port", None)
            new_master_ssh_options = getattr(self, "ssh_options", None)

            if self.failover_type == self.FAILOVER_TYPE_HARD:
                new_master_ssh_user = getattr(self, "ssh_user", None)
            else:
                new_master_ssh_user = getattr(self, "new_master_ssh_user",
                                              None)
        except AttributeError as e:
            print(
                "Failed to read one or more required new master parameter(s): %s"
                % str(e))
            return False

        # Setup MySQL connection
        mysql_new_master = MySQLHelper(new_master_ip, new_master_mysql_port,
                                       new_master_mysql_user,
                                       new_master_mysql_pass)

        try:
            print("Connecting to mysql on the new master '%s'" %
                  self.new_master_host)
            if not mysql_new_master.connect():
                return False

            print("Setting read_only to '0' on the new master '%s'" %
                  self.new_master_host)
            if not mysql_new_master.unset_read_only(
            ) or mysql_new_master.is_read_only():
                return False

            if self.new_master_config.get_manage_vip():
                vip_type = self.new_master_config.get_vip_type()
                print(
                    "Adding the vip using the '%s' provider to the new master '%s'"
                    % (vip_type, self.new_master_host))

                if not self.__add_vip_to_host(
                        vip_type, self.new_master_host, new_master_ssh_ip,
                        new_master_ssh_user, new_master_ssh_port,
                        new_master_ssh_options):
                    return False
        except Exception as e:
            print("Unexpected error: %s" % str(e))
            return False
        finally:
            print("Disconnecting from mysql on the new master '%s'" %
                  self.new_master_host)
            mysql_new_master.disconnect()

        return True
示例#6
0
 def __init__(self, host):
     config_helper = ConfigHelper(host)
     self._smtp_host = config_helper.get_smtp_host()
     self._sender = "mha_helper@%s" % socket.getfqdn()
     self._receiver = config_helper.get_report_email()
示例#7
0
# -*- coding:utf-8 -*-

import sys
import time
import datetime
from peewee import DoesNotExist
try:
    from ..config_helper import ConfigHelper
    from ..model.short_content_model import short_content as short_content_table
except:
    sys.path.append('../')
    sys.path.append('../../')
    from config_helper import ConfigHelper
    from model.short_content_model import short_content as short_content_table

DOMAIN_NAME = ConfigHelper().get('DOMAIN_NAME')

DICT = {
    0: '1',
    1: '2',
    2: '3',
    3: '4',
    4: '5',
    5: '6',
    6: '7',
    7: '8',
    8: '9',
    9: 'a',
    10: 'b',
    11: 'c',
    12: 'd',