Skip to content

Commit

Permalink
Allow passing reservation when creating accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
fridim committed Nov 2, 2023
1 parent 50db727 commit 67a9e4a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
46 changes: 46 additions & 0 deletions playbooks/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,49 @@ sandbox-list --sort name -all |awk '/^sandbox3001 /{flag=1}flag{print $1 " " $3}
# Go back on admin host, ensure they are all valide
./validate.yml -e account_num_start=3001 -e account_num_end=3010
----

=== Create new sandboxes for a specific reservation and OU ===

WARNING: This should be done only when strictly necessary. Prefer the regular process of creating/scaling a reservation using existing sandboxes from the available pool instead, see link:../tools/readme.adoc[tools/readme.adoc]

. First, Make sure the reservation already exists in the DB, see link:../tools/readme.adoc[tools/readme.adoc]
+
----
[opentlc-mgr@admin (PROD) ~]$ . ~/pool_management/python_virtualenv/bin/activate
(python_virtualenv) [opentlc-mgr@admin (PROD) ~]$ cd pool_management/sandbox/playbooks
START=3200
COUNT=10
END=3210
RESERVATION=rosa-test
# .create 10 AWS sandbox accounts: sandbox$START .. sandbox$END
./create_range.yml -e account_num_start=$START -e account_count=$COUNT -e sandbox_reservation=$RESERVATION -e account_destination_ou=rosa
# Add GOLD IMAGES to the new accounts
# Generate the list of new sandboxes
sandbox-list --sort name -all |awk '/^sandbox'$START' /{flag=1}flag{print $1 " " $3}' > new_sandboxes.txt
# SSH to QA or a place where node is installed, copy new_sandboxes.txt there
# Run cloud-automation to subscribe to GOLD images, see cloud-automation readme
# Go back on admin host, ensure they are all valide
./validate.yml -e account_num_start=$START -e account_num_end=$END
# If all goes well, enable the sandboxes
for i in $(seq $START $END); do
sandbox_enable.sh sandbox$i
done
# check the new number of sandboxes in the reservation
sandbox-list --all --reservation $RESERVATION
sandbox-list --all --no-headers --reservation $RESERVATION | wc -l
----
. Manually update the count in the `reservations` to match the number of sandboxes in the reservation.
+
.Increase the count to match the actual number, replace `CHANGE_ME`
[source,sql]
----
update reservation set request = jsonb_set(request, '{resources, 0, count}',to_jsonb(CHANGE_ME)) where reservation_name='rosa-test';
----
12 changes: 11 additions & 1 deletion playbooks/roles/infra-aws-sandbox/tasks/pool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
- debug:
var: _getaccount

- when: sandbox_reservation | default("", true) not in ["", "None", "null"]
set_fact:
additional_data:
reservation:
S: "{{ sandbox_reservation }}"

- when: sandbox_reservation | default("", true) in ["", "None", "null"]
set_fact:
additional_data: {}

- name: Create account in DB if it doesn't exist
vars:
_data:
Expand All @@ -35,7 +45,7 @@
aws --profile {{ dynamodb_profile }} --region {{ dynamodb_region }}
dynamodb put-item
--table-name {{ dynamodb_table }}
--item '{{ _data | to_json }}'
--item '{{ _data | combine(additional_data | default({}), recursive=True) | to_json }}'
register: _putaccount
when: _getaccount.stdout == '' or force_create

Expand Down

0 comments on commit 67a9e4a

Please sign in to comment.