OpenStack and EC2 API 教學
description
Transcript of OpenStack and EC2 API 教學
![Page 1: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/1.jpg)
1
OpenStack and EC2 API教學
國立交通大學 資訊技術服務中心蘇俊憲2013/06/04
![Page 2: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/2.jpg)
2
Outline OpenStack API Client Architecture Install the OpenStack Clients Command List for nova Client Nova API Client Glance API Client
資訊技術服務中心
![Page 3: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/3.jpg)
3
OpenStack API Client Architecture資訊技術服務中心
140.113.98.2
![Page 4: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/4.jpg)
4
Install the OpenStack Clients Virtual Box
Import Ubuntu 12.04 Image from Hard Disk Check PC Room PC IP address Config Port Forwarding
資訊技術服務中心
![Page 5: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/5.jpg)
5
Install the OpenStack Clients Install ssh in API Client
#sudo api-get install ssh Use ssh connect to API client by 22 port
openstacklab / nctuopenstack Install aptitude
#sudo apt-get install aptitude Install pip(Python Package Index)
#sudo aptitude install python-pip Install Nova-API Client
#sudo pip install python-novaclient
資訊技術服務中心
![Page 6: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/6.jpg)
6
Install the OpenStack Clients資訊技術服務中心
Install or update the client packages sudo pip install [--update] python-<project>client nova -> Compute API quantum ->Networking API keystone -> Identity service API glance -> Image service API swift -> Object storage API cinder -> Block storage API
Install,upgrade,uninstall Nova-API Client #sudo pip install python-novaclient #sudo pip install --upgrade python-novaclient #sudo pip uninstall python-novaclient
![Page 7: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/7.jpg)
7
下載 OpenStack RC file 上傳 RC file 到 API Client 變更檔案執行權限
#sudo chmod +x rc_filename.sh 載入環境變數
#sudo source rc_filename.sh 輸入密碼 測試
#nova image-list
Install the OpenStack Clients資訊技術服務中心
![Page 8: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/8.jpg)
8
Install the OpenStack Clients 下載 OpenStack RC file
資訊技術服務中心
![Page 9: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/9.jpg)
9
資訊技術服務中心Install the OpenStack Clients
![Page 10: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/10.jpg)
10
Command List for nova Client資訊技術服務中心
#nova help#nova help <subcommand>
![Page 11: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/11.jpg)
11
NOVA API Client資訊技術服務中心
List Instances, Images, and Flavors
#nova image-list#nova flavor-list#nova list
![Page 12: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/12.jpg)
12
資訊技術服務中心NOVA API Client – Key Pair
Creating New Keys #nova keypair-add mykey > mykey.pem
List Key Pair #nova keypair-list
![Page 13: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/13.jpg)
13
Security Group
![Page 14: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/14.jpg)
14
NOVA API Client – Security Group資訊技術服務中心
Manage Security Groups #nova secgroup-list #nova secgroup-list-rules default
![Page 15: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/15.jpg)
15
NOVA API Client – Security Group資訊技術服務中心
Add or delete a security group #nova secgroup-create secure1 "Test security group" #nova secgroup-delete secure1
![Page 16: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/16.jpg)
16
NOVA API Client – Security Group資訊技術服務中心
Modify security group rules #nova secgroup-add-rule secure1 tcp 80 80 140.113.0.0/16 #nova secgroup-add-rule secure1 icmp -1 -1 140.113.0.0/16 #nova secgroup-delete-rule secure1 tcp 80 80 140.113.0.0/16
![Page 17: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/17.jpg)
17
NOVA API Client – Security Group資訊技術服務中心
Add security group to instances nova add-secgroup testapi secure1
![Page 18: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/18.jpg)
18
Instances
![Page 19: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/19.jpg)
19
資訊技術服務中心NOVA API Client - Launch an Instance
Launch an Instance – without ssh-key#nova boot testapi --image "7c421510-3923-4057-b038-94b59d1396bb" --flavor 1
![Page 20: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/20.jpg)
20
NOVA API Client - Launch an Instance Launch an Instance – with ssh-key
資訊技術服務中心
#nova boot testapi --image "7c421510-3923-4057-b038-94b59d1396bb" --flavor 1 --key_name mykey
![Page 21: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/21.jpg)
21
NOVA API Client - Launch an Instance資訊技術服務中心
Launch an Instance with security group
#nova boot testapi --image "7c421510-3923-4057-b038-94b59d1396bb" --flavor 1 --key_name mykey --security-groups secure1
![Page 22: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/22.jpg)
22
NOVA API Client - Launch an Instance資訊技術服務中心
Launch an Instance – with user_data#nova boot testapi --image "7c421510-3923-4057-b038-94b59d1396bb" --flavor 1 --key_name mykey --user_data mydata.random
![Page 23: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/23.jpg)
23
NOVA API Client – User_Data資訊技術服務中心
mydata.random
![Page 24: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/24.jpg)
24
NOVA API Client – Instance資訊技術服務中心
Stop and Start an Instance #nova pause / nova unpause <instance Name or ID> #nova suspend / nova resume <instance Name or ID>
![Page 25: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/25.jpg)
25
NOVA API Client - Instance資訊技術服務中心
Reboot 、 Terminate an Instance #nova reboot <instance Name or ID> #nova delete <instance Name or ID>
![Page 26: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/26.jpg)
26
Floating IPs
![Page 27: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/27.jpg)
27
NOVA API Client資訊技術服務中心
Manage Floating IP Addresses #nova floating-ip-pool-list #nova floating-ip-create ext-net # nova floating-ip-delete 140.113.98.33
![Page 28: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/28.jpg)
28
NOVA API Client資訊技術服務中心
Manage Floating IP Addresses #nova add-floating-ip testapi 140.113.98.33 #nova floating-ip-list #nova remove-floating-ip <server> <address>
![Page 29: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/29.jpg)
29
Usage Statistics
![Page 30: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/30.jpg)
30
NOVA API Client – Instance Usage 資訊技術服務中心
# nova diagnostics <server Name or ID>
![Page 31: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/31.jpg)
31
Glance API Client
![Page 32: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/32.jpg)
32
Glance API Client - List Images資訊技術服務中心
Install Glance API Client # sudo pip install python-glanceclient
List Images #glance image-list
![Page 33: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/33.jpg)
33
Glance API Client - Add a New Image資訊技術服務中心
Download the test image http://cloud-images.ubuntu.com/precise/current/precise-server-
cloudimg-amd64-disk1.img Upload an image to glance
#glance image-create --name StudentID-image --disk-format=qcow2 --container-format=bare --is-public=True --file precise-server-cloudimg-amd64-disk1.img
#glance image-create --name StudentID-image --disk-format=qcow2 --container-format=bare --is-public=True --copy-from http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img
![Page 34: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/34.jpg)
34
Glance API Client - Add a New Image資訊技術服務中心
Image is a local file
Image from Internet
![Page 35: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/35.jpg)
35
資訊技術服務中心Glance API Client - Add a New Image Download the test image
http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img
Upload an image to glance #glance image-create --name StudentID-image --disk-
format=qcow2 --container-format=bare --is-public=True --file precise-server-cloudimg-amd64-disk1.img
#glance image-create --name StudentID-image --disk-format=qcow2 --container-format=bare --is-public=True --copy-from http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img
![Page 36: OpenStack and EC2 API 教學](https://reader035.fdocuments.net/reader035/viewer/2022062310/568165f7550346895dd91fad/html5/thumbnails/36.jpg)
36
http://docs.openstack.org/cli/quick-start/content/authenticate.html