@@ -31,7 +31,7 @@ class Instance(object):
3131 params: all of the parameters defined in the configuration.
3232 """
3333
34- def __init__ (self , name , working_dir , sudo = False , params = None ):
34+ def __init__ (self , name , replica_number , working_dir , sudo = False , params = None ):
3535
3636 if not params :
3737 params = {}
@@ -41,6 +41,7 @@ def __init__(self, name, working_dir, sudo=False, params=None):
4141 self .instance = None
4242 self .sudo = sudo
4343 self .set_name (name , params )
44+ self .replica_number = replica_number
4445
4546 # Start includes networking args and command
4647 self .set_start (params )
@@ -61,7 +62,7 @@ def __init__(self, name, working_dir, sudo=False, params=None):
6162 self .get ()
6263
6364 def __str__ (self ):
64- return "(instance:%s)" % self .name
65+ return "(instance:%s)" % self .get_replica_name ()
6566
6667 def __repr__ (self ):
6768 return self .__str__ ()
@@ -77,9 +78,12 @@ def set_name(self, name, params):
7778 """
7879 self .name = params .get ("name" , name )
7980
81+ def get_replica_name (self ):
82+ return f"{ self .name } { self .replica_number } "
83+
8084 @property
8185 def uri (self ):
82- return "instance://%s" % self .name
86+ return "instance://%s" % self .get_replica_name ()
8387
8488 def set_context (self , params ):
8589 """set and validate parameters from the singularity-compose.yml,
@@ -385,24 +389,23 @@ def get_build_options(self):
385389 return options
386390
387391 # State
388-
389392 def exists (self ):
390393 """return boolean if an instance exists. We do this by way of listing
391394 instances, and so the calling user is important.
392395 """
393396 instances = [x .name for x in self .client .instances (quiet = True , sudo = self .sudo )]
394- return self .name in instances
397+ return self .get_replica_name () in instances
395398
396399 def get (self ):
397400 """If an instance exists, add to self.instance"""
398401 for instance in self .client .instances (quiet = True , sudo = self .sudo ):
399- if instance .name == self .name :
402+ if instance .name == self .get_replica_name () :
400403 self .instance = instance
401404 break
402405
403406 def stop (self , timeout = None ):
404407 """delete the instance, if it exists. Singularity doesn't have delete
405- or remove commands, everyting is a stop.
408+ or remove commands, everything is a stop.
406409 """
407410 if self .instance :
408411 bot .info ("Stopping %s" % self )
@@ -454,7 +457,9 @@ def clear_logs(self):
454457 log_folder = self ._get_log_folder ()
455458
456459 for ext in ["out" , "err" ]:
457- logfile = os .path .join (log_folder , "%s.%s" % (self .name , ext .lower ()))
460+ logfile = os .path .join (
461+ log_folder , "%s.%s" % (self .get_replica_name (), ext .lower ())
462+ )
458463
459464 # Use Try/catch to account for not existing.
460465 try :
@@ -486,7 +491,9 @@ def logs(self, tail=0):
486491 log_folder = self ._get_log_folder ()
487492
488493 for ext in ["OUT" , "ERR" ]:
489- logfile = os .path .join (log_folder , "%s.%s" % (self .name , ext .lower ()))
494+ logfile = os .path .join (
495+ log_folder , "%s.%s" % (self .get_replica_name (), ext .lower ())
496+ )
490497
491498 # Use Try/catch to account for not existing.
492499 try :
@@ -497,7 +504,9 @@ def logs(self, tail=0):
497504 # If the user only wants to see certain number
498505 if tail > 0 :
499506 result = "\n " .join (result .split ("\n " )[- tail :])
500- bot .custom (prefix = self .name , message = ext , color = "CYAN" )
507+ bot .custom (
508+ prefix = self .get_replica_name (), message = ext , color = "CYAN"
509+ )
501510 print (result )
502511 bot .newline ()
503512
@@ -534,7 +543,7 @@ def create(self, ip_address=None, sudo=False, writable_tmpfs=False):
534543 # Finally, create the instance
535544 if not self .exists ():
536545
537- bot .info ("Creating %s" % self .name )
546+ bot .info ("Creating %s" % self .get_replica_name () )
538547
539548 # Command options
540549 options = []
@@ -550,18 +559,23 @@ def create(self, ip_address=None, sudo=False, writable_tmpfs=False):
550559 options += self .start_opts
551560
552561 # Hostname
553- options += ["--hostname" , self .name ]
562+ options += ["--hostname" , self .get_replica_name () ]
554563
555564 # Writable Temporary Directory
556565 if writable_tmpfs :
557566 options += ["--writable-tmpfs" ]
558567
559568 # Show the command to the user
560- commands = "%s %s %s %s" % (" " .join (options ), image , self .name , self .args )
569+ commands = "%s %s %s %s" % (
570+ " " .join (options ),
571+ image ,
572+ self .get_replica_name (),
573+ self .args ,
574+ )
561575 bot .debug ("singularity instance start %s" % commands )
562576
563577 self .instance = self .client .instance (
564- name = self .name ,
578+ name = self .get_replica_name () ,
565579 sudo = self .sudo ,
566580 options = options ,
567581 image = image ,
0 commit comments