Пример #1
0
 def test_replace_file_custom_mode_twice(self):
     file_mode = 0o722
     file.replace_file(self.file_name, self.data, file_mode)
     self.data = "new data to copy"
     file_mode = 0o777
     file.replace_file(self.file_name, self.data, file_mode)
     self._verify_result(file_mode)
Пример #2
0
 def test_replace_file_custom_mode_twice(self):
     file_mode = 0o722
     file.replace_file(self.file_name, self.data, file_mode)
     self.data = "new data to copy"
     file_mode = 0o777
     file.replace_file(self.file_name, self.data, file_mode)
     self._verify_result(file_mode)
Пример #3
0
    def _output_config_file(self):
        config_str = self.config.get_config_str()
        LOG.debug("Router %s keepalived config: %s",
                  self.resource_id, config_str)
        config_path = self.get_full_config_file_path('keepalived.conf')
        file_utils.replace_file(config_path, config_str)

        return config_path
Пример #4
0
    def _output_config_file(self):
        config_str = self.config.get_config_str()
        LOG.debug("Router %s keepalived config: %s",
                  self.resource_id, config_str)
        config_path = self.get_full_config_file_path('keepalived.conf')
        file_utils.replace_file(config_path, config_str)

        return config_path
Пример #5
0
 def ensure_config_file(self, kind, template, vpnservice, file_mode=None):
     """Update config file,  based on current settings for service."""
     config_str = self._gen_config_content(template, vpnservice)
     config_file_name = self._get_config_filename(kind)
     if file_mode is None:
         file_utils.replace_file(config_file_name, config_str)
     else:
         file_utils.replace_file(config_file_name, config_str, file_mode)
Пример #6
0
 def ensure_config_file(self, kind, template, vpnservice, file_mode=None):
     """Update config file,  based on current settings for service."""
     config_str = self._gen_config_content(template, vpnservice)
     config_file_name = self._get_config_filename(kind)
     if file_mode is None:
         file_utils.replace_file(config_file_name, config_str)
     else:
         file_utils.replace_file(config_file_name, config_str, file_mode)
Пример #7
0
    def _generate_radvd_conf(self, router_ports):
        radvd_conf = utils.get_conf_file_name(self._agent_conf.ra_confs,
                                              self._router_id, 'radvd.conf',
                                              True)
        buf = six.StringIO()
        for p in router_ports:
            subnets = p.get('subnets', [])
            v6_subnets = [
                subnet for subnet in subnets
                if netaddr.IPNetwork(subnet['cidr']).version == 6
            ]
            if not v6_subnets:
                continue
            ra_modes = {subnet['ipv6_ra_mode'] for subnet in v6_subnets}
            auto_config_prefixes = [
                subnet['cidr'] for subnet in v6_subnets
                if subnet['ipv6_ra_mode'] == constants.IPV6_SLAAC
                or subnet['ipv6_ra_mode'] == constants.DHCPV6_STATELESS
            ]
            stateful_config_prefixes = [
                subnet['cidr'] for subnet in v6_subnets
                if subnet['ipv6_ra_mode'] == constants.DHCPV6_STATEFUL
            ]
            interface_name = self._dev_name_helper(p['id'])
            slaac_subnets = [
                subnet for subnet in v6_subnets
                if subnet['ipv6_ra_mode'] == constants.IPV6_SLAAC
            ]
            dns_servers = list(
                iter_chain(*[
                    subnet['dns_nameservers'] for subnet in slaac_subnets
                    if subnet.get('dns_nameservers')
                ]))
            network_mtu = p.get('mtu', 0)

            buf.write('%s' % CONFIG_TEMPLATE.render(
                ra_modes=list(ra_modes),
                interface_name=interface_name,
                auto_config_prefixes=auto_config_prefixes,
                stateful_config_prefixes=stateful_config_prefixes,
                dns_servers=dns_servers[0:MAX_RDNSS_ENTRIES],
                n_const=n_const,
                constants=constants,
                min_rtr_adv_interval=self._agent_conf.min_rtr_adv_interval,
                max_rtr_adv_interval=self._agent_conf.max_rtr_adv_interval,
                network_mtu=int(network_mtu)))

        contents = buf.getvalue()
        LOG.debug("radvd config = %s", contents)
        # radvd conf file can't be writeable by self/group
        file_utils.replace_file(radvd_conf, contents, file_mode=0o444)
        return radvd_conf
Пример #8
0
def _store_listener_crt(haproxy_base_dir, listener, cert):
    """Store TLS certificate

    :param haproxy_base_dir: location of the instances state data
    :param listener: the listener object
    :param cert: the TLS certificate
    :returns: location of the stored certificate
    """
    cert_path = _retrieve_crt_path(haproxy_base_dir, listener, cert.primary_cn)
    # build a string that represents the pem file to be saved
    pem = _build_pem(cert)
    file_utils.replace_file(cert_path, pem)
    return cert_path
Пример #9
0
def save_config(conf_path, loadbalancer, socket_path, user_group,
                haproxy_base_dir):
    """Convert a logical configuration to the HAProxy version.

    :param conf_path: location of Haproxy configuration
    :param loadbalancer: the load balancer object
    :param socket_path: location of haproxy socket data
    :param user_group: user group
    :param haproxy_base_dir: location of the instances state data
    """
    config_str = render_loadbalancer_obj(loadbalancer, user_group, socket_path,
                                         haproxy_base_dir)
    file_utils.replace_file(conf_path, config_str)
Пример #10
0
    def _generate_radvd_conf(self, router_ports):
        radvd_conf = utils.get_conf_file_name(self._agent_conf.ra_confs,
                                              self._router_id,
                                              'radvd.conf',
                                              True)
        buf = six.StringIO()
        for p in router_ports:
            subnets = p.get('subnets', [])
            v6_subnets = [subnet for subnet in subnets if
                          netaddr.IPNetwork(subnet['cidr']).version == 6]
            if not v6_subnets:
                continue
            ra_modes = {subnet['ipv6_ra_mode'] for subnet in v6_subnets}
            auto_config_prefixes = [
                subnet['cidr'] for subnet in v6_subnets
                if (subnet['ipv6_ra_mode'] == constants.IPV6_SLAAC or
                    subnet['ipv6_ra_mode'] == constants.DHCPV6_STATELESS)
            ]
            stateful_config_prefixes = [
                subnet['cidr'] for subnet in v6_subnets
                if subnet['ipv6_ra_mode'] == constants.DHCPV6_STATEFUL
            ]
            interface_name = self._dev_name_helper(p['id'])
            slaac_subnets = [
                subnet for subnet in v6_subnets
                if subnet['ipv6_ra_mode'] == constants.IPV6_SLAAC
            ]
            dns_servers = list(iter_chain(*[
                subnet['dns_nameservers'] for subnet in slaac_subnets
                if subnet.get('dns_nameservers')
            ]))
            network_mtu = p.get('mtu', 0)

            buf.write('%s' % CONFIG_TEMPLATE.render(
                ra_modes=list(ra_modes),
                interface_name=interface_name,
                auto_config_prefixes=auto_config_prefixes,
                stateful_config_prefixes=stateful_config_prefixes,
                dns_servers=dns_servers[0:MAX_RDNSS_ENTRIES],
                n_const=constants,
                constants=constants,
                min_rtr_adv_interval=self._agent_conf.min_rtr_adv_interval,
                max_rtr_adv_interval=self._agent_conf.max_rtr_adv_interval,
                network_mtu=int(network_mtu)))

        contents = buf.getvalue()
        LOG.debug("radvd config = %s", contents)
        # radvd conf file can't be writeable by self/group
        file_utils.replace_file(radvd_conf, contents, file_mode=0o444)
        return radvd_conf
Пример #11
0
def _store_listener_crt(haproxy_base_dir, listener, cert):
    """Store TLS certificate

    :param haproxy_base_dir: location of the instances state data
    :param listener: the listener object
    :param cert: the TLS certificate
    :returns: location of the stored certificate
    """
    cert_path = _retrieve_crt_path(haproxy_base_dir, listener,
                                   cert.primary_cn)
    # build a string that represents the pem file to be saved
    pem = _build_pem(cert)
    file_utils.replace_file(cert_path, pem)
    return cert_path
Пример #12
0
def save_config(conf_path, loadbalancer, socket_path, user_group,
                haproxy_base_dir):
    """Convert a logical configuration to the HAProxy version.

    :param conf_path: location of Haproxy configuration
    :param loadbalancer: the load balancer object
    :param socket_path: location of haproxy socket data
    :param user_group: user group
    :param haproxy_base_dir: location of the instances state data
    """
    config_str = render_loadbalancer_obj(loadbalancer,
                                         user_group,
                                         socket_path,
                                         haproxy_base_dir)
    file_utils.replace_file(conf_path, config_str)
Пример #13
0
def main():
    """Expected arguments:
    sys.argv[1] - The add/update/delete operation performed by the PD agent
    sys.argv[2] - The file where the new prefix should be written
    sys.argv[3] - The process ID of the L3 agent to be notified of this change
    """
    operation = sys.argv[1]
    prefix_fname = sys.argv[2]
    agent_pid = sys.argv[3]
    prefix = os.getenv('PREFIX1', "::")

    if operation == "add" or operation == "update":
        file_utils.replace_file(prefix_fname, "%s/64" % prefix)
    elif operation == "delete":
        file_utils.replace_file(prefix_fname, "::/64")
    os.kill(int(agent_pid), signal.SIGUSR1)
Пример #14
0
def main():
    """Expected arguments:
    sys.argv[1] - The add/update/delete operation performed by the PD agent
    sys.argv[2] - The file where the new prefix should be written
    sys.argv[3] - The process ID of the L3 agent to be notified of this change
    """
    operation = sys.argv[1]
    prefix_fname = sys.argv[2]
    agent_pid = sys.argv[3]
    prefix = os.getenv('PREFIX1', "::")

    if operation == "add" or operation == "update":
        file_utils.replace_file(prefix_fname, "%s/64" % prefix)
    elif operation == "delete":
        file_utils.replace_file(prefix_fname, "::/64")
    os.kill(int(agent_pid), signal.SIGUSR1)
Пример #15
0
    def _generate_dibbler_conf(self, ex_gw_ifname, lla):
        dcwa = self.dibbler_client_working_area
        script_path = utils.get_conf_file_name(dcwa, 'notify', 'sh', True)
        buf = six.StringIO()
        buf.write('%s' % SCRIPT_TEMPLATE.render(
                             prefix_path=self.prefix_path,
                             l3_agent_pid=os.getpid()))
        file_utils.replace_file(script_path, buf.getvalue())
        os.chmod(script_path, 0o744)

        dibbler_conf = utils.get_conf_file_name(dcwa, 'client', 'conf', False)
        buf = six.StringIO()
        buf.write('%s' % CONFIG_TEMPLATE.render(
                             enterprise_number=cfg.CONF.vendor_pen,
                             va_id='0x%s' % self.converted_subnet_id,
                             script_path='"%s/notify.sh"' % dcwa,
                             interface_name='"%s"' % ex_gw_ifname,
                             bind_address='%s' % lla))

        file_utils.replace_file(dibbler_conf, buf.getvalue())
        return dcwa
Пример #16
0
 def test_replace_file_custom_mode(self):
     file_mode = 0o722
     file.replace_file(self.file_name, self.data, file_mode)
     self._verify_result(file_mode)
Пример #17
0
    def _output_config_file(self):
        config_str = self.config.get_config_str()
        config_path = self.get_full_config_file_path('keepalived.conf')
        file_utils.replace_file(config_path, config_str)

        return config_path
Пример #18
0
    def write_check_script(self):
        if not self._is_needed():
            return

        file_utils.replace_file(self._get_script_location(),
                                self._get_script_str(), 0o520)
Пример #19
0
 def test_replace_file_default_mode(self):
     file_mode = 0o644
     file.replace_file(self.file_name, self.data)
     self._verify_result(file_mode)
Пример #20
0
def replace_file(file_name, data, file_mode=0o644):
    file_utils.replace_file(file_name, data, file_mode=file_mode)
Пример #21
0
 def test_replace_file_custom_mode(self):
     file_mode = 0o722
     file.replace_file(self.file_name, self.data, file_mode)
     self._verify_result(file_mode)
Пример #22
0
def replace_file(file_name, data, file_mode=0o644):
    file_utils.replace_file(file_name, data, file_mode=file_mode)
Пример #23
0
 def test_replace_file_default_mode(self):
     file_mode = 0o644
     file.replace_file(self.file_name, self.data)
     self._verify_result(file_mode)
Пример #24
0
    def _output_config_file(self):
        config_str = self.config.get_config_str()
        config_path = self.get_full_config_file_path('keepalived.conf')
        file_utils.replace_file(config_path, config_str)

        return config_path
Пример #25
0
    def write_check_script(self):
        if not self._is_needed():
            return

        file_utils.replace_file(
            self._get_script_location(), self._get_script_str(), 0o520)