Exemple #1
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)
Exemple #2
0
    def init_hosts(self):
        if len(self.env_config) > 1:
            hosts_file = FileModify('/tmp/hosts', autocreate=True)
            hosts_file.cover("""
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
""")
            threads = []
            for ip_address in self.env_config:
                t = ExcTread(target=self.edit_hosts_file,
                             args=(ip_address, hosts_file),
                             name=ip_address)
                t.start()
                threads.append(t)

            for i in threads:
                i.join()
                if i.exception:
                    self._exception[i.name] = i.exception
                    self.env_config.pop(i.name)
Exemple #3
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)
Exemple #4
0
def init_network():
    # 关掉NetworkManager服务
    stop_service(['NetworkManager'])
    # 修改配置文件
    net_info = get_netcard()
    for n, ip in net_info:
        path = '/etc/sysconfig/network-scripts/ifcfg-{0}'.format(n)
        if os.path.isfile(path):
            gateway = get_gateway(n)
            f = FileModify(path)
            f.cover("""
            TYPE="Ethernet"
            BOOTPROTO=static
            IPADDR={ip}
            NETMASK=255.255.255.0
            GATEWAY={gateway}
            NM_CONTROLLED=no
            NAME={name}
            DEVICE={name}
            ONBOOT=yes
            DNS1=223.5.5.5
            """.format(name=n, ip=ip, gateway=gateway))
    # 重启服务
    restart_service(['network'])
Exemple #5
0
def set_hostname(hostname):
    exec_shell('hostname {0}'.format(hostname))
    path = '/etc/hostname'
    f = FileModify(path)
    f.cover(hostname)