sh Openstack命令示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Openstack命令示例相关的知识,希望对你有一定的参考价值。
#!/bin/bash
# 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 172.16.1.0/24 --name private --dns-nameserver 8.8.8.8 --gateway 172.16.1.1
# 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 0.0.0.0/0
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
# 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.
parameters:
ImageID:
type: string
description: Image to use for the instance.
NetID:
type: string
description: Network ID to use for the instance.
resources:
server:
type: OS::Nova::Server
properties:
image: { get_param: ImageID }
flavor: m1.tiny
networks:
- network: { get_param: NetID }
outputs:
instance_name:
description: Name of the instance.
value: { get_attr: [ server, name ] }
instance_ip:
description: IP address of the instance.
value: { get_attr: [ server, first_address ] }
EOF
# 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
以上是关于sh Openstack命令示例的主要内容,如果未能解决你的问题,请参考以下文章
sh Openstack CLI命令使用标识V3(包含组)创建新项目/租户和网络
sh Openstack:使用python-novaclient命令将浮动IP与实例解除关联/重新关联,以纠正连接问题。
sh Openstack:使用python-novaclient命令将浮动IP与实例解除关联/重新关联,以纠正连接问题。