-
-
Save mtorrisi/d445e4dc25b0aaf52aa0f8551745c2e1 to your computer and use it in GitHub Desktop.
Openstack CLI commands to create a new Project/Tenant, networks and security group using specific Openstack service CLI commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
############## Define those variables for the tenant | |
TENANT=$1 | |
PASSWORD=$2 | |
TENANT_DESC="$3" | |
TENANT_EMAIL="$4" | |
TENANT_NET_CIDR="10.0.1.0/24" | |
TENANT_NET_GW="10.0.1.1" | |
DEFAULT_DNS="8.8.8.8" | |
SEC_GROUP_NAME="addis-use-cases" | |
############### | |
# Create a new project and get the id | |
keystone tenant-create --name $TENANT --description $TENANT_DESC | |
TENANT_ID=$(keystone tenant-list | awk "/\ $TENANT\ / { print \$2 }") | |
# Create a new user | |
keystone user-create --name $TENANT --tenant $TENANT --pass $PASSWORD --email $TENANT_EMAIL | |
# Create the network with VLAN | |
neutron net-create --tenant-id $TENANT_ID "$TENANT-net" | |
# Create the subnet and get the ID | |
neutron subnet-create --name "$TENANT-subnet" --tenant-id $TENANT_ID --gateway $TENANT_NET_GW --dns-nameserver $DEFAULT_DNS "$TENANT-net" $TENANT_NET_CIDR | |
TENANT_SUBNET_ID=$(neutron subnet-list -f csv -F id -F cidr | grep "$TENANT_NET_CIDR" | cut -f1 -d',' | tr -d '"') | |
# Create a Router and get the ID | |
neutron router-create --tenant-id $TENANT_ID "$TENANT-router" | |
ROUTER_ID=$(neutron router-list -f csv -F id -F name | grep "$TENANT-router" | cut -f1 -d',' | tr -d '"') | |
# Set the gw for the new router | |
neutron router-gateway-set "$TENANT-router" "ext-net" | |
# Add a new interface in the main router | |
neutron router-interface-add $ROUTER_ID "$TENANT-subnet" | |
# Create the security group | |
neutron security-group-create --tenant-id $TENANT_ID $SEC_GROUP_NAME | |
SEC_GROUP_ID=$(neutron security-group-list -f csv -F id -F name | grep $SEC_GROUP_NAME | cut -f1 -d',' | tr -d '"') | |
# Add rules the security group | |
neutron security-group-rule-create --direction ingress --ethertype IPv4 --port-range-min 22 --port-range-max 22 --protocol tcp --tenant-id $TENANT_ID $SEC_GROUP_ID | |
neutron security-group-rule-create --direction ingress --ethertype IPv4 --port-range-min 80 --port-range-max 80 --protocol tcp --tenant-id $TENANT_ID $SEC_GROUP_ID | |
neutron security-group-rule-create --direction ingress --ethertype IPv4 --port-range-min 443 --port-range-max 443 --protocol tcp --tenant-id $TENANT_ID $SEC_GROUP_ID | |
neutron security-group-rule-create --direction ingress --ethertype IPv4 --port-range-min 8888 --port-range-max 8888 --protocol tcp --tenant-id $TENANT_ID $SEC_GROUP_ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mtorrisi, wouldn't it be better if we added a playbook for doing this to the repo ? These Ansible modules may be useful : http://docs.ansible.com/ansible/list_of_cloud_modules.html#openstack