How to Build VM in OpenStack Cloud Using CLI

OpenStack VM Setup Using Command Line

(i have tested below setup in RHEL6.4)

How to upload OS image into Glance repo

[root@desktop30 ~(keystone_admin)]# glance image-create   –copy-from http://192.168.0.254/pub/LinuxWorld-Extra/BT5R3-GNOME-64/BT5R3-GNOME-64.iso   –is-public    true     –container-format     bare  –disk-format   iso    –name   bt5r3

Where :

–copy-from :  location to get OS image from

(

The same thing is done when using the STDIN redirection with < such as below :

# glance image-create    –is-public    true     –container-format     bare  –disk-format   iso    –name   bt5r3   <  myosimage.img

)

–container-format: bare (there is no container or metadata envelope for the image)

–disk-format : type of image like iso , vdi(virtual box) , vmdk(vmware) , vhd (xen and Hyper-V)

 

Get list of all image into glance with basic summary

[root@desktop30 ~(keystone_admin)]# glance image-list

Get details list of particular image from glance

[root@desktop30 ~(keystone_admin)]# glance image-show  bt5r3

Get details about image using image ID (get from above command)

[root@desktop30 ~(keystone_admin)]# glance show 6ac8deb4-e864-45d0-a18f-fe5e775981c7

 

Where internally glance manage all images

[root@desktop30 ~(keystone_admin)]# cd /var/lib/glance/images/

[root@desktop30 images(keystone_admin)]# ls

a55c3f12-bab9-4aca-a139-648f2676424b

 

Create network named “public” that we will connect to external world

[root@desktop30 images(keystone_admin)]# quantum net-create public –router:external=True

[root@desktop30 images(keystone_admin)]# quantum net-list

 

Create Subnetwork named “subpublic” into network “public”, from where we will assign floating ip to our VM

[root@desktop30 images(keystone_admin)]# quantum subnet-create –disable-dhcp –dns-nameserver 192.168.0.254  –allocation-pool          start=192.168.0.200,end=192.168.0.210    –gateway 192.168.0.254   –name  subpublic  public 192.168.0.0/24

[root@desktop30 images(keystone_admin)]# quantum subnet-list

Create network named “private” that connect to our VM

[root@desktop30 images(keystone_admin)]# quantum net-create private

 

Create subnetwork named “subprivate” under “private” network from where our VM get IP address

[root@desktop30 images(keystone_admin)]# quantum subnet-create   –name  subprivate  private  10.0.1.0/24

Note: By default DHCP server is enable

Create Router named “lwrouter” that connect our “public” and “private” network , so that VM can go to real world

[root@desktop30 images(keystone_admin)]# quantum router-create lwrouter

[root@desktop30 images(keystone_admin)]# quantum router-list

 

Router can only go to real world via our “public” network, set it

[root@desktop30 images(keystone_admin)]# quantum router-gateway-set  lwrouter  public

Connect one interface of router to “subprivate” to get internet connectivity to our VM

[root@desktop30 images(keystone_admin)]# quantum router-interface-add  lwrouter  subprivate

[root@desktop30 images(keystone_admin)]# quantum router-port-list lwrouter

Check network name space that managed by quantum or neutron

[root@desktop30 images(keystone_admin)]# ip netns

qrouter-8679bf29-304f-4485-834b-482f07b99f62

[root@desktop30 images(keystone_admin)]# ip netns exec qrouter-8679bf29-304f-4485-834b-482f07b99f62 bash

 

Get the ip address listed on the router interfaces

[root@desktop30 images(keystone_admin)]# ip a

9: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

10: qg-f2f60929-99: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether fa:16:3e:03:8c:94 brd ff:ff:ff:ff:ff:ff

inet 192.168.0.200/24 brd 192.168.0.255 scope global qg-f2f60929-99

inet6 fe80::f816:3eff:fe03:8c94/64 scope link

valid_lft forever preferred_lft forever

12: qr-dd00f64a-97: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether fa:16:3e:92:7d:dd brd ff:ff:ff:ff:ff:ff

inet 10.0.1.1/24 brd 10.0.1.255 scope global qr-dd00f64a-97

inet6 fe80::f816:3eff:fe92:7ddd/64 scope link

       valid_lft forever preferred_lft forever

Get all the network exists with network ID that used in launching instances bcoz we have to provide with network our instance will launch

[root@desktop30 images(keystone_admin)]# nova net-list

+————————————–+———+——+

| ID                                   | Label   | CIDR |

+————————————–+———+——+

| 047d2aff-a5f7-4c51-8430-ce1b3a6219a8 | public  | None |

| 39b77063-ecfe-48c2-81c2-266971a0e7a8 | private | None |

+————————————–+———+——+

Launch instance named “bt5instance” that use “private” network and using “bt5r3” image to boot or install OS

[root@desktop30 images(keystone_admin)]# nova  boot –poll –flavor m1.small  –image bt5r3  –nic net-id=39b77063-ecfe-48c2-81c2-266971a0e7a8  bt5instance

Where:

–poll :  Blocks while servers doing some action, so progress can be reported.

Nic net-id: where to connect to our VM instances

[root@desktop30 ~(keystone_admin)]# nova  hypervisor-list

+—-+———————–+

| ID | Hypervisor hostname   |

+—-+———————–+

| 1  | desktop30.example.com |

+—-+———————–+

Above cmd list all the hypervisor used for compute in our openstack, used in multi node cluster environment

[root@desktop30 ~(keystone_admin)]# nova hypervisor-show 1

Above cmd Give details of running usage by hypervisor

[root@desktop30 ~(keystone_admin)]# nova hypervisor-uptime  1

[root@desktop30 ~(keystone_admin)]# nova list

This list all the active VM running in nova compute

Get Floating IP (real ip) from “public” network

[root@desktop30 ~(keystone_admin)]# quantum floatingip-create  public

[root@desktop30 ~(keystone_admin)]# quantum floatingip-list

+————————————–+——————+———————+———+

| id                                   | fixed_ip_address | floating_ip_address | port_id |

+————————————–+——————+———————+———+

| 486f1def-9002-4555-935c-18aad1f47d2c |                  | 192.168.0.201       |         |

+————————————–+——————+———————+———+

 

Get the list of all port connected to router or VM

[root@desktop30 ~(keystone_admin)]# quantum port-list

+————————————–+——+——————-+————————————————————————————–+

| id                                   | name | mac_address       | fixed_ips                                                                            |

+————————————–+——+——————-+————————————————————————————–+

| c3fbaaf9-2778-4c1b-9e1f-f79de214e8e5 |      | fa:16:3e:65:71:f7 | {“subnet_id”: “4f55d0de-c3e6-4ce5-a8ba-68f5b739b241″, “ip_address”: “10.0.1.2″}      |

 

Get associate floating ip to port on the VM, (get from above commands)

[root@desktop30 ~(keystone_admin)]# quantum floatingip-associate  486f1def-9002-4555-935c-18aad1f47d2c  c3fbaaf9-2778-4c1b-9e1f-f79de214e8e5

Note : get Associated floatingip  486f1def-9002-4555-935c-18aad1f47d2c from “floatingip-list” cmd

 

Update Security Group “default” rule to allow tcp connection

[root@desktop30 ~(keystone_admin)]# quantum security-group-rule-create  –protocol tcp  default

Note: bydefault it allow ingress

[root@desktop30 ~(keystone_admin)]# quantum security-group-rule-list

Update Security Group “default” rule to allow icmp (ping) connection

[root@desktop30 ~(keystone_admin)]# quantum security-group-rule-create  –protocol icmp  default

 

Create Flavor named “my.lwnew” with flavour ID 20 and has Ram size 1024MB and Disk size 0 and has 1 vCPU with 8GB ephemeral disk

[root@desktop30 ~(keystone_admin)]# nova flavor-create  –ephemeral 8 my.lwnew  20  1024  0  1

+—-+———-+———–+——+———–+——+——-+————-+———–+————-+

| ID | Name     | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | extra_specs |

+—-+———-+———–+——+———–+——+——-+————-+———–+————-+

| 20 | my.lwnew | 1024      | 0    | 8         |      | 1     | 1.0         | True      | {}          |

+—-+———-+———–+——+———–+——+——-+————-+———–+————-+

[root@desktop30 ~(keystone_admin)]# nova flavor-list