Exemple #1
0
 def put(self, site_label=None, *a, **kw):
     errors = _h.get_validation_errors()
     s = DBSession.query(Site).filter_by(label=site_label).first()
     group = _h.get_group_by_name(kw.get('group_name', None))
     all_p = DBSession.query(Project).all()
     _h.protect_obj(s)
     
     if not s:
         raise HTTPNotFound         
     if not group:
         errors['group'] = 'Group does not exist!'
         
     s.label = unicode(re.sub(' ', '_', kw['label']).lower())
     s.display_name = unicode(kw.get('display_name', None))
     s.desc = kw.get('desc', None)
     s.url = unicode(kw.get('url', None))
     s.contact_name = unicode(kw.get('contact_name', None))
     s.contact_email = unicode(kw.get('contact_email', None))
     s.sync_base_path = unicode(kw.get('sync_base_path', None))
     s.user = request.identity['user']
     s.group = group
 
     if len(errors) > 0:
         all_projects = [x for x in all_p if x not in s.projects]
         all_hosts = [x for x in request.identity['user'].hosts \
                         if x not in s.hosts]
         transaction.doom()
         return dict(page='site', errors=errors, site=s,
                     all_projects=all_projects, all_hosts=all_hosts)
         
     transaction.commit()
     flash(_("%s updated successfully!" % kw['display_name']), 'info')
     redirect(url('/site/%s/edit' % kw['label']))
Exemple #2
0
    def put(self, host_id=None, *a, **kw):
        h = DBSession.query(Host).filter_by(id=host_id).first()
        if not h:
            raise HTTPNotFound
            
        errors  = _h.get_validation_errors()
        h.user  = request.identity['user']
        h.group = _h.get_group_by_name(kw.get('group_name', None))
        h.address = unicode(kw['address'].strip())
        h.online_status = DBSession.query(Status)\
                          .filter_by(label='Offline').first()
                          
        res = self._get_geoip_data(h.address)
        if not res:
            errors['host_address'] = "The host '%s' could not be " + \
                                     "identified via GeoIP.  Please " + \
                                     "ensure the hostname resolves" % h.address
        if errors:
            transaction.doom()
            return dict(errors=errors, host=h)

        h.city = unicode(res.get('city', None))
        h.region_name   = unicode(res.get('region_name', None))
        h.longitude     = res.get('longitude', None)
        h.latitude      = res.get('latitude', None)
        h.country_name  = unicode(res.get('country_name', None))
        h.country_code  = unicode(res.get('country_code', None))
        h.country_code3 = unicode(res.get('country_code3', None))
        h.postal_code   = res.get('postal_code', None)
        flash(_("%s updated successfully!" % kw['address']), 'info')
        redirect(url('/dashboard'))
Exemple #3
0
    def put(self, project_id=None, *a, **kw):
        errors = _h.get_validation_errors()
        p = DBSession.query(Project).filter_by(id=project_id).first()
        if not p:
            raise HTTPNotFound
        if kw['label'] != p.label:
            other_p = DBSession.query(Project).filter_by(label=kw['label'])\
                      .first()
            if other_p:
                errors['label'] = "%s already exists, use another label." % \
                    other_p.label
        group = _h.get_group_by_name(kw.get('group_name', None))
        protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
        all_protocols = DBSession.query(SyncProtocol).all()

        _h.protect_obj_modify(p)
        
        p.display_name = unicode(kw['display_name'])
        p.desc = kw['desc']
        p.url = unicode(kw['url'])
        p.sync_base_path = unicode(kw.get('sync_base_path', None))
        p.sync_flags = unicode(kw.get('sync_flags', None))
        p.sync_protocol = protocol
        p.group = group
        
        if len(errors) > 0:
            transaction.doom()
            return dict(errors=errors, project=p, all_protocols=all_protocols)

        p.label = unicode(re.sub(' ', '_', kw['label']).lower())
        _label = p.label
        transaction.commit()
        flash(_("%s updated successfully!" % kw['display_name']), 'info')
        redirect(url('/project/%s/edit' % _label))
Exemple #4
0
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     group = _h.get_group_by_name(kw.get('group_name', None))
     protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
     all_protocols = DBSession.query(SyncProtocol).all()
     
     if not group:
         errors['group'] = 'Group does not exist!'
     if not protocol:
         errors['sync_protocol'] = 'Sync Protocol does not exist!'
         
     p = Project()
     p.label = unicode(re.sub(' ', '_', kw['label']).lower())
     _label = p.label
     p.display_name = unicode(kw.get('display_name', None))
     p.desc = kw.get('desc', None)
     p.url = unicode(kw.get('url', None))
     p.user = request.identity['user']
     p.sync_base_path = unicode(kw.get('sync_base_path', None))
     p.sync_flags = unicode(kw.get('sync_flags', None))
     p.group = group
     p.sync_protocol = protocol
     
     if len(errors) > 0:
         transaction.doom()
         return dict(page="project", errors=errors, project=p,
                     all_protocols=all_protocols)
     DBSession.add(p)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/project/%s/edit' % _label))
Exemple #5
0
 def new(self, *a, **kw):
     h = Host()
     group   = _h.get_group_by_name(kw.get('group_name', None))
     project = _h.get_project_by_name(kw.get('project_label', None))
     site    = _h.get_site_by_name(kw.get('site_label', None))
         
     _h.protect_obj(project)
     _h.protect_obj(site)
     
     h.user = request.identity['user']
     h.address = kw.get('address', 'host.example.com').strip()
     h.group = group
     transaction.doom()
     return dict(errors={}, host=h)
Exemple #6
0
 def new(self, *a, **kw):
     group = _h.get_group_by_name(kw.get('group_name', None))
     s = Site()
     s.label = kw.get('label', None)
     s.display_name = kw.get('display_name', None)
     s.desc = kw.get('desc', None)
     s.url = kw.get('url', None)
     s.contact_name = kw.get('contact_name', None)
     s.contact_email = kw.get('contact_email', None)
     s.sync_base_path = kw.get('sync_base_path', None)
     s.user = request.identity['user']
     s.group = group
     
     transaction.doom()
     return dict(page='site', errors={}, site=s)
Exemple #7
0
 def new(self, *a, **kw):
     group = _h.get_group_by_name(kw.get('group_name', None))
     protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
     if not protocol:
         protocol = DBSession.query(SyncProtocol).filter_by(label='rsync')\
                     .first()
     
     all_protocols = DBSession.query(SyncProtocol).all()
     
     p = Project()
     p.label = kw.get('label', None)
     p.display_name = kw.get('display_name', None)
     p.desc = kw.get('desc', None)
     p.url = kw.get('url', None)
     p.sync_base_path = kw.get('sync_base_path', None)
     p.sync_flags = kw.get('sync_flags', None)
     p.group = group
     p.sync_protocol = protocol
     transaction.doom()
     return dict(page='project', errors={}, project=p, 
                 all_protocols=all_protocols)
Exemple #8
0
    def post(self, *a, **kw):
        h = _h.get_host_by_address(kw.get('address', None))
        errors  = _h.get_validation_errors()
        if h:
            errors['address'] = "Host %s already exists!" % h.address

        h = Host()            
        group = _h.get_group_by_name(kw.get('group_name', None))
        
        h.address = unicode(kw['address'].strip())
        h.user = request.identity['user']
        h.group = group
        
        res = self._get_geoip_data(h.address)
        if not res:
            errors['host_address'] = "The host '%s' could " % h.address + \
                                     "not be identified via GeoIP. " + \
                                     "Please ensure the hostname resolves" 
                    
        if errors:
            transaction.doom()
            return dict(errors=errors, host=h)
        
        _h.protect_obj(h)
        h.online_status = DBSession.query(Status)\
                          .filter_by(label='Offline').first()
        h.city = unicode(res.get('city', None))
        h.region_name   = unicode(res.get('region_name', None))
        h.longitude     = res.get('longitude', None)
        h.latitude      = res.get('latitude', None)
        h.country_name  = unicode(res.get('country_name', None))
        h.country_code  = unicode(res.get('country_code', None))
        h.country_code3 = unicode(res.get('country_code3', None))
        h.postal_code   = res.get('postal_code', None)
            
        flash(_("%s created successfully!" % kw['address']), 'info')
        redirect(url('/host/new'))