Exploit the --or-show functionality of openstackclient,
rather than issuing two different commands at the shell level,
let the CLI handle things.
Change-Id: I1db239fd3473eb580def1c5fb28ce472a1363569
| ... | ... |
@@ -831,15 +831,14 @@ function get_or_create_user {
|
| 831 | 831 |
fi |
| 832 | 832 |
# Gets user id |
| 833 | 833 |
local user_id=$( |
| 834 |
- # Gets user id |
|
| 835 |
- $os_cmd user show $1 $domain -f value -c id 2>/dev/null || |
|
| 836 |
- # Creates new user |
|
| 834 |
+ # Creates new user with --or-show |
|
| 837 | 835 |
$os_cmd user create \ |
| 838 | 836 |
$1 \ |
| 839 | 837 |
--password "$2" \ |
| 840 | 838 |
--project $3 \ |
| 841 | 839 |
$email \ |
| 842 | 840 |
$domain \ |
| 841 |
+ --or-show \ |
|
| 843 | 842 |
-f value -c id |
| 844 | 843 |
) |
| 845 | 844 |
echo $user_id |
| ... | ... |
@@ -856,10 +855,8 @@ function get_or_create_project {
|
| 856 | 856 |
os_cmd="$os_cmd --os-url=$KEYSTONE_SERVICE_URI/v3 --os-identity-api-version=3" |
| 857 | 857 |
fi |
| 858 | 858 |
local project_id=$( |
| 859 |
- # Gets project id |
|
| 860 |
- $os_cmd project show $1 $domain -f value -c id 2>/dev/null || |
|
| 861 |
- # Creates new project if not exists |
|
| 862 |
- $os_cmd project create $1 $domain -f value -c id |
|
| 859 |
+ # Creates new project with --or-show |
|
| 860 |
+ $os_cmd project create $1 $domain --or-show -f value -c id |
|
| 863 | 861 |
) |
| 864 | 862 |
echo $project_id |
| 865 | 863 |
} |
| ... | ... |
@@ -868,10 +865,8 @@ function get_or_create_project {
|
| 868 | 868 |
# Usage: get_or_create_role <name> |
| 869 | 869 |
function get_or_create_role {
|
| 870 | 870 |
local role_id=$( |
| 871 |
- # Gets role id |
|
| 872 |
- openstack role show $1 -f value -c id 2>/dev/null || |
|
| 873 |
- # Creates role if not exists |
|
| 874 |
- openstack role create $1 -f value -c id |
|
| 871 |
+ # Creates role with --or-show |
|
| 872 |
+ openstack role create $1 --or-show -f value -c id |
|
| 875 | 873 |
) |
| 876 | 874 |
echo $role_id |
| 877 | 875 |
} |