Exemplo n.º 1
0
def list_volume_coordinators( config, volume_id ):
    """
    Find all the gateways for a given volume that can coordinate writes
    """
    gateway_cert_paths = certs.list_gateway_cert_paths( config )
    ret = []

    for path in gateway_cert_paths:
       
        gateway_cert = None 

        try:
            with open(path, "r") as f:
                cert_bin = f.read()

            gateway_cert = ms_pb2.ms_gateway_cert()
            gateway_cert.ParseFromString( cert_bin )

        except Exception, e:
            log.exception(e)
            log.error("Failed to load '%s'" % path)
            return None

        if gateway_cert.volume_id != volume_id:
            continue

        if (gateway_cert.caps & (ms_pb2.ms_gateway_cert.CAP_COORDINATE)) == 0:
            continue 

        log.debug("%s can coordinate" % gateway_cert.name)
        ret.append( gateway_cert )
Exemplo n.º 2
0
def list_volume_gateways_by_host(config, volume_id, hostname):
    """
    Find all gateway certs in a volume with the given hostname.
    Only applies to gateways generated by this amd server.
    """
    gateway_cert_paths = certs.list_gateway_cert_paths(config)
    ret = []

    for path in gateway_cert_paths:

        gateway_cert = None

        try:
            with open(path, "r") as f:
                cert_bin = f.read()

            gateway_cert = ms_pb2.ms_gateway_cert()
            gateway_cert.ParseFromString(cert_bin)

        except Exception, e:
            log.exception(e)
            log.error("Failed to load '%s'" % path)
            return None

        if gateway_cert.volume_id != volume_id:
            continue

        if gateway_cert.host != hostname:
            continue

        log.debug("%s on %s" % (gateway_cert.name, hostname))
        ret.append(gateway_cert)
Exemplo n.º 3
0
def list_volume_coordinators(config, volume_id):
    """
    Find all the gateways for a given volume that can coordinate writes
    """
    gateway_cert_paths = certs.list_gateway_cert_paths(config)
    ret = []

    for path in gateway_cert_paths:

        gateway_cert = None

        try:
            with open(path, "r") as f:
                cert_bin = f.read()

            gateway_cert = ms_pb2.ms_gateway_cert()
            gateway_cert.ParseFromString(cert_bin)

        except Exception, e:
            log.exception(e)
            log.error("Failed to load '%s'" % path)
            return None

        if gateway_cert.volume_id != volume_id:
            continue

        if (gateway_cert.caps & (ms_pb2.ms_gateway_cert.CAP_COORDINATE)) == 0:
            continue

        log.debug("%s can coordinate" % gateway_cert.name)
        ret.append(gateway_cert)
Exemplo n.º 4
0
def list_volume_gateways_by_host(config, volume_id, hostname):
    """
    Find all gateway certs in a volume with the given hostname.
    Only applies to gateways generated by this amd server.
    """
    gateway_cert_paths = certs.list_gateway_cert_paths(config)
    ret = []

    for path in gateway_cert_paths:

        gateway_cert = None

        try:
            with open(path, "r") as f:
                cert_bin = f.read()

            gateway_cert = ms_pb2.ms_gateway_cert()
            gateway_cert.ParseFromString(cert_bin)

        except Exception, e:
            log.exception(e)
            log.error("Failed to load '%s'" % path)
            return None

        if gateway_cert.volume_id != volume_id:
            continue

        if gateway_cert.host != hostname:
            continue

        log.debug("%s on %s" % (gateway_cert.name, hostname))
        ret.append(gateway_cert)
Exemplo n.º 5
0
def list_gateways_by_type( config, volume_id, gateway_type_str ):
    """
    Find all the gateways for a given volume with a particular type.
    The type should be a type alias, like "UG" or "RG" or "AG"
    Return the list of gateway certs on success.
    Raise on error
    """
    gateway_cert_paths = certs.list_gateway_cert_paths( config )
    ret = []
    
    type_aliases = object_stub.load_gateway_type_aliases( config )
    if type_aliases is None:
        raise Exception("Missing gateway type aliases")

    gateway_type = type_aliases.get(gateway_type_str, None)
    if gateway_type is None:
        raise ValueError("Unknown gateway type alias '%s'" % gateway_type_str )

    for path in gateway_cert_paths:
       
        gateway_cert = None 

        try:
            with open(path, "r") as f:
                cert_bin = f.read()

            gateway_cert = ms_pb2.ms_gateway_cert()
            gateway_cert.ParseFromString( cert_bin )

        except Exception, e:
            log.exception(e)
            log.error("Failed to load '%s'" % path)
            return None

        if gateway_cert.volume_id != volume_id:
            continue

        if gateway_cert.gateway_type != gateway_type:
            continue 

        log.debug("%s is type %s" % (gateway_cert.name, gateway_type))
        ret.append( gateway_cert )
Exemplo n.º 6
0
def list_gateways_by_type(config, volume_id, gateway_type_str):
    """
    Find all the gateways for a given volume with a particular type.
    The type should be a type alias, like "UG" or "RG" or "AG"
    Return the list of gateway certs on success.
    Raise on error
    """
    gateway_cert_paths = certs.list_gateway_cert_paths(config)
    ret = []

    type_aliases = object_stub.load_gateway_type_aliases(config)
    if type_aliases is None:
        raise Exception("Missing gateway type aliases")

    gateway_type = type_aliases.get(gateway_type_str, None)
    if gateway_type is None:
        raise ValueError("Unknown gateway type alias '%s'" % gateway_type_str)

    for path in gateway_cert_paths:

        gateway_cert = None

        try:
            with open(path, "r") as f:
                cert_bin = f.read()

            gateway_cert = ms_pb2.ms_gateway_cert()
            gateway_cert.ParseFromString(cert_bin)

        except Exception, e:
            log.exception(e)
            log.error("Failed to load '%s'" % path)
            return None

        if gateway_cert.volume_id != volume_id:
            continue

        if gateway_cert.gateway_type != gateway_type:
            continue

        log.debug("%s is type %s" % (gateway_cert.name, gateway_type))
        ret.append(gateway_cert)