Esempio n. 1
0
def fill_server_info_form(server_form=None, env='', mirror='', server_status='', use_status='', owner=''):
    host_info = ServerList()

    env_list = host_info.list_supported_env()
    mirror_list = host_info.list_supported_mirror()
    use_status_list = host_info.list_supported_use_status()
    server_status_list = host_info.list_supported_status()
    owner_list = host_info.list_supported_dba()
    server_form.env.choices = env_list
    server_form.mirror.choices = mirror_list
    server_form.server_status.choices = server_status_list
    server_form.use_status.choices = use_status_list
    server_form.owner.choices = owner_list

    if not env: env = ''
    if not mirror: mirror = ''
    if not owner: owner = ''
    if not server_status: server_status = ''
    if not use_status: use_status = ''
    server_form.env.data = env
    server_form.mirror.data = mirror
    server_form.owner.data = owner
    server_form.server_status.data = server_status
    server_form.use_status.data = use_status
    return server_form
Esempio n. 2
0
def add_server():
    try:
        host_info = ServerList()
        env = host_info.list_supported_env()
        mirror = host_info.list_supported_mirror()
        use_status = host_info.list_supported_use_status()
        owner = host_info.list_supported_dba()
        status = host_info.list_supported_status()

        server_form = ServerInfoForm()
        server_form.env.choices = env
        server_form.mirror.choices = mirror
        server_form.server_status.choices = status
        server_form.use_status.choices = use_status
        server_form.owner.choices = owner
        data = dict()
        if request.method == 'POST':
            server_post = request.form
            server_info = ServerList()
            result = server_info.add_server(server_post)
            page_data = dict()
            page_data['add_result'] = dict()
            flash('Add Server Success!', 'success')
            return redirect(url_for('server_info', server_id=request.form['server_id']))
            data['form_data'] = server_post
        else:
            page_data = ''
            data['form_data'] = dict()
        data['page_name'] = 'Add Server'
        data['form'] = server_form
        data['page_data'] = page_data
        return render_template('addserver.html', data=data)
    except CmdbApiCallException, e:
        flash(e.detail_msg(), 'danger')
        return render_template('blank.html')