openstack 开发step-by-step

Set up your Open Stack

There are several ways to deploy openstack, Devstack is easily for developer to deploy Open Stack.

Please follow this URL to set up your Open Stack.

http://docs.openstack.org/developer/devstack/

nested KVM support:

  • Kernel

    • First check if your system has already configured nested kvm:
[email protected]:~# dpkg -S /etc/modprobe.d/qemu-system-x86.conf
qemu-system-x86: /etc/modprobe.d/qemu-system-x86.conf
[email protected]:~# cat /etc/modprobe.d/qemu-system-x86.conf
options kvm_intel nested=1
  • If not, run:
echo “options kvm-intel nested=1″ | sudo tee /etc/modprobe.d/kvm-intel.conf
  • then reload kvm_intel.ko
rmmod kvm_intel
modprobe kvm_intel
  • Nova

    • Optional: Modify nova.conf and add host-passthrough. Please note it may impact migration.
libvirt_cpu_mode = host-passthrough
  • Restart nova services.

PCI PassThrough Support

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Virtualization/chap-Virtualization-PCI_passthrough.html

There are two ways to support PCI PassThrough.

  1. legacy UIO framework(PCI Assign);
  2. VFIO, it is recommended http://lwn.net/Articles/509153/

For PCI SR-IOV device we have a specially way to setup.

Preparation for PCI PassThrough

(1) Enable the Intel VT-d extensions http://www.linux-kvm.org/page/How_to_assign_devices_with_VT-d_in_KVM

Setup in your bios. Check you have enable it.

$sudo dmesg | grep -e DMAR -e IOMMU

(2) Activate Intel VT-d in the kernel http://www.zerg.sc/technote/?p=241

$ sudo echo 1 > /sys/module/kvm/parameters/allow_unsafe_assigned_interrupts

update the the kernel cmdline.

https://www.gnu.org/software/grub/manual/html_node/Simple-configuration.html

$ sudo su
$ sudo sed -i -e ‘s/\(^GRUB_CMDLINE_LINUX_DEFAULT.*\)"$/\1 intel_iommu=on"/‘ /etc/default/grub
$ sudo update-grub
$ sudo grep intel_iommu=on /boot/grub/grub.cfg

Use legacy UIO framework instead of VFIO

Why we still need the legacy UIO framework, for there are some thing wrong with vfio and igb in some PC.

http://www.linux-kvm.org/page/How_to_assign_devices_with_VT-d_in_KVM

Set parameter KVM allow_unsafe_assigned_interrupts

Transient configure (take effect Immediately)

$ sudo echo 1 > /sys/module/kvm/parameters/allow_unsafe_assigned_interrupts

Or persistent

$ sudo echo "options kvm allow_unsafe_assigned_interrupts=1" >>  /etc/modprobe.d/kvm_iommu.conf

Search the PCI device

$ lspci -n
01:00.0 0200: 8086:10fb (rev 01)
01:00.1 0200: 8086:10fb (rev 01)
$ lspci
01:00.0 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
01:00.1 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)

Bind pci_stub driver to PCI device

$ sudo modprobe pci_stub
$ sudo su(take effect Immediately)
$ echo "8086 10fb" > /sys/bus/pci/drivers/pci-stub/new_id
$ echo 0000:01:00.0   > /sys/bus/pci/devices/0000\:01\:00.0/driver/unbind
$ echo 0000:01:00.0  > /sys/bus/pci/drivers/pci-stub/bind
$ echo 0000:01:00.1   > /sys/bus/pci/devices/0000\:01\:00.1/driver/unbind
$ echo 0000:01:00.1  > /sys/bus/pci/drivers/pci-stub/bind

Start attach PCI device to guest and start

  1. in this way, if you want to use virsh to start your guest, you must assign the driver name, or you will failed for libvirt will use vfio driver as default.
  2. name=‘kvm‘ means: the legacy pci device assignment handled directly by the KVM kernel module
$ echo "
<hostdev mode=‘subsystem‘ type=‘pci‘ managed=‘yes‘>
  <driver name=‘kvm‘/>
  <source>
    <address domain=‘0x0000‘ bus=‘0x01‘ slot=‘0x00‘ function=‘0x1‘/>
  </source>
</hostdev>" > new-pci.xml
$ virsh attach-device guest-name --config new-pci.xml
$ virsh start guest-name

Use VFIO

There are tons of tutorials on how to get VT-d working with KVM/libvirt/Qemu/etc. It’s still a fairly new and unused feature, which means that it is getting updated pretty frequently. Unfortunately, the Internet doesn’t update as quickly, so most of the documentation out there is not accurate or the best approach. readlink You can refer this when any trouble.

http://hinish.com/?p=338

We need this command to load the kernel modules at boot time

$ sudo echo "vfio
vfio_iommu_type1
vfio_pci" >> /etc/modules

Set vfio_iommu_type1 allow_unsafe_interrupts parameters If you‘re overriding the ivrs table to enable intremap you dont need this line Persistent (need reboot.)

$ echo "options vfio_iommu_type1 allow_unsafe_interrupts=1" > /etc/modprobe.d/vfio_iommu_type1.conf

Or transient (take effect Immediately)

$ sudo echo 1 >  /sys/module/vfio_iommu_type1/parameters/allow_unsafe_interrupts

Disable AppArmor for libvirtd

Actually, we do not need to disable Apparmor, this is a bug on ubuntu, we need to work around it. (It may can not works)

https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1276719

http://libvirt.org/drvqemu.html#securitysvirtaa

$ apt-get install apparmor-utils
$ sudo aa-complain /usr/sbin/libvirtd
$ sudo su
$ for x in /etc/apparmor.d/libvirt/libvirt-*[0-9a-b];do aa-complain $x; done

Or (It may can not works)

$ sudo ln -s  /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/
$ sudo ln -s /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper /etc/apparmor.d/disable/
$ sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.libvirtd
$ sudo apparmor_parser -R /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper
$ sudo service libvirt-bin restart

Or remove it (the best way)

http://www.techytalk.info/disable-and-remove-apparmor-on-ubuntu-based-linux-distributions/

$ sudo /etc/init.d/apparmor stop
$ sudo update-rc.d -f apparmor remove
$ sudo apt-get --purge remove apparmor apparmor-utils libapparmor-perl libapparmor1

It may cause the ubuntu-desktop crash, please reinstall it.

$ sudo apt-get install ubuntu-desktop

Find the all the pci devices in sam iommu group

We must binding all devices in same group to the vfio-pci driver creates.

$ readlink /sys/bus/pci/devices/0000\:01\:00.0/iommu_group
../../../../kernel/iommu_groups/1
$ ls -l /sys/bus/pci/devices/0000\:01\:00.0/iommu_group/devices

Bind vfio driver to PCI device

$ sudo su
$ echo "8086 10fb" > /sys/bus/pci/drivers/vfio-pci/new_id
$ echo "0000:01:00.1" > /sys/bus/pci/devices/0000\:01\:00.1/driver/unbind
$ echo "0000:01:00.1" > /sys/bus/pci/drivers/vfio-pci/bind
$ echo "0000:01:00.0" > /sys/bus/pci/devices/0000\:01\:00.0/driver/unbind
$ echo "0000:01:00.0" > /sys/bus/pci/drivers/vfio-pci/bind

Start attach PCI device to guest and start

$ echo "
<hostdev mode=‘subsystem‘ type=‘pci‘ managed=‘yes‘>
  <driver name=‘vfio‘/>
  <source>
    <address domain=‘0x0000‘ bus=‘0x01‘ slot=‘0x00‘ function=‘0x1‘/>
  </source>
</hostdev>" > new-pci.xml
$ virsh attach-device guest-name --config new-pci.xml
$ virsh start guest-name

Configure for igb module for SR-IOV support.

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/sect-Virtualization_Host_Configuration_and_Guest_Installation_Guide-SR_IOV-How_SR_IOV_Libvirt_Works.html

Persistent configure for igb module.

https://communities.intel.com/community/wired/blog/2011/08/31/using-sr-iov-with-intel-ethernet-and-red-hat-enterprise-linux

$ sudo echo ‘options igb max_vfs=7‘ > /etc/modprobe.d/igb.conf
$ sudo echo "igb" >> /etc/modules
$ sudo update-initramfs -k all -t -u

Transient configure for igb module.

$ sudo su
$ sudo rmmod igb && sudo modprobe igb max_vfs=7

It maill failed as follow on PC:

Jan 10 04:42:18 localhost kernel: [ 8441.914658] ixgbe 0000:01:00.1: SR-IOV: bus number out of range
Jan 10 04:42:18 localhost kernel: [ 8441.914662] ixgbe 0000:01:00.1 0000:01:00.1 (uninitialized): Failed to enable PCI sriov: -12

This is intel official document, it is some different from the above.

http://www.intel.com/content/www/us/en/network-adapters/10-gigabit-network-adapters/ethernet-x520-sr-iov-red-hat-tech-brief.html

Work around if pci-passthrough can not work.

Upgrade your kernel.

Download the latest stable kernel. https://www.kernel.org/

$ wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.1.tar.xz
$ tar -xvf linux-3.18.1.tar.xz
$ cd linux-3.18.1
$ cp /boot/config-3.13.0-43-generic ./.config
$ echo "" | make oldconfig

Please enable CONFIG_IP_NF_NAT the config, kernel 3.17 change the macro define for nat.

$ sed -i -e "s/# CONFIG_IP_NF_NAT.*/CONFIG_IP_NF_NAT=m/" ./.config
$ make -j8
$ make modules_install
$ make install
$ sudo reboot

compile your owen qemu
$ git clone git://git.qemu.org/qemu.git
$ apt-get install libglib2.0-dev zlib1g-dev libspice-server-dev libspice-protocol-dev
$ ./configure ‘--target-list=x86_64-softmmu‘ ‘--enable-debug‘ ‘--enable-kvm‘ ‘--enable-spice‘ ‘--prefix=/home/shhfeng/qemu/‘
$ make

re make you initrd
$ gunzip # uncompress your initrd-*.img file
$ mkdir tmp
$ cd tmp/
$ cpio -i --make-directories < "your uncompress  initrd direction."
$ tree -C .

# tree: option -C color show,-n shutdown color show.

or

$ cd tmp/
$ gzip -dc ../sth.gz |cpio -id

# edit your initrd,

$ cd tmp/

# add or remove *.ko

$ find ./ | cpio -H newc -o > /boot/initrd-2.6.22.6.img-ahci
$ gzip /boot/initrd-2.6.22.6.img-ahci
$ mv initrd-2.6.22.6.img-ahci.gz /boot/initrd-2.6.22.6.img-ahci

Build up your skills to develop Open stack

Doc In Repository

Please read the docs in /opt/stack/nova/doc/source/devref first. Then you will get some ideas about Open Stack. Read up these files, you can ignore them if you already know them.

http://docs.openstack.org/api/quick-start/content/index.html#Compute_API_Quick_Start

  • gerrit.rst

It introduce the gerrit work flow.

  • development.environment.rst

It introduce how to set up development environment.

  • architecture.rst

Introduce the profile of the Open Stack.

  • rpc.rst

Open Stack rpc is different with the traditional SUN IPC, it base on a AMQP broker. http://www.rabbitmq.com/getstarted.html

Learn more about implementation of rpc. Please seen the Open Stack Common Library.

$ git clone git://git.openstack.org/openstack/oslo.git

Also learn more about kombu:

http://kombu.readthedocs.org/en/latest/

  • threading.rst

All OpenStack services use *green thread* model of threading, If your know coroutine, you will learn greenthread quickly.

All the above files also can be access by this url link.

http://docs.openstack.org/developer/nova/devref/rpc.html

import component

You had better do some exercise about some technologies that Open Stack uses. This is helpful for you to know Open Stack.

  • Rabbitmq python tutorials

Tutorial:

https://github.com/rabbitmq/rabbitmq-tutorials/
http://wenku.baidu.com/view/800285ea0975f46527d3e19b.html (a Chinese Document for Rabbitmq)
http://www.openstack.cn/p136.html (a Chinese Simple Document for Rabbitmq)

Tutorial Source Code:

https://github.com/rabbitmq/rabbitmq-tutorials/

Tutorial Source Code:

http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html
  • WSGI And eventlet

Read the Red hat REST API Guide. It is useful to understand REST API. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Virtualization/3.0/html-single/REST_API_Guide/index.html#sect-REST_API_Guide-Common_Features-Resources-Creating_Resources

Join The Open Stack Community to do Contributions

  • Join the IRC

IRC: https://wiki.openstack.org/wiki/IRC

  • Subscribe the mail-list

Dev: http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

General: http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack

  • To submit the patch

Workflow: https://wiki.openstack.org/wiki/Gerrit_Workflow

Play with Open Stack

DashBoard

http://docs.openstack.org/user-guide/content/log_in_dashboard.html

Try to access http://localhost/

CURL

http://docs.openstack.org/api/quick-start/content/index.html#Compute_API_Quick_Start

I have write a small script to get token ID, as follow, you can name it as “get-token”:

#!/bin/bash
return=`curl -i ‘http://127.0.0.1:5000/v2.0/tokens‘ -X POST -H "Content-Type: application/json" -H "Accept: application/json"  -d ‘{"auth": {"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "123"}}}‘`
echo $return
echo "-----------------------------------------------------------------------------"
ID=""
for x in $return; do
    if [ "x$ID" = "xtokenID" ] ;then
        id=`echo $x | tr -d ‘[",]‘`
        export TOKEN=$id
        echo "TOKEN=$id"
        ID=""
        break
    fi
    if [ "x$x" = ‘x"id":‘ ] ;then
        ID="tokenID"
    fi
done
echo ""

This script just is a sample, you can improve it.

Run it by

$ . get-token

Then you can run other commands use the TOKEN environment value, such as get all the tenents, as follow:

$ curl -i -X GET http://127.0.0.1:35357/v2.0/tenants -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: $TOKEN"

Open Stack Client

http://docs.openstack.org/api/quick-start/content/index.html#Compute_API_Quick_Start

You should export the OS_USERNAME and OS_TENANT_NAME environment by the follow command firstly.

$ cd devstack/
$ . openrc OS_USERNAME OS_TENANT_NAME

http://docs.openstack.org/juno/config-reference/content/section_compute-scheduler.html

update your /etc/nova/nova.conf

Add the follow option to “[DEFAULT]” section.

$ grep -e DEFAULT -e pci_passthrough -e pci_alias -e scheduler_available_filters /etc/nova/nova.conf
[DEFAULT]
pci_passthrough_whitelist={"product_id":"10fb", "vendor_id":"8086", "deviceids":"0000:01:00.0, 0000:01:00.1"}
pci_passthrough_whitelist={"product_id":"8c20", "vendor_id":"8086", "deviceids":"0000:00:1b.0"}
pci_alias = {"vendor_id":"8086", "product_id":"10fb", "name":"intelnic"}
scheduler_available_filters = nova.scheduler.filters.pci_passthrough_filter.PciPassthroughFilter

Create a instance with pci-passthrough device.

https://wiki.openstack.org/wiki/Pci_passthrough

$ nova flavor-list
$ nova flavor-key m1.tiny set pci_passthrough:alias=intelnic:1
$ nova boot  pci  --flavor m1.tiny  --image=cirros-0.3.2-x86_64-uec

Debug with Open Stack

I usually use “print” for debugging. The “print” is on the stack screen terminal.

$ cd devstack/
$ ./rejoin-stack.sh

Or

$ screen –ls
There is a screen on:
	13846.stack
$ screen -r stack

Some useful operation:

run a command by “Ctrl + A + :”,  you can input help command to show more info.
Swith to any window by “Ctrl + A + ‘  ”, input the windows number you want to switch.
Swith to any window by “Ctrl + A + "  ”, select the windows you want to switch.

write testcase

https://wiki.openstack.org/wiki/SmallTestingGuide

时间: 2024-08-02 12:52:43

openstack 开发step-by-step的相关文章

C++开发WPF,Step by Step

示例代码 使用C++来开发WPF,主要是如何在MFC(Win32)的窗口中Host WPF的Page.下面我就做个详细的介绍. 一.创建工程, 由于MFC的Wizard会生成很多用不到的代码,所以我准备从一个空的工程开始创建一个MFC的工程. a)         打开VS2005,菜单File->New->Projects-, 左面选择Visual C++->Win32,右面选择Win32 Console Application,给工程起个名字CPlusPlus_WPF, Ok进入下一

数据库设计 Step by Step (1)——扬帆启航

引言:一直在从事数据库开发和设计工作,也看了一些书籍,算是略有心得.很久之前就想针 对关系数据库设计进行整理.总结,但因为种种原因迟迟没有动手,主要还是惰性使然.今天也算是痛下决心开始这项卓绝又令我兴奋的工作.这将是一个系列的文 章,我将以讲座式的口吻展开讨论(个人偷懒,这里的总结直接拿去公司培训新人用). 系列的第一讲我们先来回答下面几个问题 数据库是大楼的根基 大多数程序员都很急切,在了解基本需求之后希望很快的进入到编码阶段(可能只有产出代码才能反映工作量),对于数据库设计思考得比较少. 这

WinForm RDLC SubReport Step by step

最近在做的一个PO管理系统,因为要用到订单打印,没有用水晶报表,直接使用VS2010的Reporting.参考了网上的一些文章,但因为找到的数据是用于WebForm的,适配到WinForm有点区别,竟然花了很久才搞通.所以现在做个Step By Step以记录. 参考Jimmy.Yang的博文: http://www.cnblogs.com/yjmyzz/archive/2011/09/19/2180940.html 开发环境:      VS2010 C# 第一步,新建项目 2.在项目中新建数

study Mvc step by step (一) 什么是Mvc啊?

当我们开始逐步把Net平台上面的Web开发从webform过度到MVC 开发的时候.我们总想弄清楚Mvc到底是什么??其实Mvc并不是Net特有的一种开发技术.而是一种软件开发的模式.早在上个世界80年代.Xerox PARC为编程语言Smalltalk-80发明的一种软件设计模式,已被广泛使用.那么什么是Mvc呢? MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式: Model(模型)表示应用程序核心(比如数据库记录列

WPF MVVM 架构 Step By Step(6)(把actions从view model解耦)

到现在为止,我们创建了一个简单的MVVM的例子,包含了实现了的属性和命令.我们现在有这样一个包含了例如textbox类似的输入元素的视图,textbox用绑定来和view model联系,像点击button这样的行为用命令来联系.view model和model在内部通信. 但是在上面的架构中有一个问题,command类和view model有很严重的耦合.如果你记得command类的代码(在下面也有展示),在构造函数中传递view model对象,意味着这个command 类不能再其他的vie

WPF Step By Step 控件介绍

WPF Step By Step 控件介绍 回顾 上一篇,我们主要讨论了WPF的几个重点的基本知识的介绍,本篇,我们将会简单的介绍几个基本控件的简单用法,本文会举几个项目中的具体的例子,结合这些 例子,希望我们可以对WPF的掌握会更深刻.本文涉及的内容可能较多.请大家慢慢看看.错误之处,还请指出. 本文大纲 1.基本控件介绍与用法. 基本控件介绍与用法 文本控件 Label控件 label控件:一般用户描述性文字显示. 在Label控件使用时,一般给予用户提示.用法上没有什么很特殊的,label

WPF Step By Step 完整布局介绍

WPF Step By Step 完整布局介绍 回顾 上一篇,我们介绍了基本控件及控件的重要属性和用法,我们本篇详细介绍WPF中的几种布局容器及每种布局容器的使用场景,当 然这些都是本人在实际项目中的使用经验,可能还存在错误之处,还请大家指出. 本文大纲 1.Grid 2.StackPanel 3.DockPanel 4.WrapPanel Grid 1.Row和Column 我们下面来介绍Grid的行的用法,及我们在UI设计过程中需要注意的细节. 由于前面我们在第一章中已经介绍了基本的关于Gr

WPF Step By Step 系列-Prism框架在项目中使用

WPF Step By Step 系列-Prism框架在项目中使用 回顾 上一篇,我们介绍了关于控件模板的用法,本节我们将继续说明WPF更加实用的内容,在大型的项目中如何使用Prism框架,并给予Prism框架来构建基础的应用框架,并且如何来设计项目的架构和模块,下面我们就来一步步开始吧. 本文大纲 1.Prism框架下载和说明 2.Prism项目预览及简单介绍. 3.Prism框架如何在项目中使用. Prism框架下载和说明 Prism框架是针对WPF和Silverlight的MVVM框架,这

Step by step Install a Local Report Server and Remote Report Server Database

原创地址:http://www.cnblogs.com/jfzhu/p/4012097.html 转载请注明出处 前面的文章<Step by step SQL Server 2012的安装 >中,介绍过如何安装SQL Server 2012,其中的Database Engine Services和Reporting Services - Native安装在了同一台服务器上,但是为了提高性能,我们可以将Database Engine与Reporting Service分别安装在不同的服务器上.

持续交付工具ThoughtWorks Go部署step by step

持续交付工具ThoughtWorks Go部署step by step http://blogs.360.cn/360cloud/2014/05/13/%E6%8C%81%E7%BB%AD%E4%BA%A4%E4%BB%98%E5%B7%A5%E5%85%B7thoughtworks-go%E9%83%A8%E7%BD%B2step-by-step/ Posted on 2014 年 5 月 13 日 by zieckey | Leave a reply 1. ThoughtWorks  Go简