Adds support for multi-region

Change-Id: Ib85fe7cb375692b04aca4c46f61ba7e1fbfa501b
Implements: blueprint multi-region
diff --git a/lib/ironic b/lib/ironic
index dbeb3d3..c24780f 100644
--- a/lib/ironic
+++ b/lib/ironic
@@ -223,28 +223,21 @@
 
     # Ironic
     if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
-        IRONIC_USER=$(openstack user create \
-            ironic \
-            --password "$SERVICE_PASSWORD" \
-            --project $SERVICE_TENANT \
-            --email ironic@example.com \
-            | grep " id " | get_field 2)
-        openstack role add \
-            $ADMIN_ROLE \
-            --project $SERVICE_TENANT \
-            --user $IRONIC_USER
+        # Get ironic user if exists
+
+        IRONIC_USER=$(get_or_create_user "ironic" \
+            "$SERVICE_PASSWORD" $SERVICE_TENANT "ironic@example.com")
+        get_or_add_user_role $ADMIN_ROLE $IRONIC_USER $SERVICE_TENANT
+
         if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
-            IRONIC_SERVICE=$(openstack service create \
-                ironic \
-                --type=baremetal \
-                --description="Ironic baremetal provisioning service" \
-                | grep " id " | get_field 2)
-            openstack endpoint create \
-                $IRONIC_SERVICE \
-                --region RegionOne \
-                --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
-                --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
-                --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
+
+            IRONIC_SERVICE=$(get_or_create_service "ironic" \
+                "baremetal" "Ironic baremetal provisioning service")
+            get_or_create_endpoint $IRONIC_SERVICE \
+                "$REGION_NAME" \
+                "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
+                "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
+                "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
         fi
     fi
 }