| Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 1 | # lib/marconi | 
|  | 2 | # Install and start **Marconi** service | 
|  | 3 |  | 
|  | 4 | # To enable a minimal set of Marconi services, add the following to localrc: | 
|  | 5 | #   enable_service marconi-server | 
|  | 6 | # | 
|  | 7 | # Dependencies: | 
|  | 8 | # - functions | 
|  | 9 | # - OS_AUTH_URL for auth in api | 
|  | 10 | # - DEST set to the destination directory | 
|  | 11 | # - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api | 
|  | 12 | # - STACK_USER service user | 
|  | 13 |  | 
|  | 14 | # stack.sh | 
|  | 15 | # --------- | 
|  | 16 | # install_marconi | 
|  | 17 | # configure_marconi | 
|  | 18 | # init_marconi | 
|  | 19 | # start_marconi | 
|  | 20 | # stop_marconi | 
|  | 21 | # cleanup_marconi | 
|  | 22 |  | 
|  | 23 | # Save trace setting | 
|  | 24 | XTRACE=$(set +o | grep xtrace) | 
|  | 25 | set +o xtrace | 
|  | 26 |  | 
|  | 27 |  | 
|  | 28 | # Defaults | 
|  | 29 | # -------- | 
|  | 30 |  | 
|  | 31 | # Set up default directories | 
|  | 32 | MARCONI_DIR=$DEST/marconi | 
|  | 33 | MARCONICLIENT_DIR=$DEST/python-marconiclient | 
|  | 34 | MARCONI_CONF_DIR=/etc/marconi | 
|  | 35 | MARCONI_CONF=$MARCONI_CONF_DIR/marconi.conf | 
|  | 36 | MARCONI_API_LOG_DIR=/var/log/marconi-api | 
|  | 37 | MARCONI_AUTH_CACHE_DIR=${MARCONI_AUTH_CACHE_DIR:-/var/cache/marconi} | 
|  | 38 |  | 
|  | 39 | # Support potential entry-points console scripts | 
|  | 40 | MARCONI_BIN_DIR=$(get_python_exec_prefix) | 
|  | 41 |  | 
|  | 42 | # Set up database backend | 
|  | 43 | MARCONI_BACKEND=${MARCONI_BACKEND:-mongodb} | 
|  | 44 |  | 
|  | 45 |  | 
|  | 46 | # Set Marconi repository | 
|  | 47 | MARCONI_REPO=${MARCONI_REPO:-${GIT_BASE}/openstack/marconi.git} | 
|  | 48 | MARCONI_BRANCH=${MARCONI_BRANCH:-master} | 
|  | 49 |  | 
|  | 50 | # Set client library repository | 
|  | 51 | MARCONICLIENT_REPO=${MARCONICLIENT_REPO:-${GIT_BASE}/openstack/python-marconiclient.git} | 
|  | 52 | MARCONICLIENT_BRANCH=${MARCONICLIENT_BRANCH:-master} | 
|  | 53 |  | 
|  | 54 | # Functions | 
|  | 55 | # --------- | 
|  | 56 |  | 
|  | 57 | # cleanup_marconi() - Remove residual data files, anything left over from previous | 
|  | 58 | # runs that a clean run would need to clean up | 
|  | 59 | function cleanup_marconi() { | 
|  | 60 | mongo marconi --eval "db.dropDatabase();" | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | # configure_marconiclient() - Set config files, create data dirs, etc | 
|  | 64 | function configure_marconiclient() { | 
|  | 65 | setup_develop $MARCONICLIENT_DIR | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | # configure_marconi() - Set config files, create data dirs, etc | 
|  | 69 | function configure_marconi() { | 
|  | 70 | setup_develop $MARCONI_DIR | 
|  | 71 |  | 
|  | 72 | [ ! -d $MARCONI_CONF_DIR ] && sudo mkdir -m 755 -p $MARCONI_CONF_DIR | 
|  | 73 | sudo chown $USER $MARCONI_CONF_DIR | 
|  | 74 |  | 
|  | 75 | [ ! -d $MARCONI_API_LOG_DIR ] &&  sudo mkdir -m 755 -p $MARCONI_API_LOG_DIR | 
|  | 76 | sudo chown $USER $MARCONI_API_LOG_DIR | 
|  | 77 |  | 
|  | 78 | iniset $MARCONI_CONF DEFAULT verbose True | 
|  | 79 | iniset $MARCONI_CONF 'drivers:transport:wsgi' bind '0.0.0.0' | 
|  | 80 |  | 
|  | 81 | # Install the policy file for the API server | 
|  | 82 | cp $MARCONI_DIR/etc/marconi/policy.json $MARCONI_CONF_DIR | 
|  | 83 | iniset $MARCONI_CONF DEFAULT policy_file $MARCONI_CONF_DIR/policy.json | 
|  | 84 |  | 
|  | 85 | iniset $MARCONI_CONF keystone_authtoken auth_protocol http | 
|  | 86 | iniset $MARCONI_CONF keystone_authtoken admin_user marconi | 
|  | 87 | iniset $MARCONI_CONF keystone_authtoken admin_password $SERVICE_PASSWORD | 
|  | 88 | iniset $MARCONI_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME | 
|  | 89 | iniset $MARCONI_CONF keystone_authtoken signing_dir $MARCONI_AUTH_CACHE_DIR | 
|  | 90 |  | 
|  | 91 | if [[ "$MARCONI_BACKEND" = 'mongodb' ]]; then | 
|  | 92 | iniset $MARCONI_CONF database connection mongodb://localhost:27017/marconi | 
|  | 93 | configure_mongodb | 
|  | 94 | cleanup_marconi | 
|  | 95 | fi | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | function configure_mongodb() { | 
|  | 99 | # Set nssize to 2GB. This increases the number of namespaces supported | 
|  | 100 | # # per database. | 
|  | 101 | sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod | 
|  | 102 |  | 
|  | 103 | restart_service mongod | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | # init_marconi() - Initialize etc. | 
|  | 107 | function init_marconi() { | 
|  | 108 | # Create cache dir | 
|  | 109 | sudo mkdir -p $MARCONI_AUTH_CACHE_DIR | 
|  | 110 | sudo chown $STACK_USER $MARCONI_AUTH_CACHE_DIR | 
|  | 111 | rm -f $MARCONI_AUTH_CACHE_DIR/* | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | # install_marconi() - Collect source and prepare | 
|  | 115 | function install_marconi() { | 
|  | 116 | git_clone $MARCONI_REPO $MARCONI_DIR $MARCONI_BRANCH | 
|  | 117 | setup_develop $MARCONI_DIR | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | # install_marconiclient() - Collect source and prepare | 
|  | 121 | function install_marconiclient() { | 
|  | 122 | git_clone $MARCONICLIENT_REPO $MARCONICLIENT_DIR $MARCONICLIENT_BRANCH | 
|  | 123 | setup_develop $MARCONICLIENT_DIR | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | # start_marconi() - Start running processes, including screen | 
|  | 127 | function start_marconi() { | 
|  | 128 | screen_it marconi-server "marconi-server --config-file $MARCONI_CONF" | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | # stop_marconi() - Stop running processes | 
|  | 132 | function stop_marconi() { | 
|  | 133 | # Kill the marconi screen windows | 
|  | 134 | for serv in marconi-server; do | 
|  | 135 | screen -S $SCREEN_NAME -p $serv -X kill | 
|  | 136 | done | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | function create_marconi_accounts() { | 
|  | 140 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") | 
|  | 141 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") | 
|  | 142 |  | 
|  | 143 | MARCONI_USER=$(get_id keystone user-create --name=marconi \ | 
|  | 144 | --pass="$SERVICE_PASSWORD" \ | 
|  | 145 | --tenant_id $SERVICE_TENANT \ | 
|  | 146 | --email=marconi@example.com) | 
|  | 147 | keystone user-role-add --tenant-id $SERVICE_TENANT \ | 
|  | 148 | --user-id $MARCONI_USER \ | 
|  | 149 | --role-id $ADMIN_ROLE | 
|  | 150 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
|  | 151 | MARCONI_SERVICE=$(get_id keystone service-create \ | 
|  | 152 | --name=marconi \ | 
|  | 153 | --type=queuing \ | 
|  | 154 | --description="Marconi Service") | 
|  | 155 | keystone endpoint-create \ | 
|  | 156 | --region RegionOne \ | 
|  | 157 | --service_id $MARCONI_SERVICE \ | 
|  | 158 | --publicurl "http://$SERVICE_HOST:8888" \ | 
|  | 159 | --adminurl "http://$SERVICE_HOST:8888" \ | 
|  | 160 | --internalurl "http://$SERVICE_HOST:8888" | 
|  | 161 | fi | 
|  | 162 |  | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 |  | 
|  | 166 | # Restore xtrace | 
|  | 167 | $XTRACE | 
|  | 168 |  | 
|  | 169 | # Local variables: | 
|  | 170 | # mode: shell-script | 
|  | 171 | # End: |