code: def _initiate_replset(self, port, name, maxwait=30):
          
          if not self.args['replicaset'] and name != 'configRepl':
              if self.args['verbose']:
                  print('Skipping replica set initialization for %s' % name)
              return
  
          con = self.client('localhost:%i' % port)
          try:
              rs_status = con['admin'].command({'replSetGetStatus': 1})
              return rs_status
          except OperationFailure as e:
              # not initiated yet
              for i in range(maxwait):
                  try:
                      con['admin'].command({'replSetInitiate':
                                            self.config_docs[name]})
                      break
                  except OperationFailure as e:
                      print(e.message + " - will retry")
                      time.sleep(1)
  
              if self.args['verbose']:
                  print("initializing replica set '%s' with configuration: %s"
                        % (name, self.config_docs[name]))
              print("replica set '%s' initialized." % name)
docs: Initiate replica set.