4/12/2017 - 11:48 AM

Openstack commands example

Openstack commands example


# load authentication key
cd $HOME
source keystonerc_admin

# list neutron routers
neutron router-list --max-width 50

# remove router gateway
neutron router-gateway-clear <router name>

# list neutron router interfaces
neutron router-port-list <router name> --max-width 50

# remove neutron router interfaces
neutron router-interface-delete <router name> <"subnet_id">

# remove neutron router
neutron router-delete <router name>

# list neutron subnet
neutron subnet-list --max-width 50

# list neutron network
neutron net-list --max-width 50

# remove neutron subnet
neutron subnet-delete <subnet name>

# remove neutron network
neutron net-delete <network name>

# launch public and private instance example
# Source launchinstance.sh from https://github.com/prasetiyohadi/openstack-centos-install
# create public network 
source $HOME/admin-openrc.sh
neutron net-create public --shared --provider:physical_network public --provider:network_type flat
neutron subnet-create public <public network>/<public netmask> --name public --allocation-pool start=<first public ip>,end=<last public ip> --dns-nameserver <public dns> --gateway <public network gateway>

# create private network
source $HOME/demo-openrc.sh
neutron net-create private
neutron subnet-create private --name private --dns-nameserver --gateway

# set public network as external network
source $HOME/admin-openrc.sh
neutron net-update public --router:external

# create router and add private interface and set public network as gateway
source $HOME/demo-openrc.sh
neutron router-create router
neutron router-interface-add router private
neutron router-gateway-set router public

# show userspace network configuration and port list
source $HOME/admin-openrc.sh
ip netns
neutron router-port-list router

# create ssh-key and add to openstack as mykey
source $HOME/demo-openrc.sh
ssh-keygen -q -N ""
nova keypair-add --pub-key .ssh/id_rsa.pub mykey
nova keypair-list

# open icmp and ssh in default security group
nova secgroup-add-rule default icmp -1 -1
nova secgroup-add-rule default tcp 22 22

# show openstack compute and networking status
source $HOME/demo-openrc.sh
nova flavor-list
nova image-list
neutron net-list
nova secgroup-list

# launch cirros instance in public network as public-instance and get vnc link
nova boot --flavor m1.tiny --image cirros --nic net-id=<public network id> --security-group default --key-name mykey public-instance
nova list
nova get-vnc-console public-instance novnc

# show openstack compute and networking status
source $HOME/demo-openrc.sh
nova flavor-list
nova image-list
neutron net-list
nova secgroup-list

# launch cirros instance in private network as private-instance and get vnc link and assign floating ip
nova boot --flavor m1.tiny --image cirros --nic net-id=<private network id> --security-group default --key-name mykey private-instance
nova list
nova get-vnc-console private-instance novnc
neutron floatingip-create public
nova floating-ip-associate private-instance <floating public ip>
nova list

# create new 1GB volume as volume1 
source $HOME/demo-openrc.sh
cinder create --display-name volume1 1
cinder list

# attach volume1 to public instance
nova volume-attach public-instance <volume id>
nova volume-list

# create new orchestration template as demo-template.yml
cat << EOF > $HOME/demo-template.yml
heat_template_version: 2015-10-15
description: Launch a basic instance using the ``m1.tiny`` flavor and one network.

    type: string
    description: Image to use for the instance.
    type: string
    description: Network ID to use for the instance.

    type: OS::Nova::Server
      image: { get_param: ImageID }
      flavor: m1.tiny
      - network: { get_param: NetID }

    description: Name of the instance.
    value: { get_attr: [ server, name ] }
    description: IP address of the instance.
    value: { get_attr: [ server, first_address ] }

# deploy orchestration template demo-template.yml, show and then delete
source $HOME/demo-openrc.sh
neutron net-list
export NET_ID=$(neutron net-list | awk '/ public / { print $2 }')
heat stack-create -f $HOME/demo-template.yml -P "ImageID=cirros;NetID=$NET_ID" stack
sleep 5m
heat stack-list
heat output-show --all stack
nova list
heat stack-delete stack