예제 #1
0
    def update_soa_record(self, db_session):
        """
        Form new SOA record from the information stored in the zi
        """
        if self.zone.use_apex_ns:
            # Read in values from DB global config
            sg = self.zone.sg
            mname = zone_cfg.get_row(db_session, 'soa_mname', sg=sg)
            rname = zone_cfg.get_row(db_session, 'soa_rname', sg=sg)
            refresh = zone_cfg.get_row(db_session, 'soa_refresh', sg=sg)
            retry = zone_cfg.get_row(db_session, 'soa_retry', sg=sg)
            expire = zone_cfg.get_row(db_session, 'soa_expire', sg=sg)
            # Update zi if different
            if mname != self.soa_mname:
                self.soa_mname = mname
            if rname != self.soa_rname:
                self.soa_rname = rname
            if refresh != self.soa_refresh:
                self.soa_refresh = refresh
            if retry != self.soa_retry:
                self.soa_retry = retry
            if expire != self.soa_expire:
                self.soa_expire = expire
            # Set the SOA TTL from zone_ttl so no TTL 'funnies' happen
            # when use_apex_ns is set
            if self.soa_ttl:
                self.soa_ttl = None

        rdata = ("%s %s %s %s %s %s %s" 
                    % (self.soa_mname, self.soa_rname, self.soa_serial,
                            self.soa_refresh, self.soa_retry, self.soa_expire,
                            self.soa_minimum))
        ttl = self.soa_ttl
        zone_ttl = self.zone_ttl
        new_soa_rr = RR_SOA(label='@', ttl=ttl, zone_ttl=zone_ttl,
                rdata=rdata, domain=self.zone.name)
        
        # Put in new SOA record
        # Remove every soa rr but the first. Have to be careful as deleting
        # from lists while looping over them can be problematic, and ordering
        # can influence SQL statement ordering, which could be sensitive here.
        # Being hyper cautious here...
        old_soa_rrs = [r for r in self.rrs if type(r) == RR_SOA]
        if len(old_soa_rrs):
            # Remove every soa rr but the first, then grab comment, then remove
            # thold SOA RR.
            old_soa_rr = old_soa_rrs.pop(0)
            for rr in old_soa_rrs:
                self.remove_rr(rr)
                db_session.delete(rr)
            rr_comment = old_soa_rr.rr_comment
            self.remove_rr(old_soa_rr)
            db_session.delete(old_soa_rr)
        else:
            rr_comment = None
        self.add_rr(new_soa_rr)
        db_session.add(new_soa_rr)
        new_soa_rr.group_comment = self.apex_comment
        new_soa_rr.rr_comment = rr_comment
예제 #2
0
파일: server_sm.py 프로젝트: kenser/dms
def new_server(db_session,
               server_name,
               address,
               sg_name,
               server_type=None,
               ssh_address=None):
    """
    Create a new server
    """
    server_name = server_name.lower()
    if server_name.endswith('.'):
        server_name = server_name[:-1]
    if not sg_name:
        sg_name = zone_cfg.get_row_exc(db_session, 'default_sg')
    if not sg_name in list_all_sgs(db_session):
        raise NoSgFound(sg_name)
    try:
        server_list = db_session.query(ServerSM)\
                        .filter(ServerSM.name == server_name).all()
        if len(server_list):
            raise ServerExists(server_name)
    except NoResultFound:
        pass
    if not server_type:
        server_type = zone_cfg.get_row(db_session,
                                       'default_stype',
                                       raise_exc=True)
    server_sm = ServerSM(server_name, address, sg_name, server_type,
                         ssh_address)
    try:
        db_session.add(server_sm)
        db_session.flush()
    except IntegrityError as exc:
        raise ServerAddressExists(address)
    sg = find_sg_byname(db_session, sg_name, raise_exc=True)
    server_sm.set_sg(sg)
    db_session.flush()
    return server_sm
예제 #3
0
파일: zone_instance.py 프로젝트: kenser/dms
    def update_soa_record(self, db_session):
        """
        Form new SOA record from the information stored in the zi
        """
        if self.zone.use_apex_ns:
            # Read in values from DB global config
            sg = self.zone.sg
            mname = zone_cfg.get_row(db_session, 'soa_mname', sg=sg)
            rname = zone_cfg.get_row(db_session, 'soa_rname', sg=sg)
            refresh = zone_cfg.get_row(db_session, 'soa_refresh', sg=sg)
            retry = zone_cfg.get_row(db_session, 'soa_retry', sg=sg)
            expire = zone_cfg.get_row(db_session, 'soa_expire', sg=sg)
            # Update zi if different
            if mname != self.soa_mname:
                self.soa_mname = mname
            if rname != self.soa_rname:
                self.soa_rname = rname
            if refresh != self.soa_refresh:
                self.soa_refresh = refresh
            if retry != self.soa_retry:
                self.soa_retry = retry
            if expire != self.soa_expire:
                self.soa_expire = expire
            # Set the SOA TTL from zone_ttl so no TTL 'funnies' happen
            # when use_apex_ns is set
            if self.soa_ttl:
                self.soa_ttl = None

        rdata = (
            "%s %s %s %s %s %s %s" %
            (self.soa_mname, self.soa_rname, self.soa_serial, self.soa_refresh,
             self.soa_retry, self.soa_expire, self.soa_minimum))
        ttl = self.soa_ttl
        zone_ttl = self.zone_ttl
        new_soa_rr = RR_SOA(label='@',
                            ttl=ttl,
                            zone_ttl=zone_ttl,
                            rdata=rdata,
                            domain=self.zone.name)

        # Put in new SOA record
        # Remove every soa rr but the first. Have to be careful as deleting
        # from lists while looping over them can be problematic, and ordering
        # can influence SQL statement ordering, which could be sensitive here.
        # Being hyper cautious here...
        old_soa_rrs = [r for r in self.rrs if type(r) == RR_SOA]
        if len(old_soa_rrs):
            # Remove every soa rr but the first, then grab comment, then remove
            # thold SOA RR.
            old_soa_rr = old_soa_rrs.pop(0)
            for rr in old_soa_rrs:
                self.remove_rr(rr)
                db_session.delete(rr)
            rr_comment = old_soa_rr.rr_comment
            self.remove_rr(old_soa_rr)
            db_session.delete(old_soa_rr)
        else:
            rr_comment = None
        self.add_rr(new_soa_rr)
        db_session.add(new_soa_rr)
        new_soa_rr.group_comment = self.apex_comment
        new_soa_rr.rr_comment = rr_comment