Пример #1
0
	def list(self):
		if not 'page' in request.params:
			page = 1
		else:
			page = request.params['page']
		c.users = webhelpers.paginate.Page(
			meta.Session.query(User).order_by(desc(User.login)),
			page = int(page),
			items_per_page = 15)
		
		if 'partial' in request.params:
			return render('user_list_ajax.mako')
		else:
			# Render the full page
			return render('user_list.mako')
Пример #2
0
    def list(self):
        if not 'page' in request.params:
            page = 1
        else:
            page = request.params['page']
        c.appliances = webhelpers.paginate.Page(
            meta.Session.query(Appliance).order_by(desc(Appliance.name)),
            page=int(page),
            items_per_page=15)

        if 'partial' in request.params:
            return render('appliance_list_ajax.mako')
        else:
            # Render the full page
            return render('appliance_list.mako')
Пример #3
0
	def changepass(self, id):
		c.user = meta.Session.query(User).filter(User.id == id).first()
		if not c.user:
			c.user =  User(None, '', '', '', '')
			c.error = 'User does not exist'

		return render('user_change.mako')
Пример #4
0
	def edit(self, id):
		# Use the existing user account
		c.user = meta.Session.query(User).filter(User.id == id).first()
		if not c.user:
			# Create a new user account
			c.user = User(None, '', '', '', '')
		return render('user_edit.mako')
Пример #5
0
	def save(self):
		if not self.get_user_info():
			c.user = User(None, '', '', '', '')
			return render('user_edit.mako')

		if c.user_id == '':
			c.user_id = None

		user = User(
				c.user_id,
				c.account_name,
				c.first_name,
				c.second_name,
				c.department)
		
		if user.id:
			# Update the account info
			user = meta.Session.merge(user)
			meta.Session.update(user)
			user = meta.Session.query(User).filter(User.id == user.id).one()
			attr = user.get_attr('rights')
			attr.value = c.rights
			attr = meta.Session.merge(attr)
			meta.Session.update(attr)
		else:
			# Create a new account
			user.password = hashlib.md5(c.account_pwd).hexdigest()
			attr =  UserAttribute(name = 'rights',
					value = c.rights)
			user.attributes.append(attr)
			meta.Session.add(user)
			meta.Session.add(attr)
		meta.Session.commit()

		return redirect_to(url_for(action = 'info', id = user.id))
Пример #6
0
 def info(self, id):
     c.appl = meta.Session.query(Appliance).filter(Appliance.id == id).one()
     refs = meta.Session.query(ServerAppliance).filter(
         ServerAppliance.appliance_id == id)
     ids = []
     for r in refs:
         ids.append(r.node_id)
     c.hosts = meta.Session.query(Server).filter(Server.id.in_(ids)).all()
     return render('appliance_info.mako')
Пример #7
0
	def build_list(self, running):
		if not 'page' in request.params:
			page = 1
		else:
			page = request.params['page']
		
		selection = meta.Session.query(Activity).order_by(desc(Activity.start_time))
		if running:
			selection = selection.filter(Activity.status == 1)
			
		c.activities = webhelpers.paginate.Page(
				selection,
                page = int(page),
                items_per_page = 15)
		if 'partial' in request.params:
			return render('activity_list_ajax.mako')
		else:
			# Render the full page
			return render('activity_list.mako')
Пример #8
0
    def render_edit_2(self):
        #save name, arch, desc and type
        if not self.get_appl():
            c.stage = None
            return render('appliance_edit.mako')

        #get options for selected type
        plugins = get_plugins('enlargeweb/plugins')
        current_plugin = None
        tmp_options = []
        for p in plugins:
            print '------:APPL:------- check type', p.type_id, c.appl_plugin_id
            if p.type_id == c.appl_plugin_id:
                tmp_options = p.options
                current_plugin = getPluginInstance(p.type_id)
                break
        print '------:APPL:------- tmp options', tmp_options
        if not tmp_options:
            c.error = 'Failed to query options.'
            return render('appliance_edit.mako')

        #populate enumerational options
        c.options = []
        for opt_desc, opt_name, opt_type, opt_func in tmp_options:
            if opt_type == 'enum' and opt_func:
                variants = getattr(current_plugin, opt_func)()
                print '------------ VARIANTS FOR %s : %s' % (opt_name,
                                                             variants)
                c.options.append(
                    PluginOption(opt_name, opt_desc, opt_type, variants))
            elif opt_type == 'text' and opt_func:
                c.options.append(
                    PluginOption(opt_name, opt_desc, opt_type, opt_func))
            else:
                c.options.append(PluginOption(opt_name, opt_desc, opt_type,
                                              ''))
        print '------:APPL:------- options', c.options

        #populate list of available appliances
        c.appls = meta.Session.query(Appliance).all()
        return render('appliance_edit.mako')
Пример #9
0
    def list(self):
        if not 'page' in request.params:
            page = 1
        else:
            page = request.params['page']

        selection = meta.Session.query(Server).order_by(Server.id)

        if 'filter_dept' in request.params:
            selection = selection.filter(
                Server.department == request.params['filter_dept'])
            c.filter_dept = request.params['filter_dept']

        c.hosts = webhelpers.paginate.Page(selection,
                                           page=int(page),
                                           items_per_page=50)

        if 'partial' in request.params:
            return render('host_list_ajax.mako')
        else:
            # Render the full page
            return render('host_list.mako')
Пример #10
0
	def applypass(self):
		if not self.get_passwords():
			c.user =  meta.Session.query(User).filter(User.id == c.user_id).first()
			return render('user_change.mako')

		if c.user_id == '':
			c.user_id = None
		
		user = meta.Session.query(User).filter(User.id == c.user_id).first()
		current_md5 = hashlib.md5(c.current_password).hexdigest()
		# Update the password
		if current_md5 == user.password:
			user.password = hashlib.md5(c.new_password).hexdigest()
			user = meta.Session.merge(user)
			meta.Session.update(user)
			meta.Session.commit()
		else:
			c.error = 'Wrong Password Given'
			c.user =  meta.Session.query(User).filter(User.id == c.user_id).first()
			return render('user_change.mako')
		
		return redirect_to(url_for(action = 'info', id = user.id))
Пример #11
0
 def edit(self, id, stage=None):
     print '------:APPL:------- edit appl received', c.appl
     c.appl = meta.Session.query(Appliance).filter(
         Appliance.id == id).first()
     if not c.appl:
         c.appl = Appliance(None, '', '', '', '', None)
     c.stage = stage
     print '------:APPL:------- edit appl used', c.appl
     print '------:APPL:------- stage', c.stage
     if stage is None or len(str(stage)) == 0:
         #first stage, show appliance name, arch and type selection
         return render('appliance_edit.mako')
     elif stage == 'stage_2':
         return self.render_edit_2()
Пример #12
0
    def info(self, id):
        """# Get the server Info
		http_host = request.environ.get('HTTP_HOST')
		conn = Connection('http://%s/api/' %http_host)
		disks_json = conn.request_get('/add_host', 
				args = {'srv_id': id},
				headers = {'Accept':'text/json'})
		try:
			disks = simplejson.loads(disks_json['body'])
		except Exception, e:
			print '#' * 50
			print 'Exception:', str(e)
		else:
			print '#' * 50
			print disks"""
        c.srv = meta.Session.query(Server).filter(Server.id == id).first()
        c.running_activities, c.history_activities = c.srv.get_activities()
        if 'partial' in request.params:
            c.partial = True
            return render('host_info_ajax.mako')
        else:
            # Render the full page
            return render('host_info.mako')
Пример #13
0
	def stop(self, action, id):
		message = request.params.get('message')
		activity = meta.Session.query(Activity).filter(Activity.id==id).one()
		c.activity = activity
		c.action = action
		if not action or not message:
		    return render('activity_stop.mako')
		else:
			log.debug('going to %s activity with id=%s' % (action, id))
			#set new activity status according to action
			if action == 'cancel':
				activity.cancel(message, self.get_user_name(), 127)
			else:
				activity.finish(message, self.get_user_name(), 0)
			
			return redirect_to(url_for(action='info', id = activity.id))
Пример #14
0
 def edit(self, id):
     c.srv = meta.Session.query(Server).filter(Server.id == id).first()
     return render('host_edit.mako')
Пример #15
0
	def add(self):
		# Create a new user account
		c.user = User(None, '', '', '', '')
		return render('user_edit.mako')
Пример #16
0
	def login(self):
		return render('login.mako')
Пример #17
0
	def info(self, id):
		c.user = meta.Session.query(User).filter(User.id == id).one()
		return render('user_info.mako')
Пример #18
0
 def render_1(self):
     #write list of classes
     c.appl_types = get_plugins('enlargeweb/plugins')
     return render('appliance.mako')
Пример #19
0
 def add(self):
     c.appl = Appliance(None, '', '', '', '', None)
     c.plugins = get_plugins('enlargeweb/plugins')
     return render('appliance_edit.mako')
Пример #20
0
	def info(self, id):
		c.activity = meta.Session.query(Activity).filter(Activity.id==id).one()
		return render('activity_info.mako')
Пример #21
0
 def add(self):
     c.srv = Server(None, '', '', '', '', '', False, 0)
     return render('host_edit.mako')
Пример #22
0
    def save(self):
        if not self.get_appl():
            return render('appliance_edit.mako')

        #save dependences
        depend_on_list = self.get_appl_deps()

        if c.appl_id == '':
            c.appl_id = None

        #get option names to read values from request params
        plugins = get_plugins('enlargeweb/plugins')
        current_plugin = None
        options = None
        icon = None
        for p in plugins:
            if p.type_id == c.appl_plugin_id:
                options = p.options
                icon = p.icon
                break
        if not options:
            c.error = 'Failed to query options.'
            return render('appliance_edit.mako')

        #Creating new appliance
        appl = Appliance(c.appl_id, c.appl_name, c.appl_description,
                         c.appl_arch, c.appl_plugin_id, icon)
        if appl.id:
            appl = meta.Session.merge(appl)
            meta.Session.update(appl)
        else:
            meta.Session.add(appl)
        meta.Session.commit()

        print '------:APPL:------- SAVED %s' % str(appl)

        #create ApplicanceProperty for each read option value
        appl_props = []
        for opt_desc, opt_name, opt_type, opt_func in options:
            value = request.params.get(opt_name)
            if not value:
                value = ''
            if opt_type == 'enum' and len(value) <= 0:
                c.error = 'Please specify %s.' % opt_name
                return self.render_edit_2()

            #try to get existing property
            if appl.id and not appl.get_prop(opt_name) is None:
                prop = appl.get_prop_inst(opt_name)
                prop.value = value
            else:
                prop = ApplianceProperty(appl.id, opt_name, opt_desc, value)
            print '------:APPL:------- PROP %s' % str(prop)
            meta.Session.add(prop)

        #add dependences
        for dep_appl_id in depend_on_list:
            dep_appl = meta.Session.query(Appliance).filter(
                Appliance.id == int(dep_appl_id)).one()
            appl.depends_on.append(dep_appl)

        meta.Session.commit()
        print '------:APPL:------- DONE SAVING'
        return redirect_to(url_for(action='info', id=appl.id))
Пример #23
0
 def render_2(self):
     c.appliances = meta.Session.query(Appliance).filter(
         Appliance.plugin_id == c.appl_plugin_id).order_by(Appliance.name)
     return render('appliance.mako')