Exemple #1
0
def view(view_type):
    add_device_form = AddDevice(request.form)
    add_link_form = AddLink(request.form)
    all_devices = Device.choices()
    add_link_form.source.choices = all_devices
    add_link_form.destination.choices = all_devices
    view_options_form = ViewOptionsForm(request.form)
    google_earth_form = GoogleEarthForm(request.form)
    scheduling_form = SchedulingForm(request.form)
    scheduling_form.job.choices = Job.choices()
    scheduling_form.devices.choices = all_devices
    scheduling_form.pools.choices = Pool.choices()
    labels = {'device': 'name', 'link': 'name'}
    if 'view_options' in request.form:
        # update labels
        labels = {
            'device': request.form['device_label'],
            'link': request.form['link_label']
        }
    # for the sake of better performances, the view defaults to markercluster
    # if there are more than 2000 devices
    view = 'leaflet' if len(Device.query.all()) < 2000 else 'markercluster'
    if 'view' in request.form:
        view = request.form['view']
    # name to id
    name_to_id = {
        device.name: id for id, device in enumerate(Device.query.all())
    }
    return render_template(
        f'{view_type}_view.html',
        pools=Pool.query.all(),
        parameters=Parameters.query.one().serialized,
        view=view,
        scheduling_form=scheduling_form,
        view_options_form=view_options_form,
        google_earth_form=google_earth_form,
        add_device_form=add_device_form,
        add_link_form=add_link_form,
        device_fields=device_public_properties,
        link_fields=link_public_properties,
        labels=labels,
        names=pretty_names,
        device_subtypes=device_subtypes,
        link_colors=link_subtype_to_color,
        name_to_id=name_to_id,
        devices=Device.serialize(),
        links=Link.serialize()
    )
Exemple #2
0
def device_management():
    return render_template(
        'device_management.html',
        names=pretty_names,
        fields=device_public_properties,
        devices=Device.serialize(),
        add_device_form=AddDevice(request.form)
    )
Exemple #3
0
def pool_management():
    pool_object_form = PoolObjectsForm(request.form)
    pool_object_form.devices.choices = Device.choices()
    pool_object_form.links.choices = Link.choices()
    return render_template('pool_management.html',
                           form=AddPoolForm(request.form),
                           pool_object_form=pool_object_form,
                           names=pretty_names,
                           fields=pool_public_properties,
                           pools=Pool.serialize())
Exemple #4
0
def task_management(task_type):
    scheduling_form = SchedulingForm(request.form)
    scheduling_form.devices.choices = Device.choices()
    scheduling_form.pools.choices = Pool.choices()
    scheduling_form.job.choices = Job.choices()
    task_class = ScriptTask if task_type == 'script' else WorkflowTask
    return render_template(f'{task_type}_tasks.html',
                           fields=task_public_properties,
                           tasks=task_class.serialize(),
                           compare_form=CompareForm(request.form),
                           scheduling_form=scheduling_form)
Exemple #5
0
def view(view_type):
    add_link_form = AddLink(request.form)
    all_devices = Device.choices()
    add_link_form.source.choices = all_devices
    add_link_form.destination.choices = all_devices
    labels = {'device': 'name', 'link': 'name'}
    if 'view_options' in request.form:
        labels = {
            'device': request.form['device_label'],
            'link': request.form['link_label']
        }
    if len(Device.query.all()) < 50:
        view = 'glearth'
    elif len(Device.query.all()) < 2000:
        view = 'leaflet'
    else:
        view = 'markercluster'
    if 'view' in request.form:
        view = request.form['view']
    # name to id
    name_to_id = {
        device.name: id
        for id, device in enumerate(Device.query.all())
    }
    return render_template(f'{view_type}_view.html',
                           pools=Pool.query.all(),
                           parameters=Parameters.query.one().serialized,
                           view=view,
                           view_options_form=ViewOptionsForm(request.form),
                           google_earth_form=GoogleEarthForm(request.form),
                           add_device_form=AddDevice(request.form),
                           add_link_form=add_link_form,
                           device_fields=device_public_properties,
                           link_fields=link_public_properties,
                           labels=labels,
                           names=pretty_names,
                           device_subtypes=device_subtypes,
                           link_colors=link_subtype_to_color,
                           name_to_id=name_to_id,
                           devices=Device.serialize(),
                           links=Link.serialize())
Exemple #6
0
def task_management():
    scheduling_form = SchedulingForm(request.form)
    scheduling_form.devices.choices = Device.choices()
    scheduling_form.pools.choices = Pool.choices()
    scheduling_form.job.choices = Job.choices()
    return render_template(
        'task_management.html',
        fields=task_public_properties,
        tasks=Task.serialize(),
        compare_form=CompareForm(request.form),
        scheduling_form=scheduling_form
    )
Exemple #7
0
def scripts():
    scheduling_form = SchedulingForm(request.form)
    scheduling_form.devices.choices = Device.choices()
    scheduling_form.pools.choices = Pool.choices()
    scheduling_form.job.choices = Job.choices()
    return render_template(
        'script_management.html',
        fields=script_public_properties,
        type_to_form={t: s(request.form)
                      for t, s in type_to_form.items()},
        names=pretty_names,
        scheduling_form=scheduling_form,
        scripts=Script.serialize())
Exemple #8
0
def workflow_management():
    workflow_creation_form = WorkflowForm(request.form)
    workflow_creation_form.devices.choices = Device.choices()
    workflow_creation_form.pools.choices = Pool.choices()
    return render_template(
        'workflow_management.html',
        compare_logs_form=CompareLogsForm(request.form),
        names=pretty_names,
        fields=workflow_table_properties,
        property_types={k: str(v)
                        for k, v in property_types.items()},
        workflows=Workflow.serialize(),
        workflow_creation_form=workflow_creation_form)
Exemple #9
0
def service_management():
    service_form = JobForm(request.form)
    service_form.devices.choices = Device.choices()
    service_form.pools.choices = Pool.choices()
    return render_template(
        'service_management.html',
        compare_logs_form=CompareLogsForm(request.form),
        fields=service_table_properties,
        names=pretty_names,
        property_types={k: str(v)
                        for k, v in property_types.items()},
        service_form=service_form,
        services_classes=list(service_classes),
        services=Service.serialize())
Exemple #10
0
def workflow_builder():
    add_job_form = AddJobForm(request.form)
    add_job_form.job.choices = Job.choices()
    workflow_builder_form = WorkflowBuilderForm(request.form)
    workflow_builder_form.workflow.choices = Workflow.choices()
    service_form = JobForm(request.form)
    service_form.devices.choices = Device.choices()
    service_form.pools.choices = Pool.choices()
    return render_template(
        'workflow_builder.html',
        workflow=session.get('workflow', None),
        add_job_form=add_job_form,
        workflow_builder_form=workflow_builder_form,
        compare_logs_form=CompareLogsForm(request.form),
        names=pretty_names,
        property_types={k: str(v)
                        for k, v in property_types.items()},
        service_form=service_form,
        services_classes=list(service_classes))
Exemple #11
0
def workflow_editor(workflow_id=None):
    add_existing_task_form = AddExistingTaskForm(request.form)
    workflow_editor_form = WorkflowEditorForm(request.form)
    workflow_editor_form.workflow.choices = Workflow.choices()
    workflow = retrieve(Workflow, id=workflow_id)
    scheduling_form = SchedulingForm(request.form)
    scheduling_form.job.choices = Job.choices()
    scheduling_form.devices.choices = Device.choices()
    scheduling_form.pools.choices = Pool.choices()
    add_existing_task_form.task.choices = Task.choices()
    return render_template(
        'workflow_editor.html',
        add_existing_task_form=add_existing_task_form,
        workflow_editor_form=workflow_editor_form,
        scheduling_form=scheduling_form,
        compare_form=CompareForm(request.form),
        names=pretty_names,
        workflow=workflow.serialized if workflow_id else None
    )
Exemple #12
0
def objects_download():
    devices = Device.serialize()
    ws = {}
    wb = xlwt.Workbook()
    style0 = xlwt.easyxf(
        'font: name Times New Roman, color-index black, bold on',
        num_format_str='#,##0.00'
    )
    style1 = xlwt.easyxf(num_format_str='#,##0.00')
    header_index = 0
    for tab, header in cls_to_properties.items():
        column = 0
        ws[tab] = wb.add_sheet(tab)
        ws[tab].row_index = 1
        for entry in header:
            ws[tab].write(header_index, column, entry, style0)
            column = column + 1
    column = 0
    for device in devices:
        for k, v in device.items():
            if k is not 'id':
                try:
                    ws[device['type']].write(
                        ws[device['type']].row_index,
                        column,
                        v,
                        style1
                    )
                    column = column + 1
                except Exception:
                    continue
        column = 0
        ws[device['type']].row_index = ws[device['type']].row_index + 1
    obj_file = Path.cwd() / 'projects' / 'objects.xls'
    wb.save(str(obj_file))
    sfd = send_file(
        filename_or_fp=str(obj_file),
        as_attachment=True,
        attachment_filename='objects.xls'
    )
    return sfd