code: def get_allowed_units(self, database, username, relation_id=None):
          
          self.connect(password=self.get_mysql_root_password())
          allowed_units = set()
          for unit in related_units(relation_id):
              settings = relation_get(rid=relation_id, unit=unit)
              # First check for setting with prefix, then without
              for attr in ["%s_hostname" % (database), 'hostname']:
                  hosts = settings.get(attr, None)
                  if hosts:
                      break
  
              if hosts:
                  # hostname can be json-encoded list of hostnames
                  try:
                      hosts = json.loads(hosts)
                  except ValueError:
                      hosts = [hosts]
              else:
                  hosts = [settings['private-address']]
  
              if hosts:
                  for host in hosts:
                      host = self.normalize_address(host)
                      if self.grant_exists(database, username, host):
                          log("Grant exists for host '%s' on db '%s'" %
                              (host, database), level=DEBUG)
                          if unit not in allowed_units:
                              allowed_units.add(unit)
                      else:
                          log("Grant does NOT exist for host '%s' on db '%s'" %
                              (host, database), level=DEBUG)
              else:
                  log("No hosts found for grant check", level=INFO)
  
          return allowed_units
docs: Get list of units with access grants for database with username.
  
          This is typically used to provide shared-db relations with a list of
          which units have been granted access to the given database.