Example #1
0
def vault_view(vault_name):
    """
  Display the specified vault with all its contents...
  """
    region = get_set_region()
    vault = Vault.query.filter_by(region=region, name=vault_name).first()
    if vault is None:
        return redirect(url_for('main'))
    #Update the jobs
    null = check_job_status(vault_name)
    if vault.lock:
        #Check the jobs, execute the one we want if it's done
        live = vault.get_inventory_jobs()
        #Unlock if we have no live inventory jobs left, or the only live jobs left have completed
        if live is None or live[0].completed:
            #The successful option
            if live is not None:
                return redirect(
                    url_for('run_jobs',
                            vault_name=vault_name,
                            job_id=live[0].job_id))
            vault.lock = False
            WG.db.session.add(vault)
            WG.db.session.commit()
    altvaults = Vault.query.filter_by(region=vault.region).all()
    altclients = WG.queues.keys()
    altclients.sort()
    #Get any completed jobs
    live = vault.get_inventory_jobs()
    #Check the lock status and set the complete job if available
    inv_job = None
    if live is not None:
        for j in live:
            if not j.completed:
                #If there's an incomplete inventory job, make sure we're locked and finish
                if not vault.lock:
                    vault.lock = True
                    WG.db.session.add(vault)
                    WG.db.session.commit()
                inv_job = None
                break
            elif j.status_code == "Succeeded":
                #There's at least one complete job
                #They're sorted by date, so the first one is what we want if there are more than one
                if inv_job is None:
                    inv_job = url_for('run_jobs',
                                      vault_name=vault_name,
                                      job_id=j.job_id)
    return render_template("vault.html",
                           vault=vault,
                           altvaults=altvaults,
                           inv_job=inv_job,
                           clients=get_valid_clients())
Example #2
0
def main():
    """The main interface for the glacier database."""
    region = get_set_region()
    #Update from server
    _ = get_vaults()
    #Get all the vaults
    vaults = Vault.query.filter_by(region=region)
    #Render them all nicely
    return render_template("main.html",
                           vaults=vaults,
                           rnom=region,
                           regions=WG.handlers.keys(),
                           clients=get_valid_clients())
Example #3
0
def multi_dispatch(vault_name):
  """
  This should handle the big form submit.  That is, when we hit any of the
  buttons on the vault pages, it should end up here and do what was
  asked after some validation.
  """
  #Get the valid clients and make sure the one we selected is one of them
  clients = get_valid_clients()
  client = request.form.get("client_select")
  if client in clients:
    #We've got a valid client, save it
    WG.app.config['current_client'] = client
  if WG.app.config.get("VERBOSE",False):
    print "Handling multi-dispatch.  Client is %s"%str(client)
  #Are we just changing vaults, if so don't need the extra validation stuff
  if 'vault_select_pressed' in request.form:
    if WG.app.config.get("VERBOSE",False):
      print "Changing vault"
    #Change vault and we're done
    return redirect(url_for("vault_view",vault_name=request.form['vault_select']))
  #Either we're done, or we need to do something else
  if client in clients:
    #Did we press upload?
    if 'upload_pressed' in request.form:
      #Extract description
      description=request.form.get('upload_description','')
      if description=="Description of file.":
        description=''
      #Do upload
      if WG.app.config.get("VERBOSE",False):
        print "Doing upload via client from vault %s with path %s"%(vault_name,request.form['upload_path'])
      upload_archive_queue(vault_name,request.form['upload_path'],client,description)
    elif 'download' in request.form:
      #Do download
      if WG.app.config.get("VERBOSE",False):
        print "Doing download via client from vault %s with id %s"%(vault_name,request.form['download'])
      download_archive(vault_name,request.form['download'],client)
  else:
    if 'add_archive_via_server' in request.form:
      if WG.app.config.get("VERBOSE",False):
        print "Doing upload via server with request.form %s and request.files %s"%(str(request.form),str(request.files))
      #Need to do the via elsewhere upload.
      return upload_file(vault_name)
    if WG.app.config.get("VERBOSE",False):
      print "Doing nothing"
  if WG.app.config.get("VERBOSE",False):
    print "Form that did nothing much was %s"%str(request.form)
  return redirect(request.referrer)
Example #4
0
def settings():
    """
  The settings page.  Where you can edit the settings.
  """
    form = SettingsForm(**WG.app.config)
    if form.validate_on_submit():
        cfile = os.path.join(WG.__path__[0], "../settings.cfg")
        save_settings(form.data, cfile)
        WG.app.config.from_pyfile("../settings.cfg")
        WG.app.config.from_envvar("GLACIER_CONFIG", silent=True)
        return redirect(url_for('main'))
    rnom = get_set_region()
    return render_template("settings.html",
                           config=WG.app.config,
                           regions=WG.handlers.keys(),
                           rnom=rnom,
                           form=form,
                           clients=get_valid_clients())
Example #5
0
def vault_view(vault_name):
  """
  Display the specified vault with all its contents...
  """
  region = get_set_region()
  vault = Vault.query.filter_by(region=region,name=vault_name).first()
  if vault is None:
    return redirect(url_for('main'))
  #Update the jobs
  null=check_job_status(vault_name)
  if vault.lock:
    #Check the jobs, execute the one we want if it's done
    live=vault.get_inventory_jobs()
    #Unlock if we have no live inventory jobs left, or the only live jobs left have completed
    if live is None or live[0].completed:
      #The successful option
      if live is not None:
        return redirect(url_for('run_jobs',vault_name=vault_name,job_id=live[0].job_id))
      vault.lock=False
      WG.db.session.add(vault)
      WG.db.session.commit()
  altvaults=Vault.query.filter_by(region=vault.region).all()
  altclients=WG.queues.keys()
  altclients.sort()
  #Get any completed jobs
  live=vault.get_inventory_jobs()
  #Check the lock status and set the complete job if available
  inv_job=None
  if live is not None:
    for j in live:
      if not j.completed:
        #If there's an incomplete inventory job, make sure we're locked and finish
        if not vault.lock:
          vault.lock=True
          WG.db.session.add(vault)
          WG.db.session.commit()
        inv_job=None
        break
      elif j.status_code=="Succeeded":
        #There's at least one complete job
        #They're sorted by date, so the first one is what we want if there are more than one
        if inv_job is None:
          inv_job=url_for('run_jobs',vault_name=vault_name,job_id=j.job_id)
  return render_template("vault.html",vault=vault,altvaults=altvaults,inv_job=inv_job,clients=get_valid_clients())
Example #6
0
def help():
  """A simple help page"""
  return render_template("help.html",clients=get_valid_clients())
Example #7
0
def main():
  """The main interface for the glacier database."""
  region = get_set_region()
  #Update from server
  _ = get_vaults()
  #Get all the vaults
  vaults = Vault.query.filter_by(region=region)
  #Render them all nicely
  return render_template("main.html",vaults=vaults,rnom=region,regions=WG.handlers.keys(),clients=get_valid_clients())
Example #8
0
def settings():
  """
  The settings page.  Where you can edit the settings.
  """
  form=SettingsForm(**WG.app.config)
  if form.validate_on_submit():
    cfile=os.path.join(WG.__path__[0],"../settings.cfg")
    save_settings(form.data,cfile)
    WG.app.config.from_pyfile("../settings.cfg")
    WG.app.config.from_envvar("GLACIER_CONFIG",silent=True)
    return redirect(url_for('main'))
  rnom=get_set_region()
  return render_template("settings.html",config=WG.app.config,regions=WG.handlers.keys(),rnom=rnom,form=form,clients=get_valid_clients())
Example #9
0
def help():
    """A simple help page"""
    return render_template("help.html", clients=get_valid_clients())