示例#1
0
  def post(self):                     #  Create POST endpoint
    """
    Create a VM in Azure cloud from an image
    """
    conf = config.readConfig()
    if conf == 1:
      logger.error('Missing configuration')
      return 'Internal Error : Missing configuration. Fix it at ' + request.url_root + 'config'
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Internal Error : Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    extra_vars = {}
    payload = {}
    extra_vars['resource_group'] = api.payload['vm_resourcegroup']
    extra_vars['image'] = api.payload['vm_image']
    extra_vars['size'] = api.payload['vm_size']
    extra_vars['owner'] = api.payload['vm_owner_gaia']
    extra_vars['operating_system'] = api.payload['vm_os']
    extra_vars['target_dc'] = api.payload['vm_dc']
    extra_vars['vmname'] = api.payload['vm_name']
    payload['extra_vars'] = extra_vars

    logger.info('Creating an Azure VM from an image with the following parameters : ' + dumps(payload['extra_vars']))
    return common.launchAWXItem(awx_url=awx_url, awx_token=conf['awx_token'], item_type='workflow_job_templates', item_name='Create Windows VM On Azure', payload=payload)
示例#2
0
  def post(self):                     #  Create POST endpoint
    """
    Create a VM on premise on VMWare
    """
    conf = config.readConfig()
    if conf == 1:
      logger.error('Missing configuration')
      return 'Internal Error : Missing configuration. Fix it at ' + request.url_root + 'config'
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Internal Error : Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    extra_vars = {}
    payload = {}
    extra_vars['target_env'] = api.payload['target_env']
    extra_vars['site'] = api.payload['site']
    extra_vars['application_trigram'] = api.payload['application_trigram']
    extra_vars['owner'] = api.payload['owner']
    extra_vars['operating_system'] = api.payload['operating_system']
    extra_vars['cpu_count'] = int(api.payload['cpu_count'])
    extra_vars['ram_size'] = int(api.payload['ram_size'])
    extra_vars['disk_size'] = str(api.payload['disk_size'])
    extra_vars['vmname'] = api.payload['vmname']
    payload['extra_vars'] = extra_vars

    logger.info('Creating a VM on Premise with the following parameters : ' + dumps(payload['extra_vars']))
    return common.launchAWXItem(awx_url=awx_url, awx_token=conf['awx_token'], item_type='workflow_job_templates', item_name='Create Windows VM On Premise', payload=payload)
示例#3
0
  def delete(self):
    """
    Delete an Azure VM
    """
    conf = config.readConfig()
    if conf == 1:
      logger.error('Missing configuration')
      return 'Internal Error : Missing configuration. Fix it at ' + request.url_root + 'config'
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Internal Error : Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    extra_vars = {}
    payload = {}
    extra_vars['resource_group'] = api.payload['resource_group']
    extra_vars['vm_name'] = api.payload['vm_name']
    payload['extra_vars'] = extra_vars

    logger.info('Deleting an Azure VM with the following parameters : ' + dumps(payload['extra_vars']))
    return common.launchAWXItem(awx_url=awx_url, awx_token=conf['awx_token'], item_type='job_templates', item_name='Remove azure VM', payload=payload)
示例#4
0
  def delete(self):
    """
    Delete a VM on premise on VMWare
    """
    conf = config.readConfig()
    if conf == 1:
      logger.error('Missing configuration')
      return 'Internal Error : Missing configuration. Fix it at ' + request.url_root + 'config'
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Internal Error : Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    extra_vars = {}
    payload = {}
    extra_vars['target_env'] = api.payload['target_env']
    extra_vars['vm_name'] = api.payload['vm_name']
    payload['extra_vars'] = extra_vars

    logger.info('Deleting a VM on Premise with the following parameters : ' + dumps(payload['extra_vars']))
    return common.launchAWXItem(awx_url=awx_url, awx_token=conf['awx_token'], item_type='workflow_job_templates', item_name='Delete Windows VM On Premise', payload=payload)
示例#5
0
def home():
  mots = ["Bonjour", "à", "toi,", "anonyme citoyen."]
  createvmform = CreateVMForm()
  createazvmform = CreateAzureVMForm()
  deletevmform = DeleteVMForm()
  deleteazvmform = DeleteAzureVMForm()
  getinfosform = GetInfosForm()
  
  missing_config = True
  conf = config.readConfig()
  if conf != 1:
    missing_config = False

  if createvmform.create_button.data:
    if missing_config:
      logger.error('Missing configuration : awx_token')
      return 'Internal Error : Missing configuration : awx_token'
    
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    extra_vars = {}
    payload = {}
    extra_vars['target_env'] = createvmform.target_env.data
    extra_vars['site'] = createvmform.target_site.data
    extra_vars['application_trigram'] = createvmform.app_trigram.data
    extra_vars['owner'] = createvmform.vm_owner_gaia.data
    extra_vars['operating_system'] = createvmform.vm_os.data
    extra_vars['cpu_count'] = int(createvmform.vm_cpu_count.data)
    extra_vars['ram_size'] = int(createvmform.vm_ram_size.data)
    extra_vars['disk_size'] = str(createvmform.vm_disk_size.data)
    extra_vars['vmname'] = createvmform.vm_name.data
    payload['extra_vars'] = extra_vars

    logger.info('Creating a VM on Premise with the following parameters : ' + dumps(payload['extra_vars']))
    result = common.launchAWXItem(awx_url=awx_url, awx_token=conf['awx_token'], item_type='workflow_job_templates', item_name='Create Windows VM On Premise', payload=payload)
    # flash('{}'.format(dumps(result, indent=4, sort_keys=True)))
    # return redirect('/#flash')
    return redirect('/api/v1/infos/' + str(result['id']))
  
  elif deletevmform.delete_button.data:
    if missing_config:
      logger.error('Missing configuration : awx_token')
      return 'Internal Error : Missing configuration : awx_token'
    
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    extra_vars = {}
    payload = {}
    extra_vars['target_env'] = deletevmform.target_env.data
    extra_vars['vm_name'] = deletevmform.vm_name.data
    payload['extra_vars'] = extra_vars

    logger.info('Deleting a VM on Premise with the following parameters : ' + dumps(payload['extra_vars']))
    result = common.launchAWXItem(awx_url=awx_url, awx_token=conf['awx_token'], item_type='workflow_job_templates', item_name='Delete Windows VM On Premise', payload=payload)
    # flash('{}'.format(dumps(result, indent=4, sort_keys=True)))
    # return redirect('/#flash')
    return redirect('/api/v1/infos/' + str(result['id']))

  elif createazvmform.createaz_button.data:
    if missing_config:
      logger.error('Missing configuration : awx_token')
      return 'Internal Error : Missing configuration : awx_token'
    
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    extra_vars = {}
    payload = {}
    extra_vars['resource_group'] = createazvmform.vm_resourcegroup.data
    extra_vars['image'] = createazvmform.vm_image.data
    extra_vars['size'] = createazvmform.vm_size.data
    extra_vars['owner'] = createazvmform.vm_owner_gaia.data
    extra_vars['operating_system'] = createazvmform.vm_os.data
    extra_vars['target_dc'] = createazvmform.vm_dc.data
    extra_vars['vmname'] = createazvmform.vm_name.data
    payload['extra_vars'] = extra_vars

    logger.info('Creating an Azure VM with the following parameters : ' + dumps(payload['extra_vars']))
    result = common.launchAWXItem(awx_url=awx_url, awx_token=conf['awx_token'], item_type='workflow_job_templates', item_name='Create Windows VM On Azure', payload=payload)
    # flash('{}'.format(dumps(result, indent=4, sort_keys=True)))
    # return redirect('/#flash')
    return redirect('/api/v1/infos/' + str(result['id']))

  elif deleteazvmform.deleteaz_button.data:
    if missing_config:
      logger.error('Missing configuration : awx_token')
      return 'Internal Error : Missing configuration : awx_token'
    
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    extra_vars = {}
    payload = {}
    extra_vars['resource_group'] = deleteazvmform.resource_group.data
    extra_vars['vmname'] = deleteazvmform.vmname.data
    payload['extra_vars'] = extra_vars

    logger.info('Deleting an Azure VM with the following parameters : ' + dumps(payload['extra_vars']))
    result = common.launchAWXItem(awx_url=awx_url, awx_token=conf['awx_token'], item_type='job_templates', item_name='Remove azure VM', payload=payload)
    # flash('{}'.format(dumps(result, indent=4, sort_keys=True)))
    # return redirect('/#flash')
    return redirect('/api/v1/infos/' + str(result['id']))

  elif getinfosform.getinfos_button.data:
    if missing_config:
      logger.error('Missing configuration : awx_token')
      return 'Internal Error : Missing configuration : awx_token'
    
    check_con = common.checkAWXconnection(awx_url=awx_url)
    check_status = check_con['status_code']
    if check_status != 200:
      return 'Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')'
    
    logger.info('Getting information for the following AWX workflow : ' + str(getinfosform.item_id.data))
    result = common.getAWXInfos(awx_url=awx_url, awx_token=conf['awx_token'], item_id=getinfosform.item_id.data)
    # flash('{}'.format(dumps(result, indent=4, sort_keys=True)))
    return redirect('/api/v1/infos/' + str(getinfosform.item_id.data))

  else:
    if missing_config:
      logger.error('Missing configuration : awx_token')
      flash('ERROR : Missing configuration : awx_token')
      return redirect('/config')
    else:
      check_con = common.checkAWXconnection(awx_url=awx_url)
      check_status = check_con['status_code']
      if check_status != 200:
        logger.error('Impossible to connect to AWX [' + awx_url + '] ('+ str(check_con['status_code']) + ' : ' + check_con['reason'] + ')')
        missing_config = True
        connection_ok = False
      else:
        connection_ok = True

      return render_template('index.html', 
        titre=env.upper() + " GIAC Portal",
        connection_ok=connection_ok,
        check_con=check_con,
        mots=mots,
        form=createvmform,
        createazvmform=createazvmform,
        deletevmform=deletevmform,
        deleteazvmform=deleteazvmform,
        getinfosform=getinfosform)