예제 #1
0
def FormatAddress(address, family=None):
    """Format a socket address

  @type address: family specific (usually tuple)
  @param address: address, as reported by this class
  @type family: integer
  @param family: socket family (one of socket.AF_*) or None

  """
    if family is None:
        try:
            family = IPAddress.GetAddressFamily(address[0])
        except errors.IPAddressError:
            raise errors.ParameterError(address)

    if family == socket.AF_UNIX and len(address) == 3:
        return "pid=%s, uid=%s, gid=%s" % address

    if family in (socket.AF_INET, socket.AF_INET6) and len(address) == 2:
        host, port = address
        if family == socket.AF_INET6:
            res = "[%s]" % host
        else:
            res = host

        if port is not None:
            res += ":%s" % port

        return res

    raise errors.ParameterError(family, address)
예제 #2
0
파일: jstore.py 프로젝트: sajalcody/ganeti
def ParseJobId(job_id):
    """Parses a job ID and converts it to integer.

  """
    try:
        return int(job_id)
    except (ValueError, TypeError):
        raise errors.ParameterError("Invalid job ID '%s'" % job_id)