parameters: (project_id)
docstring: Create the user the contains the given project data.   It is safe to
      call this function even if the user already exists.
docstring_summary: Create the user the contains the given project data.   It is safe to
      call this function even if the user already exists.
docstring_tokens: Create the user the contains the given project data . It is safe to call this function even if the user already exists .
function: def create_user(project_id):
      """
      Create the user the contains the given project data.   It is safe to
      call this function even if the user already exists.
      """
      name = username(project_id)
      id = uid(project_id)
      r = open('/etc/passwd').read()
      i = r.find(name)
      if i != -1:
          r = r[i:]
          i = r.find('\n')
          u = int(r[:i].split(':')[2])
      else:
          u = 0
      if u == id:
          # user already exists and has correct id
          return
      if u != 0:
          # there's the username but with wrong id
          ##  during migration deleting that user would be a disaster!
          raise RuntimeError("user %s already exists but with wrong id"%name)
          #cmd("userdel %s"%name)  # this also deletes the group
  
      # Now make the correct user.  The -o makes it so in the incredibly unlikely
      # event of a collision, no big deal.
      c = "groupadd -g %s -o %s"%(id, name)
      for i in range(3):
          try:
              cmd(c)
              break
          except:
              time.sleep(random.random())
  
      # minimal attemp to avoid locking issues
      c = "useradd -u %s -g %s -o -d %s %s"%(id, id, home(project_id), name)
      for i in range(3):
          try:
              cmd(c)
              break
          except:
              time.sleep(random.random())
  
  
      # Save account info so it persists through reboots/upgrades/etc. that replaces the ephemeral root fs.
      if os.path.exists("/mnt/home/etc/"): # UW nodes
          cmd("cp /etc/passwd /etc/shadow /etc/group /mnt/home/etc/")
      if os.path.exists("/mnt/conf/etc/"): # GCE nodes
          cmd("cp /etc/passwd /etc/shadow /etc/group /mnt/conf/etc/")
function_tokens: def create_user ( project_id ) : name = username ( project_id ) id = uid ( project_id ) r = open ( '/etc/passwd' ) . read ( ) i = r . find ( name ) if i != - 1 : r = r [ i : ] i = r . find ( '\n' ) u = int ( r [ : i ] . split ( ':' ) [ 2 ] ) else : u = 0 if u == id : # user already exists and has correct id return if u != 0 : # there's the username but with wrong id ##  during migration deleting that user would be a disaster! raise RuntimeError ( "user %s already exists but with wrong id" % name ) #cmd("userdel %s"%name)  # this also deletes the group # Now make the correct user.  The -o makes it so in the incredibly unlikely # event of a collision, no big deal. c = "groupadd -g %s -o %s" % ( id , name ) for i in range ( 3 ) : try : cmd ( c ) break except : time . sleep ( random . random ( ) ) # minimal attemp to avoid locking issues c = "useradd -u %s -g %s -o -d %s %s" % ( id , id , home ( project_id ) , name ) for i in range ( 3 ) : try : cmd ( c ) break except : time . sleep ( random . random ( ) ) # Save account info so it persists through reboots/upgrades/etc. that replaces the ephemeral root fs. if os . path . exists ( "/mnt/home/etc/" ) : # UW nodes cmd ( "cp /etc/passwd /etc/shadow /etc/group /mnt/home/etc/" ) if os . path . exists ( "/mnt/conf/etc/" ) : # GCE nodes cmd ( "cp /etc/passwd /etc/shadow /etc/group /mnt/conf/etc/" )