예제 #1
0
파일: dhcp.py 프로젝트: nveeser/dino
    def query_subnets(self, session):
        
        base_data = {
            'subnet' : None,
            'subnet-mask' : None,
            'routers' : None, 
            'broadcast-address' : None,
            'options' : None,             
        }
                
        data = dict(base_data)
        
        dc_info = self.pull_rapids_datacenter(self.settings, self.settings.site)
        
        subnets = session.query(Subnet).join(Site).filter_by(name=self.settings.site).all()        
        for s in subnets:
            self.log.fine("  Subnet: %s" % s.addr)
            data['subnet'] = s.addr
            data['subnet-mask'] = s.mask
            
            data['routers'] = IpType.ntoa(s.naddr + s.gateway)
            data['broadcast-address'] = IpType.ntoa(s.broadcast)


            data['options'] = ""
            
            for r in s.ranges:
                self.log.fine("   Range: %s", r)
                if r.range_type == 'dhcp':
                    data['options'] += "range %s %s;\n" % (r.start_addr, r.end_addr)
                            
            yield self.check_data(data)
예제 #2
0
파일: rapids.py 프로젝트: nveeser/dino
    def query(self):
        session = self.db_config.session()

        query = session.query(Host).join(Device).join(Rack).join(Site).filter_by(name=self.settings.site)

        for host in query:
            d = copy.deepcopy(data_base)
            d["host_no"] = host.id
            d["fqdn"] = d["host"] = host.hostname() + "." + self.settings.domain
            d["release_proto"] = "svn-https"
            d["release_source"] = self.settings.rapids_svn_path + host.appliance.os.name

            d["inherit"]["appliance"] = host.appliance.name
            d["inherit"]["datacenter"] = host.device.rack.site.name
            d["inherit"]["pod"] = host.pod.name + "." + host.device.rack.site.name
            if bool(self.settings.rapids_force_stage_inherit):
                d["inherit"]["stage-definitions"] = "default"
            d["inherit"]["host"] = d["host"]

            d["os_codename"] = host.appliance.os.name
            d["portage"] = host.appliance.os.name
            d["gentoo_version"] = host.appliance.os.name
            d["release"] = host.appliance.os.name

            if host.ssh_key_info is None:
                self.log.error("  Skipping host: %s: No ssh keys", str(host))
                continue

            d["tmpl_data"]["ssh-rsa-key"] = host.ssh_key_info.rsa_key
            d["tmpl_data"]["ssh-rsa-pub"] = host.ssh_key_info.rsa_pub
            d["tmpl_data"]["ssh-dsa-key"] = host.ssh_key_info.dsa_key
            d["tmpl_data"]["ssh-dsa-pub"] = host.ssh_key_info.dsa_pub

            for p in host.device.ports:
                if not p.interface:
                    continue

                if p.is_blessed:
                    name = 0
                else:
                    name = p.interface.name()
                    if name.startswith("eth"):
                        name = int(name[3])

                if p.interface.address is None:
                    self.log.error("Inteface have no Address: %s", p.interface)
                    continue

                if p.interface.address.subnet is None:
                    raise GeneratorExecutionError("Address has no Subnet: %s" % p.interface.address)

                d["nic"][name] = {}
                d["nic"][name]["ip"] = p.interface.address.value
                d["nic"][name]["gw"] = IpType.ntoa(
                    p.interface.address.subnet.naddr + p.interface.address.subnet.gateway
                )
                d["nic"][name]["nm"] = p.interface.address.subnet.mask
                d["nic"][name]["bc"] = IpType.ntoa(p.interface.address.subnet.broadcast)

            if d["nic"][0]["ip"] is None:
                raise GeneratorExecutionError("Host has no blessed interface: %s" % host)

            yield d

        session.close()