def apply_config(self): dnsmasq = templates.render('dnsmasq.conf', domain=self.domain, dhcps=self.dhcps) self.container.upload_content('/etc/dnsmasq.conf', dnsmasq) dhcp = templates.render('dhcp', dhcps=self.dhcps) self.container.upload_content('/etc/dhcp', dhcp) for process in self.container.client.process.list(): if 'dnsmasq' in process['cmdline']: self.container.client.process.kill(process['pid'], signal.SIGTERM) start = time.time() while start + 10 > time.time(): if not self.is_running(): break time.sleep(0.2) break self.container.client.system(DNSMASQ) # check if command is listening for dhcp start = time.time() while start + 10 > time.time(): if self.is_running(): break time.sleep(0.2) else: raise RuntimeError('Failed to run dnsmasq')
def apply_config(self): influx_conf = templates.render('influxdb.conf', ip=self.ip, port=self.port, rpcport=self.rpcport) self.container.upload_content('/etc/influxdb/influxdb.conf', influx_conf)
def init(job): from zeroos.orchestrator.configuration import get_jwt_token from zeroos.orchestrator.sal.templates import render from zeroos.orchestrator.sal.StorageCluster import StorageCluster service = job.service influxdb_actor = service.aysrepo.actorGet('influxdb') args = { 'node': service.model.data.node, 'port': service.model.data.port, 'databases': ['statistics'] } influxdb_service = influxdb_actor.serviceCreate(instance='statsdb', args=args) service.consume(influxdb_service) grafana_actor = service.aysrepo.actorGet('grafana') args = { 'node': service.model.data.node, 'influxdb': ['statsdb'] } grafana_service = grafana_actor.serviceCreate(instance='statsdb', args=args) service.consume(grafana_service) dashboard_actor = service.aysrepo.actorGet('dashboard') args = { 'grafana': 'statsdb', 'dashboard': render('dashboards/overview.json') } dashboard_actor.serviceCreate(instance='overview', args=args) # Install stats_collector on all nodes stats_collector_actor = job.service.aysrepo.actorGet('stats_collector') node_services = job.service.aysrepo.servicesFind(actor='node.zero-os') for node_service in node_services: stats_collector_service = get_stats_collector_from_node(node_service) if not stats_collector_service: args = { 'node': node_service.name, 'port': job.service.model.data.port, 'ip': job.service.parent.model.data.redisAddr, } stats_collector_service = stats_collector_actor.serviceCreate(instance=node_service.name, args=args) stats_collector_service.consume(node_service) # Create storage cluster dashboards cluster_services = job.service.aysrepo.servicesFind(actor='storage_cluster') for clusterservice in cluster_services: cluster = StorageCluster.from_ays(clusterservice, get_jwt_token(service.aysrepo)) board = cluster.dashboard args = { 'grafana': 'statsdb', 'dashboard': board } dashboard_actor.serviceCreate(instance=cluster.name, args=args) stats_collector_service.consume(clusterservice)
def apply_rules(self): # nftables nftables = templates.render('nftables.conf', privatenetworks=self.privatenetworks, publicnetwork=self.publicnetwork, portforwards=self.forwards) self.container.upload_content('/etc/nftables.conf', nftables) job = self.container.client.system('nft -f /etc/nftables.conf').get() if job.state != 'SUCCESS': raise RuntimeError("Failed to apply nftables {} {}".format( job.stdout, job.stderr))
def apply_config(self): dnsmasq = templates.render('dnsmasq.conf', domain=self.domain, dhcps=self.dhcps) self.container.upload_content('/etc/dnsmasq.conf', dnsmasq) dhcp = templates.render('dhcp', dhcps=self.dhcps) self.container.upload_content('/etc/dhcp', dhcp) self.stop() self.container.client.system(DNSMASQ, id='dhcp.{}'.format(self.container.name)) # check if command is listening for dhcp start = time.time() while start + 10 > time.time(): if self.is_running(): break time.sleep(0.2) else: raise RuntimeError('Failed to run dnsmasq')
def apply_rules(self): # caddy caddyconfig = templates.render('caddy.conf', httpproxies=self.httpproxies) self.container.upload_content('/etc/caddy.conf', caddyconfig) job = self.get_job() if job: self.container.client.job.kill(job['cmd']['id'], int(signal.SIGUSR1)) else: self.container.client.system('caddy -agree -conf /etc/caddy.conf', stdin='\n') start = time.time() while start + 10 > time.time(): if self.is_running(): return True time.sleep(0.5) raise RuntimeError("Failed to start caddy server")
def apply_rules(self): # caddy type = self.service.model.data.type caddyconfig = templates.render('caddy.conf', type=type, httpproxies=self.httpproxies).strip() conf = '/etc/caddy-{}.conf'.format(type) self.container.upload_content(conf, caddyconfig) self.container.client.job.kill(self.id(), int(signal.SIGUSR1)) if caddyconfig == '': return self.container.client.system('caddy -agree -conf {}'.format(conf), stdin='\n', id=self.id()) start = time.time() while start + 10 > time.time(): if self.is_running(): return True time.sleep(0.5) raise RuntimeError("Failed to start caddy server")