Skip to content

Instantly share code, notes, and snippets.

@cnf
Created October 8, 2016 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnf/25f5ffde6af44c67a7c5c4e44bf15dc9 to your computer and use it in GitHub Desktop.
Save cnf/25f5ffde6af44c67a7c5c4e44bf15dc9 to your computer and use it in GitHub Desktop.
OpenStack Keystone setup scripts
#!/bin/sh
testexit() {
if [ ! $? -eq 0 ]; then
echo "something went wrong, exiting"
exit 1
fi
}
echoerr() {
echo "$@" 1>&2;
}
## Domain Stuff
domain() {
name=$1
desc="$1 Domain"
echoerr "Create or show Domain $name"
did=$(openstack domain create --or-show -f value -c id --description "${2:-$desc}" $name)
testexit
echoerr $did
printf $did
}
## User stuff
userid() {
mydomain=${DOMAIN:-default}
uid=$(openstack user show --domain $mydomain -c id -f value $1)
testexit
printf $uid
}
usercreate() {
mydomain=${DOMAIN:-default}
uid=$(openstack user create --or-show --domain $mydomain -f value -c id --password $2 $1)
testexit
printf $uid
}
user() {
echoerr "Create or update User $1"
uid=$(userid $1)
if [ $? -eq 1 ]; then
uid=$(usercreate $1 $2)
testexit
else
tmp=$(openstack user set --password $2 $uid)
testexit
fi
echoerr $uid
printf $uid
}
# Project Stuff
project() {
echoerr "Create or show Project $1"
desc="$1 Project"}
mydomain=${DOMAIN:-default}
pid=$(openstack project create --domain $mydomain --or-show -f value -c id --description "${2:-$desc}" $1)
testexit
echoerr $pid
printf $pid
}
# Roles stuff
roleid() {
rid=$(openstack role create --or-show -f value -c id $1)
testexit
printf $pid
}
role() {
name=$1
pid=$2
uid=$3
echoerr "Create or show Role $name P:$pid; U:$uid"
rid=$(openstack role create --or-show -f value -c id $name)
testexit
role=$(openstack role assignment list --effective --project $pid --role $rid --user $uid --name -f value -c User)
testexit
if [ -z $role ]; then
role=$(openstack role add --project $pid --user $uid $name)
testexit
fi
}
# Service stuff
serviceid() {
sid=$(openstack service show -f value -c id $1)
testexit
printf $sid
}
service() {
type=$1
name=$2
desc=${3:-"Openstack $2"}
echoerr "Create or show Service: $name $type"
sid=$(serviceid $name)
if [ $? -eq 1 ]; then
sid=$(openstack service create -f value -c id --name $name --description "$desc" $type)
testexit
fi
printf $sid
}
# Endpoint
endpointid() {
service=$1
interface=$2
eid=$(openstack endpoint list --service $service --interface $interface -f value -c ID)
testexit
if [ -z $eid ]; then
exit 1
fi
printf $eid
}
endpoint() {
service=$1
interface=$2
url=$3
myregion=${REGION:-RegionOne}
echoerr "Create or update endpoint $service $interface to $url"
eid=$(endpointid $service $interface)
if [ $? -eq 1 ]; then
eid=$(openstack endpoint create --region $myregion $service $interface $url)
testexit
else
tmp=$(openstack endpoint set --url $url $eid)
testexit
fi
echoerr $eid
printf $eid
}
#!/bin/sh
. functions.sh
PASSWORD=<MyPassWord>
IDENTIP=10.1.2.30:5000
IDENTSCHEME=http
## Keystone
# DOMAIN
DID=$(domain default "Default Domain")
testexit
# USER create / update
USERID=$(user admin $PASSWORD)
testexit
# PROJECT
ADMINPID=$(project admin "Admin Project")
testexit
SERVICEPID=$(project service "Services Project")
testexit
# ROLE
RID=$(role admin $ADMINPID $USERID)
testexit
# Service
SID=$(service identity keystone "OpenStack Identity")
testexit
# Endpoints
MYSCHEME=${IDENTSCHEME:-http}
MYPUBIP=${PUBIDENTIP:-$IDENTIP}
MYPUBSCHEME=${PUBIDENTSCHEME:-$MYSCHEME}
endpoint identity public ${MYPUBSCHEME}://${MYPUBIP}/v3
testexit
MYINTIP=${INTIDENTITYIP:-$IDENTIP}
MYINTSCHEME=${INTIDENTSCHEME:-$MYSCHEME}
endpoint identity internal ${MYINTSCHEME}://${MYINTIP}/v3
testexit
MYADMIP=${ADMIDENTIP:-$IDENTIP}
MYADMSCHEME=${ADMIDENTSCHEME:-$MYSCHEME}
endpoint identity admin ${MYADMSCHEME}://${MYADMIP}/v3
testexit
#!/bin/sh
. functions.sh
PASSWORD=<MyPassWord>
OBJECTIP=10.1.2.31:8080
OBJECTSCHEME=http
## Swift
# USER create / update
USERID=$(user swift $PASSWORD)
testexit
# PROJECT
PID=$(project service "Services Project")
testexit
# ROLE
RID=$(role admin $PID $USERID)
testexit
# Service
SID=$(service object-store swift "OpenStack Object Store")
testexit
# Endpoints
OBJECTSCHEME=${OBJECTSCHEME:-http}
PUBOBJIP=${PUBOBJECTIP:-$OBJECTIP}
PUBOBJSCHEME=${PUBOBJECTSCHEME:-$OBJECTSCHEME}
endpoint object-store public ${PUBOBJSCHEME}://${PUBOBJIP}/v1/AUTH_%\(tenant_id\)s
testexit
INTOBJIP=${INTOBJECTIP:-$OBJECTIP}
INTOBJSCHEME=${INTOBJECTSCHEME:-$OBJECTSCHEME}
endpoint object-store internal ${INTOBJSCHEME}://${INTOBJIP}/v1/AUTH_%\(tenant_id\)s
testexit
ADMOBJIP=${ADMOBJECTIP:-$OBJECTIP}
ADMOBJSCHEME=${ADMOBJECTSCHEME:-$OBJECTSCHEME}
endpoint object-store admin ${ADMOBJSCHEME}://${ADMOBJIP}/v1/
testexit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment