Repository navigation
feat: check proxmox creation status and fail if it fails #226
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45944ee
feat: check proxmox creation status and fail if it fails
BigSpaceships e9c9330
fix: vms from proxstar are in fact vms
BigSpaceships 0412db2
fix: lint
BigSpaceships 1e2b649
fix: lint
BigSpaceships 25901f8
feat: extract ci functions
BigSpaceships File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| get_template, | ||
| ) | ||
| from proxstar.mail import send_vm_expire_email, send_rtp_vm_delete_email | ||
| from proxstar.proxmox import connect_proxmox, get_pools | ||
| from proxstar.proxmox import connect_proxmox, get_pools, get_task_status | ||
| from proxstar.starrs import get_next_ip, register_starrs, delete_starrs | ||
| from proxstar.user import User, get_vms_for_rtp | ||
| from proxstar.vm import VM, clone_vm, create_vm | ||
|
|
@@ -69,17 +69,30 @@ def create_vm_task(user, name, cores, memory, disk, iso): # pylint: disable=too | |
| starrs = connect_starrs() | ||
| logging.info('[{}] Creating VM.'.format(name)) | ||
| set_job_status(job, 'creating VM') | ||
| vmid = create_vm(proxmox, user, name, cores, memory, disk, iso) | ||
| vmid, task_id = create_vm(proxmox, user, name, cores, memory, disk, iso) | ||
| logging.info('[{}] Waiting until Proxmox is done provisioning.'.format(name)) | ||
| set_job_status(job, 'waiting for Proxmox') | ||
| timeout = 20 | ||
| retry = 0 | ||
| while retry < timeout: | ||
| status = get_task_status(proxmox, task_id) | ||
|
|
||
| if status['status'] == 'stopped' and status['exitstatus'] != 'OK': | ||
| logging.warning( | ||
| 'Failed to provision, error code is {}'.format(status['exitstatus']) | ||
| ) | ||
| set_job_status( | ||
| job, 'Failed to provision, error code is {}'.format(status['exitstatus']) | ||
| ) | ||
| delete_vm_task(vmid) | ||
| return | ||
|
|
||
| if not VM(vmid).is_provisioned(): | ||
| retry += 1 | ||
| time.sleep(3) | ||
| continue | ||
| break | ||
|
|
||
| if retry == timeout: | ||
| logging.info('[{}] Failed to provision, deleting.'.format(name)) | ||
| set_job_status(job, 'failed to provision') | ||
|
|
@@ -190,17 +203,30 @@ def setup_template_task( | |
| get_template(db, template_id) | ||
| logging.info('[{}] Cloning template {}.'.format(name, template_id)) | ||
| set_job_status(job, 'cloning template') | ||
| vmid = clone_vm(proxmox, template_id, name, user) | ||
| vmid, task_id = clone_vm(proxmox, template_id, name, user) | ||
| logging.info('[{}] Waiting until Proxmox is done provisioning.'.format(name)) | ||
| set_job_status(job, 'waiting for Proxmox') | ||
| timeout = 25 | ||
| retry = 0 | ||
| while retry < timeout: | ||
| status = get_task_status(proxmox, task_id) | ||
|
|
||
| if status['status'] == 'stopped' and status['exitstatus'] != 'OK': | ||
| logging.warning( | ||
| 'Failed to provision, error code is {}'.format(status['exitstatus']) | ||
| ) | ||
|
Comment on lines
+215
to
+217
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. 🟡 Low: Code Quality Violationdo not use format with logging (...read more)Avoid using format string with the Helpful? 👍/👎 |
||
| set_job_status( | ||
| job, 'Failed to provision, error code is {}'.format(status['exitstatus']) | ||
| ) | ||
| delete_vm_task(vmid) | ||
| return | ||
|
|
||
| if not VM(vmid).is_provisioned(): | ||
| retry += 1 | ||
| time.sleep(12) | ||
| continue | ||
| break | ||
|
|
||
| if retry == timeout: | ||
| logging.info('[{}] Failed to provision, deleting.'.format(name)) | ||
| set_job_status(job, 'failed to provision') | ||
|
|
@@ -213,16 +239,15 @@ def setup_template_task( | |
| set_job_status(job, 'registering in STARRS') | ||
| ip = get_next_ip(starrs, app.config['STARRS_IP_RANGE']) | ||
| register_starrs(starrs, name, app.config['STARRS_USER'], vm.get_mac(), ip) | ||
|
|
||
| get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS']) | ||
| logging.info('[{}] Setting CPU and memory.'.format(name)) | ||
| set_job_status(job, 'setting CPU and memory') | ||
| vm.set_cpu(cores) | ||
| vm.set_mem(memory) | ||
| logging.info('[{}] Applying cloud-init config.'.format(name)) | ||
| set_job_status(job, 'applying cloud-init') | ||
| vm.set_ci_user(user) | ||
| vm.set_ci_ssh_key(ssh_key) | ||
| vm.set_ci_network() | ||
| vm.set_ci(user, ssh_key) | ||
|
|
||
| if app.config['USE_STARRS']: | ||
| logging.info('[{}] Waiting for STARRS to propogate before starting VM.'.format(name)) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🟡 Low: Code Quality Violation
do not use format with logging (...read more)
Avoid using format string with the
formatmethod when logging information.Helpful? 👍/👎


🚩 Report as false positive. Flags the rule for review to improve detection accuracy.