Ejemplo n.º 1
0
def unit_tests_example_unit_tests_example_page_form():
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if not form.validate_on_submit():
        g.user.logger.info('Form data was not valid.')
        return render_template(
            'unit_tests_example_page.html',
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )

    print(form.configuration.data)
    print(form.email.data)
    print(form.password.data)
    print(form.mac_address.data)
    print(form.ip_address.data)
    print(form.url.data)
    print(form.file.data)
    print(form.boolean_checked.data)
    print(form.boolean_unchecked.data)
    print(form.date_time.data)
    print(form.submit.data)

    # Put form processing logic here
    g.user.logger.info('SUCCESS')
    flash('success', 'succeed')
    return redirect(
        url_for(
            'unit_tests_exampleunit_tests_example_unit_tests_example_page'))
def update_alias_record_update_alias_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations()
    if form.validate_on_submit():
        try:
            # Retrieve form attributes and declare variables
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form["view"])

            # Retrieve alias record
            alias_record = view.get_alias_record(request.form["alias_record"] +
                                                 "." + request.form["zone"])

            # Update the alias record's name and linkedRecordName
            alias_record.set_name(form.alias_name.data)
            alias_record.set_property(
                "linkedRecordName",
                request.form["linked_record"] + "." +
                request.form["linked_record_zone"],
            )
            alias_record.update()

            # Put form processing code here
            g.user.logger.info(
                "Success - Alias Record Modified - Object ID: " +
                str(alias_record.get_id()))
            flash(
                "Success - Alias Record Modified - Object ID: " +
                str(alias_record.get_id()),
                "succeed",
            )
            return redirect(
                url_for(
                    "update_alias_recordupdate_alias_record_update_alias_record_page"
                ))
        except Exception as e:
            flash(str(e))
            # Log error and render workflow page
            g.user.logger.warning(f"EXCEPTION THROWN: {e}")
            return render_template(
                "update_alias_record_page.html",
                form=form,
                text=util.get_text(module_path(), config.language),
                options=g.user.get_options(),
            )
    else:
        g.user.logger.info("Form data was not valid.")
        return render_template(
            "update_alias_record_page.html",
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )
def bulk_engine_example_bulk_engine_example_page_form():
    form = GenericFormTemplate()
    form.configuration.choices = util.get_configurations(default_val=True)
    data = json.loads(form.data_box.data)
    name = g.user.get_api().get_entity_by_id(
        form.configuration.data).get_name()
    view = form.view.data
    globals = {
        "configuration": name,
        "view": view,
        "on_fail": form.on_fail.data
    }
    r = load(data, **globals)

    response = ""
    for type, result in r.items():
        response += "<h2>%s</2>" % type
        response += "<pre>%s</pre>" % str(result).replace(',', ',\n')

    form.results.plain_html = response

    return render_template(
        'bulk_engine_example_page.html',
        form=form,
        text=util.get_text(module_path(), config.language),
        options=g.user.get_options(),
    )
def update_host_record_example_update_host_record_example_page():
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    return render_template('update_host_record_example_page.html',
                           form=form,
                           text=util.get_text(module_path(), config.language),
                           options=g.user.get_options())
def update_text_record_update_text_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            text_record = g.user.get_api().get_entity_by_id(
                request.form["txt_list"])

            # Set text record attributes
            text_record.set_name(form.name.data)
            text_record.set_property("txt", form.text.data)
            text_record.update()

            # Put form processing code here
            g.user.logger.info("Success - Text Record Modified - Object ID: " +
                               str(text_record.get_id()))
            flash(
                "Success - Text Record Modified - Object ID: " +
                str(text_record.get_id()),
                "succeed",
            )
            return redirect(
                url_for(
                    "update_text_recordupdate_text_record_update_text_record_page"
                ))

        except Exception as e:
            flash(str(e))
            # Log error and render workflow page
            g.user.logger.warning(f"EXCEPTION THROWN: {e}")
            form.txt_filter.data = ""
            form.name.data = ""
            form.text.data = ""
            return render_template(
                "update_text_record_page.html",
                form=form,
                text=util.get_text(module_path(), config.language),
                options=g.user.get_options(),
            )

    else:
        g.user.logger.info("Form data was not valid.")
        form.txt_filter.data = ""
        form.name.data = ""
        form.text.data = ""
        return render_template(
            "update_text_record_page.html",
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )
def add_dhcp_ip4_address_add_dhcp_ip4_address_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form.get('view', ''))
            hostinfo = "%s.%s,%s,true,false" % (form.hostname.data,
                                                request.form.get(
                                                    'zone', ''), view.get_id())
            properties = 'name=' + form.description.data

            # Assign DHCP reserved IP4 object
            ip4_object = configuration.assign_ip4_address(
                util.safe_str(request.form.get('ip4_address', '')),
                util.safe_str(form.mac_address.data), hostinfo,
                IPAssignmentActionValues.MAKE_DHCP_RESERVED, properties)

            # Put form processing code here
            g.user.logger.info(
                'Success-DHCP Reserved IP4 Address ' +
                util.safe_str(request.form.get('ip4_address', '')) +
                ' Assigned with Object ID: ' +
                util.safe_str(ip4_object.get_id()))
            flash(
                'Success - DHCP Reserved IP4 Address ' +
                util.safe_str(request.form.get('ip4_address', '')) +
                ' Assigned with Object ID: ' +
                util.safe_str(ip4_object.get_id()), 'succeed')
            return redirect(
                url_for(
                    'add_dhcp_ip4_addressadd_dhcp_ip4_address_add_dhcp_ip4_address_page'
                ))
        except APIException as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('add_dhcp_ip4_address_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('add_dhcp_ip4_address_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
def bulk_engine_example_bulk_engine_example_page():
    form = GenericFormTemplate()
    form.configuration.choices = util.get_configurations(default_val=True)
    return render_template(
        'bulk_engine_example_page.html',
        form=form,
        text=util.get_text(module_path(), config.language),
        options=g.user.get_options(),
    )
Ejemplo n.º 8
0
def delete_host_record_delete_host_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    # pylint: disable=broad-except
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(form.configuration.data)

            view = configuration.get_view(request.form['view'])

            # Retrieve host record
            host_record = view.get_host_record(request.form['host_record'] + '.' + request.form['parent_zone'])

            # Retrieve host record attributes for flash message
            host_record_name = host_record.get_property('absoluteName')
            host_record_id = util.safe_str(host_record.get_id())

            # Delete host record
            host_record.delete()

            # Put form processing code here
            g.user.logger.info('Success - Host  (A) Record ' + host_record_name + ' Deleted with Object ID: ' +
                               host_record_id)
            flash('Success - Host  (A) Record ' + host_record_name + ' Deleted with Object ID: ' +
                  host_record_id, 'succeed')

            # Perform Selective Deployment (RELATED Scope) on host record if checkbox is checked
            if form.deploy_now.data:
                entity_id_list = [host_record.get_id()]
                deploy_token = g.user.get_api().selective_deploy(entity_id_list)
                return render_template('delete_host_record_page.html',
                                       form=form,
                                       status_token=deploy_token,
                                       text=util.get_text(module_path(), config.language),
                                       options=g.user.get_options())
            return redirect(url_for('delete_host_recorddelete_host_record_delete_host_record_page'))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e), msg_type=g.user.logger.EXCEPTION)
            return render_template('delete_host_record_page.html',
                                   form=form,
                                   text=util.get_text(module_path(), config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('delete_host_record_page.html',
                               form=form,
                               text=util.get_text(module_path(), config.language),
                               options=g.user.get_options())
def update_text_record_update_text_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    # pylint: disable=broad-except
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            text_record = g.user.get_api().get_entity_by_id(
                request.form['txt_list'])

            # Set text record attributes
            text_record.set_name(form.name.data)
            text_record.set_property('txt', form.text.data)
            text_record.update()

            # Put form processing code here
            g.user.logger.info('Success - Text Record Modified - Object ID: ' +
                               util.safe_str(text_record.get_id()))
            flash(
                'Success - Text Record Modified - Object ID: ' +
                util.safe_str(text_record.get_id()), 'succeed')
            return redirect(
                url_for(
                    'update_text_record_exampleupdate_text_record_update_text_record_page'
                ))

        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            form.txt_filter.data = ''
            form.name.data = ''
            form.text.data = ''
            return render_template('update_text_record_example_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())

    else:
        g.user.logger.info('Form data was not valid.')
        form.txt_filter.data = ''
        form.name.data = ''
        form.text.data = ''
        return render_template('update_text_record_example_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
def delete_alias_record_delete_alias_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes and declare variables
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form["view"])

            # Retrieve alias record
            alias_record = view.get_alias_record(request.form["alias_record"] +
                                                 "." + request.form["zone"])

            # Retrieve alias_record attributes for flash message
            alias_name = alias_record.get_name()
            alias_id = str(alias_record.get_id())

            # Delete alias record
            alias_record.delete()

            # Put form processing code here
            g.user.logger.info("Success - Alias Record " + alias_name +
                               " Deleted with Object ID: " + alias_id)
            flash(
                "Success - Alias Record " + alias_name +
                " Deleted with Object ID: " + alias_id,
                "succeed",
            )
            return redirect(
                url_for(
                    "delete_alias_recorddelete_alias_record_delete_alias_record_page"
                ))
        except Exception as e:
            flash(str(e))
            g.user.logger.warning(f"EXCEPTION THROWN: {e}")
            return render_template(
                "delete_alias_record_page.html",
                form=form,
                text=util.get_text(module_path(), config.language),
                options=g.user.get_options(),
            )
    else:
        g.user.logger.info("Form data was not valid.")
        return render_template(
            "delete_alias_record_page.html",
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )
Ejemplo n.º 11
0
def add_static_ip4_address_example_add_static_ip4_address_example_page_form():
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            selected_view = request.form.get('view', '')
            selected_hostname = request.form.get('hostname', '')
            hostinfo = ''
            if selected_view != '' and selected_hostname != '':
                view = configuration.get_view(selected_view)
                hostinfo = util.safe_str(
                    selected_hostname) + '.' + util.safe_str(
                        request.form.get('zone', '')) + ',' + util.safe_str(
                            view.get_id()) + ',' + 'true' + ',' + 'false'
            properties = 'name=' + form.description.data

            # Assign ip4 object
            ip4_object = configuration.assign_ip4_address(
                request.form.get('ip4_address', ''), form.mac_address.data,
                hostinfo, 'MAKE_STATIC', properties)

            # Put form processing code here
            g.user.logger.info('Success - Static IP4 Address ' +
                               ip4_object.get_property('address') +
                               ' Added with Object ID: ' +
                               util.safe_str(ip4_object.get_id()))
            flash(
                'Success - Static IP4 Address ' +
                ip4_object.get_property('address') +
                ' Added with Object ID: ' + util.safe_str(ip4_object.get_id()),
                'succeed')
            return redirect(
                url_for(
                    'add_static_ip4_address_exampleadd_static_ip4_address_example_add_static_ip4_address_example_page'
                ))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('add_static_ip4_address_example_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('add_static_ip4_address_example_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
def update_alias_record_update_alias_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    # pylint: disable=broad-except
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations()
    if form.validate_on_submit():
        try:
            # Retrieve form attributes and declare variables
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form['view'])

            # Retrieve alias record
            alias_record = view.get_alias_record(request.form['alias_record'] +
                                                 '.' + request.form['zone'])

            # Update the alias record's name and linkedRecordName
            alias_record.set_name(form.alias_name.data)
            alias_record.set_property(
                'linkedRecordName', request.form['linked_record'] + '.' +
                request.form['linked_record_zone'])
            alias_record.update()

            # Put form processing code here
            g.user.logger.info(
                'Success - Alias Record Modified - Object ID: ' +
                util.safe_str(alias_record.get_id()))
            flash(
                'Success - Alias Record Modified - Object ID: ' +
                util.safe_str(alias_record.get_id()), 'succeed')
            return redirect(
                url_for(
                    'update_alias_recordupdate_alias_record_update_alias_record_page'
                ))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('update_alias_record_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('update_alias_record_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
Ejemplo n.º 13
0
def get_configs(cached=False):
    cache = False
    if cached:
        configs = read_cache("configurations.json", 120)
        if len(configs) != 0:
            cache = True
    if cache == False:
        configs = util.get_configurations(default_val=True)
        cache_it(configs, "configurations.json")
    return configs
def onload():
    bam_name = common.get_bam_name()
    configurations = util.get_configurations()
    configuration_id = configurations[0][0]
    servers = common.get_server_list(configuration_id)
    return jsonify({
        'bam': bam_name,
        'configurations': configurations,
        'server': servers
    })
Ejemplo n.º 15
0
def delete_alias_record_delete_alias_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    # pylint: disable=broad-except
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes and declare variables
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form['view'])

            # Retrieve alias record
            alias_record = view.get_alias_record(request.form['alias_record'] +
                                                 '.' + request.form['zone'])

            # Retrieve alias_record attributes for flash message
            alias_name = alias_record.get_name()
            alias_id = util.safe_str(alias_record.get_id())

            # Delete alias record
            alias_record.delete()

            # Put form processing code here
            g.user.logger.info('Success - Alias Record ' + alias_name +
                               ' Deleted with Object ID: ' + alias_id)
            flash(
                'Success - Alias Record ' + alias_name +
                ' Deleted with Object ID: ' + alias_id, 'succeed')
            return redirect(
                url_for(
                    'delete_alias_recorddelete_alias_record_delete_alias_record_page'
                ))
        except Exception as e:
            flash(util.safe_str(e))
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('delete_alias_record_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('delete_alias_record_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
Ejemplo n.º 16
0
def add_next_available_dual_stack_host_add_next_available_dual_stack_host_page(
):
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    return render_template(
        'add_next_available_dual_stack_host_page.html',
        form=form,
        text=util.get_text(module_path(), config.language),
        options=g.user.get_options(),
    )
def delete_ip4_address_delete_ip4_address_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    # pylint: disable=broad-except
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)

            # Retrieve IP4 Object
            ip4_object = configuration.get_ip4_address(
                util.safe_str(request.form.get('ip4_address', '')))

            # Retrieve alias_record attributes for flash message
            ip4_address = util.safe_str(ip4_object.get_property('address'))
            ip4_id = util.safe_str(ip4_object.get_id())

            # Delete IP4 Object
            ip4_object.delete()

            # Put form processing code here
            g.user.logger.info('Success - IP4 Object ' + ip4_address +
                               ' Deleted with Object ID: ' + ip4_id)
            flash(
                'Success - IP4 Object ' + ip4_address +
                ' Deleted with Object ID: ' + ip4_id, 'succeed')
            return redirect(
                url_for(
                    'delete_ip4_addressdelete_ip4_address_delete_ip4_address_page'
                ))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('delete_ip4_address_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('delete_ip4_address_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
def add_alias_record_add_alias_record_page():
    """
    Renders the form the user would first see when selecting the workflow.

    :return:
    """
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    return render_template('add_alias_record_page.html', form=form, text=util.get_text(module_path(), config.language),
                           options=g.user.get_options())
def add_host_record_example_add_host_record_example_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    # pylint: disable=broad-except
    form = GenericFormTemplate()
    form.configuration.choices = util.get_configurations(default_val=True)

    if form.validate_on_submit():
        ip4_address_list = []
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(form.configuration.data)
            view = configuration.get_view(request.form['view'])
            absolute_name = form.hostname.data + '.' + request.form['zone']
            ip4_address = request.form['ip4_address']
            ip4_address_list.append(ip4_address)

            # Add host Record
            host_record = view.add_host_record(absolute_name, ip4_address_list)

            # Put form processing code here
            g.user.logger.info('Success - Host (A) Record ' + host_record.get_property('absoluteName') +
                               ' added with Object ID: ' + util.safe_str(host_record.get_id()))
            flash('Success - Host (A) Record ' + host_record.get_property('absoluteName') + ' added with Object ID: ' +
                  util.safe_str(host_record.get_id()), 'succeed')

            # Perform Selective Deployment (RELATED Scope) on host record if checkbox is checked
            if form.deploy_now.data:
                entity_id_list = [host_record.get_id()]
                deploy_token = g.user.get_api().selective_deploy(entity_id_list)
                return render_template('add_host_record_example_page.html',
                                       form=form,
                                       status_token=deploy_token,
                                       text=util.get_text(module_path(), config.language),
                                       options=g.user.get_options())
            return redirect(url_for('add_host_record_exampleadd_host_record_example_add_host_record_example_page'))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e), msg_type=g.user.logger.EXCEPTION)
            return render_template('add_host_record_example_page.html',
                                   form=form,
                                   text=util.get_text(module_path(), config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('add_host_record_example_page.html',
                               form=form,
                               text=util.get_text(module_path(), config.language),
                               options=g.user.get_options())
def delete_host_record_example_delete_host_record_example_page_form():
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)

            view = configuration.get_view(request.form['view'])

            # Retrieve host record
            host_record = view.get_host_record(request.form['host_record'] +
                                               '.' +
                                               request.form['parent_zone'])

            # Retrieve host record attributes for flash message
            host_record_name = host_record.get_property('absoluteName')
            host_record_id = util.safe_str(host_record.get_id())

            # Delete host record
            host_record.delete()

            # Put form processing code here
            g.user.logger.info('Success - Host  (A) Record ' +
                               host_record_name + ' Deleted with Object ID: ' +
                               host_record_id)
            flash(
                'Success - Host  (A) Record ' + host_record_name +
                ' Deleted with Object ID: ' + host_record_id, 'succeed')
            return redirect(
                url_for(
                    'delete_host_record_exampledelete_host_record_example_delete_host_record_example_page'
                ))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('delete_host_record_example_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('delete_host_record_example_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
def add_text_record_add_text_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    # pylint: disable=broad-except
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve configuration, view, and absolute name
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form['view'])
            absolute_name = form.name.data + '.' + request.form.get('zone', '')

            # Attempt to add the text record
            text_record = view.add_text_record(absolute_name, form.text.data)

            g.user.logger.info('Success-Text Record ' +
                               text_record.get_property('absoluteName') +
                               ' Added with Object ID: ' +
                               util.safe_str(text_record.get_id()))
            flash(
                'Success - Text Record ' +
                text_record.get_property('absoluteName') +
                ' Added with Object ID: ' +
                util.safe_str(text_record.get_id()), 'succeed')
            return redirect(
                url_for(
                    'add_text_record_exampleadd_text_record_add_text_record_page'
                ))

        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('add_text_record_example_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('add_text_record_example_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
def update_ip4_address_update_ip4_address_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)

            # Retrieve the IP4 address object
            ip4_address = configuration.get_ip4_address(
                request.form.get('ip4_address', ''))

            # Update the form name and mac address properties
            ip4_address.set_name(form.description.data)
            ip4_address.set_property('macAddress', form.mac_address.data)
            ip4_address.update()

            # Put form processing code here
            g.user.logger.info('Success - IP4 Address Modified - Object ID: ' +
                               util.safe_str(ip4_address.get_id()))
            flash(
                'Success - IP4 Address Modified - Object ID: ' +
                util.safe_str(ip4_address.get_id()), 'succeed')
            return redirect(
                url_for(
                    'update_ip4_addressupdate_ip4_address_update_ip4_address_page'
                ))
        except APIException as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('update_ip4_address_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('update_ip4_address_page.html',
                               form=form,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
Ejemplo n.º 23
0
def create_server_vro_create_server_vro_page_form():
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():

        configuration = g.user.get_api().get_entity_by_id(
            form.configuration.data)
        view = configuration.get_view(form.view.data)
        network = form.ip4_network.data.split('/')
        network = configuration.get_ip_range_by_ip('IP4Network', network[0])

        props = {'excludeDHCPRange': 'True'}
        hostinfo = util.safe_str(form.hostname.data) + '.' + util.safe_str(
            form.zone.data) + ',' + util.safe_str(
                view.get_id()) + ',' + 'True' + ',' + 'False'

        assigned_ip = network.assign_next_available_ip4_address(
            form.mac_address.data,
            hostinfo,
            'MAKE_DHCP_RESERVED',
            properties=props)

        absoluteName = form.hostname.data + '.' + form.zone.data

        g.user.logger.info(
            'Success - Host (A) Record ' + absoluteName + ' IP Address: ' +
            util.safe_str(assigned_ip.get_property('address')) + ' State: ' +
            util.safe_str(assigned_ip.get_property('state')) +
            ' Mac Address: ' +
            util.safe_str(assigned_ip.get_property('macAddress')))
        flash(
            'Success - Host (A) Record ' + absoluteName + ' IP Address: ' +
            util.safe_str(assigned_ip.get_property('address')) + ' State: ' +
            util.safe_str(assigned_ip.get_property('state')) +
            ' Mac Address: ' +
            util.safe_str(assigned_ip.get_property('macAddress')), 'succeed')
        return redirect(
            url_for(
                'create_server_vrocreate_server_vro_create_server_vro_page'))
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template(
            'create_server_vro_page.html',
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )
Ejemplo n.º 24
0
def cisco_aci_example_cisco_aci_example_page():
    """
    Renders the form the user would first see when selecting the workflow.

    :return:
    """
    if get_api().get_version() < '9.1.0':
        message = 'Warning! Current BAM version {version} is less than 9.1.0 and Cisco ACI Import will not work!'
        flash(message.format(version=get_api().get_version()))

    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    return render_template(
        'cisco_aci_example_page.html',
        form=form,
        text=util.get_text(module_path(), config.language),
        options=g.user.get_options(),
    )
def add_host_record_example_add_host_record_example_page_form():
    form = GenericFormTemplate()
    form.configuration.choices = util.get_configurations(default_val=True)

    if form.validate_on_submit():
        ip4_address_list = []
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(form.configuration.data)
            view = configuration.get_view(request.form['view'])
            absolute_name = form.hostname.data + '.' + request.form['zone']
            ip4_address = request.form['ip4_address']
            ip4_address_list.append(ip4_address)

            # Add host Record
            host_record = view.add_host_record(absolute_name, ip4_address_list)

            # Put form processing code here
            g.user.logger.info('Success - Host (A) Record ' + host_record.get_property('absoluteName') +
                               ' added with Object ID: ' + util.safe_str(host_record.get_id()))
            flash('Success - Host (A) Record ' + host_record.get_property('absoluteName') + ' added with Object ID: ' +
                  util.safe_str(host_record.get_id()), 'succeed')
            return redirect(url_for('add_host_record_exampleadd_host_record_example_add_host_record_example_page'))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e), msg_type=g.user.logger.EXCEPTION)
            return render_template('add_host_record_example_page.html',
                                   form=form,
                                   text=util.get_text(module_path(), config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('add_host_record_example_page.html',
                               form=form,
                               text=util.get_text(module_path(), config.language),
                               options=g.user.get_options())
def update_host_record_example_update_host_record_example_page_form():
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    ip4_address = []
    if form.validate_on_submit():
        try:
            # Retrieve form attributes and declare variables
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form['view'])

            # Retrieve ip4 addresses removing spaces and put into list
            ip4_addresses = form.ip4_address.data.replace(' ', '')
            ip4_addresses = ip4_addresses.split(',')

            # Retrieve host record
            host_record = view.get_host_record(request.form['host_record'] +
                                               '.' +
                                               request.form['parent_zone'])

            # Retrieve original IP4 Addresses
            original_ip4 = host_record.get_property('addresses')

            for ip in ip4_addresses:
                if util.safe_str(configuration.get_ip4_address(
                        ip).get_type()) == 'None' or ip in original_ip4:
                    ip4_address.append(ip)
                else:
                    g.user.logger.info('Form data was not valid.')
                    flash('Host record update failed: ' + ip +
                          ' has already been assigned')
                    return render_template(
                        'update_host_record_example_page.html',
                        form=form,
                        view=request.form.get('view', ''),
                        host_record=request.form.get('host_record', ''),
                        name=form.name.data,
                        ip4_address=form.ip4_address.data,
                        text=util.get_text(module_path(), config.language),
                        options=g.user.get_options())

            ip4_address = ','.join(ip4_address)

            # Update host record's attributes
            host_record.set_name(form.name.data)
            host_record.set_property('addresses', ip4_address)
            # host_record.set_addresses(ip4_addresses)
            host_record.update()

            # Put form processing code here
            g.user.logger.info('Success - Host Record Modified - Object ID: ' +
                               util.safe_str(host_record.get_id()))
            flash(
                'Success - Host Record Modified - Object ID: ' +
                util.safe_str(host_record.get_id()), 'succeed')
            return redirect(
                url_for(
                    'update_host_record_exampleupdate_host_record_example_update_host_record_example_page'
                ))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('update_host_record_example_page.html',
                                   form=form,
                                   view=request.form.get('view', ''),
                                   host_record=request.form.get(
                                       'host_record', ''),
                                   name=form.name.data,
                                   ip4_address=form.ip4_address.data,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template('update_host_record_example_page.html',
                               form=form,
                               view=request.form.get('view', ''),
                               host_record=request.form.get('host_record', ''),
                               name=form.name.data,
                               ip4_address=form.ip4_address.data,
                               text=util.get_text(module_path(),
                                                  config.language),
                               options=g.user.get_options())
def add_static_ip4_address_add_static_ip4_address_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            selected_view = request.form.get("view", "")
            selected_hostname = request.form.get("hostname", "")
            hostinfo = ""
            if selected_view != "" and selected_hostname != "":
                view = configuration.get_view(selected_view)
                hostinfo = (selected_hostname + "." +
                            str(request.form.get("zone", "")) + "," +
                            str(view.get_id()) + "," + "true" + "," + "false")
            properties = "name=" + form.description.data

            # Assign ip4 object
            ip4_object = configuration.assign_ip4_address(
                request.form.get("ip4_address", ""),
                form.mac_address.data,
                hostinfo,
                "MAKE_STATIC",
                properties,
            )

            # Put form processing code here
            g.user.logger.info("Success - Static IP4 Address " +
                               ip4_object.get_property("address") +
                               " Added with Object ID: " +
                               str(ip4_object.get_id()))
            flash(
                "Success - Static IP4 Address " +
                ip4_object.get_property("address") +
                " Added with Object ID: " + str(ip4_object.get_id()),
                "succeed",
            )
            page = "add_static_ip4_addressadd_static_ip4_address_add_static_ip4_address_page"
            return redirect(url_for(page))
        except Exception as e:
            flash(str(e))
            # Log error and render workflow page
            g.user.logger.warning(f"EXCEPTION THROWN: {e}")
            return render_template(
                "add_static_ip4_address_page.html",
                form=form,
                text=util.get_text(module_path(), config.language),
                options=g.user.get_options(),
            )
    else:
        g.user.logger.info("Form data was not valid.")
        return render_template(
            "add_static_ip4_address_page.html",
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )
Ejemplo n.º 28
0
def add_host_record_add_host_record_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    form = GenericFormTemplate()
    form.configuration.choices = util.get_configurations(default_val=True)

    if form.validate_on_submit():
        ip4_address_list = []
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form["view"])
            absolute_name = form.hostname.data + "." + request.form["zone"]
            ip4_address = request.form["ip4_address"]
            ip4_address_list.append(ip4_address)

            # Add host Record
            host_record = view.add_host_record(absolute_name, ip4_address_list)

            # Put form processing code here
            g.user.logger.info("Success - Host (A) Record " +
                               host_record.get_property("absoluteName") +
                               " added with Object ID: " +
                               str(host_record.get_id()))
            flash(
                "Success - Host (A) Record " +
                host_record.get_property("absoluteName") +
                " added with Object ID: " + str(host_record.get_id()),
                "succeed",
            )

            # Perform Selective Deployment (RELATED Scope) on host record if checkbox is checked
            if form.deploy_now.data:
                entity_id_list = [host_record.get_id()]
                deploy_token = g.user.get_api().selective_deploy(
                    entity_id_list)
                return render_template(
                    "add_host_record_page.html",
                    form=form,
                    status_token=deploy_token,
                    text=util.get_text(module_path(), config.language),
                    options=g.user.get_options(),
                )
            return redirect(
                url_for("add_host_recordadd_host_record_add_host_record_page"))
        except Exception as e:
            flash(str(e))
            # Log error and render workflow page
            g.user.logger.warning(f"EXCEPTION THROWN: {e}")
            return render_template(
                "add_host_record_page.html",
                form=form,
                text=util.get_text(module_path(), config.language),
                options=g.user.get_options(),
            )
    else:
        g.user.logger.info("Form data was not valid.")
        return render_template(
            "add_host_record_page.html",
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )
Ejemplo n.º 29
0
def add_dual_stack_host_add_dual_stack_host_page_form():
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)

    address_list = []
    if form.validate_on_submit():
        try:
            # Retrieve form attributes
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
            view = configuration.get_view(request.form['view'])
            absolute_name = form.hostname.data + '.' + request.form['zone']
            ip4_address = request.form['ip_address']
            ip6_address = request.form['ip6_address']

            # Add IP4 and IP6 addresses to address list
            address_list.append(ip4_address)
            address_list.append(ip6_address)
            add_device = request.form.get(
                'add_device'
            )  # Must use 'get' otherwise returns a 400 error on False

            # Add Host Record
            host_record = view.add_host_record(absolute_name, address_list)

            # Optionally Add Device
            if add_device:
                device_id = g.user.get_api()._api_client.service.addDevice(
                    configurationId=form.configuration.data,
                    deviceSubtypeId='0',
                    deviceTypeId='0',
                    ip4Addresses=ip4_address,
                    ip6Addresses=ip6_address,
                    name=form.hostname.data)
                device_name = g.user.get_api().get_entity_by_id(
                    device_id).get_name()
                g.user.logger.info('Success - Device ' + device_name +
                                   ' added with Object ID: ' +
                                   util.safe_str(device_id))
                flash(
                    'Success - Device ' + device_name +
                    ' added with Object ID: ' + util.safe_str(device_id),
                    'succeed')

            # Put form processing code here
            g.user.logger.info('Success - Host (A & AAAA) Record ' +
                               host_record.get_property('absoluteName') +
                               ' added with Object ID: ' +
                               util.safe_str(host_record.get_id()))

            flash(
                'Success - Host (A & AAAA) Record ' +
                host_record.get_property('absoluteName') +
                ' added with Object ID: ' +
                util.safe_str(host_record.get_id()), 'succeed')

            return redirect(
                url_for(
                    'add_dual_stack_hostadd_dual_stack_host_add_dual_stack_host_page'
                ))
        except Exception as e:
            flash(util.safe_str(e))
            # Log error and render workflow page
            g.user.logger.warning('%s' % util.safe_str(e),
                                  msg_type=g.user.logger.EXCEPTION)
            return render_template('add_dual_stack_host_page.html',
                                   form=form,
                                   text=util.get_text(module_path(),
                                                      config.language),
                                   options=g.user.get_options())

    else:
        g.user.logger.info('Form data was not valid.')
        return render_template(
            'add_dual_stack_host_page.html',
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )
def add_mac_address_add_mac_address_page_form():
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    if form.validate_on_submit():
        # Retrieve configuration and view
        try:
            configuration = g.user.get_api().get_entity_by_id(
                form.configuration.data)
        except PortalException as e:
            g.user.logger.warning('%s' % e, msg_type=g.user.logger.EXCEPTION)
            flash('Configuration %s undefined in BAM' %
                  form.configuration.data)
            return render_template(
                'add_mac_address_page.html',
                form=form,
                text=util.get_text(module_path(), config.language),
                options=g.user.get_options(),
            )

        # Check if mac address pool has been specified
        if form.mac_pool_boolean.data:
            try:
                mac_pool = g.user.get_api(
                )._api_client.service.getEntityByName(configuration.get_id(),
                                                      form.mac_pool.data,
                                                      'MACPool')
            except Exception as e:
                g.user.logger.error('%s' % e, msg_type=g.user.logger.EXCEPTION)
                flash('Unable to retrieve MAC Pool: %s with error: %s' %
                      (form.mac_pool.data, util.safe_str(e)))
                return render_template(
                    'add_mac_address_page.html',
                    form=form,
                    text=util.get_text(module_path(), config.language),
                    options=g.user.get_options(),
                )

            # Instantiate mac pool object to a Gateway object
            mac_pool = g.user.get_api().instantiate_entity(mac_pool)
        else:
            mac_pool = ''

        # Add MAC address
        try:
            mac_address = configuration.add_mac_address(
                form.mac_address.data, form.mac_address_name.data, mac_pool)
        except BAMException as e:
            g.user.logger.error('%s' % e, msg_type=g.user.logger.EXCEPTION)
            if 'Duplicate of another item' in util.safe_str(e):
                flash(
                    'MAC Address %s is a duplicate of an existing MAC in Address Manager'
                    % form.mac_address.data)
            else:
                flash('Unable to add MAC Address with error: %s' %
                      util.safe_str(e))
            return render_template(
                'add_mac_address_page.html',
                form=form,
                text=util.get_text(module_path(), config.language),
                options=g.user.get_options(),
            )

        # Display success message
        if form.mac_pool_boolean.data:
            flash(
                'MAC Address: %s has been successfully added with object ID: %s and to MAC Pool: %s'
                % (form.mac_address.data, mac_address.get_id(),
                   form.mac_pool.data), 'succeed')
        else:
            flash(
                'MAC Address: %s has been successfully added to BAM with object ID: %s'
                % (form.mac_address.data, mac_address.get_id()), 'succeed')

        return redirect(
            url_for('add_mac_addressadd_mac_address_add_mac_address_page'))
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template(
            'add_mac_address_page.html',
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )