Пример #1
0
def addApplicationSite(group_name, url_back):
    """
    add application-site

    add a new application-site inside a group

    arguments:
        group_id: the id number of the application-site groups

    return: renders the show application-sites page
    """
    form = ApplicationSiteForm(request.form)

    if form.validate():

        appl = APIObject('APPL_' + form.name.data, 'application-site')
        appl.add(url_list=form.url_list.data,
                 primary_category='Custom_Application_Site')  # required
        appl.add_to_group('set-application-site-group', group_name)
        appl.add_to_group('set-application-site-group', 'APGR_GENERAL')
        api.api_call('publish')
        flash('URL added')
        return redirect(url_for(url_back))

    # I have to check what to do here
    return redirect(url_for('blockURL'))
Пример #2
0
def addHost(group_name, url_back):
    """add host
    Add a new host inside a group

    Arguments:
        group_nam - the name of the group where the host has to be added
        url_back - url for redirecting when finished

    Return: if form validates, create the host and add it to the group, if
        doesn't render a page with the errors
    """
    form = HostForm(request.form)
    if request.method == 'POST' and form.validate():
        host = APIObject('HOST_' + form.name.data, 'host')
        add = host.add(ipv4_address=form.ipv4_address.data)
        if not add.success:
            if 'errors' in add.res_obj['data']:
                message = add.res_obj['data']['errors'][0]['message']
                if message[:26] == 'More than one object named':
                    flash('A computer with that name already exists')
            if 'warnings' in add.res_obj['data']:
                message = add.res_obj['data']['warnings'][0]['message']
                if message[:37] == 'More than one object have the same IP':
                    flash('A computer with this IP already exists')
        else:
            host.add_to_group('set-group', group_name)
            api.api_call('publish')
            flash('Equipment added')
        return redirect(url_for(url_back))
    else:
        return render_template('form-errors.html',
                               form=form,
                               url_back=url_back)