Esempio n. 1
0
def close_selinux():
    resp = get_shell_response('getenforce').strip()
    if resp != 'Disabled':
        path = '/etc/selinux/config'
        f = FileModify(path)
        f.replace('(?<=SELINUX=).*', 'disabled')
        exec_shell('setenforce 0')
Esempio n. 2
0
 def device_alter(self, server_path):
     path = os.path.join(server_path, 'yaobili-business-device', 'src',
                         'main', 'java', 'com', 'yaobili', 'platform',
                         'device', 'constants', 'TopicConstants.java')
     topic = CONFIG.TOPIC.get(self.env)
     f = FileModify(path)
     f.replace('TOPIC_SUF = ".*?";', 'TOPIC_SUF = "{}";'.format(topic))
     print('修改device topic为 {}, 文件地址为:{}'.format(topic, path), flush=True)
Esempio n. 3
0
def init_controller_manager_config():
    path = os.path.join(TEMPLATE_DIR, 'master',
                        'kube-controller-manager.service')
    f = FileModify(path)
    for i in IPS.get('master'):
        f.replace('(?<=service-cluster-ip-range=).*',
                  '{} \\'.format(SETTINGS.SERVICE_CIDR))
        f.replace('(?<=cluster-cidr=).*', '{} \\'.format(SETTINGS.POD_CIDR))
        send_files(
            os.path.join(TEMPLATE_DIR, 'master',
                         'kube-controller-manager.service'),
            '/usr/lib/systemd/system', i)
Esempio n. 4
0
def init_api_server_config():
    path = os.path.join(TEMPLATE_DIR, 'master', 'kube-apiserver.service')
    f = FileModify(path)
    for i in IPS.get('master'):
        ip, port = parse_address(i)
        f.replace('(?<=--bind-address=).*', '{} \\'.format(ip))
        f.replace('(?<=service-cluster-ip-range=).*',
                  '{} \\'.format(SETTINGS.SERVICE_CIDR))
        f.replace('(?<=service-node-port-range=).*',
                  '{} \\'.format(SETTINGS.NODE_PORT_RANGE))
        f.replace('(?<=etcd-servers=).*', '{} \\'.format(get_etcd_endpoints()))
        send_files(
            os.path.join(TEMPLATE_DIR, 'master', 'kube-apiserver.service'),
            '/usr/lib/systemd/system', i)
Esempio n. 5
0
def shop_alter(project_path, project):
    index_html_path = os.path.join(project_path, 'index.html')
    f = FileModify(index_html_path)
    f.replace('<title>.*?</title>',
              '<title>{}</title>'.format(CONFIG.TOPICS[project].get('title')))

    appvue_path = os.path.join(project_path, 'src', 'App.vue')
    f = FileModify(appvue_path)
    f.replace('(?<=import bodyHeader from "@/components/).*(?=";)',
              CONFIG.TOPICS[project].get('top'))
    f.replace('(?<=import submenu from "@/components/).*?(?=";)',
              CONFIG.TOPICS[project].get('left'))

    route_path = os.path.join(project_path, 'src', 'router', 'index.js')
    f = FileModify(route_path)
    login = CONFIG.TOPICS[project].get('login')
    f.replace_all(
        '// region.*?path: \'/\'.*?},', """// region
        {
          path: '/',
          name: '%s',
          component: %s,
          meta: {
            keepAlive: false,
          }
        },""" % (login, login))
    def is_alarm(self,k,result):
        """
        判断是否进行告警提示,相同告警进行拦截,相同告警在过了间隔时间后才会再次预警
        :return: 返回True,则可以进行告警,反之则否
        """
        history_path = os.path.join(BASE_DIR, '.history')
        f = FileModify(history_path, autocreate=True)
        data = self.get_history_data(k)
        now = int(time.time())
        if data and isinstance(data,tuple):
            alarm_data_3 = eval(data[2]).get('alarm_data').get('3')
            if alarm_data_3 == result.get('alarm_data').get('3'):
                time_diff = now - int(data[1])
                if time_diff > 3600 * CONFIG.ISOLATE_TIME:
                    f.replace(data[1],now)
                    return True
                else:
                    return False
            else:
                f.replace('^{}.*'.format(k),'{}||{}||{}'.format(k,now,result))
                return True

        f.add('{}||{}||{}'.format(k,now,result))
        return True
Esempio n. 7
0
def init_config():
    path = os.path.join(TEMPLATE_DIR, 'etcd', 'etcd.conf')
    f = FileModify(path)
    etcd_cluster = get_etcd_cluster()
    f.replace('(?<=ETCD_INITIAL_CLUSTER=").*(?=")',etcd_cluster)
    etcd_cluster_dict = get_etcd_cluster('dict')
    for i in IPS.get('etcd'):
        ip,port = parse_address(i)
        f.replace('(?<=ETCD_NAME=").*(?=")',etcd_cluster_dict.get(ip))
        f.replace('(?<=ETCD_LISTEN_PEER_URLS=").*(?=")','https://{}:2380'.format(ip))
        f.replace('(?<=ETCD_LISTEN_CLIENT_URLS=").*(?=")','https://{}:2379,https://127.0.0.1:2379'.format(ip))
        f.replace('(?<=ETCD_INITIAL_ADVERTISE_PEER_URLS=").*(?=")','https://{}:2380'.format(ip))
        f.replace('(?<=ETCD_ADVERTISE_CLIENT_URLS=").*(?=")','https://{}:2379'.format(ip))
        send_files(path,'/opt/kubernetes/cfg/',i)
Esempio n. 8
0
def api_alter(project_path):
    main_js_path = os.path.join(project_path, 'src', 'main.js')
    f = FileModify(main_js_path)
    f.replace("(?<=import api from './assets/js/).*?(?=';)", 'api_old')
Esempio n. 9
0
    def init_yaml_file(self):
        for service in self.services:
            svc_yaml_path = self.get_svc_yaml_path(service)
            yaml = FileModify(svc_yaml_path)

            # Domain Ingress
            if service in self.treafik_domain:
                exec_shell('cat {} >> {}'.format(CONFIG.INGRESS_TEMPLATE, svc_yaml_path))
                yaml.replace('DOMAIN', self.treafik_domain.get(service))

            # base settings
            yaml.replace('MINREADYSECONDS', str(CONFIG.MINREADYSECONDS))
            yaml.replace('REVISIONHISTORYLIMIT', str(CONFIG.REVISIONHISTORYLIMIT))
            yaml.replace('APPNAME', service)
            # namespace
            yaml.replace('NAMESPACE', self.namespace)
            # replicas
            yaml.replace('REPLICAS', str(self.replicas))
            # nfs
            yaml.replace('NFS_SERVER', CONFIG.NFS_SERVER.get(self.env))
            # port
            yaml.replace('PORT', str(self.port if self.port else CONFIG.SERVICE_PORTS.get(service)))
            # images path 镜像地址
            yaml.replace('IMAGE_PATH', self.get_image_path(service))

            # 传yaml文件
            self.sftp_client.put(svc_yaml_path, '{}/{}.yaml'.format(CONFIG.DEPLOY_YAMLS_DIR, service))