Skip to content

Instantly share code, notes, and snippets.

@jriguera
Created April 27, 2015 11:17
Show Gist options
  • Save jriguera/a1ffd131ade35ece8dd0 to your computer and use it in GitHub Desktop.
Save jriguera/a1ffd131ade35ece8dd0 to your computer and use it in GitHub Desktop.
Example of a creation of a new tenant in OpenStack using the command line
#!/bin/bash
TENANT=cf
PASSWORD=cf
TENANT_DESC="Cloud Foundry"
TENANT_EMAIL="[email protected]"
TENANT_NET="10.0.1.0/24"
TENANT_NET_GW="10.0.1.1"
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_TENANT_NAME=admin
export OS_AUTH_URL=http://controller:35357/v2.0
export OS_REGION_NAME=regionOne
# Create a new Project
keystone tenant-create --name $TENANT --description "$TENANT_DESC" --enabled true
TENANT_ID=$(keystone tenant-list | awk "/\ $TENANT\ / { print \$2 }")
# Admin user for tenant
keystone user-create --name $TENANT --tenant-id $TENANT_ID --pass $PASSWORD --email "$TENANT_EMAIL" --enabled true
USER_ID=$(keystone user-list --tenant-id $TENANT_ID | sed -ne "s/^| \(.*\) |[[:space:]]* $TENANT .*/\1/p")
# Admin role for the admin user. first, we need the admin role ID
ROLE_ID=$(keystone role-list | awk '/\ admin\ / {print $2}')
keystone user-role-add --user $USER_ID --role $ROLE_ID --tenant-id $TENANT_ID
# Create the network with VLAN
neutron net-create --tenant-id $TENANT_ID "$TENANT-net" --provider:network_type vlan
# Create the subnet
neutron subnet-create --tenant-id $TENANT_ID "$TENANT-net" $TENANT_NET --gateway $TENANT_NET_GW
TENANT_SUBNET_ID=$(neutron subnet-list -f csv -F id -F cidr | grep "$TENANT_NET" | cut -f1 -d',' | tr -d '"')
# Create a router
neutron router-create --tenant-id $TENANT_ID "ext-to-$TENANT-net"
ROUTER_ID=$(neutron router-list -f csv -F id -F name | grep "ext-to-$TENANT-net" | cut -f1 -d',' | tr -d '"')
# Set the gw for the new router
neutron router-gateway-set "ext-to-$TENANT-net" ext-net
# Add a new interface in the main router
neutron router-interface-add $ROUTER_ID $TENANT_SUBNET_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment