Exemple #1
0
def cmd_set_nodedesc(argv,o):
    """Set or display the node description for CAs.
       Usage: %prog [-v] [NAME]

       By default all CAs are altered, use -C or -P to select a single CA."""
    o.add_option("-v",dest="view_all",action="store_true",
                 help="Increase the verbosity level of diagnostic messages, each -v increases by 1.")
    o.add_option("-C","--Ca",dest="CA",
                 help="RDMA device to use. Specify a device name or node GUID");
    o.add_option("-P","--Port",dest="port",
                 help="RDMA end port to use. Specify a GID, port GUID, DEVICE/PORT or port number.");
    (args,values) = o.parse_args(argv);

    dev = None
    if args.CA is not None:
        dev = rdma.get_device(args.CA);
    if dev is None and args.port is not None:
        dev = rdma.get_end_port(args.port).parent;

    if args.view_all or len(values) <= 0:
        for I in rdma.get_devices():
            if dev is not None and I != dev:
                continue;
            print "%s: %s"%(I.name,IBA_describe.dstr(I.node_desc))
    else:
        name = values[0].decode();
        name = name.encode("utf-8");
        for I in rdma.get_devices():
            if dev is not None and I != dev:
                continue;
            with open(os.path.join(I._dir,"node_desc"),"w") as F:
                F.write(name);
    return True;
Exemple #2
0
def cmd_set_nodedesc(argv,o):
    """Set or display the node description for CAs.
       Usage: %prog [-v] [NAME]

       By default all CAs are altered, use -C or -P to select a single CA."""
    o.add_option("-v",dest="view_all",action="store_true",
                 help="Increase the verbosity level of diagnostic messages, each -v increases by 1.")
    o.add_option("-C","--Ca",dest="CA",
                 help="RDMA device to use. Specify a device name or node GUID");
    o.add_option("-P","--Port",dest="port",
                 help="RDMA end port to use. Specify a GID, port GUID, DEVICE/PORT or port number.");
    (args,values) = o.parse_args(argv);

    dev = None
    if args.CA is not None:
        dev = rdma.get_device(args.CA);
    if dev is None and args.port is not None:
        dev = rdma.get_end_port(args.port).parent;

    if args.view_all or len(values) <= 0:
        for I in rdma.get_devices():
            if dev is not None and I != dev:
                continue;
            print "%s: %s"%(I.name,IBA_describe.dstr(I.node_desc))
    else:
        name = values[0].decode();
        name = name.encode("utf-8");
        for I in rdma.get_devices():
            if dev is not None and I != dev:
                continue;
            with open(os.path.join(I._dir,"node_desc"),"w") as F:
                F.write(name);
    return True;
Exemple #3
0
 def __init__(self,end_port,**kwargs):
     """*end_port* is the :class:`rdma.devices.EndPort` this path is
     associated with. *kwargs* is applied to set attributes of the
     instance during initialization."""
     if isinstance(end_port,str) or isinstance(end_port,unicode):
         end_port = rdma.get_end_port(end_port);
     self.end_port = end_port;
     for k,v in kwargs.iteritems():
         setattr(self,k,v);
Exemple #4
0
 def get_end_port(self):
     """Process the options for specifying the device similar to libib, this
     version is much richer though."""
     if self.args.CA is None and self.args.port is None:
         for dev in rdma.get_devices():
             for ep in dev.end_ports:
                 if ep.state >= IBA.PORT_STATE_INIT:
                     return ep
         return rdma.get_end_port()
     if self.args.CA is None:
         try:
             return rdma.get_end_port(self.args.port)
         except rdma.RDMAError:
             pass
         dev = rdma.get_device()
     else:
         dev = rdma.get_device(self.args.CA)
     if self.args.port is None:
         return dev.end_ports.first()
     return rdma.get_end_port("%s/%s" % (dev.name, self.args.port))
Exemple #5
0
 def get_end_port(self):
     """Process the options for specifying the device similar to libib, this
     version is much richer though."""
     if self.args.CA is None and self.args.port is None:
         for dev in rdma.get_devices():
             for ep in dev.end_ports:
                 if ep.state >= IBA.PORT_STATE_INIT:
                     return ep
         return rdma.get_end_port();
     if self.args.CA is None:
         try:
             return rdma.get_end_port(self.args.port);
         except rdma.RDMAError:
             pass;
         dev = rdma.get_device()
     else:
         dev = rdma.get_device(self.args.CA);
     if self.args.port is None:
         return dev.end_ports.first();
     return rdma.get_end_port("%s/%s"%(dev.name,self.args.port));
Exemple #6
0
 def test_good(self):
     """Test get_end_port calls that succeed."""
     devices = rdma.get_devices()
     dev = devices.first()
     ep = dev.end_ports.first()
     self.assertEquals(rdma.get_end_port(), ep)
     self.assertEquals(rdma.get_end_port(dev.name), ep)
     self.assertEquals(rdma.get_end_port("%s/%s" % (dev.name, ep.port_id)), ep)
     self.assertEquals(rdma.get_end_port(ep.port_guid), ep)
     self.assertEquals(rdma.get_end_port("%s" % (ep.port_guid)), ep)
     self.assertEquals(rdma.get_end_port(ep.default_gid), ep)
     self.assertEquals(rdma.get_end_port("%s" % (ep.default_gid)), ep)
Exemple #7
0
 def test_good(self):
     """Test get_end_port calls that succeed."""
     devices = rdma.get_devices()
     dev = devices.first()
     ep = dev.end_ports.first()
     self.assertEquals(rdma.get_end_port(), ep)
     self.assertEquals(rdma.get_end_port(dev.name), ep)
     self.assertEquals(rdma.get_end_port("%s/%s" % (dev.name, ep.port_id)),
                       ep)
     self.assertEquals(rdma.get_end_port(ep.port_guid), ep)
     self.assertEquals(rdma.get_end_port("%s" % (ep.port_guid)), ep)
     self.assertEquals(rdma.get_end_port(ep.default_gid), ep)
     self.assertEquals(rdma.get_end_port("%s" % (ep.default_gid)), ep)
    def setUp(self):
        self.extra_opts = None;
        if self.cmd_mod is None:
            fn = os.path.join(os.path.dirname(sys.modules[__name__].__file__),
                              os.path.pardir,
                              "ibtool");
            self.cmd_mod = imp.load_source("__ibtool__",fn);
            self.get_cmd_func = self.cmd_mod.get_cmd_func;

            self.end_port = rdma.get_end_port();

            self.peer_dr = "0,%u"%(self.end_port.port_id);
            with rdma.get_umad(self.end_port) as umad:
                dr = rdma.path.IBDRPath(self.end_port,drPath="\0" +
                                        chr(self.end_port.port_id));
                self.peer_pinf = umad.SubnGet(IBA.SMPPortInfo,dr);
                self.peer_ninf = umad.SubnGet(IBA.SMPNodeInfo,dr);
Exemple #9
0
    def setUp(self):
        self.extra_opts = None
        if self.cmd_mod is None:
            fn = os.path.join(os.path.dirname(sys.modules[__name__].__file__),
                              os.path.pardir, "ibtool")
            self.cmd_mod = imp.load_source("__ibtool__", fn)
            self.get_cmd_func = self.cmd_mod.get_cmd_func

            self.end_port = rdma.get_end_port()

            self.peer_dr = "0,%u" % (self.end_port.port_id)
            with rdma.get_umad(self.end_port) as umad:
                dr = rdma.path.IBDRPath(self.end_port,
                                        drPath="\0" +
                                        chr(self.end_port.port_id))
                self.peer_pinf = umad.SubnGet(IBA.SMPPortInfo, dr)
                self.peer_ninf = umad.SubnGet(IBA.SMPNodeInfo, dr)
Exemple #10
0
def cmd_ibstatus(argv,o):
    """Display the RDMA end ports in the system.
       Usage: %prog [DEVICE[/PORT]]"""
    (args,values) = o.parse_args(argv);

    if len(values) == 0:
        end_ports = (I for J in rdma.get_devices() for I in J.end_ports);
    elif len(values) == 1:
        end_ports = (rdma.get_end_port(values[0]),);
    else:
        raise CmdError("Too many arguments");

    for I in end_ports:
        print """Infiniband device %r port %u status:
\tdefault gid:\t %s
\tbase lid:\t %u
\tsm lid:\t\t %u
\tstate:\t\t %u: %s
\tphys state:\t %u: %s
\trate:\t\t %s\n"""%(I.parent.name,I.port_id,I.default_gid,I.lid,I.sm_lid,
             I.state,IBA_describe.link_state(I.state).upper(),
             I.phys_state,IBA_describe.phys_link_state(I.phys_state),I.rate);
    return True;
Exemple #11
0
def cmd_ibstatus(argv,o):
    """Display the RDMA end ports in the system.
       Usage: %prog [DEVICE[/PORT]]"""
    (args,values) = o.parse_args(argv);

    if len(values) == 0:
        end_ports = (I for J in rdma.get_devices() for I in J.end_ports);
    elif len(values) == 1:
        end_ports = (rdma.get_end_port(values[0]),);
    else:
        raise CmdError("Too many arguments");

    for I in end_ports:
        print """Infiniband device %r port %u status:
\tdefault gid:\t %s
\tbase lid:\t %u
\tsm lid:\t\t %u
\tstate:\t\t %u: %s
\tphys state:\t %u: %s
\trate:\t\t %s\n"""%(I.parent.name,I.port_id,I.default_gid,I.lid,I.sm_lid,
             I.state,IBA_describe.link_state(I.state).upper(),
             I.phys_state,IBA_describe.phys_link_state(I.phys_state),I.rate);
    return True;
Exemple #12
0
def from_string(s,default_end_port=None,require_dev=None,require_ep=None):
    """Convert the string *s* into an instance of :class:`Path` or
    derived.

    Supported formats for *s* are:
      =========== ============================ ========================
      Format      Example                      Creates
      =========== ============================ ========================
      Port GID    fe80::2:c903:0:1491          IBPath.DGID = s
      Scope'd GID fe80::2:c903:0:1491%mlx4_0/1 IBPath.DGID = s
      Port GUID   0002:c903:0000:1491          IBPath.DGID = fe80:: + s
      LID         12                           IBPath.DLID = 12
      Hex LID     0xc                          IBPath.DLID = 12
      DR Path     0,1,                         IBDRPath.drPath = '\\\\0\\\\1'
      Path Spec   IBPath(DLID=2,SL=2)          IBPath.{DLID=2,SL=2}
      =========== ============================ ========================

    If the format unambiguously specifies an end port, eg due to a provided
    scope or by specifying the subnet prefix then the result will have `end_port`
    set appropriately. Otherwise `end_port` is set to `default_end_port`.

    *require_dev* and *require_ep* will restrict the lookup to returning
    a path for those conditions. If a scoped address is given that doesn't
    match then :exc:`ValueError` is raised. These options should be used when
    a path is being parsed for use with an existing bound resource (eg
    a :class:`rdma.ibverbs.Context` or :class:`rdma.ibverbs.`)

    FUTURE: This may return paths other than IB for other technologies.

    :raises ValueError: If the string can not be parsed."""
    if require_ep is not None:
        default_end_port = require_ep;

    if s.find("(") != -1:
        ret = from_spec_string(s);
        if ret.end_port is None:
            ret.end_port = default_end_port;
        else:
            _check_ep(ret.end_port,require_dev,require_ep);
        return ret;

    dr = s.split(",");
    if len(dr) != 1:
        if dr[-1] == '':
            dr = [int(I) for I in dr[:-1]];
        else:
            dr = [int(I) for I in dr];
        for I in dr:
            if I >= 255:
                raise ValueError("Invalid DR path specification %r"%(s,));
        if len(dr) == 0:
            raise ValueError("Invalid DR path specification %r"%(s,));
        if dr[0] != 0:
            raise ValueError("Invalid DR path specification %r"%(s,));
        drPath = bytes("").join("%c"%(I) for I in dr);
        return IBDRPath(default_end_port,drPath=drPath);

    a = s.split('%');
    if len(a) == 2:
        DGID = IBA.GID(a[0])
        try:
            end_port = rdma.get_end_port(a[1]);
            _check_ep(end_port,require_dev,require_ep);
        except rdma.RDMAError, e:
            raise ValueError("Could not find %r: %s"%(a[1],e));
        return IBPath(end_port,DGID=DGID);
Exemple #13
0
 def setUp(self):
     self.end_port = rdma.get_end_port();
     self.ctx = rdma.get_verbs(self.end_port);
Exemple #14
0
def from_spec_string(s):
    """Construct a *Path* (or derived) instance from it's `repr` string.

    This parser is safe to use with untrusted data.

    :raises ValueError: If the string can not be parsed."""
    import re,itertools;
    m = re.match("^(.+?)\(\s*?(.*?)\s*?\)$",s);
    if m is None:
        raise ValueError("Invalid path specification %r"%(s,));
    m = m.groups();
    cls = getattr(sys.modules[__name__],m[0],None)
    if cls is None or not issubclass(cls,Path):
        raise ValueError("Invalid path specification %r, bad path type"%(s,));

    kwargs = dict((t[0].strip(), t[2].strip())
                  for t in (I.partition('=')
                            for I in m[1].split(',')));

    if len(kwargs) < 1:
        raise ValueError("Invalid path specification %r"%(s,));
    for k,v in kwargs.iteritems():
        if v == '':
            raise ValueError("Invalid path specification %r"%(s,));
        if not hasattr(cls,k):
            raise ValueError("Path attribute %r is not known"%(k,));

        if v.startswith("GID("):
            v = v[4:-1];
            if v[0] == '"' or v[0] == "'":
                v = v[1:-1];
            kwargs[k] = IBA.GID(v);
        elif k.find("GID") != -1:
            kwargs[k] = IBA.GID(v);
        elif k == "drPath":
            # Using : because I am too lazy to fix the splitter to respect quotes.
            dr = v.split(":");
            if len(dr) == 1:
                raise ValueError("Invalid DR path specification %r"%(v,));
            if dr[-1] == '':
                dr = [int(I) for I in dr[:-1]];
            else:
                dr = [int(I) for I in dr];
            for I in dr:
                if I >= 255:
                    raise ValueError("Invalid DR path specification %r"%(v,));
                if len(dr) == 0:
                    raise ValueError("Invalid DR path specification %r"%(s,));
                if dr[0] != 0:
                    raise ValueError("Invalid DR path specification %r"%(s,));
            kwargs[k] = bytes("").join("%c"%(I) for I in dr);
        elif k == "end_port":
            if v[0] == '"' or v[0] == "'":
                v = v[1:-1];
            try:
                if v == "None":
                    kwargs[k] = None;
                else:
                    kwargs[k] = rdma.get_end_port(v);
            except rdma.RDMAError, e:
                raise ValueError("Could not find %r: %s"%(v,e));
        else:
            try:
                kwargs[k] = int(v,0);
            except ValueError:
                raise ValueError("%r=%r is not a valid integer"%(k,v));
 def setUp(self):
     self.end_port = rdma.get_end_port();
     self.umad = rdma.get_umad(self.end_port);
     self.local_path = rdma.path.IBDRPath(self.end_port);
Exemple #16
0
 def setUp(self):
     self.end_port = rdma.get_end_port()
     self.umad = rdma.get_umad(self.end_port)
     self.local_path = rdma.path.IBDRPath(self.end_port)
Exemple #17
0
def cmd_ibstat(argv,o):
    """Display the RDMA end ports in the system.
       Usage: %prog [-lsp] [DEVICE [PORT]]"""
    o.add_option("-l","--list_of_cas",action="store_true",dest="list_cas",
                 help="List all IB devices names");
    o.add_option("-s","--short",action="store_true",dest="short",
                 help="Do not show port information");
    o.add_option("-p","--port_list",action="store_true",dest="ports",
                 help="Show only port GUIDs");
    (args,values) = o.parse_args(argv);

    if args.list_cas:
        if len(values) != 0: raise CmdError("Too many arguments");
        for I in rdma.get_devices():
            print I.name;
        return True;

    if len(values) == 0:
        end_ports = (I for J in rdma.get_devices() for I in J.end_ports);
    elif len(values) == 1:
        end_ports = (I for I in rdma.get_device(values[0]).end_ports);
    elif len(values) == 2:
        end_ports = (rdma.get_end_port("%s/%s"%(values[0],values[1])),);
    else:
        raise CmdError("Too many arguments");

    if args.ports:
        for I in end_ports:
            print I.port_guid;
        return True;

    def show_ca(dev):
        print "CA %r"%(dev.name);
        print "\tCA type: %s"%(dev.hca_type);
        print "\tNumber of ports: %s"%(len(dev.end_ports));
        print "\tFirmware version: %s"%(IBA_describe.dstr(dev.fw_ver));
        print "\tHardware version: %s"%(IBA_describe.dstr(dev.hw_ver));
        print "\tNode GUID: %s"%(dev.node_guid);
        print "\tSystem image GUID: %s"%(dev.sys_image_guid);
    def show_port(port,offset="\t\t"):
        print "%sState: %s"%(offset,IBA_describe.link_state(port.state));
        print "%sPhysical state: %s"%(offset,IBA_describe.phys_link_state(port.phys_state));
        print "%sRate: %r"%(offset,port.rate);
        print "%sBase lid: %r"%(offset,port.lid);
        print "%sLMC: %r"%(offset,port.lmc);
        print "%sSM lid: %r"%(offset,port.sm_lid);
        print "%sCapability mask: 0x%08x"%(offset,port.cap_mask);
        print "%sPort GUID: %s"%(offset,port.port_guid);

    last_ca = None;
    if args.short:
        for I in end_ports:
            if last_ca != I.parent:
                show_ca(I.parent);
                last_ca = I.parent;
        return True;

    if isinstance(end_ports,tuple):
        I = end_ports[0];
        print "CA: %r"%(I.parent.name);
        print "Port %u:"%(I.port_id);
        show_port(I,offset="");
        return True;

    for I in end_ports:
        if last_ca != I.parent:
            show_ca(I.parent);
            last_ca = I.parent;
        print "\tPort %u:"%(I.port_id);
        show_port(I);
    return True;
Exemple #18
0
 def setUp(self):
     self.end_port = rdma.get_end_port();
     self.ctx = rdma.get_verbs(self.end_port);
Exemple #19
0
def cmd_ibstat(argv, o):
    """Display the RDMA end ports in the system.
       Usage: %prog [-lsp] [DEVICE [PORT]]"""
    o.add_option("-l",
                 "--list_of_cas",
                 action="store_true",
                 dest="list_cas",
                 help="List all IB devices names")
    o.add_option("-s",
                 "--short",
                 action="store_true",
                 dest="short",
                 help="Do not show port information")
    o.add_option("-p",
                 "--port_list",
                 action="store_true",
                 dest="ports",
                 help="Show only port GUIDs")
    (args, values) = o.parse_args(argv)

    if args.list_cas:
        if len(values) != 0: raise CmdError("Too many arguments")
        for I in rdma.get_devices():
            print I.name
        return True

    if len(values) == 0:
        end_ports = (I for J in rdma.get_devices() for I in J.end_ports)
    elif len(values) == 1:
        end_ports = (I for I in rdma.get_device(values[0]).end_ports)
    elif len(values) == 2:
        end_ports = (rdma.get_end_port("%s/%s" % (values[0], values[1])), )
    else:
        raise CmdError("Too many arguments")

    if args.ports:
        for I in end_ports:
            print I.port_guid
        return True

    def show_ca(dev):
        print "CA %r" % (dev.name)
        print "\tCA type: %s" % (dev.hca_type)
        print "\tNumber of ports: %s" % (len(dev.end_ports))
        print "\tFirmware version: %s" % (IBA_describe.dstr(dev.fw_ver))
        print "\tHardware version: %s" % (IBA_describe.dstr(dev.hw_ver))
        print "\tNode GUID: %s" % (dev.node_guid)
        print "\tSystem image GUID: %s" % (dev.sys_image_guid)

    def show_port(port, offset="\t\t"):
        print "%sState: %s" % (offset, IBA_describe.link_state(port.state))
        print "%sPhysical state: %s" % (
            offset, IBA_describe.phys_link_state(port.phys_state))
        print "%sRate: %r" % (offset, port.rate)
        print "%sBase lid: %r" % (offset, port.lid)
        print "%sLMC: %r" % (offset, port.lmc)
        print "%sSM lid: %r" % (offset, port.sm_lid)
        print "%sCapability mask: 0x%08x" % (offset, port.cap_mask)
        print "%sPort GUID: %s" % (offset, port.port_guid)

    last_ca = None
    if args.short:
        for I in end_ports:
            if last_ca != I.parent:
                show_ca(I.parent)
                last_ca = I.parent
        return True

    if isinstance(end_ports, tuple):
        I = end_ports[0]
        print "CA: %r" % (I.parent.name)
        print "Port %u:" % (I.port_id)
        show_port(I, offset="")
        return True

    for I in end_ports:
        if last_ca != I.parent:
            show_ca(I.parent)
            last_ca = I.parent
        print "\tPort %u:" % (I.port_id)
        show_port(I)
    return True