-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Helper scripts #24
base: main
Are you sure you want to change the base?
Helper scripts #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
SITE="https://credits.apps.staging.hpc.cam.ac.uk" | ||
|
||
|
||
# Set up some variables | ||
CONTENT_TYPE="Content-Type: application/json" | ||
|
||
TOKEN="CHANGE THIS AFTER REDEPLOY" | ||
|
||
AUTH_HEADER="Authorization: Bearer $TOKEN" | ||
|
||
# rcp-azimuth-cloud-portal-dev | ||
PROJECT_ID="79b2c7925276436091fa9301c4b05fd2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, lets make this a script parameter. |
||
|
||
# 3. Add an account | ||
echo "Adding an account:" | ||
ACCOUNT_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
'{ | ||
"name": "Tes1452 Account", | ||
"email": "[email protected]" | ||
}' \ | ||
$SITE/account/ | jq -r '.url') | ||
echo "Account URL: $ACCOUNT_ID" | ||
|
||
PROVIDER_ID="$SITE/resource_provider/1/" | ||
|
||
echo "Adding a resource provider account:" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this script fails when the account already exists, I think we need to make the script idempotent, ideally. |
||
RPA_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
"{ | ||
\"account\": \"$ACCOUNT_ID\", | ||
\"provider\": \"$PROVIDER_ID\", | ||
\"project_id\": \"$PROJECT_ID\" | ||
}" \ | ||
$SITE/resource_provider_account/| jq -r '.id') | ||
echo "Resource Provider Account ID: $RPA_ID" | ||
|
||
START_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
END_DATE=$(date -u -d "+30 day" +"%Y-%m-%dT%H:%M:%SZ") | ||
# 5. Add some credit allocation | ||
echo "Adding credit allocation:" | ||
ALLOCATION_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
"{ | ||
\"name\": \"Test Allocation\", | ||
\"account\": \"$ACCOUNT_ID\", | ||
\"start\": \"$START_DATE\", | ||
\"end\": \"$END_DATE\" | ||
}" \ | ||
$SITE/allocation/ | jq -r '.id') | ||
echo "Credit Allocation ID: $ALLOCATION_ID" | ||
|
||
# 6. Add allocation to resource | ||
echo "Adding allocation to resources:" | ||
curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
"{ | ||
\"VCPU\": 10000, | ||
\"MEMORY_MB\": 24000000, | ||
\"DISK_GB\": 50000 | ||
}" \ | ||
$SITE/allocation/$ALLOCATION_ID/resources/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/bash | ||
set -eux | ||
|
||
SITE=https://credits.apps.staging.hpc.cam.ac.uk | ||
|
||
TEST_PASSWORD="testpassword" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we probably need a separate script that prompts the user for a password, then generates the token. I guess that is what the above script should be depending on. |
||
|
||
# Set up some variables | ||
CONTENT_TYPE="Content-Type: application/json" | ||
|
||
# Get a token | ||
echo "Getting an auth token:" | ||
TOKEN=$(curl -s -X POST -H "$CONTENT_TYPE" -d \ | ||
"{ | ||
\"username\": \"admin\", | ||
\"password\": \"$TEST_PASSWORD\" | ||
}" \ | ||
$SITE/api-token-auth/ | jq -r '.token') | ||
echo "Auth Token: $TOKEN" | ||
|
||
AUTH_HEADER="Authorization: Bearer $TOKEN" | ||
|
||
# 1. Add a resource provider | ||
echo "Adding a resource provider:" | ||
RESOURCE_PROVIDER_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
'{ | ||
"name": "Test Provider", | ||
"email": "[email protected]", | ||
"info_url": "http://testprovider.com" | ||
}' \ | ||
$SITE/resource_provider/ | jq -r '.url') | ||
echo "Resource Provider URL: $RESOURCE_PROVIDER_ID" | ||
|
||
# 2. Add resource classes | ||
echo "Adding resource classes:" | ||
VCPU_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d '{"name": "VCPU"}' $SITE/resource_class/ | jq -r '.id') | ||
MEMORY_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d '{"name": "MEMORY_MB"}' $SITE/resource_class/ | jq -r '.id') | ||
DISK_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d '{"name": "DISK_GB"}' $SITE/resource_class/ | jq -r '.id') | ||
echo "Resource Class IDs: VCPU=$VCPU_ID, MEMORY_MB=$MEMORY_ID, DISK_GB=$DISK_ID" | ||
|
||
# 3. Add an account | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we drop these bits from this script, and leave that to the other script that adds credits for a given account? |
||
echo "Adding an account:" | ||
ACCOUNT_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
'{ | ||
"name": "Test Account", | ||
"email": "[email protected]" | ||
}' \ | ||
$SITE/account/ | jq -r '.url') | ||
echo "Account URL: $ACCOUNT_ID" | ||
|
||
# rcp-azimuth-cloud-portal-demo | ||
PROJECT_ID="5fcc12ae513f4eaca2e0e7772f191282" | ||
|
||
echo "Adding a resource provider account:" | ||
RPA_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
"{ | ||
\"account\": \"$ACCOUNT_ID\", | ||
\"provider\": \"$RESOURCE_PROVIDER_ID\", | ||
\"project_id\": \"$PROJECT_ID\" | ||
}" \ | ||
$SITE/resource_provider_account/| jq -r '.id') | ||
echo "Resource Provider Account ID: $RPA_ID" | ||
|
||
START_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
END_DATE=$(date -u -d "+30 day" +"%Y-%m-%dT%H:%M:%SZ") | ||
# 5. Add some credit allocation | ||
echo "Adding credit allocation:" | ||
ALLOCATION_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
"{ | ||
\"name\": \"Test Allocation\", | ||
\"account\": \"$ACCOUNT_ID\", | ||
\"start\": \"$START_DATE\", | ||
\"end\": \"$END_DATE\" | ||
}" \ | ||
$SITE/allocation/ | jq -r '.id') | ||
echo "Credit Allocation ID: $ALLOCATION_ID" | ||
|
||
# 6. Add allocation to resource | ||
echo "Adding allocation to resources:" | ||
curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ | ||
"{ | ||
\"VCPU\": 10000, | ||
\"MEMORY_MB\": 24000000, | ||
\"DISK_GB\": 50000 | ||
}" \ | ||
$SITE/allocation/$ALLOCATION_ID/resources/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change these to required params for the script please? Or maybe just a required env variable, in the case of the token?