Home Archives Categories Tags

采用setuptools为centos编译OpenStack RPM包

发布时间: 更新时间: 总字数:1138 阅读时间:3m 作者: 分享

OpenStack使用过程中经常会遇到打patch的时候,但有些时候patch太多管理起来又十分的不方便,还好OpenStack使用setuptools来管理安装包,下面总结一下setuptools在OpenStack的使用。

setuptools 简介

setuptools是Python的包管理工具,因此OpenStack使用setuptools管理安装包也是理所当然。

setuptools是Python distutils增强版的集合,它可以帮助我们更简单的创建和分发Python包,尤其是拥有依赖关系的。用户在使用setuptools创建的包时,并不需要已安装setuptools,只要一个启动模块即可。

优点

  1. 利用EasyInstall自动查找、下载、安装、升级依赖包

  2. 创建Python Eggs

  3. 包含包目录内的数据文件

  4. 自动包含包目录内的所有的包,而不用在setup.py中列举

  5. 自动包含包内和发布有关的所有相关文件,而不用创建一个MANIFEST.in文件

  6. 自动生成经过包装的脚本或Windows执行文件

  7. 支持Pyrex,即在可以setup.py中列出.pyx文件,而最终用户无须安装Pyrex

  8. 支持上传到PyPI

  9. 可以部署开发模式,使项目在sys.path中

  10. 用新命令或setup()参数扩展distutils,为多个项目发布/重用扩展

  11. 在项目setup()中简单声明entry points,创建可以自动发现扩展的应用和框架

因此,setuptools成为了OpenStack项目安装和打包的重要工具。

环境部署

本实例才CentOS6.5平台演示,如何将github中OpenStack的novaclient制作层rpm安装包。

环境部署

安装python-setuptools

[root@xianbin ~]# yum -y install python-setuptools

安装rpm相关包

[root@xianbin ~]# yum -y install rpm-build rpmdevtools

克隆novaclient源码

[root@xianbin openstack]# git clone https://github.com/openstack/python-novaclient.git
Initialized empty Git repository in /root/openstack/python-novaclient/.git/
remote: Counting objects: 15342, done.
remote: Total 15342 (delta 0), reused 0 (delta 0), pack-reused 15342
Receiving objects: 100% (15342/15342), 6.71 MiB | 58 KiB/s, done.
Resolving deltas: 100% (11232/11232), done.
[root@xianbin openstack]# ll
total 8
drwxr-xr-x  8 root root 4096 Dec  1 07:20 python-novaclient
[root@xianbin openstack]# 

切换到icehouse对应的tag(2.17.0),主要是考虑兼容问题,由于CentOS安装的python2.6:

[root@xianbin openstack]# cd python-novaclient/
[root@xianbin python-novaclient]#
[root@xianbin python-novaclient]# git checkout 2.17.0
Note: checking out '2.17.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 3393cb9... Merge "Add os-server-external-events support"
[root@xianbin python-novaclient]# 

运行python setup.py bdist_rpm,经过短暂的等待过程即可完成rpm包的制作过程。

[root@xianbin python-novaclient]# python setup.py bdist_rpm
...
...
Requires: /usr/bin/python python(abi) = 2.6
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/openstack/python-novaclient/build/bdist.linux-x86_64/rpm/BUILDROOT/python-novaclient-2.17.0-1.x86_64
warning: Could not canonicalize hostname: xianbin
Wrote: /root/openstack/python-novaclient/build/bdist.linux-x86_64/rpm/SRPMS/python-novaclient-2.17.0-1.src.rpm
Wrote: /root/openstack/python-novaclient/build/bdist.linux-x86_64/rpm/RPMS/noarch/python-novaclient-2.17.0-1.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.cVg61J
+ umask 022
+ cd /root/openstack/python-novaclient/build/bdist.linux-x86_64/rpm/BUILD
+ cd python-novaclient-2.17.0
+ rm -rf /root/openstack/python-novaclient/build/bdist.linux-x86_64/rpm/BUILDROOT/python-novaclient-2.17.0-1.x86_64
+ exit 0
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.Bv2jvv
+ umask 022
+ cd /root/openstack/python-novaclient/build/bdist.linux-x86_64/rpm/BUILD
+ rm -rf python-novaclient-2.17.0
+ exit 0
moving build/bdist.linux-x86_64/rpm/SRPMS/python-novaclient-2.17.0-1.src.rpm -> dist
moving build/bdist.linux-x86_64/rpm/RPMS/noarch/python-novaclient-2.17.0-1.noarch.rpm -> dist
[root@xianbin python-novaclient]# 

安装制作好的RPM包:

[root@xianbin python-novaclient]# cd dist/
[root@xianbin dist]# ll
total 936 
-rw-r--r-- 1 root root 456932 Dec  1 07:41 python-novaclient-2.17.0-1.noarch.rpm
-rw-r--r-- 1 root root 256608 Dec  1 07:41 python-novaclient-2.17.0-1.src.rpm
-rw-r--r-- 1 root root 237821 Dec  1 07:41 python-novaclient-2.17.0.tar.gz
[root@xianbin dist]# rpm -ivh python-novaclient-2.17.0-1.noarch.rpm 
Preparing...                ########################################### [100%]
   1:python-novaclient      ########################################### [100%]
[root@xianbin dist]#

完毕。

最新评论
加载中...