简化 Openstack Havana 版 compute 节点部署程序

  1. 云栖社区>
  2. 博客>
  3. 正文

简化 Openstack Havana 版 compute 节点部署程序

科技小能手 2017-11-12 02:48:00 浏览468
展开阅读全文
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python
#-*-coding:UTF-8-*-
"""
@Item   :  Install Openstack Compute
@Author :  william
@Group  :  Network System Group
@Date   :  2014-03-20
@Funtion:
    Function: Depoly Openstack Compute  ...
"""
import os,sys,time
import traceback,shutil
import commands
import re
def LOG(info):
    logfile = '/tmp/openstack_compute_install.log'
    files = open(logfile,'a')
    try:
        files.write('%s : %s'%(time.ctime(),info))
    except IOError:
        files.close()
    files.close()
class DepolyCompute(object):
    def __init__(self):
        print "Please write in the script master IP public IP and local management ... \n"
        self.masterIPaddr = '192.168.220.1'
        self.localIPaddr  = '192.168.220.1'
        self.URL = 'http://%s/source/'%self.masterIPaddr
        self.nova_path  = '/etc/nova/'
    def install_packstack(self):
        yum_path = '/etc/yum.repos.d/'
        # epel 源目前不在更新OpenStack Havana版本,在下载源的时候默认已经移植了目录结构 ,需要重新安装RDO,在修改源路径,才能正常安装OpenStack 等
        comds = "https://repos.fedorapeople.org/repos/openstack/EOL/openstack-havana/rdo-release-havana-9.noarch.rpm"
        commands.getstatusoutput(cmd)
        try:
            cmd = "https://repos.fedorapeople.org/repos/openstack/EOL/openstack-havana/rdooo-release-havana-9.noarch.rpm"
            x,y = commands.getstatusoutput(cmd)
            if x != 0:
                fp = open('%s/rdo-release.repo'%yum_path,'w')
                fp.write("""[openstack-havana] \n""")
                fp.write("""name=OpenStack Havana Repository \n""")
                fp.write("""baseurl=https://repos.fedorapeople.org/repos/openstack/EOL/openstack-havana/epel-6/ \n""")
                fp.write("""enabled=1 \n""")
                fp.write("""skip_if_unavailable=0 \n""")
                fp.write("""gpgcheck=1 \n""")
                fp.write("""gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-RDO-Havana \n""")
                fp.write("""priority=98 \n""")
                fp.close()
            cmd = "rpm -Uvh http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm"
            x,y = commands.getstatusoutput(cmd)
            if x != 0:
                fp = open('%s/epel.repo'%yum_path,'w')
                fp.write("""[epel] \n""")
                fp.write("""name=Extra Packages for Enterprise Linux 6 - $basearch \n""")
                fp.write("""#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch \n""")
                fp.write("""mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch \n""")
                fp.write("""failovermethod=priority \n""")
                fp.write("""enabled=1 \n""")
                fp.write("""gpgcheck=1 \n""")
                fp.write("""gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 \n""")
                fp.write(""" \n""")
                fp.write("""[epel-debuginfo] \n""")
                fp.write("""name=Extra Packages for Enterprise Linux 6 - $basearch - Debug \n""")
                fp.write("""#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug \n""")
                fp.write("""mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch \n""")
                fp.write("""failovermethod=priority \n""")
                fp.write("""enabled=0 \n""")
                fp.write("""gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 \n""")
                fp.write("""gpgcheck=1 \n""")
                fp.write(""" \n""")
                fp.write("""[epel-source] \n""")
                fp.write("""name=Extra Packages for Enterprise Linux 6 - $basearch - Source \n""")
                fp.write("""#baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS \n""")
                fp.write("""mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch \n""")
                fp.write("""failovermethod=priority \n""")
                fp.write("""enabled=0 \n""")
                fp.write("""gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 \n""")
                fp.write("""gpgcheck=1 \n""")
                fp.close()
        except:
            LOG(traceback.format_exc())
    def install_kvm_compute(self):
        try:
            os.system(""" yum -y install kvm libvirt qemu virt-*""")
            os.system(""" yum -y install lrzsz gcc sysstat net-snmp-* """)
            os.system(""" yum -y install openstack-nova-compute openstack-nova-network libguestfs-winsupport""")
            #ip = self.localIPaddr.split('.')
            #hostname = "athCompute.%s.%s.autohome.com.cn"%(ip[2],ip[3])
            #os.system("hostname %s"% hostname)
            #os.system(""" sed -i 's/^HOSTNAME=.*/HOSTNAME=%s/' /etc/sysconfig/network """%hostname)
            os.system("easy_install psutil")
            os.system("easy_install ipdb")
        except:
            LOG(traceback.format_exc())
 
    def install_compute_source(self):
        try:
            cmd = " wget %s/athCloudOpenStack.tgz  -O /opt/athCloudOpenStack.tgz"%self.URL
            x,y = commands.getstatusoutput(cmd)
            if x == 0:
                os.chdir('/opt/')
                os.system(""" tar -xzvf athCloudOpenStack.tgz -C /""")
                os.chdir(self.nova_path)
                if os.path.exists('nova.conf'):
                    shutil.move('nova.conf','nova.conf.default')
                if os.path.exists('nova.conf.example'):
                    shutil.move('nova.conf.example','nova.conf')
                    self._nova_conf()
                self._start_nova_compute()
            else:
                LOG("wget athCloudOpenStack.tgz false")
                sys.exit()
        except:
            LOG(traceback.format_exc())
    def _start_nova_compute(self):
        try:
            servers = ['openstack-nova-compute','openstack-nova-network','openstack-nova-extend','libvirtd']
            for in servers:
                os.system(""" /sbin/service %s restart """ %i)
                os.system(""" /sbin/chkconfig %s on """ %i)
        except:
            LOG(traceback.format_exc())
    def _nova_config(self):
        # Compute node nova.conf init
        try:
            fp = open('%s/nova.conf'%self.nova_path)
            f = fp.readlines()
            fp.close()
            for n, s in enumerate(f):
                if re.match('#?glance_api_servers.*',s):
                    f[n] = 'glance_api_servers=%s:9292\n' %self.masterIPaddr
                if re.match('#?metadata_host.*',s):
                    f[n] = 'metadata_host=%s  \n' %self.masterIPaddr
                if re.match('#?qpid_hostname.*',s):
                    f[n] = 'qpid_hostname=%s\n' %self.masterIPaddr
                if re.match('#?novncproxy_base_url.*',s):
                    f[n] = 'novncproxy_base_url=http://%s:6080/vnc_auto.html \n' %self.masterIPaddr
                if re.match('#?sql_connection.*',s):
                    str = s.split('@')[0] + '@%s/nova'%self.masterIPaddr
                    f[n] = '%s \n' %str
                if re.match('#?my_ip.*',s):
                    f[n] = 'my_ip=%s\n' %self.localIPaddr
                if re.match('#?vncserver_listen.*',s):
                    f[n] = 'vncserver_listen=%s\n' %self.localIPaddr
                if re.match('#?vncserver_proxyclient_address.*',s):
                    f[n] = 'vncserver_proxyclient_address=%s\n' %self.localIPaddr
            fp = open('%s/nova.conf'%self.nova_path,'w')
            fp.writelines(f)
            fp.close()
        except Exception,e:
            LOG(traceback.format_exc())
if __name__ == "__main__":
    sc = DepolyCompute()
    sc.install_packstack()
    sc.install_kvm_compute()
    sc.install_compute_source()


网友评论

登录后评论
0/500
评论
科技小能手
+ 关注