add logging around ssh keys to capsul creation to support a user who is
experiencing bugs
This commit is contained in:
		@ -1,5 +1,6 @@
 | 
			
		||||
import re
 | 
			
		||||
import sys
 | 
			
		||||
import json
 | 
			
		||||
from datetime import datetime, timedelta
 | 
			
		||||
from flask import Blueprint
 | 
			
		||||
from flask import flash
 | 
			
		||||
@ -127,6 +128,9 @@ def create():
 | 
			
		||||
  account_balance = get_account_balance(get_vms(), get_payments(), datetime.utcnow())
 | 
			
		||||
  capacity_avaliable = current_app.config["VIRTUALIZATION_MODEL"].capacity_avaliable(512*1024*1024)
 | 
			
		||||
  errors = list()
 | 
			
		||||
  
 | 
			
		||||
  email_to_log = session["account"]
 | 
			
		||||
  current_app.logger.info(f"create for {email_to_log}: ssh keys from db:\n {json.dumps(ssh_public_keys)}")
 | 
			
		||||
 | 
			
		||||
  if request.method == "POST":
 | 
			
		||||
    if "csrf-token" not in request.form or request.form['csrf-token'] != session['csrf-token']:
 | 
			
		||||
@ -151,11 +155,15 @@ def create():
 | 
			
		||||
      errors.append("something went wrong with ssh keys")
 | 
			
		||||
    else:
 | 
			
		||||
      for i in range(0, posted_keys_count):
 | 
			
		||||
        to_log_bool = f"ssh_key_{i}" in request.form
 | 
			
		||||
        current_app.logger.info(f"checking for ssh_key_{i}: {to_log_bool}")
 | 
			
		||||
        if f"ssh_key_{i}" in request.form:
 | 
			
		||||
          posted_name = request.form[f"ssh_key_{i}"]
 | 
			
		||||
          current_app.logger.info(f"ssh key posted_name: {posted_name}")
 | 
			
		||||
          key = None
 | 
			
		||||
          for x in ssh_public_keys:
 | 
			
		||||
            if x['name'] == posted_name:
 | 
			
		||||
              current_app.logger.info(f"ssh key posted_name {posted_name} was found")
 | 
			
		||||
              key = x
 | 
			
		||||
          if key:
 | 
			
		||||
            posted_keys.append(key)
 | 
			
		||||
@ -172,6 +180,8 @@ def create():
 | 
			
		||||
        host(s) at capacity. no capsuls can be created at this time. sorry. 
 | 
			
		||||
      """)
 | 
			
		||||
 | 
			
		||||
    current_app.logger.info(f"create for {email_to_log}: posted_keys:\n {json.dumps(posted_keys)}")
 | 
			
		||||
 | 
			
		||||
    if len(errors) == 0:
 | 
			
		||||
      id = makeCapsulId()
 | 
			
		||||
      get_model().create_vm(
 | 
			
		||||
 | 
			
		||||
@ -113,6 +113,8 @@ class DBModel:
 | 
			
		||||
    )
 | 
			
		||||
    
 | 
			
		||||
    for ssh_public_key in ssh_public_keys:
 | 
			
		||||
      current_app.logger.info(f"INSERT INTO vm_ssh_public_key (email, vm_id, ssh_public_key_name) VALUES  (\"{email}\", \"{id}\", \"{ssh_public_key}\")")
 | 
			
		||||
      
 | 
			
		||||
      self.cursor.execute(""" 
 | 
			
		||||
        INSERT INTO vm_ssh_public_key (email, vm_id, ssh_public_key_name)
 | 
			
		||||
        VALUES  (%s, %s, %s)
 | 
			
		||||
 | 
			
		||||
@ -126,6 +126,8 @@ class ShellScriptVirtualization(VirtualizationInterface):
 | 
			
		||||
 | 
			
		||||
    ssh_keys_string = "\n".join(ssh_public_keys)
 | 
			
		||||
 | 
			
		||||
    current_app.logger.info(f"create vm virt model ssh_keys_string: {ssh_keys_string}")
 | 
			
		||||
 | 
			
		||||
    completedProcess = run([
 | 
			
		||||
      join(current_app.root_path, 'shell_scripts/create.sh'),
 | 
			
		||||
      id,
 | 
			
		||||
@ -147,6 +149,8 @@ class ShellScriptVirtualization(VirtualizationInterface):
 | 
			
		||||
      ssh_public_keys={ssh_keys_string}
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    current_app.logger.info(f"create vm status: {status} vmSettings: {vmSettings}")
 | 
			
		||||
 | 
			
		||||
    if not status == "success":
 | 
			
		||||
      raise ValueError(f"""failed to create vm for {email} with:
 | 
			
		||||
        {vmSettings}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user