Example #1
0
File: site.py Project: jness/dmirr
    def assign_project(self, site_id, *a, **kw):
        errors = _h.get_validation_errors()
        s = DBSession.query(Site).filter_by(id=site_id).first()
        p = DBSession.query(Project).filter_by(id=kw.get('project_id', None))\
            .first()
        all_p = DBSession.query(Project).all()
        
        _h.protect_obj(s)
        _h.protect_obj(p)

        if not s:
            raise HTTPNotFound
        if not p:
            raise HTTPNotFound    
        
        all_projects = [x for x in all_p if x not in s.projects]
        
        if errors:
            transaction.doom()
            return dict(errors=errors, site=s, all_projects=all_projects)

        _s_label = s.label
        s.projects.append(p)

        if kw.get('sync_path', None):
            self._add_site_sync_path(s.id, p.id, kw['sync_path'])
        else:
            transaction.doom()
            flash(_('Site sync path required for each project.'), 'warning')
            redirect(url("/site/%s/edit#mirrored_projects" % _s_label))

        transaction.commit()    
        redirect(url("/site/%s/edit#projects" % _s_label))
Example #2
0
File: site.py Project: jness/dmirr
 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']))
Example #3
0
File: host.py Project: jness/dmirr
 def edit(self, host_address=None, *a, **kw):
     h = _h.get_host_by_address(host_address)
     if not h:
         raise HTTPNotFound
         
     _h.protect_obj(h)
     return dict(errors={}, original_host=h, host=h)
Example #4
0
File: host.py Project: jness/dmirr
 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)
Example #5
0
File: site.py Project: jness/dmirr
    def unassign_host(self, site_id, host_id):
        s = DBSession.query(Site).filter_by(id=int(site_id)).first()
        h = DBSession.query(Host).filter_by(id=int(host_id)).first()
        
        _h.protect_obj(s)
        _h.protect_obj(h)

        if not s:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
                
        _s_label = s.label
        s.hosts.remove(h)
        transaction.commit()
        redirect(url("/site/%s/edit#downstream_mirrors" % _s_label))
        return dict(errors={}, site=s)    
Example #6
0
    def unassign_host(self, project_id, host_id):
        p = DBSession.query(Project).filter_by(id=int(project_id)).first()
        h = DBSession.query(Host).filter_by(id=int(host_id)).first()
        
        _h.protect_obj(p)
        _h.protect_obj(h)

        if not p:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
                
        _p_label = p.label
        p.hosts.remove(h)
        transaction.commit()
        redirect(url("/project/%s/edit#upstream_mirrors" % _p_label))
        return dict(errors={}, project=p)    
Example #7
0
 def delete(self, project_label=None, *a, **kw):
     _p = DBSession.query(Project).filter_by(label=project_label).first()   
     if not _p:
         raise HTTPNotFound
     _p_label = _p.label
     _h.protect_obj(_p)
         
     confirmed = kw.get('confirmed', None)        
     if not confirmed:
         display_name = _p.display_name
         action = url('/project/%s/delete' % _p.label)
         came_from = url('/project/%s/edit' % _p_label)
         return dict(page="project", errors={}, display_name=display_name, action=action, came_from=came_from)
     else:
         DBSession.delete(_p)
         transaction.commit()
         flash(_("%s and all associated data have been deleted." % _p.display_name), 'info')
         redirect(url('/dashboard'))
Example #8
0
File: site.py Project: jness/dmirr
    def assign_host(self, site_id, *a, **kw):
        errors = _h.get_validation_errors()
        s = DBSession.query(Site).filter_by(id=site_id).first()
        h = DBSession.query(Host).filter_by(id=kw.get('host_id', None)).first()
        
        _h.protect_obj(s)
        _h.protect_obj(h)

        if not s:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
        
        if errors:
            return dict(errors=errors, site=s)
            
        _s_label = s.label
        s.hosts.append(h)
        transaction.commit()
        redirect(url("/site/%s/edit#downstream_mirrors" % _s_label))
Example #9
0
File: host.py Project: jness/dmirr
 def delete(self, host_address=None, *a, **kw):
     h = DBSession.query(Host).filter_by(address=host_address).first()   
     if not h:
         raise HTTPNotFound
     _host_address = h.address
     _h.protect_obj(h)
         
     confirmed = kw.get('confirmed', None)        
     if not confirmed:
         display_name = h.address
         action = url('/host/%s/delete' % h.address)
         came_from = url('/host/%s/edit' % h.address)
         return dict(errors={}, display_name=display_name, action=action, 
                     came_from=came_from)
     else:
         DBSession.delete(h)
         transaction.commit()
         flash(_("%s and all associated data have been deleted." % \
             _host_address), 'info')
         redirect(url('/dashboard'))
Example #10
0
    def assign_host(self, project_id, *a, **kw):
        errors = _h.get_validation_errors()
        p = DBSession.query(Project).filter_by(id=project_id).first()
        h = DBSession.query(Host).filter_by(id=kw.get('host_id', None)).first()
        
        _h.protect_obj(p)
        _h.protect_obj(h)

        if not p:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
        
        if errors:
            return dict(errors=errors, project=p)
            
        _p_label = p.label
        p.hosts.append(h)
        transaction.commit()
        redirect(url("/project/%s/edit#upstream_mirrors" % _p_label))
Example #11
0
File: site.py Project: jness/dmirr
 def delete(self, site_label=None, *a, **kw):
     s = DBSession.query(Site).filter_by(label=site_label).first()
     _display_name = s.display_name
     if not s:
         raise HTTPNotFound
     
     _h.protect_obj(s)
     
     confirmed = kw.get('confirmed', None)        
     if not confirmed:
         display_name = s.display_name
         action = url('/site/%s/delete' % s.label)
         came_from = url('/site/%s/edit' % s.label)
         return dict(errors={}, display_name=display_name, action=action, 
                     came_from=came_from)
     else:
         DBSession.delete(s)
         transaction.commit()
         flash(_("%s and all associated data have been deleted." % \
                 _display_name), 'info')
         redirect(url('/dashboard'))
Example #12
0
File: site.py Project: jness/dmirr
    def unassign_project(self, site_id, project_id):
        s = DBSession.query(Site).filter_by(id=int(site_id)).first()
        p = DBSession.query(Project).filter_by(id=int(project_id)).first()
        
        _h.protect_obj(s)
        _h.protect_obj(p)

        if not s:
            raise HTTPNotFound
        if not p:
            raise HTTPNotFound    
                
        _s_label = s.label
        
        sync_path = DBSession.query(SiteSyncPath).filter_by(site_id=s.id)\
              .filter_by(project_id=p.id).first()
        if sync_path:
            DBSession.delete(sync_path)
            
        s.projects.remove(p)
        transaction.commit()
        
        redirect(url("/site/%s/edit#mirrored_projects" % _s_label))
Example #13
0
File: host.py Project: jness/dmirr
    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'))
Example #14
0
File: site.py Project: jness/dmirr
 def get_one(self, site_label=None, *a, **kw):
     s = _h.get_site_by_name(site_label)
     _h.protect_obj(s)
     return dict(page='site', errors={}, site=s)