def configure(self):
        restart = False

        server = "{}:{}".format(self.charm_config['listen'],
                                self.charm_config['port'])

        hookenv.log("Configuring taskd server {}".format(server), 'DEBUG')

        templating.render('config.j2', '/var/lib/taskd/config',
                          {'server': server})

        if any_file_changed(['/var/lib/taskd/config']):
            restart = True

        if self.charm_config['tls_cn']:
            cn = self.charm_config['tls_cn']
        else:
            cn = socket.getfqdn()

        templating.render(
            'vars.j2', '/usr/share/taskd/pki/vars', {
                'expiry': self.charm_config['tls_expiry'],
                'org': self.charm_config['tls_org'],
                'cn': cn,
                'country': self.charm_config['tls_country'],
                'state': self.charm_config['tls_state'],
                'locality': self.charm_config['tls_locality']
            })

        if any_file_changed(['/usr/share/taskd/pki/vars']):
            p = subprocess.Popen(['/usr/share/taskd/pki/generate'],
                                 cwd='/usr/share/taskd/pki')
            p.wait()
            restart = True

        fullport = "{}/tcp".format(self.charm_config['port'])

        for port in hookenv.opened_ports():
            if not fullport == port:
                cport, cproto = port.split('/')
                hookenv.close_port(cport, cproto)

        if fullport not in hookenv.opened_ports():
            hookenv.open_port(self.charm_config['port'], 'tcp')

        self.fix_permissions()
        self.start_enable()

        if restart:
            self.restart()
 def configure_ports(self):
     """Configure listening ports."""
     listen_port = self.charm_config["listen-port"]
     for open_port in hookenv.opened_ports():
         port, protocol = open_port.split("/")
         if protocol != 'udp' and port != listen_port:
             hookenv.close_port(port, protocol=protocol.upper())
     hookenv.open_port(self.charm_config["listen-port"], protocol="UDP")
Beispiel #3
0
 def open_ports(self):
     """Open ports based on configuration."""
     ports = ["80", str(self.charm_config["ssh_port"])]
     opened_ports = hookenv.opened_ports()
     for open_port in opened_ports:
         port_no = open_port.split("/")[0]
         if port_no not in ports:
             hookenv.close_port(port_no)
     for port in ports:
         if "{}/tcp".format(port) not in opened_ports:
             hookenv.open_port(port)
Beispiel #4
0
 def close_ports(self):
     """Close all open ports."""
     opened_ports = hookenv.opened_ports()
     for open_port in opened_ports:
         port_no = open_port.split("/")[0]
         hookenv.close_port(port_no)