Esempio n. 1
0
 def generate_resolv_conf(self):
     """generate a resolv.conf file to bind to the containers.
        We use the template provided by scompose.
     """
     resolv_conf = os.path.join(self.working_dir, "resolv.conf")
     if not os.path.exists(resolv_conf):
         template = read_file(get_template("resolv.conf"))
         write_file(resolv_conf, template)
     return resolv_conf
Esempio n. 2
0
    def create_hosts(self, lookup):
        """create a hosts file to bind to all containers, where we define the
           correct hostnames to correspond with the ip addresses created.
           Note: This function is terrible. Singularity should easily expose 
                 these addresses. See issue here:
                 https://github.com/sylabs/singularity/issues/3751

           Parameters
           ==========
           lookup: a lookup of ip addresses to assign the containers
        """
        template = read_file(get_template("hosts"))
        hosts_file = os.path.join(self.working_dir, "etc.hosts")

        # Add an entry for each instance hostname to see the others
        for name, ip_address in lookup.items():
            template = ["%s\t%s\n" % (ip_address, name)] + template

        # Add the host file to be mounted
        write_file(hosts_file, template)
        return hosts_file