Beispiel #1
0
def init():
    ips = get_all_ip(IPS)
    scripts_dir = os.path.join(CONFIG.PROJECT_DIR, 'utils', 'scripts', 'k8s',
                               'init')
    for ipa in ips:
        if not check_rsa_secret():
            create_rsa_secret()
        ssh_copy_id(ipa)
        ip, port = parse_address(ipa)
        print('init {}...'.format(ip))
        if not check_is_localip(ip):
            ssh = SSHConnect(host=ip, port=int(port))
            for filename in os.listdir(scripts_dir):
                f = FileModify(os.path.join(scripts_dir, filename))
                ssh.run(f.content())
            ssh.close()
        else:
            for filename in os.listdir(scripts_dir):
                f = FileModify(os.path.join(scripts_dir, filename))
                exec_shell(f.content())
Beispiel #2
0
def init_etcd_ca():
    path = os.path.join(TEMPLATE_DIR,'etcd','etcd-csr.json')
    f = FileModify(path)
    template_content = f.content()
    result = json.loads(template_content,encoding='UTF-8')
    for ip_ in IPS.get('etcd'):
        ip,port = parse_address(ip_)
        result['hosts'].append(ip)
    f.cover(json.dumps(result))
    cfssl_dir = get_cfssl_dir()
    os.chdir(os.path.join(TEMPLATE_DIR,'etcd'))
    exec_shell('{0}/cfssl gencert -ca={1}/ca.pem -ca-key={1}/ca-key.pem -config={1}/ca-config.json '
               '-profile=kubernetes etcd-csr.json | {0}/cfssljson -bare etcd'.format(cfssl_dir,os.path.join(TEMPLATE_DIR,'ca')))
    f.cover(template_content)
 def get_history_data(self,k=None):
     """  返回历史数据 """
     history_path = os.path.join(BASE_DIR, '.history')
     f = FileModify(history_path, autocreate=True)
     data = []
     for line in f.content().split('\n')[:-1]:
         data.append(tuple(line.split('||')))
     if k:
         for i in data:
             if i[0] == k:
                 return i
         return ()
     else:
         return data
Beispiel #4
0
    def base_init(self, ssh, sftp_client):
        # 基础文件夹
        ssh.run('mkdir -p %s/{lib,pid,history}' %
                os.path.dirname(CONFIG.DEPLOY_DIR))

        # 初始化python36环境
        f = FileModify(
            os.path.join(get_project_root_path(), 'utils',
                         'install_python36.sh'))
        ssh.run(f.content())

        # 传python文件
        sftp_client.put(os.path.join(BASE_DIR, 'config.py'),
                        os.path.join(CONFIG.ROOT_DIR, 'config.py'))
        sftp_client.put(os.path.join(BASE_DIR, 'deploy.py'),
                        os.path.join(CONFIG.ROOT_DIR, 'deploy.py'))
        put_dir(sftp_client, os.path.join(get_project_root_path(), 'utils'),
                os.path.join(CONFIG.ROOT_DIR, 'utils'))
Beispiel #5
0
def init_ca():
    path = os.path.join(TEMPLATE_DIR, 'master', 'kubernetes-csr.json')
    f = FileModify(path)
    template_content = f.content()
    result = json.loads(template_content, encoding='UTF-8')
    for ip_ in IPS.get('master'):
        ip, port = parse_address(ip_)
        result['hosts'].append(ip)
    result['hosts'].append(SETTINGS.CLUSTER_KUBERNETES_SVC_IP)
    f.cover(json.dumps(result))
    cfssl_dir = get_cfssl_dir()
    os.chdir(os.path.join(TEMPLATE_DIR, 'master'))
    ca_dir = os.path.join(TEMPLATE_DIR, 'ca')
    exec_shell(
        '{0}/cfssl gencert -ca={1}/ca.pem -ca-key={1}/ca-key.pem -config={1}/ca-config.json '
        '-profile=kubernetes kubernetes-csr.json | {0}/cfssljson -bare kubernetes'
        .format(cfssl_dir, ca_dir))
    exec_shell(
        '{0}/cfssl gencert -ca={1}/ca.pem -ca-key={1}/ca-key.pem -config={1}/ca-config.json '
        '-profile=kubernetes admin-csr.json | {0}/cfssljson -bare admin'.
        format(cfssl_dir, ca_dir))
    f.cover(template_content)